]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-3.0-3.18.1-201412280900.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.18.1-201412280900.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index 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
237 diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt
238 index a311db8..415b28c 100644
239 --- a/Documentation/kbuild/makefiles.txt
240 +++ b/Documentation/kbuild/makefiles.txt
241 @@ -23,10 +23,11 @@ This document describes the Linux kernel Makefiles.
242 === 4 Host Program support
243 --- 4.1 Simple Host Program
244 --- 4.2 Composite Host Programs
245 - --- 4.3 Using C++ for host programs
246 - --- 4.4 Controlling compiler options for host programs
247 - --- 4.5 When host programs are actually built
248 - --- 4.6 Using hostprogs-$(CONFIG_FOO)
249 + --- 4.3 Defining shared libraries
250 + --- 4.4 Using C++ for host programs
251 + --- 4.5 Controlling compiler options for host programs
252 + --- 4.6 When host programs are actually built
253 + --- 4.7 Using hostprogs-$(CONFIG_FOO)
254
255 === 5 Kbuild clean infrastructure
256
257 @@ -642,7 +643,29 @@ Both possibilities are described in the following.
258 Finally, the two .o files are linked to the executable, lxdialog.
259 Note: The syntax <executable>-y is not permitted for host-programs.
260
261 ---- 4.3 Using C++ for host programs
262 +--- 4.3 Defining shared libraries
263 +
264 + Objects with extension .so are considered shared libraries, and
265 + will be compiled as position independent objects.
266 + Kbuild provides support for shared libraries, but the usage
267 + shall be restricted.
268 + In the following example the libkconfig.so shared library is used
269 + to link the executable conf.
270 +
271 + Example:
272 + #scripts/kconfig/Makefile
273 + hostprogs-y := conf
274 + conf-objs := conf.o libkconfig.so
275 + libkconfig-objs := expr.o type.o
276 +
277 + Shared libraries always require a corresponding -objs line, and
278 + in the example above the shared library libkconfig is composed by
279 + the two objects expr.o and type.o.
280 + expr.o and type.o will be built as position independent code and
281 + linked as a shared library libkconfig.so. C++ is not supported for
282 + shared libraries.
283 +
284 +--- 4.4 Using C++ for host programs
285
286 kbuild offers support for host programs written in C++. This was
287 introduced solely to support kconfig, and is not recommended
288 @@ -665,7 +688,7 @@ Both possibilities are described in the following.
289 qconf-cxxobjs := qconf.o
290 qconf-objs := check.o
291
292 ---- 4.4 Controlling compiler options for host programs
293 +--- 4.5 Controlling compiler options for host programs
294
295 When compiling host programs, it is possible to set specific flags.
296 The programs will always be compiled utilising $(HOSTCC) passed
297 @@ -693,7 +716,7 @@ Both possibilities are described in the following.
298 When linking qconf, it will be passed the extra option
299 "-L$(QTDIR)/lib".
300
301 ---- 4.5 When host programs are actually built
302 +--- 4.6 When host programs are actually built
303
304 Kbuild will only build host-programs when they are referenced
305 as a prerequisite.
306 @@ -724,7 +747,7 @@ Both possibilities are described in the following.
307 This will tell kbuild to build lxdialog even if not referenced in
308 any rule.
309
310 ---- 4.6 Using hostprogs-$(CONFIG_FOO)
311 +--- 4.7 Using hostprogs-$(CONFIG_FOO)
312
313 A typical pattern in a Kbuild file looks like this:
314
315 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
316 index 479f332..2475ac2 100644
317 --- a/Documentation/kernel-parameters.txt
318 +++ b/Documentation/kernel-parameters.txt
319 @@ -1182,6 +1182,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
320 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
321 Default: 1024
322
323 + grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
324 + ignore grsecurity's /proc restrictions
325 +
326 +
327 hashdist= [KNL,NUMA] Large hashes allocated during boot
328 are distributed across NUMA nodes. Defaults on
329 for 64-bit NUMA, off otherwise.
330 @@ -2259,6 +2263,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
331 noexec=on: enable non-executable mappings (default)
332 noexec=off: disable non-executable mappings
333
334 + nopcid [X86-64]
335 + Disable PCID (Process-Context IDentifier) even if it
336 + is supported by the processor.
337 +
338 nosmap [X86]
339 Disable SMAP (Supervisor Mode Access Prevention)
340 even if it is supported by processor.
341 @@ -2551,6 +2559,30 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
342 the specified number of seconds. This is to be used if
343 your oopses keep scrolling off the screen.
344
345 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
346 + virtualization environments that don't cope well with the
347 + expand down segment used by UDEREF on X86-32 or the frequent
348 + page table updates on X86-64.
349 +
350 + pax_sanitize_slab=
351 + Format: { 0 | 1 | off | fast | full }
352 + Options '0' and '1' are only provided for backward
353 + compatibility, 'off' or 'fast' should be used instead.
354 + 0|off : disable slab object sanitization
355 + 1|fast: enable slab object sanitization excluding
356 + whitelisted slabs (default)
357 + full : sanitize all slabs, even the whitelisted ones
358 +
359 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
360 +
361 + pax_extra_latent_entropy
362 + Enable a very simple form of latent entropy extraction
363 + from the first 4GB of memory as the bootmem allocator
364 + passes the memory pages to the buddy allocator.
365 +
366 + pax_weakuderef [X86-64] enables the weaker but faster form of UDEREF
367 + when the processor supports PCID.
368 +
369 pcbit= [HW,ISDN]
370
371 pcd. [PARIDE]
372 diff --git a/Makefile b/Makefile
373 index 3f84029..3c5b65e 100644
374 --- a/Makefile
375 +++ b/Makefile
376 @@ -298,7 +298,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
377 HOSTCC = gcc
378 HOSTCXX = g++
379 HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -std=gnu89
380 -HOSTCXXFLAGS = -O2
381 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -std=gnu89 -fno-delete-null-pointer-checks
382 +HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
383 +HOSTCXXFLAGS = -O2 -Wall -W -Wno-array-bounds
384
385 ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
386 HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \
387 @@ -445,8 +447,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
388 # Rules shared between *config targets and build targets
389
390 # Basic helpers built in scripts/
391 -PHONY += scripts_basic
392 -scripts_basic:
393 +PHONY += scripts_basic gcc-plugins
394 +scripts_basic: gcc-plugins
395 $(Q)$(MAKE) $(build)=scripts/basic
396 $(Q)rm -f .tmp_quiet_recordmcount
397
398 @@ -620,6 +622,72 @@ endif
399 # Tell gcc to never replace conditional load with a non-conditional one
400 KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
401
402 +ifndef DISABLE_PAX_PLUGINS
403 +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
404 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
405 +else
406 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
407 +endif
408 +ifneq ($(PLUGINCC),)
409 +ifdef CONFIG_PAX_CONSTIFY_PLUGIN
410 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
411 +endif
412 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
413 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
414 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
415 +endif
416 +ifdef CONFIG_KALLOCSTAT_PLUGIN
417 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
418 +endif
419 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
420 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
421 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
422 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
423 +endif
424 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT
425 +RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
426 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
427 +RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
428 +endif
429 +endif
430 +ifdef CONFIG_CHECKER_PLUGIN
431 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
432 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
433 +endif
434 +endif
435 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
436 +ifdef CONFIG_PAX_SIZE_OVERFLOW
437 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
438 +endif
439 +ifdef CONFIG_PAX_LATENT_ENTROPY
440 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
441 +endif
442 +ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
443 +STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
444 +endif
445 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
446 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
447 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
448 +GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
449 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
450 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
451 +ifeq ($(KBUILD_EXTMOD),)
452 +gcc-plugins:
453 + $(Q)$(MAKE) $(build)=tools/gcc
454 +else
455 +gcc-plugins: ;
456 +endif
457 +else
458 +gcc-plugins:
459 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
460 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
461 +else
462 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
463 +endif
464 + $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
465 +endif
466 +endif
467 +
468 ifdef CONFIG_READABLE_ASM
469 # Disable optimizations that make assembler listings hard to read.
470 # reorder blocks reorders the control in the function
471 @@ -712,7 +780,7 @@ KBUILD_CFLAGS += $(call cc-option, -gsplit-dwarf, -g)
472 else
473 KBUILD_CFLAGS += -g
474 endif
475 -KBUILD_AFLAGS += -Wa,-gdwarf-2
476 +KBUILD_AFLAGS += -Wa,--gdwarf-2
477 endif
478 ifdef CONFIG_DEBUG_INFO_DWARF4
479 KBUILD_CFLAGS += $(call cc-option, -gdwarf-4,)
480 @@ -877,7 +945,7 @@ export mod_sign_cmd
481
482
483 ifeq ($(KBUILD_EXTMOD),)
484 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
485 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
486
487 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
488 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
489 @@ -924,6 +992,8 @@ endif
490
491 # The actual objects are generated when descending,
492 # make sure no implicit rule kicks in
493 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
494 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
495 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
496
497 # Handle descending into subdirectories listed in $(vmlinux-dirs)
498 @@ -933,7 +1003,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
499 # Error messages still appears in the original language
500
501 PHONY += $(vmlinux-dirs)
502 -$(vmlinux-dirs): prepare scripts
503 +$(vmlinux-dirs): gcc-plugins prepare scripts
504 $(Q)$(MAKE) $(build)=$@
505
506 define filechk_kernel.release
507 @@ -976,10 +1046,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
508
509 archprepare: archheaders archscripts prepare1 scripts_basic
510
511 +prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
512 +prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
513 prepare0: archprepare FORCE
514 $(Q)$(MAKE) $(build)=.
515
516 # All the preparing..
517 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
518 prepare: prepare0
519
520 # Generate some files
521 @@ -1094,6 +1167,8 @@ all: modules
522 # using awk while concatenating to the final file.
523
524 PHONY += modules
525 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
526 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
527 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
528 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
529 @$(kecho) ' Building modules, stage 2.';
530 @@ -1109,7 +1184,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
531
532 # Target to prepare building external modules
533 PHONY += modules_prepare
534 -modules_prepare: prepare scripts
535 +modules_prepare: gcc-plugins prepare scripts
536
537 # Target to install modules
538 PHONY += modules_install
539 @@ -1175,7 +1250,10 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
540 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
541 signing_key.priv signing_key.x509 x509.genkey \
542 extra_certificates signing_key.x509.keyid \
543 - signing_key.x509.signer include/linux/version.h
544 + signing_key.x509.signer include/linux/version.h \
545 + tools/gcc/size_overflow_plugin/size_overflow_hash_aux.h \
546 + tools/gcc/size_overflow_plugin/size_overflow_hash.h \
547 + tools/gcc/randomize_layout_seed.h
548
549 # clean - Delete most, but leave enough to build external modules
550 #
551 @@ -1214,7 +1292,7 @@ distclean: mrproper
552 @find $(srctree) $(RCS_FIND_IGNORE) \
553 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
554 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
555 - -o -name '.*.rej' -o -name '*%' -o -name 'core' \) \
556 + -o -name '.*.rej' -o -name '*.so' -o -name '*%' -o -name 'core' \) \
557 -type f -print | xargs rm -f
558
559
560 @@ -1380,6 +1458,8 @@ PHONY += $(module-dirs) modules
561 $(module-dirs): crmodverdir $(objtree)/Module.symvers
562 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
563
564 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
565 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
566 modules: $(module-dirs)
567 @$(kecho) ' Building modules, stage 2.';
568 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
569 @@ -1520,17 +1600,21 @@ else
570 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
571 endif
572
573 -%.s: %.c prepare scripts FORCE
574 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
575 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
576 +%.s: %.c gcc-plugins prepare scripts FORCE
577 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
578 %.i: %.c prepare scripts FORCE
579 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
580 -%.o: %.c prepare scripts FORCE
581 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
582 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
583 +%.o: %.c gcc-plugins prepare scripts FORCE
584 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
585 %.lst: %.c prepare scripts FORCE
586 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
587 -%.s: %.S prepare scripts FORCE
588 +%.s: %.S gcc-plugins prepare scripts FORCE
589 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
590 -%.o: %.S prepare scripts FORCE
591 +%.o: %.S gcc-plugins prepare scripts FORCE
592 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
593 %.symtypes: %.c prepare scripts FORCE
594 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
595 @@ -1542,11 +1626,15 @@ endif
596 $(build)=$(build-dir)
597 # Make sure the latest headers are built for Documentation
598 Documentation/: headers_install
599 -%/: prepare scripts FORCE
600 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
601 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
602 +%/: gcc-plugins prepare scripts FORCE
603 $(cmd_crmodverdir)
604 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
605 $(build)=$(build-dir)
606 -%.ko: prepare scripts FORCE
607 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
608 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
609 +%.ko: gcc-plugins prepare scripts FORCE
610 $(cmd_crmodverdir)
611 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
612 $(build)=$(build-dir) $(@:.ko=.o)
613 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
614 index 8f8eafb..3405f46 100644
615 --- a/arch/alpha/include/asm/atomic.h
616 +++ b/arch/alpha/include/asm/atomic.h
617 @@ -239,4 +239,14 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
618 #define atomic_dec(v) atomic_sub(1,(v))
619 #define atomic64_dec(v) atomic64_sub(1,(v))
620
621 +#define atomic64_read_unchecked(v) atomic64_read(v)
622 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
623 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
624 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
625 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
626 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
627 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
628 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
629 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
630 +
631 #endif /* _ALPHA_ATOMIC_H */
632 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
633 index ad368a9..fbe0f25 100644
634 --- a/arch/alpha/include/asm/cache.h
635 +++ b/arch/alpha/include/asm/cache.h
636 @@ -4,19 +4,19 @@
637 #ifndef __ARCH_ALPHA_CACHE_H
638 #define __ARCH_ALPHA_CACHE_H
639
640 +#include <linux/const.h>
641
642 /* Bytes per L1 (data) cache line. */
643 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
644 -# define L1_CACHE_BYTES 64
645 # define L1_CACHE_SHIFT 6
646 #else
647 /* Both EV4 and EV5 are write-through, read-allocate,
648 direct-mapped, physical.
649 */
650 -# define L1_CACHE_BYTES 32
651 # define L1_CACHE_SHIFT 5
652 #endif
653
654 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
655 #define SMP_CACHE_BYTES L1_CACHE_BYTES
656
657 #endif
658 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
659 index 968d999..d36b2df 100644
660 --- a/arch/alpha/include/asm/elf.h
661 +++ b/arch/alpha/include/asm/elf.h
662 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
663
664 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
665
666 +#ifdef CONFIG_PAX_ASLR
667 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
668 +
669 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
670 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
671 +#endif
672 +
673 /* $0 is set by ld.so to a pointer to a function which might be
674 registered using atexit. This provides a mean for the dynamic
675 linker to call DT_FINI functions for shared libraries that have
676 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
677 index aab14a0..b4fa3e7 100644
678 --- a/arch/alpha/include/asm/pgalloc.h
679 +++ b/arch/alpha/include/asm/pgalloc.h
680 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
681 pgd_set(pgd, pmd);
682 }
683
684 +static inline void
685 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
686 +{
687 + pgd_populate(mm, pgd, pmd);
688 +}
689 +
690 extern pgd_t *pgd_alloc(struct mm_struct *mm);
691
692 static inline void
693 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
694 index d8f9b7e..f6222fa 100644
695 --- a/arch/alpha/include/asm/pgtable.h
696 +++ b/arch/alpha/include/asm/pgtable.h
697 @@ -102,6 +102,17 @@ struct vm_area_struct;
698 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
699 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
700 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
701 +
702 +#ifdef CONFIG_PAX_PAGEEXEC
703 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
704 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
705 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
706 +#else
707 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
708 +# define PAGE_COPY_NOEXEC PAGE_COPY
709 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
710 +#endif
711 +
712 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
713
714 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
715 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
716 index 2fd00b7..cfd5069 100644
717 --- a/arch/alpha/kernel/module.c
718 +++ b/arch/alpha/kernel/module.c
719 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
720
721 /* The small sections were sorted to the end of the segment.
722 The following should definitely cover them. */
723 - gp = (u64)me->module_core + me->core_size - 0x8000;
724 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
725 got = sechdrs[me->arch.gotsecindex].sh_addr;
726
727 for (i = 0; i < n; i++) {
728 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
729 index f9c732e..78fbb0f 100644
730 --- a/arch/alpha/kernel/osf_sys.c
731 +++ b/arch/alpha/kernel/osf_sys.c
732 @@ -1295,10 +1295,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
733 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
734
735 static unsigned long
736 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
737 - unsigned long limit)
738 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
739 + unsigned long limit, unsigned long flags)
740 {
741 struct vm_unmapped_area_info info;
742 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
743
744 info.flags = 0;
745 info.length = len;
746 @@ -1306,6 +1307,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
747 info.high_limit = limit;
748 info.align_mask = 0;
749 info.align_offset = 0;
750 + info.threadstack_offset = offset;
751 return vm_unmapped_area(&info);
752 }
753
754 @@ -1338,20 +1340,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
755 merely specific addresses, but regions of memory -- perhaps
756 this feature should be incorporated into all ports? */
757
758 +#ifdef CONFIG_PAX_RANDMMAP
759 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
760 +#endif
761 +
762 if (addr) {
763 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
764 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
765 if (addr != (unsigned long) -ENOMEM)
766 return addr;
767 }
768
769 /* Next, try allocating at TASK_UNMAPPED_BASE. */
770 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
771 - len, limit);
772 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
773 +
774 if (addr != (unsigned long) -ENOMEM)
775 return addr;
776
777 /* Finally, try allocating in low memory. */
778 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
779 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
780
781 return addr;
782 }
783 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
784 index 98838a0..b304fb4 100644
785 --- a/arch/alpha/mm/fault.c
786 +++ b/arch/alpha/mm/fault.c
787 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
788 __reload_thread(pcb);
789 }
790
791 +#ifdef CONFIG_PAX_PAGEEXEC
792 +/*
793 + * PaX: decide what to do with offenders (regs->pc = fault address)
794 + *
795 + * returns 1 when task should be killed
796 + * 2 when patched PLT trampoline was detected
797 + * 3 when unpatched PLT trampoline was detected
798 + */
799 +static int pax_handle_fetch_fault(struct pt_regs *regs)
800 +{
801 +
802 +#ifdef CONFIG_PAX_EMUPLT
803 + int err;
804 +
805 + do { /* PaX: patched PLT emulation #1 */
806 + unsigned int ldah, ldq, jmp;
807 +
808 + err = get_user(ldah, (unsigned int *)regs->pc);
809 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
810 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
811 +
812 + if (err)
813 + break;
814 +
815 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
816 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
817 + jmp == 0x6BFB0000U)
818 + {
819 + unsigned long r27, addr;
820 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
821 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
822 +
823 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
824 + err = get_user(r27, (unsigned long *)addr);
825 + if (err)
826 + break;
827 +
828 + regs->r27 = r27;
829 + regs->pc = r27;
830 + return 2;
831 + }
832 + } while (0);
833 +
834 + do { /* PaX: patched PLT emulation #2 */
835 + unsigned int ldah, lda, br;
836 +
837 + err = get_user(ldah, (unsigned int *)regs->pc);
838 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
839 + err |= get_user(br, (unsigned int *)(regs->pc+8));
840 +
841 + if (err)
842 + break;
843 +
844 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
845 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
846 + (br & 0xFFE00000U) == 0xC3E00000U)
847 + {
848 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
849 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
850 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
851 +
852 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
853 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
854 + return 2;
855 + }
856 + } while (0);
857 +
858 + do { /* PaX: unpatched PLT emulation */
859 + unsigned int br;
860 +
861 + err = get_user(br, (unsigned int *)regs->pc);
862 +
863 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
864 + unsigned int br2, ldq, nop, jmp;
865 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
866 +
867 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
868 + err = get_user(br2, (unsigned int *)addr);
869 + err |= get_user(ldq, (unsigned int *)(addr+4));
870 + err |= get_user(nop, (unsigned int *)(addr+8));
871 + err |= get_user(jmp, (unsigned int *)(addr+12));
872 + err |= get_user(resolver, (unsigned long *)(addr+16));
873 +
874 + if (err)
875 + break;
876 +
877 + if (br2 == 0xC3600000U &&
878 + ldq == 0xA77B000CU &&
879 + nop == 0x47FF041FU &&
880 + jmp == 0x6B7B0000U)
881 + {
882 + regs->r28 = regs->pc+4;
883 + regs->r27 = addr+16;
884 + regs->pc = resolver;
885 + return 3;
886 + }
887 + }
888 + } while (0);
889 +#endif
890 +
891 + return 1;
892 +}
893 +
894 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
895 +{
896 + unsigned long i;
897 +
898 + printk(KERN_ERR "PAX: bytes at PC: ");
899 + for (i = 0; i < 5; i++) {
900 + unsigned int c;
901 + if (get_user(c, (unsigned int *)pc+i))
902 + printk(KERN_CONT "???????? ");
903 + else
904 + printk(KERN_CONT "%08x ", c);
905 + }
906 + printk("\n");
907 +}
908 +#endif
909
910 /*
911 * This routine handles page faults. It determines the address,
912 @@ -133,8 +251,29 @@ retry:
913 good_area:
914 si_code = SEGV_ACCERR;
915 if (cause < 0) {
916 - if (!(vma->vm_flags & VM_EXEC))
917 + if (!(vma->vm_flags & VM_EXEC)) {
918 +
919 +#ifdef CONFIG_PAX_PAGEEXEC
920 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
921 + goto bad_area;
922 +
923 + up_read(&mm->mmap_sem);
924 + switch (pax_handle_fetch_fault(regs)) {
925 +
926 +#ifdef CONFIG_PAX_EMUPLT
927 + case 2:
928 + case 3:
929 + return;
930 +#endif
931 +
932 + }
933 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
934 + do_group_exit(SIGKILL);
935 +#else
936 goto bad_area;
937 +#endif
938 +
939 + }
940 } else if (!cause) {
941 /* Allow reads even for write-only mappings */
942 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
943 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
944 index 89c4b5c..847a7be 100644
945 --- a/arch/arm/Kconfig
946 +++ b/arch/arm/Kconfig
947 @@ -1740,7 +1740,7 @@ config ALIGNMENT_TRAP
948
949 config UACCESS_WITH_MEMCPY
950 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
951 - depends on MMU
952 + depends on MMU && !PAX_MEMORY_UDEREF
953 default y if CPU_FEROCEON
954 help
955 Implement faster copy_to_user and clear_user methods for CPU
956 @@ -2004,6 +2004,7 @@ config XIP_PHYS_ADDR
957 config KEXEC
958 bool "Kexec system call (EXPERIMENTAL)"
959 depends on (!SMP || PM_SLEEP_SMP)
960 + depends on !GRKERNSEC_KMEM
961 help
962 kexec is a system call that implements the ability to shutdown your
963 current kernel, and to start another kernel. It is like a reboot
964 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
965 index e22c119..9531fcc 100644
966 --- a/arch/arm/include/asm/atomic.h
967 +++ b/arch/arm/include/asm/atomic.h
968 @@ -18,17 +18,41 @@
969 #include <asm/barrier.h>
970 #include <asm/cmpxchg.h>
971
972 +#ifdef CONFIG_GENERIC_ATOMIC64
973 +#include <asm-generic/atomic64.h>
974 +#endif
975 +
976 #define ATOMIC_INIT(i) { (i) }
977
978 #ifdef __KERNEL__
979
980 +#ifdef CONFIG_THUMB2_KERNEL
981 +#define REFCOUNT_TRAP_INSN "bkpt 0xf1"
982 +#else
983 +#define REFCOUNT_TRAP_INSN "bkpt 0xf103"
984 +#endif
985 +
986 +#define _ASM_EXTABLE(from, to) \
987 +" .pushsection __ex_table,\"a\"\n"\
988 +" .align 3\n" \
989 +" .long " #from ", " #to"\n" \
990 +" .popsection"
991 +
992 /*
993 * On ARM, ordinary assignment (str instruction) doesn't clear the local
994 * strex/ldrex monitor on some implementations. The reason we can use it for
995 * atomic_set() is the clrex or dummy strex done on every exception return.
996 */
997 #define atomic_read(v) ACCESS_ONCE((v)->counter)
998 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
999 +{
1000 + return ACCESS_ONCE(v->counter);
1001 +}
1002 #define atomic_set(v,i) (((v)->counter) = (i))
1003 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
1004 +{
1005 + v->counter = i;
1006 +}
1007
1008 #if __LINUX_ARM_ARCH__ >= 6
1009
1010 @@ -38,7 +62,25 @@
1011 * to ensure that the update happens.
1012 */
1013
1014 -#define ATOMIC_OP(op, c_op, asm_op) \
1015 +#ifdef CONFIG_PAX_REFCOUNT
1016 +#define __OVERFLOW_POST \
1017 + " bvc 3f\n" \
1018 + "2: " REFCOUNT_TRAP_INSN "\n"\
1019 + "3:\n"
1020 +#define __OVERFLOW_POST_RETURN \
1021 + " bvc 3f\n" \
1022 +" mov %0, %1\n" \
1023 + "2: " REFCOUNT_TRAP_INSN "\n"\
1024 + "3:\n"
1025 +#define __OVERFLOW_EXTABLE \
1026 + "4:\n"
1027 + _ASM_EXTABLE(2b, 4b)
1028 +#else
1029 +#define __OVERFLOW_POST
1030 +#define __OVERFLOW_EXTABLE
1031 +#endif
1032 +
1033 +#define __ATOMIC_OP(op, suffix, c_op, asm_op, post_op, extable) \
1034 static inline void atomic_##op(int i, atomic_t *v) \
1035 { \
1036 unsigned long tmp; \
1037 @@ -48,15 +90,20 @@ static inline void atomic_##op(int i, atomic_t *v) \
1038 __asm__ __volatile__("@ atomic_" #op "\n" \
1039 "1: ldrex %0, [%3]\n" \
1040 " " #asm_op " %0, %0, %4\n" \
1041 + post_op \
1042 " strex %1, %0, [%3]\n" \
1043 " teq %1, #0\n" \
1044 -" bne 1b" \
1045 +" bne 1b\n" \
1046 + extable \
1047 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1048 : "r" (&v->counter), "Ir" (i) \
1049 : "cc"); \
1050 } \
1051
1052 -#define ATOMIC_OP_RETURN(op, c_op, asm_op) \
1053 +#define ATOMIC_OP(op, c_op, asm_op) __ATOMIC_OP(op, , c_op, asm_op, , )\
1054 + __ATOMIC_OP(op, _unchecked, c_op, asm_op##s, __OVERFLOW_POST, __OVERFLOW_EXTABLE)
1055 +
1056 +#define __ATOMIC_OP_RETURN(op, suffix, c_op, asm_op, post_op, extable) \
1057 static inline int atomic_##op##_return(int i, atomic_t *v) \
1058 { \
1059 unsigned long tmp; \
1060 @@ -68,9 +115,11 @@ static inline int atomic_##op##_return(int i, atomic_t *v) \
1061 __asm__ __volatile__("@ atomic_" #op "_return\n" \
1062 "1: ldrex %0, [%3]\n" \
1063 " " #asm_op " %0, %0, %4\n" \
1064 + post_op \
1065 " strex %1, %0, [%3]\n" \
1066 " teq %1, #0\n" \
1067 -" bne 1b" \
1068 +" bne 1b\n" \
1069 + extable \
1070 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1071 : "r" (&v->counter), "Ir" (i) \
1072 : "cc"); \
1073 @@ -80,6 +129,9 @@ static inline int atomic_##op##_return(int i, atomic_t *v) \
1074 return result; \
1075 }
1076
1077 +#define ATOMIC_OP_RETURN(op, c_op, asm_op) __ATOMIC_OP_RETURN(op, , c_op, asm_op, , )\
1078 + __ATOMIC_OP_RETURN(op, _unchecked, c_op, asm_op##s, __OVERFLOW_POST_RETURN, __OVERFLOW_EXTABLE)
1079 +
1080 static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1081 {
1082 int oldval;
1083 @@ -115,12 +167,24 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1084 __asm__ __volatile__ ("@ atomic_add_unless\n"
1085 "1: ldrex %0, [%4]\n"
1086 " teq %0, %5\n"
1087 -" beq 2f\n"
1088 -" add %1, %0, %6\n"
1089 +" beq 4f\n"
1090 +" adds %1, %0, %6\n"
1091 +
1092 +#ifdef CONFIG_PAX_REFCOUNT
1093 +" bvc 3f\n"
1094 +"2: " REFCOUNT_TRAP_INSN "\n"
1095 +"3:\n"
1096 +#endif
1097 +
1098 " strex %2, %1, [%4]\n"
1099 " teq %2, #0\n"
1100 " bne 1b\n"
1101 -"2:"
1102 +"4:"
1103 +
1104 +#ifdef CONFIG_PAX_REFCOUNT
1105 + _ASM_EXTABLE(2b, 4b)
1106 +#endif
1107 +
1108 : "=&r" (oldval), "=&r" (newval), "=&r" (tmp), "+Qo" (v->counter)
1109 : "r" (&v->counter), "r" (u), "r" (a)
1110 : "cc");
1111 @@ -131,6 +195,28 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1112 return oldval;
1113 }
1114
1115 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1116 +{
1117 + unsigned long oldval, res;
1118 +
1119 + smp_mb();
1120 +
1121 + do {
1122 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1123 + "ldrex %1, [%3]\n"
1124 + "mov %0, #0\n"
1125 + "teq %1, %4\n"
1126 + "strexeq %0, %5, [%3]\n"
1127 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1128 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1129 + : "cc");
1130 + } while (res);
1131 +
1132 + smp_mb();
1133 +
1134 + return oldval;
1135 +}
1136 +
1137 #else /* ARM_ARCH_6 */
1138
1139 #ifdef CONFIG_SMP
1140 @@ -175,6 +261,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1141 return ret;
1142 }
1143
1144 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1145 +{
1146 + return atomic_cmpxchg(v, old, new);
1147 +}
1148 +
1149 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1150 {
1151 int c, old;
1152 @@ -196,16 +287,38 @@ ATOMIC_OPS(sub, -=, sub)
1153
1154 #undef ATOMIC_OPS
1155 #undef ATOMIC_OP_RETURN
1156 +#undef __ATOMIC_OP_RETURN
1157 #undef ATOMIC_OP
1158 +#undef __ATOMIC_OP
1159
1160 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1161 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1162 +{
1163 + return xchg(&v->counter, new);
1164 +}
1165
1166 #define atomic_inc(v) atomic_add(1, v)
1167 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1168 +{
1169 + atomic_add_unchecked(1, v);
1170 +}
1171 #define atomic_dec(v) atomic_sub(1, v)
1172 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1173 +{
1174 + atomic_sub_unchecked(1, v);
1175 +}
1176
1177 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1178 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1179 +{
1180 + return atomic_add_return_unchecked(1, v) == 0;
1181 +}
1182 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1183 #define atomic_inc_return(v) (atomic_add_return(1, v))
1184 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1185 +{
1186 + return atomic_add_return_unchecked(1, v);
1187 +}
1188 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1189 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1190
1191 @@ -216,6 +329,14 @@ typedef struct {
1192 long long counter;
1193 } atomic64_t;
1194
1195 +#ifdef CONFIG_PAX_REFCOUNT
1196 +typedef struct {
1197 + long long counter;
1198 +} atomic64_unchecked_t;
1199 +#else
1200 +typedef atomic64_t atomic64_unchecked_t;
1201 +#endif
1202 +
1203 #define ATOMIC64_INIT(i) { (i) }
1204
1205 #ifdef CONFIG_ARM_LPAE
1206 @@ -232,6 +353,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1207 return result;
1208 }
1209
1210 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1211 +{
1212 + long long result;
1213 +
1214 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1215 +" ldrd %0, %H0, [%1]"
1216 + : "=&r" (result)
1217 + : "r" (&v->counter), "Qo" (v->counter)
1218 + );
1219 +
1220 + return result;
1221 +}
1222 +
1223 static inline void atomic64_set(atomic64_t *v, long long i)
1224 {
1225 __asm__ __volatile__("@ atomic64_set\n"
1226 @@ -240,6 +374,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1227 : "r" (&v->counter), "r" (i)
1228 );
1229 }
1230 +
1231 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1232 +{
1233 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1234 +" strd %2, %H2, [%1]"
1235 + : "=Qo" (v->counter)
1236 + : "r" (&v->counter), "r" (i)
1237 + );
1238 +}
1239 #else
1240 static inline long long atomic64_read(const atomic64_t *v)
1241 {
1242 @@ -254,6 +397,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1243 return result;
1244 }
1245
1246 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1247 +{
1248 + long long result;
1249 +
1250 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1251 +" ldrexd %0, %H0, [%1]"
1252 + : "=&r" (result)
1253 + : "r" (&v->counter), "Qo" (v->counter)
1254 + );
1255 +
1256 + return result;
1257 +}
1258 +
1259 static inline void atomic64_set(atomic64_t *v, long long i)
1260 {
1261 long long tmp;
1262 @@ -268,29 +424,57 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1263 : "r" (&v->counter), "r" (i)
1264 : "cc");
1265 }
1266 +
1267 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1268 +{
1269 + long long tmp;
1270 +
1271 + prefetchw(&v->counter);
1272 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1273 +"1: ldrexd %0, %H0, [%2]\n"
1274 +" strexd %0, %3, %H3, [%2]\n"
1275 +" teq %0, #0\n"
1276 +" bne 1b"
1277 + : "=&r" (tmp), "=Qo" (v->counter)
1278 + : "r" (&v->counter), "r" (i)
1279 + : "cc");
1280 +}
1281 #endif
1282
1283 -#define ATOMIC64_OP(op, op1, op2) \
1284 -static inline void atomic64_##op(long long i, atomic64_t *v) \
1285 +#undef __OVERFLOW_POST_RETURN
1286 +#define __OVERFLOW_POST_RETURN \
1287 + " bvc 3f\n" \
1288 +" mov %0, %1\n" \
1289 +" mov %H0, %H1\n" \
1290 + "2: " REFCOUNT_TRAP_INSN "\n"\
1291 + "3:\n"
1292 +
1293 +#define __ATOMIC64_OP(op, suffix, op1, op2, post_op, extable) \
1294 +static inline void atomic64_##op##suffix(long long i, atomic64##suffix##_t *v)\
1295 { \
1296 long long result; \
1297 unsigned long tmp; \
1298 \
1299 prefetchw(&v->counter); \
1300 - __asm__ __volatile__("@ atomic64_" #op "\n" \
1301 + __asm__ __volatile__("@ atomic64_" #op #suffix "\n" \
1302 "1: ldrexd %0, %H0, [%3]\n" \
1303 " " #op1 " %Q0, %Q0, %Q4\n" \
1304 " " #op2 " %R0, %R0, %R4\n" \
1305 + post_op \
1306 " strexd %1, %0, %H0, [%3]\n" \
1307 " teq %1, #0\n" \
1308 -" bne 1b" \
1309 +" bne 1b\n" \
1310 + extable \
1311 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1312 : "r" (&v->counter), "r" (i) \
1313 : "cc"); \
1314 } \
1315
1316 -#define ATOMIC64_OP_RETURN(op, op1, op2) \
1317 -static inline long long atomic64_##op##_return(long long i, atomic64_t *v) \
1318 +#define ATOMIC64_OP(op, op1, op2) __ATOMIC64_OP(op, , op1, op2, , ) \
1319 + __ATOMIC64_OP(op, _unchecked, op1, op2##s, __OVERFLOW_POST, __OVERFLOW_EXTABLE)
1320 +
1321 +#define __ATOMIC64_OP_RETURN(op, op1, op2, post_op, extable) \
1322 +static inline long long atomic64_##op##_return##suffix(long long i, atomic64##suffix##_t *v) \
1323 { \
1324 long long result; \
1325 unsigned long tmp; \
1326 @@ -298,13 +482,15 @@ static inline long long atomic64_##op##_return(long long i, atomic64_t *v) \
1327 smp_mb(); \
1328 prefetchw(&v->counter); \
1329 \
1330 - __asm__ __volatile__("@ atomic64_" #op "_return\n" \
1331 + __asm__ __volatile__("@ atomic64_" #op "_return" #suffix "\n" \
1332 "1: ldrexd %0, %H0, [%3]\n" \
1333 " " #op1 " %Q0, %Q0, %Q4\n" \
1334 " " #op2 " %R0, %R0, %R4\n" \
1335 + post_op \
1336 " strexd %1, %0, %H0, [%3]\n" \
1337 " teq %1, #0\n" \
1338 -" bne 1b" \
1339 +" bne 1b\n" \
1340 + extable \
1341 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1342 : "r" (&v->counter), "r" (i) \
1343 : "cc"); \
1344 @@ -314,6 +500,9 @@ static inline long long atomic64_##op##_return(long long i, atomic64_t *v) \
1345 return result; \
1346 }
1347
1348 +#define ATOMIC64_OP_RETURN(op, op1, op2) __ATOMIC64_OP_RETURN(op, , op1, op2, , ) \
1349 + __ATOMIC64_OP_RETURN(op, _unchecked, op1, op2##s, __OVERFLOW_POST_RETURN, __OVERFLOW_EXTABLE)
1350 +
1351 #define ATOMIC64_OPS(op, op1, op2) \
1352 ATOMIC64_OP(op, op1, op2) \
1353 ATOMIC64_OP_RETURN(op, op1, op2)
1354 @@ -323,7 +512,12 @@ ATOMIC64_OPS(sub, subs, sbc)
1355
1356 #undef ATOMIC64_OPS
1357 #undef ATOMIC64_OP_RETURN
1358 +#undef __ATOMIC64_OP_RETURN
1359 #undef ATOMIC64_OP
1360 +#undef __ATOMIC64_OP
1361 +#undef __OVERFLOW_EXTABLE
1362 +#undef __OVERFLOW_POST_RETURN
1363 +#undef __OVERFLOW_POST
1364
1365 static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1366 long long new)
1367 @@ -351,6 +545,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1368 return oldval;
1369 }
1370
1371 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1372 + long long new)
1373 +{
1374 + long long oldval;
1375 + unsigned long res;
1376 +
1377 + smp_mb();
1378 +
1379 + do {
1380 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1381 + "ldrexd %1, %H1, [%3]\n"
1382 + "mov %0, #0\n"
1383 + "teq %1, %4\n"
1384 + "teqeq %H1, %H4\n"
1385 + "strexdeq %0, %5, %H5, [%3]"
1386 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1387 + : "r" (&ptr->counter), "r" (old), "r" (new)
1388 + : "cc");
1389 + } while (res);
1390 +
1391 + smp_mb();
1392 +
1393 + return oldval;
1394 +}
1395 +
1396 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1397 {
1398 long long result;
1399 @@ -376,21 +595,35 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1400 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1401 {
1402 long long result;
1403 - unsigned long tmp;
1404 + u64 tmp;
1405
1406 smp_mb();
1407 prefetchw(&v->counter);
1408
1409 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1410 -"1: ldrexd %0, %H0, [%3]\n"
1411 -" subs %Q0, %Q0, #1\n"
1412 -" sbc %R0, %R0, #0\n"
1413 +"1: ldrexd %1, %H1, [%3]\n"
1414 +" subs %Q0, %Q1, #1\n"
1415 +" sbcs %R0, %R1, #0\n"
1416 +
1417 +#ifdef CONFIG_PAX_REFCOUNT
1418 +" bvc 3f\n"
1419 +" mov %Q0, %Q1\n"
1420 +" mov %R0, %R1\n"
1421 +"2: " REFCOUNT_TRAP_INSN "\n"
1422 +"3:\n"
1423 +#endif
1424 +
1425 " teq %R0, #0\n"
1426 -" bmi 2f\n"
1427 +" bmi 4f\n"
1428 " strexd %1, %0, %H0, [%3]\n"
1429 " teq %1, #0\n"
1430 " bne 1b\n"
1431 -"2:"
1432 +"4:\n"
1433 +
1434 +#ifdef CONFIG_PAX_REFCOUNT
1435 + _ASM_EXTABLE(2b, 4b)
1436 +#endif
1437 +
1438 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1439 : "r" (&v->counter)
1440 : "cc");
1441 @@ -414,13 +647,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1442 " teq %0, %5\n"
1443 " teqeq %H0, %H5\n"
1444 " moveq %1, #0\n"
1445 -" beq 2f\n"
1446 +" beq 4f\n"
1447 " adds %Q0, %Q0, %Q6\n"
1448 -" adc %R0, %R0, %R6\n"
1449 +" adcs %R0, %R0, %R6\n"
1450 +
1451 +#ifdef CONFIG_PAX_REFCOUNT
1452 +" bvc 3f\n"
1453 +"2: " REFCOUNT_TRAP_INSN "\n"
1454 +"3:\n"
1455 +#endif
1456 +
1457 " strexd %2, %0, %H0, [%4]\n"
1458 " teq %2, #0\n"
1459 " bne 1b\n"
1460 -"2:"
1461 +"4:\n"
1462 +
1463 +#ifdef CONFIG_PAX_REFCOUNT
1464 + _ASM_EXTABLE(2b, 4b)
1465 +#endif
1466 +
1467 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1468 : "r" (&v->counter), "r" (u), "r" (a)
1469 : "cc");
1470 @@ -433,10 +678,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1471
1472 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1473 #define atomic64_inc(v) atomic64_add(1LL, (v))
1474 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1475 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1476 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1477 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1478 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1479 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1480 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1481 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1482 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1483 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1484 diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h
1485 index c6a3e73..35cca85 100644
1486 --- a/arch/arm/include/asm/barrier.h
1487 +++ b/arch/arm/include/asm/barrier.h
1488 @@ -63,7 +63,7 @@
1489 do { \
1490 compiletime_assert_atomic_type(*p); \
1491 smp_mb(); \
1492 - ACCESS_ONCE(*p) = (v); \
1493 + ACCESS_ONCE_RW(*p) = (v); \
1494 } while (0)
1495
1496 #define smp_load_acquire(p) \
1497 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1498 index 75fe66b..ba3dee4 100644
1499 --- a/arch/arm/include/asm/cache.h
1500 +++ b/arch/arm/include/asm/cache.h
1501 @@ -4,8 +4,10 @@
1502 #ifndef __ASMARM_CACHE_H
1503 #define __ASMARM_CACHE_H
1504
1505 +#include <linux/const.h>
1506 +
1507 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1508 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1509 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1510
1511 /*
1512 * Memory returned by kmalloc() may be used for DMA, so we must make
1513 @@ -24,5 +26,6 @@
1514 #endif
1515
1516 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1517 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1518
1519 #endif
1520 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1521 index 10e78d0..dc8505d 100644
1522 --- a/arch/arm/include/asm/cacheflush.h
1523 +++ b/arch/arm/include/asm/cacheflush.h
1524 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1525 void (*dma_unmap_area)(const void *, size_t, int);
1526
1527 void (*dma_flush_range)(const void *, const void *);
1528 -};
1529 +} __no_const;
1530
1531 /*
1532 * Select the calling method
1533 diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1534 index 5233151..87a71fa 100644
1535 --- a/arch/arm/include/asm/checksum.h
1536 +++ b/arch/arm/include/asm/checksum.h
1537 @@ -37,7 +37,19 @@ __wsum
1538 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1539
1540 __wsum
1541 -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1542 +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1543 +
1544 +static inline __wsum
1545 +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1546 +{
1547 + __wsum ret;
1548 + pax_open_userland();
1549 + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1550 + pax_close_userland();
1551 + return ret;
1552 +}
1553 +
1554 +
1555
1556 /*
1557 * Fold a partial checksum without adding pseudo headers
1558 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1559 index abb2c37..96db950 100644
1560 --- a/arch/arm/include/asm/cmpxchg.h
1561 +++ b/arch/arm/include/asm/cmpxchg.h
1562 @@ -104,6 +104,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1563
1564 #define xchg(ptr,x) \
1565 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1566 +#define xchg_unchecked(ptr,x) \
1567 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1568
1569 #include <asm-generic/cmpxchg-local.h>
1570
1571 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1572 index 6ddbe44..b5e38b1 100644
1573 --- a/arch/arm/include/asm/domain.h
1574 +++ b/arch/arm/include/asm/domain.h
1575 @@ -48,18 +48,37 @@
1576 * Domain types
1577 */
1578 #define DOMAIN_NOACCESS 0
1579 -#define DOMAIN_CLIENT 1
1580 #ifdef CONFIG_CPU_USE_DOMAINS
1581 +#define DOMAIN_USERCLIENT 1
1582 +#define DOMAIN_KERNELCLIENT 1
1583 #define DOMAIN_MANAGER 3
1584 +#define DOMAIN_VECTORS DOMAIN_USER
1585 #else
1586 +
1587 +#ifdef CONFIG_PAX_KERNEXEC
1588 #define DOMAIN_MANAGER 1
1589 +#define DOMAIN_KERNEXEC 3
1590 +#else
1591 +#define DOMAIN_MANAGER 1
1592 +#endif
1593 +
1594 +#ifdef CONFIG_PAX_MEMORY_UDEREF
1595 +#define DOMAIN_USERCLIENT 0
1596 +#define DOMAIN_UDEREF 1
1597 +#define DOMAIN_VECTORS DOMAIN_KERNEL
1598 +#else
1599 +#define DOMAIN_USERCLIENT 1
1600 +#define DOMAIN_VECTORS DOMAIN_USER
1601 +#endif
1602 +#define DOMAIN_KERNELCLIENT 1
1603 +
1604 #endif
1605
1606 #define domain_val(dom,type) ((type) << (2*(dom)))
1607
1608 #ifndef __ASSEMBLY__
1609
1610 -#ifdef CONFIG_CPU_USE_DOMAINS
1611 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1612 static inline void set_domain(unsigned val)
1613 {
1614 asm volatile(
1615 @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1616 isb();
1617 }
1618
1619 -#define modify_domain(dom,type) \
1620 - do { \
1621 - struct thread_info *thread = current_thread_info(); \
1622 - unsigned int domain = thread->cpu_domain; \
1623 - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1624 - thread->cpu_domain = domain | domain_val(dom, type); \
1625 - set_domain(thread->cpu_domain); \
1626 - } while (0)
1627 -
1628 +extern void modify_domain(unsigned int dom, unsigned int type);
1629 #else
1630 static inline void set_domain(unsigned val) { }
1631 static inline void modify_domain(unsigned dom, unsigned type) { }
1632 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1633 index afb9caf..9a0bac0 100644
1634 --- a/arch/arm/include/asm/elf.h
1635 +++ b/arch/arm/include/asm/elf.h
1636 @@ -115,7 +115,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1637 the loader. We need to make sure that it is out of the way of the program
1638 that it will "exec", and that there is sufficient room for the brk. */
1639
1640 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1641 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1642 +
1643 +#ifdef CONFIG_PAX_ASLR
1644 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1645 +
1646 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1647 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1648 +#endif
1649
1650 /* When the program starts, a1 contains a pointer to a function to be
1651 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1652 @@ -125,10 +132,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1653 extern void elf_set_personality(const struct elf32_hdr *);
1654 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1655
1656 -struct mm_struct;
1657 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1658 -#define arch_randomize_brk arch_randomize_brk
1659 -
1660 #ifdef CONFIG_MMU
1661 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1662 struct linux_binprm;
1663 diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1664 index de53547..52b9a28 100644
1665 --- a/arch/arm/include/asm/fncpy.h
1666 +++ b/arch/arm/include/asm/fncpy.h
1667 @@ -81,7 +81,9 @@
1668 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1669 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1670 \
1671 + pax_open_kernel(); \
1672 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1673 + pax_close_kernel(); \
1674 flush_icache_range((unsigned long)(dest_buf), \
1675 (unsigned long)(dest_buf) + (size)); \
1676 \
1677 diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1678 index 53e69da..3fdc896 100644
1679 --- a/arch/arm/include/asm/futex.h
1680 +++ b/arch/arm/include/asm/futex.h
1681 @@ -46,6 +46,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1682 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1683 return -EFAULT;
1684
1685 + pax_open_userland();
1686 +
1687 smp_mb();
1688 /* Prefetching cannot fault */
1689 prefetchw(uaddr);
1690 @@ -63,6 +65,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1691 : "cc", "memory");
1692 smp_mb();
1693
1694 + pax_close_userland();
1695 +
1696 *uval = val;
1697 return ret;
1698 }
1699 @@ -93,6 +97,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1700 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1701 return -EFAULT;
1702
1703 + pax_open_userland();
1704 +
1705 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1706 "1: " TUSER(ldr) " %1, [%4]\n"
1707 " teq %1, %2\n"
1708 @@ -103,6 +109,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1709 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1710 : "cc", "memory");
1711
1712 + pax_close_userland();
1713 +
1714 *uval = val;
1715 return ret;
1716 }
1717 @@ -125,6 +133,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1718 return -EFAULT;
1719
1720 pagefault_disable(); /* implies preempt_disable() */
1721 + pax_open_userland();
1722
1723 switch (op) {
1724 case FUTEX_OP_SET:
1725 @@ -146,6 +155,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1726 ret = -ENOSYS;
1727 }
1728
1729 + pax_close_userland();
1730 pagefault_enable(); /* subsumes preempt_enable() */
1731
1732 if (!ret) {
1733 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1734 index 83eb2f7..ed77159 100644
1735 --- a/arch/arm/include/asm/kmap_types.h
1736 +++ b/arch/arm/include/asm/kmap_types.h
1737 @@ -4,6 +4,6 @@
1738 /*
1739 * This is the "bare minimum". AIO seems to require this.
1740 */
1741 -#define KM_TYPE_NR 16
1742 +#define KM_TYPE_NR 17
1743
1744 #endif
1745 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1746 index 9e614a1..3302cca 100644
1747 --- a/arch/arm/include/asm/mach/dma.h
1748 +++ b/arch/arm/include/asm/mach/dma.h
1749 @@ -22,7 +22,7 @@ struct dma_ops {
1750 int (*residue)(unsigned int, dma_t *); /* optional */
1751 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1752 const char *type;
1753 -};
1754 +} __do_const;
1755
1756 struct dma_struct {
1757 void *addr; /* single DMA address */
1758 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1759 index f98c7f3..e5c626d 100644
1760 --- a/arch/arm/include/asm/mach/map.h
1761 +++ b/arch/arm/include/asm/mach/map.h
1762 @@ -23,17 +23,19 @@ struct map_desc {
1763
1764 /* types 0-3 are defined in asm/io.h */
1765 enum {
1766 - MT_UNCACHED = 4,
1767 - MT_CACHECLEAN,
1768 - MT_MINICLEAN,
1769 + MT_UNCACHED_RW = 4,
1770 + MT_CACHECLEAN_RO,
1771 + MT_MINICLEAN_RO,
1772 MT_LOW_VECTORS,
1773 MT_HIGH_VECTORS,
1774 - MT_MEMORY_RWX,
1775 + __MT_MEMORY_RWX,
1776 MT_MEMORY_RW,
1777 - MT_ROM,
1778 - MT_MEMORY_RWX_NONCACHED,
1779 + MT_MEMORY_RX,
1780 + MT_ROM_RX,
1781 + MT_MEMORY_RW_NONCACHED,
1782 + MT_MEMORY_RX_NONCACHED,
1783 MT_MEMORY_RW_DTCM,
1784 - MT_MEMORY_RWX_ITCM,
1785 + MT_MEMORY_RX_ITCM,
1786 MT_MEMORY_RW_SO,
1787 MT_MEMORY_DMA_READY,
1788 };
1789 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1790 index 891a56b..48f337e 100644
1791 --- a/arch/arm/include/asm/outercache.h
1792 +++ b/arch/arm/include/asm/outercache.h
1793 @@ -36,7 +36,7 @@ struct outer_cache_fns {
1794
1795 /* This is an ARM L2C thing */
1796 void (*write_sec)(unsigned long, unsigned);
1797 -};
1798 +} __no_const;
1799
1800 extern struct outer_cache_fns outer_cache;
1801
1802 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1803 index 4355f0e..cd9168e 100644
1804 --- a/arch/arm/include/asm/page.h
1805 +++ b/arch/arm/include/asm/page.h
1806 @@ -23,6 +23,7 @@
1807
1808 #else
1809
1810 +#include <linux/compiler.h>
1811 #include <asm/glue.h>
1812
1813 /*
1814 @@ -114,7 +115,7 @@ struct cpu_user_fns {
1815 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1816 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1817 unsigned long vaddr, struct vm_area_struct *vma);
1818 -};
1819 +} __no_const;
1820
1821 #ifdef MULTI_USER
1822 extern struct cpu_user_fns cpu_user;
1823 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1824 index 78a7793..e3dc06c 100644
1825 --- a/arch/arm/include/asm/pgalloc.h
1826 +++ b/arch/arm/include/asm/pgalloc.h
1827 @@ -17,6 +17,7 @@
1828 #include <asm/processor.h>
1829 #include <asm/cacheflush.h>
1830 #include <asm/tlbflush.h>
1831 +#include <asm/system_info.h>
1832
1833 #define check_pgt_cache() do { } while (0)
1834
1835 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1836 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1837 }
1838
1839 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1840 +{
1841 + pud_populate(mm, pud, pmd);
1842 +}
1843 +
1844 #else /* !CONFIG_ARM_LPAE */
1845
1846 /*
1847 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1848 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1849 #define pmd_free(mm, pmd) do { } while (0)
1850 #define pud_populate(mm,pmd,pte) BUG()
1851 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1852
1853 #endif /* CONFIG_ARM_LPAE */
1854
1855 @@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1856 __free_page(pte);
1857 }
1858
1859 +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1860 +{
1861 +#ifdef CONFIG_ARM_LPAE
1862 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1863 +#else
1864 + if (addr & SECTION_SIZE)
1865 + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1866 + else
1867 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1868 +#endif
1869 + flush_pmd_entry(pmdp);
1870 +}
1871 +
1872 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1873 pmdval_t prot)
1874 {
1875 @@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1876 static inline void
1877 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1878 {
1879 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1880 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1881 }
1882 #define pmd_pgtable(pmd) pmd_page(pmd)
1883
1884 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1885 index 5cfba15..f415e1a 100644
1886 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1887 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1888 @@ -20,12 +20,15 @@
1889 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1890 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1891 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1892 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1893 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1894 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1895 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1896 +
1897 /*
1898 * - section
1899 */
1900 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1901 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1902 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1903 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1904 @@ -37,6 +40,7 @@
1905 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1906 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1907 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1908 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1909
1910 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1911 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1912 @@ -66,6 +70,7 @@
1913 * - extended small page/tiny page
1914 */
1915 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1916 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1917 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1918 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1919 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1920 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1921 index f027941..f36ce30 100644
1922 --- a/arch/arm/include/asm/pgtable-2level.h
1923 +++ b/arch/arm/include/asm/pgtable-2level.h
1924 @@ -126,6 +126,9 @@
1925 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1926 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1927
1928 +/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1929 +#define L_PTE_PXN (_AT(pteval_t, 0))
1930 +
1931 /*
1932 * These are the memory types, defined to be compatible with
1933 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1934 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1935 index 9fd61c7..f8f1cff 100644
1936 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1937 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1938 @@ -76,6 +76,7 @@
1939 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1940 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1941 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1942 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1943 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1944
1945 /*
1946 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1947 index a31ecdad..95e98d4 100644
1948 --- a/arch/arm/include/asm/pgtable-3level.h
1949 +++ b/arch/arm/include/asm/pgtable-3level.h
1950 @@ -81,6 +81,7 @@
1951 #define L_PTE_USER (_AT(pteval_t, 1) << 6) /* AP[1] */
1952 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1953 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1954 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1955 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1956 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55)
1957 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56)
1958 @@ -92,10 +93,12 @@
1959 #define L_PMD_SECT_SPLITTING (_AT(pmdval_t, 1) << 56)
1960 #define L_PMD_SECT_NONE (_AT(pmdval_t, 1) << 57)
1961 #define L_PMD_SECT_RDONLY (_AT(pteval_t, 1) << 58)
1962 +#define PMD_SECT_RDONLY PMD_SECT_AP2
1963
1964 /*
1965 * To be used in assembly code with the upper page attributes.
1966 */
1967 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
1968 #define L_PTE_XN_HIGH (1 << (54 - 32))
1969 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1970
1971 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1972 index 3b30062..01a5f9d 100644
1973 --- a/arch/arm/include/asm/pgtable.h
1974 +++ b/arch/arm/include/asm/pgtable.h
1975 @@ -33,6 +33,9 @@
1976 #include <asm/pgtable-2level.h>
1977 #endif
1978
1979 +#define ktla_ktva(addr) (addr)
1980 +#define ktva_ktla(addr) (addr)
1981 +
1982 /*
1983 * Just any arbitrary offset to the start of the vmalloc VM area: the
1984 * current 8MB value just means that there will be a 8MB "hole" after the
1985 @@ -48,6 +51,9 @@
1986 #define LIBRARY_TEXT_START 0x0c000000
1987
1988 #ifndef __ASSEMBLY__
1989 +extern pteval_t __supported_pte_mask;
1990 +extern pmdval_t __supported_pmd_mask;
1991 +
1992 extern void __pte_error(const char *file, int line, pte_t);
1993 extern void __pmd_error(const char *file, int line, pmd_t);
1994 extern void __pgd_error(const char *file, int line, pgd_t);
1995 @@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1996 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1997 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1998
1999 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
2000 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2001 +
2002 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2003 +#include <asm/domain.h>
2004 +#include <linux/thread_info.h>
2005 +#include <linux/preempt.h>
2006 +
2007 +static inline int test_domain(int domain, int domaintype)
2008 +{
2009 + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2010 +}
2011 +#endif
2012 +
2013 +#ifdef CONFIG_PAX_KERNEXEC
2014 +static inline unsigned long pax_open_kernel(void) {
2015 +#ifdef CONFIG_ARM_LPAE
2016 + /* TODO */
2017 +#else
2018 + preempt_disable();
2019 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2020 + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2021 +#endif
2022 + return 0;
2023 +}
2024 +
2025 +static inline unsigned long pax_close_kernel(void) {
2026 +#ifdef CONFIG_ARM_LPAE
2027 + /* TODO */
2028 +#else
2029 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2030 + /* DOMAIN_MANAGER = "client" under KERNEXEC */
2031 + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2032 + preempt_enable_no_resched();
2033 +#endif
2034 + return 0;
2035 +}
2036 +#else
2037 +static inline unsigned long pax_open_kernel(void) { return 0; }
2038 +static inline unsigned long pax_close_kernel(void) { return 0; }
2039 +#endif
2040 +
2041 /*
2042 * This is the lowest virtual address we can permit any user space
2043 * mapping to be mapped at. This is particularly important for
2044 @@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2045 /*
2046 * The pgprot_* and protection_map entries will be fixed up in runtime
2047 * to include the cachable and bufferable bits based on memory policy,
2048 - * as well as any architecture dependent bits like global/ASID and SMP
2049 - * shared mapping bits.
2050 + * as well as any architecture dependent bits like global/ASID, PXN,
2051 + * and SMP shared mapping bits.
2052 */
2053 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2054
2055 @@ -267,7 +315,7 @@ PTE_BIT_FUNC(mknexec, |= L_PTE_XN);
2056 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2057 {
2058 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2059 - L_PTE_NONE | L_PTE_VALID;
2060 + L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2061 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2062 return pte;
2063 }
2064 diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2065 index c25ef3e..735f14b 100644
2066 --- a/arch/arm/include/asm/psci.h
2067 +++ b/arch/arm/include/asm/psci.h
2068 @@ -32,7 +32,7 @@ struct psci_operations {
2069 int (*affinity_info)(unsigned long target_affinity,
2070 unsigned long lowest_affinity_level);
2071 int (*migrate_info_type)(void);
2072 -};
2073 +} __no_const;
2074
2075 extern struct psci_operations psci_ops;
2076 extern struct smp_operations psci_smp_ops;
2077 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2078 index 18f5a55..5072a40 100644
2079 --- a/arch/arm/include/asm/smp.h
2080 +++ b/arch/arm/include/asm/smp.h
2081 @@ -107,7 +107,7 @@ struct smp_operations {
2082 int (*cpu_disable)(unsigned int cpu);
2083 #endif
2084 #endif
2085 -};
2086 +} __no_const;
2087
2088 struct of_cpu_method {
2089 const char *method;
2090 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2091 index ce73ab6..7310f8a 100644
2092 --- a/arch/arm/include/asm/thread_info.h
2093 +++ b/arch/arm/include/asm/thread_info.h
2094 @@ -78,9 +78,9 @@ struct thread_info {
2095 .flags = 0, \
2096 .preempt_count = INIT_PREEMPT_COUNT, \
2097 .addr_limit = KERNEL_DS, \
2098 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2099 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2100 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2101 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2102 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2103 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2104 .restart_block = { \
2105 .fn = do_no_restart_syscall, \
2106 }, \
2107 @@ -154,7 +154,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2108 #define TIF_SYSCALL_AUDIT 9
2109 #define TIF_SYSCALL_TRACEPOINT 10
2110 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2111 -#define TIF_NOHZ 12 /* in adaptive nohz mode */
2112 +/* within 8 bits of TIF_SYSCALL_TRACE
2113 + * to meet flexible second operand requirements
2114 + */
2115 +#define TIF_GRSEC_SETXID 12
2116 +#define TIF_NOHZ 13 /* in adaptive nohz mode */
2117 #define TIF_USING_IWMMXT 17
2118 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2119 #define TIF_RESTORE_SIGMASK 20
2120 @@ -168,10 +172,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2121 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2122 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2123 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2124 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2125
2126 /* Checks for any syscall work in entry-common.S */
2127 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2128 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2129 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2130
2131 /*
2132 * Change these and you break ASM code in entry-common.S
2133 diff --git a/arch/arm/include/asm/tls.h b/arch/arm/include/asm/tls.h
2134 index 5f833f7..76e6644 100644
2135 --- a/arch/arm/include/asm/tls.h
2136 +++ b/arch/arm/include/asm/tls.h
2137 @@ -3,6 +3,7 @@
2138
2139 #include <linux/compiler.h>
2140 #include <asm/thread_info.h>
2141 +#include <asm/pgtable.h>
2142
2143 #ifdef __ASSEMBLY__
2144 #include <asm/asm-offsets.h>
2145 @@ -89,7 +90,9 @@ static inline void set_tls(unsigned long val)
2146 * at 0xffff0fe0 must be used instead. (see
2147 * entry-armv.S for details)
2148 */
2149 + pax_open_kernel();
2150 *((unsigned int *)0xffff0ff0) = val;
2151 + pax_close_kernel();
2152 #endif
2153 }
2154
2155 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2156 index 4767eb9..bf00668 100644
2157 --- a/arch/arm/include/asm/uaccess.h
2158 +++ b/arch/arm/include/asm/uaccess.h
2159 @@ -18,6 +18,7 @@
2160 #include <asm/domain.h>
2161 #include <asm/unified.h>
2162 #include <asm/compiler.h>
2163 +#include <asm/pgtable.h>
2164
2165 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2166 #include <asm-generic/uaccess-unaligned.h>
2167 @@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2168 static inline void set_fs(mm_segment_t fs)
2169 {
2170 current_thread_info()->addr_limit = fs;
2171 - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2172 + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2173 }
2174
2175 #define segment_eq(a,b) ((a) == (b))
2176
2177 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
2178 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2179 +
2180 +static inline void pax_open_userland(void)
2181 +{
2182 +
2183 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2184 + if (segment_eq(get_fs(), USER_DS)) {
2185 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2186 + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2187 + }
2188 +#endif
2189 +
2190 +}
2191 +
2192 +static inline void pax_close_userland(void)
2193 +{
2194 +
2195 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2196 + if (segment_eq(get_fs(), USER_DS)) {
2197 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2198 + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2199 + }
2200 +#endif
2201 +
2202 +}
2203 +
2204 #define __addr_ok(addr) ({ \
2205 unsigned long flag; \
2206 __asm__("cmp %2, %0; movlo %0, #0" \
2207 @@ -198,8 +226,12 @@ extern int __get_user_64t_4(void *);
2208
2209 #define get_user(x,p) \
2210 ({ \
2211 + int __e; \
2212 might_fault(); \
2213 - __get_user_check(x,p); \
2214 + pax_open_userland(); \
2215 + __e = __get_user_check(x,p); \
2216 + pax_close_userland(); \
2217 + __e; \
2218 })
2219
2220 extern int __put_user_1(void *, unsigned int);
2221 @@ -244,8 +276,12 @@ extern int __put_user_8(void *, unsigned long long);
2222
2223 #define put_user(x,p) \
2224 ({ \
2225 + int __e; \
2226 might_fault(); \
2227 - __put_user_check(x,p); \
2228 + pax_open_userland(); \
2229 + __e = __put_user_check(x,p); \
2230 + pax_close_userland(); \
2231 + __e; \
2232 })
2233
2234 #else /* CONFIG_MMU */
2235 @@ -269,6 +305,7 @@ static inline void set_fs(mm_segment_t fs)
2236
2237 #endif /* CONFIG_MMU */
2238
2239 +#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2240 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2241
2242 #define user_addr_max() \
2243 @@ -286,13 +323,17 @@ static inline void set_fs(mm_segment_t fs)
2244 #define __get_user(x,ptr) \
2245 ({ \
2246 long __gu_err = 0; \
2247 + pax_open_userland(); \
2248 __get_user_err((x),(ptr),__gu_err); \
2249 + pax_close_userland(); \
2250 __gu_err; \
2251 })
2252
2253 #define __get_user_error(x,ptr,err) \
2254 ({ \
2255 + pax_open_userland(); \
2256 __get_user_err((x),(ptr),err); \
2257 + pax_close_userland(); \
2258 (void) 0; \
2259 })
2260
2261 @@ -368,13 +409,17 @@ do { \
2262 #define __put_user(x,ptr) \
2263 ({ \
2264 long __pu_err = 0; \
2265 + pax_open_userland(); \
2266 __put_user_err((x),(ptr),__pu_err); \
2267 + pax_close_userland(); \
2268 __pu_err; \
2269 })
2270
2271 #define __put_user_error(x,ptr,err) \
2272 ({ \
2273 + pax_open_userland(); \
2274 __put_user_err((x),(ptr),err); \
2275 + pax_close_userland(); \
2276 (void) 0; \
2277 })
2278
2279 @@ -474,11 +519,44 @@ do { \
2280
2281
2282 #ifdef CONFIG_MMU
2283 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2284 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2285 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2286 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2287 +
2288 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2289 +{
2290 + unsigned long ret;
2291 +
2292 + check_object_size(to, n, false);
2293 + pax_open_userland();
2294 + ret = ___copy_from_user(to, from, n);
2295 + pax_close_userland();
2296 + return ret;
2297 +}
2298 +
2299 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2300 +{
2301 + unsigned long ret;
2302 +
2303 + check_object_size(from, n, true);
2304 + pax_open_userland();
2305 + ret = ___copy_to_user(to, from, n);
2306 + pax_close_userland();
2307 + return ret;
2308 +}
2309 +
2310 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2311 -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2312 +extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2313 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2314 +
2315 +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2316 +{
2317 + unsigned long ret;
2318 + pax_open_userland();
2319 + ret = ___clear_user(addr, n);
2320 + pax_close_userland();
2321 + return ret;
2322 +}
2323 +
2324 #else
2325 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2326 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2327 @@ -487,6 +565,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2328
2329 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2330 {
2331 + if ((long)n < 0)
2332 + return n;
2333 +
2334 if (access_ok(VERIFY_READ, from, n))
2335 n = __copy_from_user(to, from, n);
2336 else /* security hole - plug it */
2337 @@ -496,6 +577,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2338
2339 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2340 {
2341 + if ((long)n < 0)
2342 + return n;
2343 +
2344 if (access_ok(VERIFY_WRITE, to, n))
2345 n = __copy_to_user(to, from, n);
2346 return n;
2347 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2348 index 5af0ed1..cea83883 100644
2349 --- a/arch/arm/include/uapi/asm/ptrace.h
2350 +++ b/arch/arm/include/uapi/asm/ptrace.h
2351 @@ -92,7 +92,7 @@
2352 * ARMv7 groups of PSR bits
2353 */
2354 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2355 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2356 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2357 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2358 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2359
2360 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2361 index a88671c..1cc895e 100644
2362 --- a/arch/arm/kernel/armksyms.c
2363 +++ b/arch/arm/kernel/armksyms.c
2364 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2365
2366 /* networking */
2367 EXPORT_SYMBOL(csum_partial);
2368 -EXPORT_SYMBOL(csum_partial_copy_from_user);
2369 +EXPORT_SYMBOL(__csum_partial_copy_from_user);
2370 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2371 EXPORT_SYMBOL(__csum_ipv6_magic);
2372
2373 @@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2374 #ifdef CONFIG_MMU
2375 EXPORT_SYMBOL(copy_page);
2376
2377 -EXPORT_SYMBOL(__copy_from_user);
2378 -EXPORT_SYMBOL(__copy_to_user);
2379 -EXPORT_SYMBOL(__clear_user);
2380 +EXPORT_SYMBOL(___copy_from_user);
2381 +EXPORT_SYMBOL(___copy_to_user);
2382 +EXPORT_SYMBOL(___clear_user);
2383
2384 EXPORT_SYMBOL(__get_user_1);
2385 EXPORT_SYMBOL(__get_user_2);
2386 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2387 index 2f5555d..d493c91 100644
2388 --- a/arch/arm/kernel/entry-armv.S
2389 +++ b/arch/arm/kernel/entry-armv.S
2390 @@ -47,6 +47,87 @@
2391 9997:
2392 .endm
2393
2394 + .macro pax_enter_kernel
2395 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2396 + @ make aligned space for saved DACR
2397 + sub sp, sp, #8
2398 + @ save regs
2399 + stmdb sp!, {r1, r2}
2400 + @ read DACR from cpu_domain into r1
2401 + mov r2, sp
2402 + @ assume 8K pages, since we have to split the immediate in two
2403 + bic r2, r2, #(0x1fc0)
2404 + bic r2, r2, #(0x3f)
2405 + ldr r1, [r2, #TI_CPU_DOMAIN]
2406 + @ store old DACR on stack
2407 + str r1, [sp, #8]
2408 +#ifdef CONFIG_PAX_KERNEXEC
2409 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2410 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2411 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2412 +#endif
2413 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2414 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2415 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2416 +#endif
2417 + @ write r1 to current_thread_info()->cpu_domain
2418 + str r1, [r2, #TI_CPU_DOMAIN]
2419 + @ write r1 to DACR
2420 + mcr p15, 0, r1, c3, c0, 0
2421 + @ instruction sync
2422 + instr_sync
2423 + @ restore regs
2424 + ldmia sp!, {r1, r2}
2425 +#endif
2426 + .endm
2427 +
2428 + .macro pax_open_userland
2429 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2430 + @ save regs
2431 + stmdb sp!, {r0, r1}
2432 + @ read DACR from cpu_domain into r1
2433 + mov r0, sp
2434 + @ assume 8K pages, since we have to split the immediate in two
2435 + bic r0, r0, #(0x1fc0)
2436 + bic r0, r0, #(0x3f)
2437 + ldr r1, [r0, #TI_CPU_DOMAIN]
2438 + @ set current DOMAIN_USER to DOMAIN_CLIENT
2439 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2440 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2441 + @ write r1 to current_thread_info()->cpu_domain
2442 + str r1, [r0, #TI_CPU_DOMAIN]
2443 + @ write r1 to DACR
2444 + mcr p15, 0, r1, c3, c0, 0
2445 + @ instruction sync
2446 + instr_sync
2447 + @ restore regs
2448 + ldmia sp!, {r0, r1}
2449 +#endif
2450 + .endm
2451 +
2452 + .macro pax_close_userland
2453 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2454 + @ save regs
2455 + stmdb sp!, {r0, r1}
2456 + @ read DACR from cpu_domain into r1
2457 + mov r0, sp
2458 + @ assume 8K pages, since we have to split the immediate in two
2459 + bic r0, r0, #(0x1fc0)
2460 + bic r0, r0, #(0x3f)
2461 + ldr r1, [r0, #TI_CPU_DOMAIN]
2462 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2463 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2464 + @ write r1 to current_thread_info()->cpu_domain
2465 + str r1, [r0, #TI_CPU_DOMAIN]
2466 + @ write r1 to DACR
2467 + mcr p15, 0, r1, c3, c0, 0
2468 + @ instruction sync
2469 + instr_sync
2470 + @ restore regs
2471 + ldmia sp!, {r0, r1}
2472 +#endif
2473 + .endm
2474 +
2475 .macro pabt_helper
2476 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2477 #ifdef MULTI_PABORT
2478 @@ -89,11 +170,15 @@
2479 * Invalid mode handlers
2480 */
2481 .macro inv_entry, reason
2482 +
2483 + pax_enter_kernel
2484 +
2485 sub sp, sp, #S_FRAME_SIZE
2486 ARM( stmib sp, {r1 - lr} )
2487 THUMB( stmia sp, {r0 - r12} )
2488 THUMB( str sp, [sp, #S_SP] )
2489 THUMB( str lr, [sp, #S_LR] )
2490 +
2491 mov r1, #\reason
2492 .endm
2493
2494 @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2495 .macro svc_entry, stack_hole=0, trace=1
2496 UNWIND(.fnstart )
2497 UNWIND(.save {r0 - pc} )
2498 +
2499 + pax_enter_kernel
2500 +
2501 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2502 +
2503 #ifdef CONFIG_THUMB2_KERNEL
2504 SPFIX( str r0, [sp] ) @ temporarily saved
2505 SPFIX( mov r0, sp )
2506 @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2507 ldmia r0, {r3 - r5}
2508 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2509 mov r6, #-1 @ "" "" "" ""
2510 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2511 + @ offset sp by 8 as done in pax_enter_kernel
2512 + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2513 +#else
2514 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2515 +#endif
2516 SPFIX( addeq r2, r2, #4 )
2517 str r3, [sp, #-4]! @ save the "real" r0 copied
2518 @ from the exception stack
2519 @@ -368,6 +462,9 @@ ENDPROC(__fiq_abt)
2520 .macro usr_entry, trace=1
2521 UNWIND(.fnstart )
2522 UNWIND(.cantunwind ) @ don't unwind the user space
2523 +
2524 + pax_enter_kernel_user
2525 +
2526 sub sp, sp, #S_FRAME_SIZE
2527 ARM( stmib sp, {r1 - r12} )
2528 THUMB( stmia sp, {r0 - r12} )
2529 @@ -478,7 +575,9 @@ __und_usr:
2530 tst r3, #PSR_T_BIT @ Thumb mode?
2531 bne __und_usr_thumb
2532 sub r4, r2, #4 @ ARM instr at LR - 4
2533 + pax_open_userland
2534 1: ldrt r0, [r4]
2535 + pax_close_userland
2536 ARM_BE8(rev r0, r0) @ little endian instruction
2537
2538 @ r0 = 32-bit ARM instruction which caused the exception
2539 @@ -512,11 +611,15 @@ __und_usr_thumb:
2540 */
2541 .arch armv6t2
2542 #endif
2543 + pax_open_userland
2544 2: ldrht r5, [r4]
2545 + pax_close_userland
2546 ARM_BE8(rev16 r5, r5) @ little endian instruction
2547 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2548 blo __und_usr_fault_16 @ 16bit undefined instruction
2549 + pax_open_userland
2550 3: ldrht r0, [r2]
2551 + pax_close_userland
2552 ARM_BE8(rev16 r0, r0) @ little endian instruction
2553 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2554 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2555 @@ -546,7 +649,8 @@ ENDPROC(__und_usr)
2556 */
2557 .pushsection .fixup, "ax"
2558 .align 2
2559 -4: str r4, [sp, #S_PC] @ retry current instruction
2560 +4: pax_close_userland
2561 + str r4, [sp, #S_PC] @ retry current instruction
2562 ret r9
2563 .popsection
2564 .pushsection __ex_table,"a"
2565 @@ -766,7 +870,7 @@ ENTRY(__switch_to)
2566 THUMB( str lr, [ip], #4 )
2567 ldr r4, [r2, #TI_TP_VALUE]
2568 ldr r5, [r2, #TI_TP_VALUE + 4]
2569 -#ifdef CONFIG_CPU_USE_DOMAINS
2570 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2571 ldr r6, [r2, #TI_CPU_DOMAIN]
2572 #endif
2573 switch_tls r1, r4, r5, r3, r7
2574 @@ -775,7 +879,7 @@ ENTRY(__switch_to)
2575 ldr r8, =__stack_chk_guard
2576 ldr r7, [r7, #TSK_STACK_CANARY]
2577 #endif
2578 -#ifdef CONFIG_CPU_USE_DOMAINS
2579 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2580 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2581 #endif
2582 mov r5, r0
2583 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2584 index 6bb09d4..113e875 100644
2585 --- a/arch/arm/kernel/entry-common.S
2586 +++ b/arch/arm/kernel/entry-common.S
2587 @@ -11,18 +11,46 @@
2588 #include <asm/assembler.h>
2589 #include <asm/unistd.h>
2590 #include <asm/ftrace.h>
2591 +#include <asm/domain.h>
2592 #include <asm/unwind.h>
2593
2594 +#include "entry-header.S"
2595 +
2596 #ifdef CONFIG_NEED_RET_TO_USER
2597 #include <mach/entry-macro.S>
2598 #else
2599 .macro arch_ret_to_user, tmp1, tmp2
2600 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2601 + @ save regs
2602 + stmdb sp!, {r1, r2}
2603 + @ read DACR from cpu_domain into r1
2604 + mov r2, sp
2605 + @ assume 8K pages, since we have to split the immediate in two
2606 + bic r2, r2, #(0x1fc0)
2607 + bic r2, r2, #(0x3f)
2608 + ldr r1, [r2, #TI_CPU_DOMAIN]
2609 +#ifdef CONFIG_PAX_KERNEXEC
2610 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2611 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2612 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2613 +#endif
2614 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2615 + @ set current DOMAIN_USER to DOMAIN_UDEREF
2616 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2617 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2618 +#endif
2619 + @ write r1 to current_thread_info()->cpu_domain
2620 + str r1, [r2, #TI_CPU_DOMAIN]
2621 + @ write r1 to DACR
2622 + mcr p15, 0, r1, c3, c0, 0
2623 + @ instruction sync
2624 + instr_sync
2625 + @ restore regs
2626 + ldmia sp!, {r1, r2}
2627 +#endif
2628 .endm
2629 #endif
2630
2631 -#include "entry-header.S"
2632 -
2633 -
2634 .align 5
2635 /*
2636 * This is the fast syscall return path. We do as little as
2637 @@ -406,6 +434,12 @@ ENTRY(vector_swi)
2638 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2639 #endif
2640
2641 + /*
2642 + * do this here to avoid a performance hit of wrapping the code above
2643 + * that directly dereferences userland to parse the SWI instruction
2644 + */
2645 + pax_enter_kernel_user
2646 +
2647 adr tbl, sys_call_table @ load syscall table pointer
2648
2649 #if defined(CONFIG_OABI_COMPAT)
2650 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2651 index 4176df7..a901f8d 100644
2652 --- a/arch/arm/kernel/entry-header.S
2653 +++ b/arch/arm/kernel/entry-header.S
2654 @@ -196,6 +196,60 @@
2655 msr cpsr_c, \rtemp @ switch back to the SVC mode
2656 .endm
2657
2658 + .macro pax_enter_kernel_user
2659 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2660 + @ save regs
2661 + stmdb sp!, {r0, r1}
2662 + @ read DACR from cpu_domain into r1
2663 + mov r0, sp
2664 + @ assume 8K pages, since we have to split the immediate in two
2665 + bic r0, r0, #(0x1fc0)
2666 + bic r0, r0, #(0x3f)
2667 + ldr r1, [r0, #TI_CPU_DOMAIN]
2668 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2669 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2670 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2671 +#endif
2672 +#ifdef CONFIG_PAX_KERNEXEC
2673 + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2674 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2675 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2676 +#endif
2677 + @ write r1 to current_thread_info()->cpu_domain
2678 + str r1, [r0, #TI_CPU_DOMAIN]
2679 + @ write r1 to DACR
2680 + mcr p15, 0, r1, c3, c0, 0
2681 + @ instruction sync
2682 + instr_sync
2683 + @ restore regs
2684 + ldmia sp!, {r0, r1}
2685 +#endif
2686 + .endm
2687 +
2688 + .macro pax_exit_kernel
2689 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2690 + @ save regs
2691 + stmdb sp!, {r0, r1}
2692 + @ read old DACR from stack into r1
2693 + ldr r1, [sp, #(8 + S_SP)]
2694 + sub r1, r1, #8
2695 + ldr r1, [r1]
2696 +
2697 + @ write r1 to current_thread_info()->cpu_domain
2698 + mov r0, sp
2699 + @ assume 8K pages, since we have to split the immediate in two
2700 + bic r0, r0, #(0x1fc0)
2701 + bic r0, r0, #(0x3f)
2702 + str r1, [r0, #TI_CPU_DOMAIN]
2703 + @ write r1 to DACR
2704 + mcr p15, 0, r1, c3, c0, 0
2705 + @ instruction sync
2706 + instr_sync
2707 + @ restore regs
2708 + ldmia sp!, {r0, r1}
2709 +#endif
2710 + .endm
2711 +
2712 #ifndef CONFIG_THUMB2_KERNEL
2713 .macro svc_exit, rpsr, irq = 0
2714 .if \irq != 0
2715 @@ -215,6 +269,9 @@
2716 blne trace_hardirqs_off
2717 #endif
2718 .endif
2719 +
2720 + pax_exit_kernel
2721 +
2722 msr spsr_cxsf, \rpsr
2723 #if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_32v6K)
2724 @ We must avoid clrex due to Cortex-A15 erratum #830321
2725 @@ -290,6 +347,9 @@
2726 blne trace_hardirqs_off
2727 #endif
2728 .endif
2729 +
2730 + pax_exit_kernel
2731 +
2732 ldr lr, [sp, #S_SP] @ top of the stack
2733 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2734
2735 diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2736 index b37752a..ff5cb72 100644
2737 --- a/arch/arm/kernel/fiq.c
2738 +++ b/arch/arm/kernel/fiq.c
2739 @@ -95,7 +95,10 @@ void set_fiq_handler(void *start, unsigned int length)
2740 void *base = vectors_page;
2741 unsigned offset = FIQ_OFFSET;
2742
2743 + pax_open_kernel();
2744 memcpy(base + offset, start, length);
2745 + pax_close_kernel();
2746 +
2747 if (!cache_is_vipt_nonaliasing())
2748 flush_icache_range((unsigned long)base + offset, offset +
2749 length);
2750 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2751 index 664eee8..f470938 100644
2752 --- a/arch/arm/kernel/head.S
2753 +++ b/arch/arm/kernel/head.S
2754 @@ -437,7 +437,7 @@ __enable_mmu:
2755 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2756 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2757 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2758 - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2759 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2760 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2761 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2762 #endif
2763 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2764 index 6a4dffe..4a86a70 100644
2765 --- a/arch/arm/kernel/module.c
2766 +++ b/arch/arm/kernel/module.c
2767 @@ -38,12 +38,39 @@
2768 #endif
2769
2770 #ifdef CONFIG_MMU
2771 -void *module_alloc(unsigned long size)
2772 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2773 {
2774 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2775 + return NULL;
2776 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2777 - GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2778 + GFP_KERNEL, prot, NUMA_NO_NODE,
2779 __builtin_return_address(0));
2780 }
2781 +
2782 +void *module_alloc(unsigned long size)
2783 +{
2784 +
2785 +#ifdef CONFIG_PAX_KERNEXEC
2786 + return __module_alloc(size, PAGE_KERNEL);
2787 +#else
2788 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2789 +#endif
2790 +
2791 +}
2792 +
2793 +#ifdef CONFIG_PAX_KERNEXEC
2794 +void module_free_exec(struct module *mod, void *module_region)
2795 +{
2796 + module_free(mod, module_region);
2797 +}
2798 +EXPORT_SYMBOL(module_free_exec);
2799 +
2800 +void *module_alloc_exec(unsigned long size)
2801 +{
2802 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2803 +}
2804 +EXPORT_SYMBOL(module_alloc_exec);
2805 +#endif
2806 #endif
2807
2808 int
2809 diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2810 index 07314af..c46655c 100644
2811 --- a/arch/arm/kernel/patch.c
2812 +++ b/arch/arm/kernel/patch.c
2813 @@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2814 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2815 int size;
2816
2817 + pax_open_kernel();
2818 if (thumb2 && __opcode_is_thumb16(insn)) {
2819 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2820 size = sizeof(u16);
2821 @@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2822 *(u32 *)addr = insn;
2823 size = sizeof(u32);
2824 }
2825 + pax_close_kernel();
2826
2827 flush_icache_range((uintptr_t)(addr),
2828 (uintptr_t)(addr) + size);
2829 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2830 index fe972a2..a772d83 100644
2831 --- a/arch/arm/kernel/process.c
2832 +++ b/arch/arm/kernel/process.c
2833 @@ -207,6 +207,7 @@ void machine_power_off(void)
2834
2835 if (pm_power_off)
2836 pm_power_off();
2837 + BUG();
2838 }
2839
2840 /*
2841 @@ -220,7 +221,7 @@ void machine_power_off(void)
2842 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2843 * to use. Implementing such co-ordination would be essentially impossible.
2844 */
2845 -void machine_restart(char *cmd)
2846 +__noreturn void machine_restart(char *cmd)
2847 {
2848 local_irq_disable();
2849 smp_send_stop();
2850 @@ -246,8 +247,8 @@ void __show_regs(struct pt_regs *regs)
2851
2852 show_regs_print_info(KERN_DEFAULT);
2853
2854 - print_symbol("PC is at %s\n", instruction_pointer(regs));
2855 - print_symbol("LR is at %s\n", regs->ARM_lr);
2856 + printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2857 + printk("LR is at %pA\n", (void *)regs->ARM_lr);
2858 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2859 "sp : %08lx ip : %08lx fp : %08lx\n",
2860 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2861 @@ -424,12 +425,6 @@ unsigned long get_wchan(struct task_struct *p)
2862 return 0;
2863 }
2864
2865 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2866 -{
2867 - unsigned long range_end = mm->brk + 0x02000000;
2868 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2869 -}
2870 -
2871 #ifdef CONFIG_MMU
2872 #ifdef CONFIG_KUSER_HELPERS
2873 /*
2874 @@ -445,7 +440,7 @@ static struct vm_area_struct gate_vma = {
2875
2876 static int __init gate_vma_init(void)
2877 {
2878 - gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2879 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2880 return 0;
2881 }
2882 arch_initcall(gate_vma_init);
2883 @@ -474,81 +469,13 @@ const char *arch_vma_name(struct vm_area_struct *vma)
2884 return is_gate_vma(vma) ? "[vectors]" : NULL;
2885 }
2886
2887 -/* If possible, provide a placement hint at a random offset from the
2888 - * stack for the signal page.
2889 - */
2890 -static unsigned long sigpage_addr(const struct mm_struct *mm,
2891 - unsigned int npages)
2892 -{
2893 - unsigned long offset;
2894 - unsigned long first;
2895 - unsigned long last;
2896 - unsigned long addr;
2897 - unsigned int slots;
2898 -
2899 - first = PAGE_ALIGN(mm->start_stack);
2900 -
2901 - last = TASK_SIZE - (npages << PAGE_SHIFT);
2902 -
2903 - /* No room after stack? */
2904 - if (first > last)
2905 - return 0;
2906 -
2907 - /* Just enough room? */
2908 - if (first == last)
2909 - return first;
2910 -
2911 - slots = ((last - first) >> PAGE_SHIFT) + 1;
2912 -
2913 - offset = get_random_int() % slots;
2914 -
2915 - addr = first + (offset << PAGE_SHIFT);
2916 -
2917 - return addr;
2918 -}
2919 -
2920 -static struct page *signal_page;
2921 -extern struct page *get_signal_page(void);
2922 -
2923 -static const struct vm_special_mapping sigpage_mapping = {
2924 - .name = "[sigpage]",
2925 - .pages = &signal_page,
2926 -};
2927 -
2928 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2929 {
2930 struct mm_struct *mm = current->mm;
2931 - struct vm_area_struct *vma;
2932 - unsigned long addr;
2933 - unsigned long hint;
2934 - int ret = 0;
2935 -
2936 - if (!signal_page)
2937 - signal_page = get_signal_page();
2938 - if (!signal_page)
2939 - return -ENOMEM;
2940
2941 down_write(&mm->mmap_sem);
2942 - hint = sigpage_addr(mm, 1);
2943 - addr = get_unmapped_area(NULL, hint, PAGE_SIZE, 0, 0);
2944 - if (IS_ERR_VALUE(addr)) {
2945 - ret = addr;
2946 - goto up_fail;
2947 - }
2948 -
2949 - vma = _install_special_mapping(mm, addr, PAGE_SIZE,
2950 - VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2951 - &sigpage_mapping);
2952 -
2953 - if (IS_ERR(vma)) {
2954 - ret = PTR_ERR(vma);
2955 - goto up_fail;
2956 - }
2957 -
2958 - mm->context.sigpage = addr;
2959 -
2960 - up_fail:
2961 + mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2962 up_write(&mm->mmap_sem);
2963 - return ret;
2964 + return 0;
2965 }
2966 #endif
2967 diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2968 index f73891b..cf3004e 100644
2969 --- a/arch/arm/kernel/psci.c
2970 +++ b/arch/arm/kernel/psci.c
2971 @@ -28,7 +28,7 @@
2972 #include <asm/psci.h>
2973 #include <asm/system_misc.h>
2974
2975 -struct psci_operations psci_ops;
2976 +struct psci_operations psci_ops __read_only;
2977
2978 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2979 typedef int (*psci_initcall_t)(const struct device_node *);
2980 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2981 index ef9119f..31995a3 100644
2982 --- a/arch/arm/kernel/ptrace.c
2983 +++ b/arch/arm/kernel/ptrace.c
2984 @@ -928,10 +928,19 @@ static void tracehook_report_syscall(struct pt_regs *regs,
2985 regs->ARM_ip = ip;
2986 }
2987
2988 +#ifdef CONFIG_GRKERNSEC_SETXID
2989 +extern void gr_delayed_cred_worker(void);
2990 +#endif
2991 +
2992 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2993 {
2994 current_thread_info()->syscall = scno;
2995
2996 +#ifdef CONFIG_GRKERNSEC_SETXID
2997 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2998 + gr_delayed_cred_worker();
2999 +#endif
3000 +
3001 /* Do the secure computing check first; failures should be fast. */
3002 #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
3003 if (secure_computing() == -1)
3004 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
3005 index c031063..e277ab8 100644
3006 --- a/arch/arm/kernel/setup.c
3007 +++ b/arch/arm/kernel/setup.c
3008 @@ -104,21 +104,23 @@ EXPORT_SYMBOL(elf_hwcap);
3009 unsigned int elf_hwcap2 __read_mostly;
3010 EXPORT_SYMBOL(elf_hwcap2);
3011
3012 +pteval_t __supported_pte_mask __read_only;
3013 +pmdval_t __supported_pmd_mask __read_only;
3014
3015 #ifdef MULTI_CPU
3016 -struct processor processor __read_mostly;
3017 +struct processor processor __read_only;
3018 #endif
3019 #ifdef MULTI_TLB
3020 -struct cpu_tlb_fns cpu_tlb __read_mostly;
3021 +struct cpu_tlb_fns cpu_tlb __read_only;
3022 #endif
3023 #ifdef MULTI_USER
3024 -struct cpu_user_fns cpu_user __read_mostly;
3025 +struct cpu_user_fns cpu_user __read_only;
3026 #endif
3027 #ifdef MULTI_CACHE
3028 -struct cpu_cache_fns cpu_cache __read_mostly;
3029 +struct cpu_cache_fns cpu_cache __read_only;
3030 #endif
3031 #ifdef CONFIG_OUTER_CACHE
3032 -struct outer_cache_fns outer_cache __read_mostly;
3033 +struct outer_cache_fns outer_cache __read_only;
3034 EXPORT_SYMBOL(outer_cache);
3035 #endif
3036
3037 @@ -252,9 +254,13 @@ static int __get_cpu_architecture(void)
3038 asm("mrc p15, 0, %0, c0, c1, 4"
3039 : "=r" (mmfr0));
3040 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3041 - (mmfr0 & 0x000000f0) >= 0x00000030)
3042 + (mmfr0 & 0x000000f0) >= 0x00000030) {
3043 cpu_arch = CPU_ARCH_ARMv7;
3044 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3045 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3046 + __supported_pte_mask |= L_PTE_PXN;
3047 + __supported_pmd_mask |= PMD_PXNTABLE;
3048 + }
3049 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3050 (mmfr0 & 0x000000f0) == 0x00000020)
3051 cpu_arch = CPU_ARCH_ARMv6;
3052 else
3053 diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3054 index bd19834..e4d8c66 100644
3055 --- a/arch/arm/kernel/signal.c
3056 +++ b/arch/arm/kernel/signal.c
3057 @@ -24,8 +24,6 @@
3058
3059 extern const unsigned long sigreturn_codes[7];
3060
3061 -static unsigned long signal_return_offset;
3062 -
3063 #ifdef CONFIG_CRUNCH
3064 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3065 {
3066 @@ -396,8 +394,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3067 * except when the MPU has protected the vectors
3068 * page from PL0
3069 */
3070 - retcode = mm->context.sigpage + signal_return_offset +
3071 - (idx << 2) + thumb;
3072 + retcode = mm->context.sigpage + (idx << 2) + thumb;
3073 } else
3074 #endif
3075 {
3076 @@ -604,33 +601,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3077 } while (thread_flags & _TIF_WORK_MASK);
3078 return 0;
3079 }
3080 -
3081 -struct page *get_signal_page(void)
3082 -{
3083 - unsigned long ptr;
3084 - unsigned offset;
3085 - struct page *page;
3086 - void *addr;
3087 -
3088 - page = alloc_pages(GFP_KERNEL, 0);
3089 -
3090 - if (!page)
3091 - return NULL;
3092 -
3093 - addr = page_address(page);
3094 -
3095 - /* Give the signal return code some randomness */
3096 - offset = 0x200 + (get_random_int() & 0x7fc);
3097 - signal_return_offset = offset;
3098 -
3099 - /*
3100 - * Copy signal return handlers into the vector page, and
3101 - * set sigreturn to be a pointer to these.
3102 - */
3103 - memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3104 -
3105 - ptr = (unsigned long)addr + offset;
3106 - flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3107 -
3108 - return page;
3109 -}
3110 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3111 index 13396d3..589d615 100644
3112 --- a/arch/arm/kernel/smp.c
3113 +++ b/arch/arm/kernel/smp.c
3114 @@ -76,7 +76,7 @@ enum ipi_msg_type {
3115
3116 static DECLARE_COMPLETION(cpu_running);
3117
3118 -static struct smp_operations smp_ops;
3119 +static struct smp_operations smp_ops __read_only;
3120
3121 void __init smp_set_ops(struct smp_operations *ops)
3122 {
3123 diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3124 index 7a3be1d..b00c7de 100644
3125 --- a/arch/arm/kernel/tcm.c
3126 +++ b/arch/arm/kernel/tcm.c
3127 @@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3128 .virtual = ITCM_OFFSET,
3129 .pfn = __phys_to_pfn(ITCM_OFFSET),
3130 .length = 0,
3131 - .type = MT_MEMORY_RWX_ITCM,
3132 + .type = MT_MEMORY_RX_ITCM,
3133 }
3134 };
3135
3136 @@ -267,7 +267,9 @@ no_dtcm:
3137 start = &__sitcm_text;
3138 end = &__eitcm_text;
3139 ram = &__itcm_start;
3140 + pax_open_kernel();
3141 memcpy(start, ram, itcm_code_sz);
3142 + pax_close_kernel();
3143 pr_debug("CPU ITCM: copied code from %p - %p\n",
3144 start, end);
3145 itcm_present = true;
3146 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3147 index 9f5d818..e013427 100644
3148 --- a/arch/arm/kernel/traps.c
3149 +++ b/arch/arm/kernel/traps.c
3150 @@ -65,7 +65,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3151 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3152 {
3153 #ifdef CONFIG_KALLSYMS
3154 - printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3155 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3156 #else
3157 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3158 #endif
3159 @@ -267,6 +267,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3160 static int die_owner = -1;
3161 static unsigned int die_nest_count;
3162
3163 +extern void gr_handle_kernel_exploit(void);
3164 +
3165 static unsigned long oops_begin(void)
3166 {
3167 int cpu;
3168 @@ -309,6 +311,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3169 panic("Fatal exception in interrupt");
3170 if (panic_on_oops)
3171 panic("Fatal exception");
3172 +
3173 + gr_handle_kernel_exploit();
3174 +
3175 if (signr)
3176 do_exit(signr);
3177 }
3178 @@ -880,7 +885,11 @@ void __init early_trap_init(void *vectors_base)
3179 kuser_init(vectors_base);
3180
3181 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3182 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3183 +
3184 +#ifndef CONFIG_PAX_MEMORY_UDEREF
3185 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3186 +#endif
3187 +
3188 #else /* ifndef CONFIG_CPU_V7M */
3189 /*
3190 * on V7-M there is no need to copy the vector table to a dedicated
3191 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3192 index 8e95aa4..595dfc8 100644
3193 --- a/arch/arm/kernel/vmlinux.lds.S
3194 +++ b/arch/arm/kernel/vmlinux.lds.S
3195 @@ -8,7 +8,11 @@
3196 #include <asm/thread_info.h>
3197 #include <asm/memory.h>
3198 #include <asm/page.h>
3199 -
3200 +
3201 +#ifdef CONFIG_PAX_KERNEXEC
3202 +#include <asm/pgtable.h>
3203 +#endif
3204 +
3205 #define PROC_INFO \
3206 . = ALIGN(4); \
3207 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3208 @@ -34,7 +38,7 @@
3209 #endif
3210
3211 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3212 - defined(CONFIG_GENERIC_BUG)
3213 + defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3214 #define ARM_EXIT_KEEP(x) x
3215 #define ARM_EXIT_DISCARD(x)
3216 #else
3217 @@ -90,6 +94,11 @@ SECTIONS
3218 _text = .;
3219 HEAD_TEXT
3220 }
3221 +
3222 +#ifdef CONFIG_PAX_KERNEXEC
3223 + . = ALIGN(1<<SECTION_SHIFT);
3224 +#endif
3225 +
3226 .text : { /* Real text segment */
3227 _stext = .; /* Text and read-only data */
3228 __exception_text_start = .;
3229 @@ -112,6 +121,8 @@ SECTIONS
3230 ARM_CPU_KEEP(PROC_INFO)
3231 }
3232
3233 + _etext = .; /* End of text section */
3234 +
3235 RO_DATA(PAGE_SIZE)
3236
3237 . = ALIGN(4);
3238 @@ -142,7 +153,9 @@ SECTIONS
3239
3240 NOTES
3241
3242 - _etext = .; /* End of text and rodata section */
3243 +#ifdef CONFIG_PAX_KERNEXEC
3244 + . = ALIGN(1<<SECTION_SHIFT);
3245 +#endif
3246
3247 #ifndef CONFIG_XIP_KERNEL
3248 . = ALIGN(PAGE_SIZE);
3249 @@ -221,6 +234,11 @@ SECTIONS
3250 #else
3251 . = ALIGN(THREAD_SIZE);
3252 __init_end = .;
3253 +
3254 +#ifdef CONFIG_PAX_KERNEXEC
3255 + . = ALIGN(1<<SECTION_SHIFT);
3256 +#endif
3257 +
3258 __data_loc = .;
3259 #endif
3260
3261 diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3262 index 9e193c8..3560fe6 100644
3263 --- a/arch/arm/kvm/arm.c
3264 +++ b/arch/arm/kvm/arm.c
3265 @@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3266 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3267
3268 /* The VMID used in the VTTBR */
3269 -static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3270 +static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3271 static u8 kvm_next_vmid;
3272 static DEFINE_SPINLOCK(kvm_vmid_lock);
3273
3274 @@ -354,7 +354,7 @@ void force_vm_exit(const cpumask_t *mask)
3275 */
3276 static bool need_new_vmid_gen(struct kvm *kvm)
3277 {
3278 - return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3279 + return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3280 }
3281
3282 /**
3283 @@ -387,7 +387,7 @@ static void update_vttbr(struct kvm *kvm)
3284
3285 /* First user of a new VMID generation? */
3286 if (unlikely(kvm_next_vmid == 0)) {
3287 - atomic64_inc(&kvm_vmid_gen);
3288 + atomic64_inc_unchecked(&kvm_vmid_gen);
3289 kvm_next_vmid = 1;
3290
3291 /*
3292 @@ -404,7 +404,7 @@ static void update_vttbr(struct kvm *kvm)
3293 kvm_call_hyp(__kvm_flush_vm_context);
3294 }
3295
3296 - kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3297 + kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3298 kvm->arch.vmid = kvm_next_vmid;
3299 kvm_next_vmid++;
3300
3301 @@ -980,7 +980,7 @@ static void check_kvm_target_cpu(void *ret)
3302 /**
3303 * Initialize Hyp-mode and memory mappings on all CPUs.
3304 */
3305 -int kvm_arch_init(void *opaque)
3306 +int kvm_arch_init(const void *opaque)
3307 {
3308 int err;
3309 int ret, cpu;
3310 diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3311 index 14a0d98..7771a7d 100644
3312 --- a/arch/arm/lib/clear_user.S
3313 +++ b/arch/arm/lib/clear_user.S
3314 @@ -12,14 +12,14 @@
3315
3316 .text
3317
3318 -/* Prototype: int __clear_user(void *addr, size_t sz)
3319 +/* Prototype: int ___clear_user(void *addr, size_t sz)
3320 * Purpose : clear some user memory
3321 * Params : addr - user memory address to clear
3322 * : sz - number of bytes to clear
3323 * Returns : number of bytes NOT cleared
3324 */
3325 ENTRY(__clear_user_std)
3326 -WEAK(__clear_user)
3327 +WEAK(___clear_user)
3328 stmfd sp!, {r1, lr}
3329 mov r2, #0
3330 cmp r1, #4
3331 @@ -44,7 +44,7 @@ WEAK(__clear_user)
3332 USER( strnebt r2, [r0])
3333 mov r0, #0
3334 ldmfd sp!, {r1, pc}
3335 -ENDPROC(__clear_user)
3336 +ENDPROC(___clear_user)
3337 ENDPROC(__clear_user_std)
3338
3339 .pushsection .fixup,"ax"
3340 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3341 index 66a477a..bee61d3 100644
3342 --- a/arch/arm/lib/copy_from_user.S
3343 +++ b/arch/arm/lib/copy_from_user.S
3344 @@ -16,7 +16,7 @@
3345 /*
3346 * Prototype:
3347 *
3348 - * size_t __copy_from_user(void *to, const void *from, size_t n)
3349 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
3350 *
3351 * Purpose:
3352 *
3353 @@ -84,11 +84,11 @@
3354
3355 .text
3356
3357 -ENTRY(__copy_from_user)
3358 +ENTRY(___copy_from_user)
3359
3360 #include "copy_template.S"
3361
3362 -ENDPROC(__copy_from_user)
3363 +ENDPROC(___copy_from_user)
3364
3365 .pushsection .fixup,"ax"
3366 .align 0
3367 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3368 index 6ee2f67..d1cce76 100644
3369 --- a/arch/arm/lib/copy_page.S
3370 +++ b/arch/arm/lib/copy_page.S
3371 @@ -10,6 +10,7 @@
3372 * ASM optimised string functions
3373 */
3374 #include <linux/linkage.h>
3375 +#include <linux/const.h>
3376 #include <asm/assembler.h>
3377 #include <asm/asm-offsets.h>
3378 #include <asm/cache.h>
3379 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3380 index d066df6..df28194 100644
3381 --- a/arch/arm/lib/copy_to_user.S
3382 +++ b/arch/arm/lib/copy_to_user.S
3383 @@ -16,7 +16,7 @@
3384 /*
3385 * Prototype:
3386 *
3387 - * size_t __copy_to_user(void *to, const void *from, size_t n)
3388 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
3389 *
3390 * Purpose:
3391 *
3392 @@ -88,11 +88,11 @@
3393 .text
3394
3395 ENTRY(__copy_to_user_std)
3396 -WEAK(__copy_to_user)
3397 +WEAK(___copy_to_user)
3398
3399 #include "copy_template.S"
3400
3401 -ENDPROC(__copy_to_user)
3402 +ENDPROC(___copy_to_user)
3403 ENDPROC(__copy_to_user_std)
3404
3405 .pushsection .fixup,"ax"
3406 diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3407 index 7d08b43..f7ca7ea 100644
3408 --- a/arch/arm/lib/csumpartialcopyuser.S
3409 +++ b/arch/arm/lib/csumpartialcopyuser.S
3410 @@ -57,8 +57,8 @@
3411 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3412 */
3413
3414 -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3415 -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3416 +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3417 +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3418
3419 #include "csumpartialcopygeneric.S"
3420
3421 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3422 index 312d43e..21d2322 100644
3423 --- a/arch/arm/lib/delay.c
3424 +++ b/arch/arm/lib/delay.c
3425 @@ -29,7 +29,7 @@
3426 /*
3427 * Default to the loop-based delay implementation.
3428 */
3429 -struct arm_delay_ops arm_delay_ops = {
3430 +struct arm_delay_ops arm_delay_ops __read_only = {
3431 .delay = __loop_delay,
3432 .const_udelay = __loop_const_udelay,
3433 .udelay = __loop_udelay,
3434 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3435 index 3e58d71..029817c 100644
3436 --- a/arch/arm/lib/uaccess_with_memcpy.c
3437 +++ b/arch/arm/lib/uaccess_with_memcpy.c
3438 @@ -136,7 +136,7 @@ out:
3439 }
3440
3441 unsigned long
3442 -__copy_to_user(void __user *to, const void *from, unsigned long n)
3443 +___copy_to_user(void __user *to, const void *from, unsigned long n)
3444 {
3445 /*
3446 * This test is stubbed out of the main function above to keep
3447 @@ -190,7 +190,7 @@ out:
3448 return n;
3449 }
3450
3451 -unsigned long __clear_user(void __user *addr, unsigned long n)
3452 +unsigned long ___clear_user(void __user *addr, unsigned long n)
3453 {
3454 /* See rational for this in __copy_to_user() above. */
3455 if (n < 64)
3456 diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3457 index 9610792..4dfb851 100644
3458 --- a/arch/arm/mach-at91/setup.c
3459 +++ b/arch/arm/mach-at91/setup.c
3460 @@ -83,7 +83,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3461
3462 desc->pfn = __phys_to_pfn(base);
3463 desc->length = length;
3464 - desc->type = MT_MEMORY_RWX_NONCACHED;
3465 + desc->type = MT_MEMORY_RW_NONCACHED;
3466
3467 pr_info("sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3468 base, length, desc->virtual);
3469 diff --git a/arch/arm/mach-keystone/keystone.c b/arch/arm/mach-keystone/keystone.c
3470 index 7f352de..6dc0929 100644
3471 --- a/arch/arm/mach-keystone/keystone.c
3472 +++ b/arch/arm/mach-keystone/keystone.c
3473 @@ -27,7 +27,7 @@
3474
3475 #include "keystone.h"
3476
3477 -static struct notifier_block platform_nb;
3478 +static notifier_block_no_const platform_nb;
3479 static unsigned long keystone_dma_pfn_offset __read_mostly;
3480
3481 static int keystone_platform_notifier(struct notifier_block *nb,
3482 diff --git a/arch/arm/mach-mvebu/coherency.c b/arch/arm/mach-mvebu/coherency.c
3483 index 044b511..afd1da8 100644
3484 --- a/arch/arm/mach-mvebu/coherency.c
3485 +++ b/arch/arm/mach-mvebu/coherency.c
3486 @@ -316,7 +316,7 @@ static void __init armada_370_coherency_init(struct device_node *np)
3487
3488 /*
3489 * This ioremap hook is used on Armada 375/38x to ensure that PCIe
3490 - * memory areas are mapped as MT_UNCACHED instead of MT_DEVICE. This
3491 + * memory areas are mapped as MT_UNCACHED_RW instead of MT_DEVICE. This
3492 * is needed as a workaround for a deadlock issue between the PCIe
3493 * interface and the cache controller.
3494 */
3495 @@ -329,7 +329,7 @@ armada_pcie_wa_ioremap_caller(phys_addr_t phys_addr, size_t size,
3496 mvebu_mbus_get_pcie_mem_aperture(&pcie_mem);
3497
3498 if (pcie_mem.start <= phys_addr && (phys_addr + size) <= pcie_mem.end)
3499 - mtype = MT_UNCACHED;
3500 + mtype = MT_UNCACHED_RW;
3501
3502 return __arm_ioremap_caller(phys_addr, size, mtype, caller);
3503 }
3504 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3505 index 97767a2..9233746 100644
3506 --- a/arch/arm/mach-omap2/board-n8x0.c
3507 +++ b/arch/arm/mach-omap2/board-n8x0.c
3508 @@ -569,7 +569,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3509 }
3510 #endif
3511
3512 -struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3513 +struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3514 .late_init = n8x0_menelaus_late_init,
3515 };
3516
3517 diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3518 index 5fa3755..1e8c247 100644
3519 --- a/arch/arm/mach-omap2/gpmc.c
3520 +++ b/arch/arm/mach-omap2/gpmc.c
3521 @@ -151,7 +151,6 @@ struct omap3_gpmc_regs {
3522 };
3523
3524 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3525 -static struct irq_chip gpmc_irq_chip;
3526 static int gpmc_irq_start;
3527
3528 static struct resource gpmc_mem_root;
3529 @@ -736,6 +735,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3530
3531 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3532
3533 +static struct irq_chip gpmc_irq_chip = {
3534 + .name = "gpmc",
3535 + .irq_startup = gpmc_irq_noop_ret,
3536 + .irq_enable = gpmc_irq_enable,
3537 + .irq_disable = gpmc_irq_disable,
3538 + .irq_shutdown = gpmc_irq_noop,
3539 + .irq_ack = gpmc_irq_noop,
3540 + .irq_mask = gpmc_irq_noop,
3541 + .irq_unmask = gpmc_irq_noop,
3542 +
3543 +};
3544 +
3545 static int gpmc_setup_irq(void)
3546 {
3547 int i;
3548 @@ -750,15 +761,6 @@ static int gpmc_setup_irq(void)
3549 return gpmc_irq_start;
3550 }
3551
3552 - gpmc_irq_chip.name = "gpmc";
3553 - gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3554 - gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3555 - gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3556 - gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3557 - gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3558 - gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3559 - gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3560 -
3561 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3562 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3563
3564 diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3565 index 6944ae3..bc587ca 100644
3566 --- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3567 +++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3568 @@ -86,7 +86,7 @@ struct cpu_pm_ops {
3569 void (*resume)(void);
3570 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3571 void (*hotplug_restart)(void);
3572 -};
3573 +} __no_const;
3574
3575 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3576 static struct powerdomain *mpuss_pd;
3577 @@ -105,7 +105,7 @@ static void dummy_cpu_resume(void)
3578 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3579 {}
3580
3581 -struct cpu_pm_ops omap_pm_ops = {
3582 +static struct cpu_pm_ops omap_pm_ops __read_only = {
3583 .finish_suspend = default_finish_suspend,
3584 .resume = dummy_cpu_resume,
3585 .scu_prepare = dummy_scu_prepare,
3586 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3587 index f961c46..4a453dc 100644
3588 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
3589 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3590 @@ -344,7 +344,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3591 return NOTIFY_OK;
3592 }
3593
3594 -static struct notifier_block __refdata irq_hotplug_notifier = {
3595 +static struct notifier_block irq_hotplug_notifier = {
3596 .notifier_call = irq_cpu_hotplug_notify,
3597 };
3598
3599 diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3600 index 8c58b71..95b655f 100644
3601 --- a/arch/arm/mach-omap2/omap_device.c
3602 +++ b/arch/arm/mach-omap2/omap_device.c
3603 @@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
3604 struct platform_device __init *omap_device_build(const char *pdev_name,
3605 int pdev_id,
3606 struct omap_hwmod *oh,
3607 - void *pdata, int pdata_len)
3608 + const void *pdata, int pdata_len)
3609 {
3610 struct omap_hwmod *ohs[] = { oh };
3611
3612 @@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3613 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3614 int pdev_id,
3615 struct omap_hwmod **ohs,
3616 - int oh_cnt, void *pdata,
3617 + int oh_cnt, const void *pdata,
3618 int pdata_len)
3619 {
3620 int ret = -ENOMEM;
3621 diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3622 index 78c02b3..c94109a 100644
3623 --- a/arch/arm/mach-omap2/omap_device.h
3624 +++ b/arch/arm/mach-omap2/omap_device.h
3625 @@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3626 /* Core code interface */
3627
3628 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3629 - struct omap_hwmod *oh, void *pdata,
3630 + struct omap_hwmod *oh, const void *pdata,
3631 int pdata_len);
3632
3633 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3634 struct omap_hwmod **oh, int oh_cnt,
3635 - void *pdata, int pdata_len);
3636 + const void *pdata, int pdata_len);
3637
3638 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3639 struct omap_hwmod **ohs, int oh_cnt);
3640 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3641 index 716247e..8df346d 100644
3642 --- a/arch/arm/mach-omap2/omap_hwmod.c
3643 +++ b/arch/arm/mach-omap2/omap_hwmod.c
3644 @@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3645 int (*init_clkdm)(struct omap_hwmod *oh);
3646 void (*update_context_lost)(struct omap_hwmod *oh);
3647 int (*get_context_lost)(struct omap_hwmod *oh);
3648 -};
3649 +} __no_const;
3650
3651 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3652 -static struct omap_hwmod_soc_ops soc_ops;
3653 +static struct omap_hwmod_soc_ops soc_ops __read_only;
3654
3655 /* omap_hwmod_list contains all registered struct omap_hwmods */
3656 static LIST_HEAD(omap_hwmod_list);
3657 diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3658 index 95fee54..cfa9cf1 100644
3659 --- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3660 +++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3661 @@ -10,6 +10,7 @@
3662
3663 #include <linux/kernel.h>
3664 #include <linux/init.h>
3665 +#include <asm/pgtable.h>
3666
3667 #include "powerdomain.h"
3668
3669 @@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3670
3671 void __init am43xx_powerdomains_init(void)
3672 {
3673 - omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3674 + pax_open_kernel();
3675 + *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3676 + pax_close_kernel();
3677 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3678 pwrdm_register_pwrdms(powerdomains_am43xx);
3679 pwrdm_complete_init();
3680 diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3681 index ff0a68c..b312aa0 100644
3682 --- a/arch/arm/mach-omap2/wd_timer.c
3683 +++ b/arch/arm/mach-omap2/wd_timer.c
3684 @@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3685 struct omap_hwmod *oh;
3686 char *oh_name = "wd_timer2";
3687 char *dev_name = "omap_wdt";
3688 - struct omap_wd_timer_platform_data pdata;
3689 + static struct omap_wd_timer_platform_data pdata = {
3690 + .read_reset_sources = prm_read_reset_sources
3691 + };
3692
3693 if (!cpu_class_is_omap2() || of_have_populated_dt())
3694 return 0;
3695 @@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3696 return -EINVAL;
3697 }
3698
3699 - pdata.read_reset_sources = prm_read_reset_sources;
3700 -
3701 pdev = omap_device_build(dev_name, id, oh, &pdata,
3702 sizeof(struct omap_wd_timer_platform_data));
3703 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3704 diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3705 index b30bf5c..d0825bf 100644
3706 --- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3707 +++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3708 @@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3709 bool entered_lp2 = false;
3710
3711 if (tegra_pending_sgi())
3712 - ACCESS_ONCE(abort_flag) = true;
3713 + ACCESS_ONCE_RW(abort_flag) = true;
3714
3715 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3716
3717 diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3718 index 2dea8b5..6499da2 100644
3719 --- a/arch/arm/mach-ux500/setup.h
3720 +++ b/arch/arm/mach-ux500/setup.h
3721 @@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
3722 .type = MT_DEVICE, \
3723 }
3724
3725 -#define __MEM_DEV_DESC(x, sz) { \
3726 - .virtual = IO_ADDRESS(x), \
3727 - .pfn = __phys_to_pfn(x), \
3728 - .length = sz, \
3729 - .type = MT_MEMORY_RWX, \
3730 -}
3731 -
3732 extern struct smp_operations ux500_smp_ops;
3733 extern void ux500_cpu_die(unsigned int cpu);
3734
3735 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3736 index 7eb94e6..799ad3e 100644
3737 --- a/arch/arm/mm/Kconfig
3738 +++ b/arch/arm/mm/Kconfig
3739 @@ -446,6 +446,7 @@ config CPU_32v5
3740
3741 config CPU_32v6
3742 bool
3743 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3744 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3745
3746 config CPU_32v6K
3747 @@ -600,6 +601,7 @@ config CPU_CP15_MPU
3748
3749 config CPU_USE_DOMAINS
3750 bool
3751 + depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3752 help
3753 This option enables or disables the use of domain switching
3754 via the set_fs() function.
3755 @@ -798,7 +800,7 @@ config NEED_KUSER_HELPERS
3756
3757 config KUSER_HELPERS
3758 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3759 - depends on MMU
3760 + depends on MMU && (!(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND)
3761 default y
3762 help
3763 Warning: disabling this option may break user programs.
3764 @@ -812,7 +814,7 @@ config KUSER_HELPERS
3765 See Documentation/arm/kernel_user_helpers.txt for details.
3766
3767 However, the fixed address nature of these helpers can be used
3768 - by ROP (return orientated programming) authors when creating
3769 + by ROP (Return Oriented Programming) authors when creating
3770 exploits.
3771
3772 If all of the binaries and libraries which run on your platform
3773 diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3774 index 83792f4..c25d36b 100644
3775 --- a/arch/arm/mm/alignment.c
3776 +++ b/arch/arm/mm/alignment.c
3777 @@ -216,10 +216,12 @@ union offset_union {
3778 #define __get16_unaligned_check(ins,val,addr) \
3779 do { \
3780 unsigned int err = 0, v, a = addr; \
3781 + pax_open_userland(); \
3782 __get8_unaligned_check(ins,v,a,err); \
3783 val = v << ((BE) ? 8 : 0); \
3784 __get8_unaligned_check(ins,v,a,err); \
3785 val |= v << ((BE) ? 0 : 8); \
3786 + pax_close_userland(); \
3787 if (err) \
3788 goto fault; \
3789 } while (0)
3790 @@ -233,6 +235,7 @@ union offset_union {
3791 #define __get32_unaligned_check(ins,val,addr) \
3792 do { \
3793 unsigned int err = 0, v, a = addr; \
3794 + pax_open_userland(); \
3795 __get8_unaligned_check(ins,v,a,err); \
3796 val = v << ((BE) ? 24 : 0); \
3797 __get8_unaligned_check(ins,v,a,err); \
3798 @@ -241,6 +244,7 @@ union offset_union {
3799 val |= v << ((BE) ? 8 : 16); \
3800 __get8_unaligned_check(ins,v,a,err); \
3801 val |= v << ((BE) ? 0 : 24); \
3802 + pax_close_userland(); \
3803 if (err) \
3804 goto fault; \
3805 } while (0)
3806 @@ -254,6 +258,7 @@ union offset_union {
3807 #define __put16_unaligned_check(ins,val,addr) \
3808 do { \
3809 unsigned int err = 0, v = val, a = addr; \
3810 + pax_open_userland(); \
3811 __asm__( FIRST_BYTE_16 \
3812 ARM( "1: "ins" %1, [%2], #1\n" ) \
3813 THUMB( "1: "ins" %1, [%2]\n" ) \
3814 @@ -273,6 +278,7 @@ union offset_union {
3815 " .popsection\n" \
3816 : "=r" (err), "=&r" (v), "=&r" (a) \
3817 : "0" (err), "1" (v), "2" (a)); \
3818 + pax_close_userland(); \
3819 if (err) \
3820 goto fault; \
3821 } while (0)
3822 @@ -286,6 +292,7 @@ union offset_union {
3823 #define __put32_unaligned_check(ins,val,addr) \
3824 do { \
3825 unsigned int err = 0, v = val, a = addr; \
3826 + pax_open_userland(); \
3827 __asm__( FIRST_BYTE_32 \
3828 ARM( "1: "ins" %1, [%2], #1\n" ) \
3829 THUMB( "1: "ins" %1, [%2]\n" ) \
3830 @@ -315,6 +322,7 @@ union offset_union {
3831 " .popsection\n" \
3832 : "=r" (err), "=&r" (v), "=&r" (a) \
3833 : "0" (err), "1" (v), "2" (a)); \
3834 + pax_close_userland(); \
3835 if (err) \
3836 goto fault; \
3837 } while (0)
3838 diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3839 index 5e65ca8..879e7b3 100644
3840 --- a/arch/arm/mm/cache-l2x0.c
3841 +++ b/arch/arm/mm/cache-l2x0.c
3842 @@ -42,7 +42,7 @@ struct l2c_init_data {
3843 void (*fixup)(void __iomem *, u32, struct outer_cache_fns *);
3844 void (*save)(void __iomem *);
3845 struct outer_cache_fns outer_cache;
3846 -};
3847 +} __do_const;
3848
3849 #define CACHE_LINE_SIZE 32
3850
3851 diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3852 index 6eb97b3..ac509f6 100644
3853 --- a/arch/arm/mm/context.c
3854 +++ b/arch/arm/mm/context.c
3855 @@ -43,7 +43,7 @@
3856 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3857
3858 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3859 -static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3860 +static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3861 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3862
3863 static DEFINE_PER_CPU(atomic64_t, active_asids);
3864 @@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3865 {
3866 static u32 cur_idx = 1;
3867 u64 asid = atomic64_read(&mm->context.id);
3868 - u64 generation = atomic64_read(&asid_generation);
3869 + u64 generation = atomic64_read_unchecked(&asid_generation);
3870
3871 if (asid != 0 && is_reserved_asid(asid)) {
3872 /*
3873 @@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3874 */
3875 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
3876 if (asid == NUM_USER_ASIDS) {
3877 - generation = atomic64_add_return(ASID_FIRST_VERSION,
3878 + generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3879 &asid_generation);
3880 flush_context(cpu);
3881 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3882 @@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3883 cpu_set_reserved_ttbr0();
3884
3885 asid = atomic64_read(&mm->context.id);
3886 - if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3887 + if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3888 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3889 goto switch_mm_fastpath;
3890
3891 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3892 /* Check that our ASID belongs to the current generation. */
3893 asid = atomic64_read(&mm->context.id);
3894 - if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3895 + if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3896 asid = new_context(mm, cpu);
3897 atomic64_set(&mm->context.id, asid);
3898 }
3899 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3900 index eb8830a..e8ff52e 100644
3901 --- a/arch/arm/mm/fault.c
3902 +++ b/arch/arm/mm/fault.c
3903 @@ -25,6 +25,7 @@
3904 #include <asm/system_misc.h>
3905 #include <asm/system_info.h>
3906 #include <asm/tlbflush.h>
3907 +#include <asm/sections.h>
3908
3909 #include "fault.h"
3910
3911 @@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3912 if (fixup_exception(regs))
3913 return;
3914
3915 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3916 + if (addr < TASK_SIZE) {
3917 + if (current->signal->curr_ip)
3918 + 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),
3919 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3920 + else
3921 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3922 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3923 + }
3924 +#endif
3925 +
3926 +#ifdef CONFIG_PAX_KERNEXEC
3927 + if ((fsr & FSR_WRITE) &&
3928 + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3929 + (MODULES_VADDR <= addr && addr < MODULES_END)))
3930 + {
3931 + if (current->signal->curr_ip)
3932 + 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),
3933 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3934 + else
3935 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3936 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3937 + }
3938 +#endif
3939 +
3940 /*
3941 * No handler, we'll have to terminate things with extreme prejudice.
3942 */
3943 @@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3944 }
3945 #endif
3946
3947 +#ifdef CONFIG_PAX_PAGEEXEC
3948 + if (fsr & FSR_LNX_PF) {
3949 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3950 + do_group_exit(SIGKILL);
3951 + }
3952 +#endif
3953 +
3954 tsk->thread.address = addr;
3955 tsk->thread.error_code = fsr;
3956 tsk->thread.trap_no = 14;
3957 @@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3958 }
3959 #endif /* CONFIG_MMU */
3960
3961 +#ifdef CONFIG_PAX_PAGEEXEC
3962 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3963 +{
3964 + long i;
3965 +
3966 + printk(KERN_ERR "PAX: bytes at PC: ");
3967 + for (i = 0; i < 20; i++) {
3968 + unsigned char c;
3969 + if (get_user(c, (__force unsigned char __user *)pc+i))
3970 + printk(KERN_CONT "?? ");
3971 + else
3972 + printk(KERN_CONT "%02x ", c);
3973 + }
3974 + printk("\n");
3975 +
3976 + printk(KERN_ERR "PAX: bytes at SP-4: ");
3977 + for (i = -1; i < 20; i++) {
3978 + unsigned long c;
3979 + if (get_user(c, (__force unsigned long __user *)sp+i))
3980 + printk(KERN_CONT "???????? ");
3981 + else
3982 + printk(KERN_CONT "%08lx ", c);
3983 + }
3984 + printk("\n");
3985 +}
3986 +#endif
3987 +
3988 /*
3989 * First Level Translation Fault Handler
3990 *
3991 @@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3992 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3993 struct siginfo info;
3994
3995 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3996 + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3997 + if (current->signal->curr_ip)
3998 + 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),
3999 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4000 + else
4001 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4002 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4003 + goto die;
4004 + }
4005 +#endif
4006 +
4007 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
4008 return;
4009
4010 +die:
4011 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
4012 inf->name, fsr, addr);
4013
4014 @@ -574,15 +647,104 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
4015 ifsr_info[nr].name = name;
4016 }
4017
4018 +asmlinkage int sys_sigreturn(struct pt_regs *regs);
4019 +asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
4020 +
4021 asmlinkage void __exception
4022 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
4023 {
4024 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
4025 struct siginfo info;
4026 + unsigned long pc = instruction_pointer(regs);
4027 +
4028 + if (user_mode(regs)) {
4029 + unsigned long sigpage = current->mm->context.sigpage;
4030 +
4031 + if (sigpage <= pc && pc < sigpage + 7*4) {
4032 + if (pc < sigpage + 3*4)
4033 + sys_sigreturn(regs);
4034 + else
4035 + sys_rt_sigreturn(regs);
4036 + return;
4037 + }
4038 + if (pc == 0xffff0f60UL) {
4039 + /*
4040 + * PaX: __kuser_cmpxchg64 emulation
4041 + */
4042 + // TODO
4043 + //regs->ARM_pc = regs->ARM_lr;
4044 + //return;
4045 + }
4046 + if (pc == 0xffff0fa0UL) {
4047 + /*
4048 + * PaX: __kuser_memory_barrier emulation
4049 + */
4050 + // dmb(); implied by the exception
4051 + regs->ARM_pc = regs->ARM_lr;
4052 + return;
4053 + }
4054 + if (pc == 0xffff0fc0UL) {
4055 + /*
4056 + * PaX: __kuser_cmpxchg emulation
4057 + */
4058 + // TODO
4059 + //long new;
4060 + //int op;
4061 +
4062 + //op = FUTEX_OP_SET << 28;
4063 + //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4064 + //regs->ARM_r0 = old != new;
4065 + //regs->ARM_pc = regs->ARM_lr;
4066 + //return;
4067 + }
4068 + if (pc == 0xffff0fe0UL) {
4069 + /*
4070 + * PaX: __kuser_get_tls emulation
4071 + */
4072 + regs->ARM_r0 = current_thread_info()->tp_value[0];
4073 + regs->ARM_pc = regs->ARM_lr;
4074 + return;
4075 + }
4076 + }
4077 +
4078 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4079 + else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4080 + if (current->signal->curr_ip)
4081 + 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),
4082 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4083 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4084 + else
4085 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4086 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4087 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4088 + goto die;
4089 + }
4090 +#endif
4091 +
4092 +#ifdef CONFIG_PAX_REFCOUNT
4093 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4094 +#ifdef CONFIG_THUMB2_KERNEL
4095 + unsigned short bkpt;
4096 +
4097 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le16(bkpt) == 0xbef1) {
4098 +#else
4099 + unsigned int bkpt;
4100 +
4101 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4102 +#endif
4103 + current->thread.error_code = ifsr;
4104 + current->thread.trap_no = 0;
4105 + pax_report_refcount_overflow(regs);
4106 + fixup_exception(regs);
4107 + return;
4108 + }
4109 + }
4110 +#endif
4111
4112 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4113 return;
4114
4115 +die:
4116 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4117 inf->name, ifsr, addr);
4118
4119 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4120 index cf08bdf..772656c 100644
4121 --- a/arch/arm/mm/fault.h
4122 +++ b/arch/arm/mm/fault.h
4123 @@ -3,6 +3,7 @@
4124
4125 /*
4126 * Fault status register encodings. We steal bit 31 for our own purposes.
4127 + * Set when the FSR value is from an instruction fault.
4128 */
4129 #define FSR_LNX_PF (1 << 31)
4130 #define FSR_WRITE (1 << 11)
4131 @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4132 }
4133 #endif
4134
4135 +/* valid for LPAE and !LPAE */
4136 +static inline int is_xn_fault(unsigned int fsr)
4137 +{
4138 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
4139 +}
4140 +
4141 +static inline int is_domain_fault(unsigned int fsr)
4142 +{
4143 + return ((fsr_fs(fsr) & 0xD) == 0x9);
4144 +}
4145 +
4146 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4147 unsigned long search_exception_table(unsigned long addr);
4148
4149 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4150 index 9481f85..6dae261 100644
4151 --- a/arch/arm/mm/init.c
4152 +++ b/arch/arm/mm/init.c
4153 @@ -31,6 +31,8 @@
4154 #include <asm/setup.h>
4155 #include <asm/tlb.h>
4156 #include <asm/fixmap.h>
4157 +#include <asm/system_info.h>
4158 +#include <asm/cp15.h>
4159
4160 #include <asm/mach/arch.h>
4161 #include <asm/mach/map.h>
4162 @@ -619,7 +621,46 @@ void free_initmem(void)
4163 {
4164 #ifdef CONFIG_HAVE_TCM
4165 extern char __tcm_start, __tcm_end;
4166 +#endif
4167
4168 +#ifdef CONFIG_PAX_KERNEXEC
4169 + unsigned long addr;
4170 + pgd_t *pgd;
4171 + pud_t *pud;
4172 + pmd_t *pmd;
4173 + int cpu_arch = cpu_architecture();
4174 + unsigned int cr = get_cr();
4175 +
4176 + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4177 + /* make pages tables, etc before .text NX */
4178 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4179 + pgd = pgd_offset_k(addr);
4180 + pud = pud_offset(pgd, addr);
4181 + pmd = pmd_offset(pud, addr);
4182 + __section_update(pmd, addr, PMD_SECT_XN);
4183 + }
4184 + /* make init NX */
4185 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4186 + pgd = pgd_offset_k(addr);
4187 + pud = pud_offset(pgd, addr);
4188 + pmd = pmd_offset(pud, addr);
4189 + __section_update(pmd, addr, PMD_SECT_XN);
4190 + }
4191 + /* make kernel code/rodata RX */
4192 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4193 + pgd = pgd_offset_k(addr);
4194 + pud = pud_offset(pgd, addr);
4195 + pmd = pmd_offset(pud, addr);
4196 +#ifdef CONFIG_ARM_LPAE
4197 + __section_update(pmd, addr, PMD_SECT_RDONLY);
4198 +#else
4199 + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4200 +#endif
4201 + }
4202 + }
4203 +#endif
4204 +
4205 +#ifdef CONFIG_HAVE_TCM
4206 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4207 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4208 #endif
4209 diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4210 index d1e5ad7..84dcbf2 100644
4211 --- a/arch/arm/mm/ioremap.c
4212 +++ b/arch/arm/mm/ioremap.c
4213 @@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4214 unsigned int mtype;
4215
4216 if (cached)
4217 - mtype = MT_MEMORY_RWX;
4218 + mtype = MT_MEMORY_RX;
4219 else
4220 - mtype = MT_MEMORY_RWX_NONCACHED;
4221 + mtype = MT_MEMORY_RX_NONCACHED;
4222
4223 return __arm_ioremap_caller(phys_addr, size, mtype,
4224 __builtin_return_address(0));
4225 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4226 index 5e85ed3..b10a7ed 100644
4227 --- a/arch/arm/mm/mmap.c
4228 +++ b/arch/arm/mm/mmap.c
4229 @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4230 struct vm_area_struct *vma;
4231 int do_align = 0;
4232 int aliasing = cache_is_vipt_aliasing();
4233 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4234 struct vm_unmapped_area_info info;
4235
4236 /*
4237 @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4238 if (len > TASK_SIZE)
4239 return -ENOMEM;
4240
4241 +#ifdef CONFIG_PAX_RANDMMAP
4242 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4243 +#endif
4244 +
4245 if (addr) {
4246 if (do_align)
4247 addr = COLOUR_ALIGN(addr, pgoff);
4248 @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4249 addr = PAGE_ALIGN(addr);
4250
4251 vma = find_vma(mm, addr);
4252 - if (TASK_SIZE - len >= addr &&
4253 - (!vma || addr + len <= vma->vm_start))
4254 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4255 return addr;
4256 }
4257
4258 @@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4259 info.high_limit = TASK_SIZE;
4260 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4261 info.align_offset = pgoff << PAGE_SHIFT;
4262 + info.threadstack_offset = offset;
4263 return vm_unmapped_area(&info);
4264 }
4265
4266 @@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4267 unsigned long addr = addr0;
4268 int do_align = 0;
4269 int aliasing = cache_is_vipt_aliasing();
4270 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4271 struct vm_unmapped_area_info info;
4272
4273 /*
4274 @@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4275 return addr;
4276 }
4277
4278 +#ifdef CONFIG_PAX_RANDMMAP
4279 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4280 +#endif
4281 +
4282 /* requesting a specific address */
4283 if (addr) {
4284 if (do_align)
4285 @@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4286 else
4287 addr = PAGE_ALIGN(addr);
4288 vma = find_vma(mm, addr);
4289 - if (TASK_SIZE - len >= addr &&
4290 - (!vma || addr + len <= vma->vm_start))
4291 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4292 return addr;
4293 }
4294
4295 @@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4296 info.high_limit = mm->mmap_base;
4297 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4298 info.align_offset = pgoff << PAGE_SHIFT;
4299 + info.threadstack_offset = offset;
4300 addr = vm_unmapped_area(&info);
4301
4302 /*
4303 @@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4304 {
4305 unsigned long random_factor = 0UL;
4306
4307 +#ifdef CONFIG_PAX_RANDMMAP
4308 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4309 +#endif
4310 +
4311 /* 8 bits of randomness in 20 address space bits */
4312 if ((current->flags & PF_RANDOMIZE) &&
4313 !(current->personality & ADDR_NO_RANDOMIZE))
4314 @@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4315
4316 if (mmap_is_legacy()) {
4317 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4318 +
4319 +#ifdef CONFIG_PAX_RANDMMAP
4320 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4321 + mm->mmap_base += mm->delta_mmap;
4322 +#endif
4323 +
4324 mm->get_unmapped_area = arch_get_unmapped_area;
4325 } else {
4326 mm->mmap_base = mmap_base(random_factor);
4327 +
4328 +#ifdef CONFIG_PAX_RANDMMAP
4329 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4330 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4331 +#endif
4332 +
4333 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4334 }
4335 }
4336 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4337 index 9f98cec..115fcb6 100644
4338 --- a/arch/arm/mm/mmu.c
4339 +++ b/arch/arm/mm/mmu.c
4340 @@ -40,6 +40,22 @@
4341 #include "mm.h"
4342 #include "tcm.h"
4343
4344 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4345 +void modify_domain(unsigned int dom, unsigned int type)
4346 +{
4347 + struct thread_info *thread = current_thread_info();
4348 + unsigned int domain = thread->cpu_domain;
4349 + /*
4350 + * DOMAIN_MANAGER might be defined to some other value,
4351 + * use the arch-defined constant
4352 + */
4353 + domain &= ~domain_val(dom, 3);
4354 + thread->cpu_domain = domain | domain_val(dom, type);
4355 + set_domain(thread->cpu_domain);
4356 +}
4357 +EXPORT_SYMBOL(modify_domain);
4358 +#endif
4359 +
4360 /*
4361 * empty_zero_page is a special page that is used for
4362 * zero-initialized data and COW.
4363 @@ -239,7 +255,15 @@ __setup("noalign", noalign_setup);
4364 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4365 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4366
4367 -static struct mem_type mem_types[] = {
4368 +#ifdef CONFIG_PAX_KERNEXEC
4369 +#define L_PTE_KERNEXEC L_PTE_RDONLY
4370 +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4371 +#else
4372 +#define L_PTE_KERNEXEC L_PTE_DIRTY
4373 +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4374 +#endif
4375 +
4376 +static struct mem_type mem_types[] __read_only = {
4377 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4378 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4379 L_PTE_SHARED,
4380 @@ -268,19 +292,19 @@ static struct mem_type mem_types[] = {
4381 .prot_sect = PROT_SECT_DEVICE,
4382 .domain = DOMAIN_IO,
4383 },
4384 - [MT_UNCACHED] = {
4385 + [MT_UNCACHED_RW] = {
4386 .prot_pte = PROT_PTE_DEVICE,
4387 .prot_l1 = PMD_TYPE_TABLE,
4388 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4389 .domain = DOMAIN_IO,
4390 },
4391 - [MT_CACHECLEAN] = {
4392 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4393 + [MT_CACHECLEAN_RO] = {
4394 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4395 .domain = DOMAIN_KERNEL,
4396 },
4397 #ifndef CONFIG_ARM_LPAE
4398 - [MT_MINICLEAN] = {
4399 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4400 + [MT_MINICLEAN_RO] = {
4401 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4402 .domain = DOMAIN_KERNEL,
4403 },
4404 #endif
4405 @@ -288,15 +312,15 @@ static struct mem_type mem_types[] = {
4406 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4407 L_PTE_RDONLY,
4408 .prot_l1 = PMD_TYPE_TABLE,
4409 - .domain = DOMAIN_USER,
4410 + .domain = DOMAIN_VECTORS,
4411 },
4412 [MT_HIGH_VECTORS] = {
4413 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4414 L_PTE_USER | L_PTE_RDONLY,
4415 .prot_l1 = PMD_TYPE_TABLE,
4416 - .domain = DOMAIN_USER,
4417 + .domain = DOMAIN_VECTORS,
4418 },
4419 - [MT_MEMORY_RWX] = {
4420 + [__MT_MEMORY_RWX] = {
4421 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4422 .prot_l1 = PMD_TYPE_TABLE,
4423 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4424 @@ -309,17 +333,30 @@ static struct mem_type mem_types[] = {
4425 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4426 .domain = DOMAIN_KERNEL,
4427 },
4428 - [MT_ROM] = {
4429 - .prot_sect = PMD_TYPE_SECT,
4430 + [MT_MEMORY_RX] = {
4431 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4432 + .prot_l1 = PMD_TYPE_TABLE,
4433 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4434 + .domain = DOMAIN_KERNEL,
4435 + },
4436 + [MT_ROM_RX] = {
4437 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4438 .domain = DOMAIN_KERNEL,
4439 },
4440 - [MT_MEMORY_RWX_NONCACHED] = {
4441 + [MT_MEMORY_RW_NONCACHED] = {
4442 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4443 L_PTE_MT_BUFFERABLE,
4444 .prot_l1 = PMD_TYPE_TABLE,
4445 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4446 .domain = DOMAIN_KERNEL,
4447 },
4448 + [MT_MEMORY_RX_NONCACHED] = {
4449 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4450 + L_PTE_MT_BUFFERABLE,
4451 + .prot_l1 = PMD_TYPE_TABLE,
4452 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4453 + .domain = DOMAIN_KERNEL,
4454 + },
4455 [MT_MEMORY_RW_DTCM] = {
4456 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4457 L_PTE_XN,
4458 @@ -327,9 +364,10 @@ static struct mem_type mem_types[] = {
4459 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4460 .domain = DOMAIN_KERNEL,
4461 },
4462 - [MT_MEMORY_RWX_ITCM] = {
4463 - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4464 + [MT_MEMORY_RX_ITCM] = {
4465 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4466 .prot_l1 = PMD_TYPE_TABLE,
4467 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4468 .domain = DOMAIN_KERNEL,
4469 },
4470 [MT_MEMORY_RW_SO] = {
4471 @@ -547,9 +585,14 @@ static void __init build_mem_type_table(void)
4472 * Mark cache clean areas and XIP ROM read only
4473 * from SVC mode and no access from userspace.
4474 */
4475 - mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4476 - mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4477 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4478 + mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4479 +#ifdef CONFIG_PAX_KERNEXEC
4480 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4481 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4482 + mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4483 +#endif
4484 + mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4485 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4486 #endif
4487
4488 /*
4489 @@ -566,13 +609,17 @@ static void __init build_mem_type_table(void)
4490 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4491 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4492 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4493 - mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4494 - mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4495 + mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4496 + mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4497 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4498 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4499 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4500 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4501 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4502 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
4503 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
4504 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
4505 + mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
4506 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
4507 + mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
4508 }
4509 }
4510
4511 @@ -583,15 +630,20 @@ static void __init build_mem_type_table(void)
4512 if (cpu_arch >= CPU_ARCH_ARMv6) {
4513 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4514 /* Non-cacheable Normal is XCB = 001 */
4515 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4516 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4517 + PMD_SECT_BUFFERED;
4518 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4519 PMD_SECT_BUFFERED;
4520 } else {
4521 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4522 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4523 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4524 + PMD_SECT_TEX(1);
4525 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4526 PMD_SECT_TEX(1);
4527 }
4528 } else {
4529 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4530 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4531 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4532 }
4533
4534 #ifdef CONFIG_ARM_LPAE
4535 @@ -607,6 +659,8 @@ static void __init build_mem_type_table(void)
4536 vecs_pgprot |= PTE_EXT_AF;
4537 #endif
4538
4539 + user_pgprot |= __supported_pte_mask;
4540 +
4541 for (i = 0; i < 16; i++) {
4542 pteval_t v = pgprot_val(protection_map[i]);
4543 protection_map[i] = __pgprot(v | user_pgprot);
4544 @@ -624,21 +678,24 @@ static void __init build_mem_type_table(void)
4545
4546 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4547 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4548 - mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4549 - mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4550 + mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4551 + mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4552 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4553 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4554 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4555 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4556 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4557 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
4558 - mem_types[MT_ROM].prot_sect |= cp->pmd;
4559 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
4560 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
4561 + mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
4562
4563 switch (cp->pmd) {
4564 case PMD_SECT_WT:
4565 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
4566 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
4567 break;
4568 case PMD_SECT_WB:
4569 case PMD_SECT_WBWA:
4570 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
4571 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
4572 break;
4573 }
4574 pr_info("Memory policy: %sData cache %s\n",
4575 @@ -856,7 +913,7 @@ static void __init create_mapping(struct map_desc *md)
4576 return;
4577 }
4578
4579 - if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
4580 + if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
4581 md->virtual >= PAGE_OFFSET &&
4582 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
4583 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
4584 @@ -1224,18 +1281,15 @@ void __init arm_mm_memblock_reserve(void)
4585 * called function. This means you can't use any function or debugging
4586 * method which may touch any device, otherwise the kernel _will_ crash.
4587 */
4588 +
4589 +static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4590 +
4591 static void __init devicemaps_init(const struct machine_desc *mdesc)
4592 {
4593 struct map_desc map;
4594 unsigned long addr;
4595 - void *vectors;
4596
4597 - /*
4598 - * Allocate the vector page early.
4599 - */
4600 - vectors = early_alloc(PAGE_SIZE * 2);
4601 -
4602 - early_trap_init(vectors);
4603 + early_trap_init(&vectors);
4604
4605 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4606 pmd_clear(pmd_off_k(addr));
4607 @@ -1248,7 +1302,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4608 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
4609 map.virtual = MODULES_VADDR;
4610 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
4611 - map.type = MT_ROM;
4612 + map.type = MT_ROM_RX;
4613 create_mapping(&map);
4614 #endif
4615
4616 @@ -1259,14 +1313,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4617 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
4618 map.virtual = FLUSH_BASE;
4619 map.length = SZ_1M;
4620 - map.type = MT_CACHECLEAN;
4621 + map.type = MT_CACHECLEAN_RO;
4622 create_mapping(&map);
4623 #endif
4624 #ifdef FLUSH_BASE_MINICACHE
4625 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
4626 map.virtual = FLUSH_BASE_MINICACHE;
4627 map.length = SZ_1M;
4628 - map.type = MT_MINICLEAN;
4629 + map.type = MT_MINICLEAN_RO;
4630 create_mapping(&map);
4631 #endif
4632
4633 @@ -1275,7 +1329,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4634 * location (0xffff0000). If we aren't using high-vectors, also
4635 * create a mapping at the low-vectors virtual address.
4636 */
4637 - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4638 + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4639 map.virtual = 0xffff0000;
4640 map.length = PAGE_SIZE;
4641 #ifdef CONFIG_KUSER_HELPERS
4642 @@ -1335,8 +1389,10 @@ static void __init kmap_init(void)
4643 static void __init map_lowmem(void)
4644 {
4645 struct memblock_region *reg;
4646 +#ifndef CONFIG_PAX_KERNEXEC
4647 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
4648 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
4649 +#endif
4650
4651 /* Map all the lowmem memory banks. */
4652 for_each_memblock(memory, reg) {
4653 @@ -1349,11 +1405,48 @@ static void __init map_lowmem(void)
4654 if (start >= end)
4655 break;
4656
4657 +#ifdef CONFIG_PAX_KERNEXEC
4658 + map.pfn = __phys_to_pfn(start);
4659 + map.virtual = __phys_to_virt(start);
4660 + map.length = end - start;
4661 +
4662 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4663 + struct map_desc kernel;
4664 + struct map_desc initmap;
4665 +
4666 + /* when freeing initmem we will make this RW */
4667 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4668 + initmap.virtual = (unsigned long)__init_begin;
4669 + initmap.length = _sdata - __init_begin;
4670 + initmap.type = __MT_MEMORY_RWX;
4671 + create_mapping(&initmap);
4672 +
4673 + /* when freeing initmem we will make this RX */
4674 + kernel.pfn = __phys_to_pfn(__pa(_stext));
4675 + kernel.virtual = (unsigned long)_stext;
4676 + kernel.length = __init_begin - _stext;
4677 + kernel.type = __MT_MEMORY_RWX;
4678 + create_mapping(&kernel);
4679 +
4680 + if (map.virtual < (unsigned long)_stext) {
4681 + map.length = (unsigned long)_stext - map.virtual;
4682 + map.type = __MT_MEMORY_RWX;
4683 + create_mapping(&map);
4684 + }
4685 +
4686 + map.pfn = __phys_to_pfn(__pa(_sdata));
4687 + map.virtual = (unsigned long)_sdata;
4688 + map.length = end - __pa(_sdata);
4689 + }
4690 +
4691 + map.type = MT_MEMORY_RW;
4692 + create_mapping(&map);
4693 +#else
4694 if (end < kernel_x_start || start >= kernel_x_end) {
4695 map.pfn = __phys_to_pfn(start);
4696 map.virtual = __phys_to_virt(start);
4697 map.length = end - start;
4698 - map.type = MT_MEMORY_RWX;
4699 + map.type = __MT_MEMORY_RWX;
4700
4701 create_mapping(&map);
4702 } else {
4703 @@ -1370,7 +1463,7 @@ static void __init map_lowmem(void)
4704 map.pfn = __phys_to_pfn(kernel_x_start);
4705 map.virtual = __phys_to_virt(kernel_x_start);
4706 map.length = kernel_x_end - kernel_x_start;
4707 - map.type = MT_MEMORY_RWX;
4708 + map.type = __MT_MEMORY_RWX;
4709
4710 create_mapping(&map);
4711
4712 @@ -1383,6 +1476,7 @@ static void __init map_lowmem(void)
4713 create_mapping(&map);
4714 }
4715 }
4716 +#endif
4717 }
4718 }
4719
4720 diff --git a/arch/arm/net/bpf_jit_32.c b/arch/arm/net/bpf_jit_32.c
4721 index e1268f9..a9755a7 100644
4722 --- a/arch/arm/net/bpf_jit_32.c
4723 +++ b/arch/arm/net/bpf_jit_32.c
4724 @@ -20,6 +20,7 @@
4725 #include <asm/cacheflush.h>
4726 #include <asm/hwcap.h>
4727 #include <asm/opcodes.h>
4728 +#include <asm/pgtable.h>
4729
4730 #include "bpf_jit_32.h"
4731
4732 @@ -71,7 +72,11 @@ struct jit_ctx {
4733 #endif
4734 };
4735
4736 +#ifdef CONFIG_GRKERNSEC_BPF_HARDEN
4737 +int bpf_jit_enable __read_only;
4738 +#else
4739 int bpf_jit_enable __read_mostly;
4740 +#endif
4741
4742 static u64 jit_get_skb_b(struct sk_buff *skb, unsigned offset)
4743 {
4744 @@ -178,8 +183,10 @@ static void jit_fill_hole(void *area, unsigned int size)
4745 {
4746 u32 *ptr;
4747 /* We are guaranteed to have aligned memory. */
4748 + pax_open_kernel();
4749 for (ptr = area; size >= sizeof(u32); size -= sizeof(u32))
4750 *ptr++ = __opcode_to_mem_arm(ARM_INST_UDF);
4751 + pax_close_kernel();
4752 }
4753
4754 static void build_prologue(struct jit_ctx *ctx)
4755 diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
4756 index 5b217f4..c23f40e 100644
4757 --- a/arch/arm/plat-iop/setup.c
4758 +++ b/arch/arm/plat-iop/setup.c
4759 @@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
4760 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
4761 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
4762 .length = IOP3XX_PERIPHERAL_SIZE,
4763 - .type = MT_UNCACHED,
4764 + .type = MT_UNCACHED_RW,
4765 },
4766 };
4767
4768 diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4769 index a5bc92d..0bb4730 100644
4770 --- a/arch/arm/plat-omap/sram.c
4771 +++ b/arch/arm/plat-omap/sram.c
4772 @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4773 * Looks like we need to preserve some bootloader code at the
4774 * beginning of SRAM for jumping to flash for reboot to work...
4775 */
4776 + pax_open_kernel();
4777 memset_io(omap_sram_base + omap_sram_skip, 0,
4778 omap_sram_size - omap_sram_skip);
4779 + pax_close_kernel();
4780 }
4781 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4782 index ce6d763..cfea917 100644
4783 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4784 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4785 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
4786 int (*started)(unsigned ch);
4787 int (*flush)(unsigned ch);
4788 int (*stop)(unsigned ch);
4789 -};
4790 +} __no_const;
4791
4792 extern void *samsung_dmadev_get_ops(void);
4793 extern void *s3c_dma_get_ops(void);
4794 diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h
4795 index 6389d60..b5d3bdd 100644
4796 --- a/arch/arm64/include/asm/barrier.h
4797 +++ b/arch/arm64/include/asm/barrier.h
4798 @@ -41,7 +41,7 @@
4799 do { \
4800 compiletime_assert_atomic_type(*p); \
4801 barrier(); \
4802 - ACCESS_ONCE(*p) = (v); \
4803 + ACCESS_ONCE_RW(*p) = (v); \
4804 } while (0)
4805
4806 #define smp_load_acquire(p) \
4807 diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4808 index 3bf8f4e..5dd5491 100644
4809 --- a/arch/arm64/include/asm/uaccess.h
4810 +++ b/arch/arm64/include/asm/uaccess.h
4811 @@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4812 flag; \
4813 })
4814
4815 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4816 #define access_ok(type, addr, size) __range_ok(addr, size)
4817 #define user_addr_max get_fs
4818
4819 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4820 index c3a58a1..78fbf54 100644
4821 --- a/arch/avr32/include/asm/cache.h
4822 +++ b/arch/avr32/include/asm/cache.h
4823 @@ -1,8 +1,10 @@
4824 #ifndef __ASM_AVR32_CACHE_H
4825 #define __ASM_AVR32_CACHE_H
4826
4827 +#include <linux/const.h>
4828 +
4829 #define L1_CACHE_SHIFT 5
4830 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4831 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4832
4833 /*
4834 * Memory returned by kmalloc() may be used for DMA, so we must make
4835 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4836 index d232888..87c8df1 100644
4837 --- a/arch/avr32/include/asm/elf.h
4838 +++ b/arch/avr32/include/asm/elf.h
4839 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4840 the loader. We need to make sure that it is out of the way of the program
4841 that it will "exec", and that there is sufficient room for the brk. */
4842
4843 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4844 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4845
4846 +#ifdef CONFIG_PAX_ASLR
4847 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4848 +
4849 +#define PAX_DELTA_MMAP_LEN 15
4850 +#define PAX_DELTA_STACK_LEN 15
4851 +#endif
4852
4853 /* This yields a mask that user programs can use to figure out what
4854 instruction set this CPU supports. This could be done in user space,
4855 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4856 index 479330b..53717a8 100644
4857 --- a/arch/avr32/include/asm/kmap_types.h
4858 +++ b/arch/avr32/include/asm/kmap_types.h
4859 @@ -2,9 +2,9 @@
4860 #define __ASM_AVR32_KMAP_TYPES_H
4861
4862 #ifdef CONFIG_DEBUG_HIGHMEM
4863 -# define KM_TYPE_NR 29
4864 +# define KM_TYPE_NR 30
4865 #else
4866 -# define KM_TYPE_NR 14
4867 +# define KM_TYPE_NR 15
4868 #endif
4869
4870 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4871 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4872 index 0eca933..eb78c7b 100644
4873 --- a/arch/avr32/mm/fault.c
4874 +++ b/arch/avr32/mm/fault.c
4875 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4876
4877 int exception_trace = 1;
4878
4879 +#ifdef CONFIG_PAX_PAGEEXEC
4880 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4881 +{
4882 + unsigned long i;
4883 +
4884 + printk(KERN_ERR "PAX: bytes at PC: ");
4885 + for (i = 0; i < 20; i++) {
4886 + unsigned char c;
4887 + if (get_user(c, (unsigned char *)pc+i))
4888 + printk(KERN_CONT "???????? ");
4889 + else
4890 + printk(KERN_CONT "%02x ", c);
4891 + }
4892 + printk("\n");
4893 +}
4894 +#endif
4895 +
4896 /*
4897 * This routine handles page faults. It determines the address and the
4898 * problem, and then passes it off to one of the appropriate routines.
4899 @@ -176,6 +193,16 @@ bad_area:
4900 up_read(&mm->mmap_sem);
4901
4902 if (user_mode(regs)) {
4903 +
4904 +#ifdef CONFIG_PAX_PAGEEXEC
4905 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4906 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4907 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4908 + do_group_exit(SIGKILL);
4909 + }
4910 + }
4911 +#endif
4912 +
4913 if (exception_trace && printk_ratelimit())
4914 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4915 "sp %08lx ecr %lu\n",
4916 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4917 index 568885a..f8008df 100644
4918 --- a/arch/blackfin/include/asm/cache.h
4919 +++ b/arch/blackfin/include/asm/cache.h
4920 @@ -7,6 +7,7 @@
4921 #ifndef __ARCH_BLACKFIN_CACHE_H
4922 #define __ARCH_BLACKFIN_CACHE_H
4923
4924 +#include <linux/const.h>
4925 #include <linux/linkage.h> /* for asmlinkage */
4926
4927 /*
4928 @@ -14,7 +15,7 @@
4929 * Blackfin loads 32 bytes for cache
4930 */
4931 #define L1_CACHE_SHIFT 5
4932 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4933 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4934 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4935
4936 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4937 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4938 index aea2718..3639a60 100644
4939 --- a/arch/cris/include/arch-v10/arch/cache.h
4940 +++ b/arch/cris/include/arch-v10/arch/cache.h
4941 @@ -1,8 +1,9 @@
4942 #ifndef _ASM_ARCH_CACHE_H
4943 #define _ASM_ARCH_CACHE_H
4944
4945 +#include <linux/const.h>
4946 /* Etrax 100LX have 32-byte cache-lines. */
4947 -#define L1_CACHE_BYTES 32
4948 #define L1_CACHE_SHIFT 5
4949 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4950
4951 #endif /* _ASM_ARCH_CACHE_H */
4952 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4953 index 7caf25d..ee65ac5 100644
4954 --- a/arch/cris/include/arch-v32/arch/cache.h
4955 +++ b/arch/cris/include/arch-v32/arch/cache.h
4956 @@ -1,11 +1,12 @@
4957 #ifndef _ASM_CRIS_ARCH_CACHE_H
4958 #define _ASM_CRIS_ARCH_CACHE_H
4959
4960 +#include <linux/const.h>
4961 #include <arch/hwregs/dma.h>
4962
4963 /* A cache-line is 32 bytes. */
4964 -#define L1_CACHE_BYTES 32
4965 #define L1_CACHE_SHIFT 5
4966 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4967
4968 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4969
4970 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4971 index 102190a..5334cea 100644
4972 --- a/arch/frv/include/asm/atomic.h
4973 +++ b/arch/frv/include/asm/atomic.h
4974 @@ -181,6 +181,16 @@ static inline void atomic64_dec(atomic64_t *v)
4975 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4976 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4977
4978 +#define atomic64_read_unchecked(v) atomic64_read(v)
4979 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4980 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4981 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4982 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4983 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4984 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4985 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4986 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4987 +
4988 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4989 {
4990 int c, old;
4991 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4992 index 2797163..c2a401df9 100644
4993 --- a/arch/frv/include/asm/cache.h
4994 +++ b/arch/frv/include/asm/cache.h
4995 @@ -12,10 +12,11 @@
4996 #ifndef __ASM_CACHE_H
4997 #define __ASM_CACHE_H
4998
4999 +#include <linux/const.h>
5000
5001 /* bytes per L1 cache line */
5002 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
5003 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5004 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5005
5006 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5007 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5008 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
5009 index 43901f2..0d8b865 100644
5010 --- a/arch/frv/include/asm/kmap_types.h
5011 +++ b/arch/frv/include/asm/kmap_types.h
5012 @@ -2,6 +2,6 @@
5013 #ifndef _ASM_KMAP_TYPES_H
5014 #define _ASM_KMAP_TYPES_H
5015
5016 -#define KM_TYPE_NR 17
5017 +#define KM_TYPE_NR 18
5018
5019 #endif
5020 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
5021 index 836f147..4cf23f5 100644
5022 --- a/arch/frv/mm/elf-fdpic.c
5023 +++ b/arch/frv/mm/elf-fdpic.c
5024 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5025 {
5026 struct vm_area_struct *vma;
5027 struct vm_unmapped_area_info info;
5028 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5029
5030 if (len > TASK_SIZE)
5031 return -ENOMEM;
5032 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5033 if (addr) {
5034 addr = PAGE_ALIGN(addr);
5035 vma = find_vma(current->mm, addr);
5036 - if (TASK_SIZE - len >= addr &&
5037 - (!vma || addr + len <= vma->vm_start))
5038 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
5039 goto success;
5040 }
5041
5042 @@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5043 info.high_limit = (current->mm->start_stack - 0x00200000);
5044 info.align_mask = 0;
5045 info.align_offset = 0;
5046 + info.threadstack_offset = offset;
5047 addr = vm_unmapped_area(&info);
5048 if (!(addr & ~PAGE_MASK))
5049 goto success;
5050 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
5051 index 2635117..fa223cb 100644
5052 --- a/arch/hexagon/include/asm/cache.h
5053 +++ b/arch/hexagon/include/asm/cache.h
5054 @@ -21,9 +21,11 @@
5055 #ifndef __ASM_CACHE_H
5056 #define __ASM_CACHE_H
5057
5058 +#include <linux/const.h>
5059 +
5060 /* Bytes per L1 cache line */
5061 -#define L1_CACHE_SHIFT (5)
5062 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5063 +#define L1_CACHE_SHIFT 5
5064 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5065
5066 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
5067 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
5068 diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
5069 index c84c88b..2a6e1ba 100644
5070 --- a/arch/ia64/Kconfig
5071 +++ b/arch/ia64/Kconfig
5072 @@ -549,6 +549,7 @@ source "drivers/sn/Kconfig"
5073 config KEXEC
5074 bool "kexec system call"
5075 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
5076 + depends on !GRKERNSEC_KMEM
5077 help
5078 kexec is a system call that implements the ability to shutdown your
5079 current kernel, and to start another kernel. It is like a reboot
5080 diff --git a/arch/ia64/Makefile b/arch/ia64/Makefile
5081 index 5441b14..039a446 100644
5082 --- a/arch/ia64/Makefile
5083 +++ b/arch/ia64/Makefile
5084 @@ -99,5 +99,6 @@ endef
5085 archprepare: make_nr_irqs_h FORCE
5086 PHONY += make_nr_irqs_h FORCE
5087
5088 +make_nr_irqs_h: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
5089 make_nr_irqs_h: FORCE
5090 $(Q)$(MAKE) $(build)=arch/ia64/kernel include/generated/nr-irqs.h
5091 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
5092 index 0bf0350..2ad1957 100644
5093 --- a/arch/ia64/include/asm/atomic.h
5094 +++ b/arch/ia64/include/asm/atomic.h
5095 @@ -193,4 +193,14 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
5096 #define atomic64_inc(v) atomic64_add(1, (v))
5097 #define atomic64_dec(v) atomic64_sub(1, (v))
5098
5099 +#define atomic64_read_unchecked(v) atomic64_read(v)
5100 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5101 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5102 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5103 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5104 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5105 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5106 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5107 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5108 +
5109 #endif /* _ASM_IA64_ATOMIC_H */
5110 diff --git a/arch/ia64/include/asm/barrier.h b/arch/ia64/include/asm/barrier.h
5111 index a48957c..e097b56 100644
5112 --- a/arch/ia64/include/asm/barrier.h
5113 +++ b/arch/ia64/include/asm/barrier.h
5114 @@ -67,7 +67,7 @@
5115 do { \
5116 compiletime_assert_atomic_type(*p); \
5117 barrier(); \
5118 - ACCESS_ONCE(*p) = (v); \
5119 + ACCESS_ONCE_RW(*p) = (v); \
5120 } while (0)
5121
5122 #define smp_load_acquire(p) \
5123 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5124 index 988254a..e1ee885 100644
5125 --- a/arch/ia64/include/asm/cache.h
5126 +++ b/arch/ia64/include/asm/cache.h
5127 @@ -1,6 +1,7 @@
5128 #ifndef _ASM_IA64_CACHE_H
5129 #define _ASM_IA64_CACHE_H
5130
5131 +#include <linux/const.h>
5132
5133 /*
5134 * Copyright (C) 1998-2000 Hewlett-Packard Co
5135 @@ -9,7 +10,7 @@
5136
5137 /* Bytes per L1 (data) cache line. */
5138 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5139 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5140 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5141
5142 #ifdef CONFIG_SMP
5143 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5144 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5145 index 5a83c5c..4d7f553 100644
5146 --- a/arch/ia64/include/asm/elf.h
5147 +++ b/arch/ia64/include/asm/elf.h
5148 @@ -42,6 +42,13 @@
5149 */
5150 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5151
5152 +#ifdef CONFIG_PAX_ASLR
5153 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5154 +
5155 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5156 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5157 +#endif
5158 +
5159 #define PT_IA_64_UNWIND 0x70000001
5160
5161 /* IA-64 relocations: */
5162 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5163 index 5767cdf..7462574 100644
5164 --- a/arch/ia64/include/asm/pgalloc.h
5165 +++ b/arch/ia64/include/asm/pgalloc.h
5166 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5167 pgd_val(*pgd_entry) = __pa(pud);
5168 }
5169
5170 +static inline void
5171 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5172 +{
5173 + pgd_populate(mm, pgd_entry, pud);
5174 +}
5175 +
5176 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5177 {
5178 return quicklist_alloc(0, GFP_KERNEL, NULL);
5179 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5180 pud_val(*pud_entry) = __pa(pmd);
5181 }
5182
5183 +static inline void
5184 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5185 +{
5186 + pud_populate(mm, pud_entry, pmd);
5187 +}
5188 +
5189 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5190 {
5191 return quicklist_alloc(0, GFP_KERNEL, NULL);
5192 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5193 index 7935115..c0eca6a 100644
5194 --- a/arch/ia64/include/asm/pgtable.h
5195 +++ b/arch/ia64/include/asm/pgtable.h
5196 @@ -12,7 +12,7 @@
5197 * David Mosberger-Tang <davidm@hpl.hp.com>
5198 */
5199
5200 -
5201 +#include <linux/const.h>
5202 #include <asm/mman.h>
5203 #include <asm/page.h>
5204 #include <asm/processor.h>
5205 @@ -142,6 +142,17 @@
5206 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5207 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5208 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5209 +
5210 +#ifdef CONFIG_PAX_PAGEEXEC
5211 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5212 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5213 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5214 +#else
5215 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5216 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5217 +# define PAGE_COPY_NOEXEC PAGE_COPY
5218 +#endif
5219 +
5220 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5221 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5222 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5223 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5224 index 45698cd..e8e2dbc 100644
5225 --- a/arch/ia64/include/asm/spinlock.h
5226 +++ b/arch/ia64/include/asm/spinlock.h
5227 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5228 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5229
5230 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5231 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5232 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5233 }
5234
5235 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5236 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5237 index 449c8c0..3d4b1e9 100644
5238 --- a/arch/ia64/include/asm/uaccess.h
5239 +++ b/arch/ia64/include/asm/uaccess.h
5240 @@ -70,6 +70,7 @@
5241 && ((segment).seg == KERNEL_DS.seg \
5242 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5243 })
5244 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5245 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5246
5247 /*
5248 @@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5249 static inline unsigned long
5250 __copy_to_user (void __user *to, const void *from, unsigned long count)
5251 {
5252 + if (count > INT_MAX)
5253 + return count;
5254 +
5255 + if (!__builtin_constant_p(count))
5256 + check_object_size(from, count, true);
5257 +
5258 return __copy_user(to, (__force void __user *) from, count);
5259 }
5260
5261 static inline unsigned long
5262 __copy_from_user (void *to, const void __user *from, unsigned long count)
5263 {
5264 + if (count > INT_MAX)
5265 + return count;
5266 +
5267 + if (!__builtin_constant_p(count))
5268 + check_object_size(to, count, false);
5269 +
5270 return __copy_user((__force void __user *) to, from, count);
5271 }
5272
5273 @@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5274 ({ \
5275 void __user *__cu_to = (to); \
5276 const void *__cu_from = (from); \
5277 - long __cu_len = (n); \
5278 + unsigned long __cu_len = (n); \
5279 \
5280 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
5281 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5282 + if (!__builtin_constant_p(n)) \
5283 + check_object_size(__cu_from, __cu_len, true); \
5284 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5285 + } \
5286 __cu_len; \
5287 })
5288
5289 @@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5290 ({ \
5291 void *__cu_to = (to); \
5292 const void __user *__cu_from = (from); \
5293 - long __cu_len = (n); \
5294 + unsigned long __cu_len = (n); \
5295 \
5296 __chk_user_ptr(__cu_from); \
5297 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
5298 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5299 + if (!__builtin_constant_p(n)) \
5300 + check_object_size(__cu_to, __cu_len, false); \
5301 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5302 + } \
5303 __cu_len; \
5304 })
5305
5306 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5307 index 24603be..948052d 100644
5308 --- a/arch/ia64/kernel/module.c
5309 +++ b/arch/ia64/kernel/module.c
5310 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5311 void
5312 module_free (struct module *mod, void *module_region)
5313 {
5314 - if (mod && mod->arch.init_unw_table &&
5315 - module_region == mod->module_init) {
5316 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5317 unw_remove_unwind_table(mod->arch.init_unw_table);
5318 mod->arch.init_unw_table = NULL;
5319 }
5320 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5321 }
5322
5323 static inline int
5324 +in_init_rx (const struct module *mod, uint64_t addr)
5325 +{
5326 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5327 +}
5328 +
5329 +static inline int
5330 +in_init_rw (const struct module *mod, uint64_t addr)
5331 +{
5332 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5333 +}
5334 +
5335 +static inline int
5336 in_init (const struct module *mod, uint64_t addr)
5337 {
5338 - return addr - (uint64_t) mod->module_init < mod->init_size;
5339 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5340 +}
5341 +
5342 +static inline int
5343 +in_core_rx (const struct module *mod, uint64_t addr)
5344 +{
5345 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5346 +}
5347 +
5348 +static inline int
5349 +in_core_rw (const struct module *mod, uint64_t addr)
5350 +{
5351 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5352 }
5353
5354 static inline int
5355 in_core (const struct module *mod, uint64_t addr)
5356 {
5357 - return addr - (uint64_t) mod->module_core < mod->core_size;
5358 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5359 }
5360
5361 static inline int
5362 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5363 break;
5364
5365 case RV_BDREL:
5366 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5367 + if (in_init_rx(mod, val))
5368 + val -= (uint64_t) mod->module_init_rx;
5369 + else if (in_init_rw(mod, val))
5370 + val -= (uint64_t) mod->module_init_rw;
5371 + else if (in_core_rx(mod, val))
5372 + val -= (uint64_t) mod->module_core_rx;
5373 + else if (in_core_rw(mod, val))
5374 + val -= (uint64_t) mod->module_core_rw;
5375 break;
5376
5377 case RV_LTV:
5378 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5379 * addresses have been selected...
5380 */
5381 uint64_t gp;
5382 - if (mod->core_size > MAX_LTOFF)
5383 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5384 /*
5385 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5386 * at the end of the module.
5387 */
5388 - gp = mod->core_size - MAX_LTOFF / 2;
5389 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5390 else
5391 - gp = mod->core_size / 2;
5392 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5393 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5394 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5395 mod->arch.gp = gp;
5396 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5397 }
5398 diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5399 index c39c3cd..3c77738 100644
5400 --- a/arch/ia64/kernel/palinfo.c
5401 +++ b/arch/ia64/kernel/palinfo.c
5402 @@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5403 return NOTIFY_OK;
5404 }
5405
5406 -static struct notifier_block __refdata palinfo_cpu_notifier =
5407 +static struct notifier_block palinfo_cpu_notifier =
5408 {
5409 .notifier_call = palinfo_cpu_callback,
5410 .priority = 0,
5411 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5412 index 41e33f8..65180b2a 100644
5413 --- a/arch/ia64/kernel/sys_ia64.c
5414 +++ b/arch/ia64/kernel/sys_ia64.c
5415 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5416 unsigned long align_mask = 0;
5417 struct mm_struct *mm = current->mm;
5418 struct vm_unmapped_area_info info;
5419 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5420
5421 if (len > RGN_MAP_LIMIT)
5422 return -ENOMEM;
5423 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5424 if (REGION_NUMBER(addr) == RGN_HPAGE)
5425 addr = 0;
5426 #endif
5427 +
5428 +#ifdef CONFIG_PAX_RANDMMAP
5429 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5430 + addr = mm->free_area_cache;
5431 + else
5432 +#endif
5433 +
5434 if (!addr)
5435 addr = TASK_UNMAPPED_BASE;
5436
5437 @@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5438 info.high_limit = TASK_SIZE;
5439 info.align_mask = align_mask;
5440 info.align_offset = 0;
5441 + info.threadstack_offset = offset;
5442 return vm_unmapped_area(&info);
5443 }
5444
5445 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5446 index 84f8a52..7c76178 100644
5447 --- a/arch/ia64/kernel/vmlinux.lds.S
5448 +++ b/arch/ia64/kernel/vmlinux.lds.S
5449 @@ -192,7 +192,7 @@ SECTIONS {
5450 /* Per-cpu data: */
5451 . = ALIGN(PERCPU_PAGE_SIZE);
5452 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5453 - __phys_per_cpu_start = __per_cpu_load;
5454 + __phys_per_cpu_start = per_cpu_load;
5455 /*
5456 * ensure percpu data fits
5457 * into percpu page size
5458 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5459 index 7225dad..2a7c8256 100644
5460 --- a/arch/ia64/mm/fault.c
5461 +++ b/arch/ia64/mm/fault.c
5462 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5463 return pte_present(pte);
5464 }
5465
5466 +#ifdef CONFIG_PAX_PAGEEXEC
5467 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5468 +{
5469 + unsigned long i;
5470 +
5471 + printk(KERN_ERR "PAX: bytes at PC: ");
5472 + for (i = 0; i < 8; i++) {
5473 + unsigned int c;
5474 + if (get_user(c, (unsigned int *)pc+i))
5475 + printk(KERN_CONT "???????? ");
5476 + else
5477 + printk(KERN_CONT "%08x ", c);
5478 + }
5479 + printk("\n");
5480 +}
5481 +#endif
5482 +
5483 # define VM_READ_BIT 0
5484 # define VM_WRITE_BIT 1
5485 # define VM_EXEC_BIT 2
5486 @@ -151,8 +168,21 @@ retry:
5487 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5488 goto bad_area;
5489
5490 - if ((vma->vm_flags & mask) != mask)
5491 + if ((vma->vm_flags & mask) != mask) {
5492 +
5493 +#ifdef CONFIG_PAX_PAGEEXEC
5494 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5495 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5496 + goto bad_area;
5497 +
5498 + up_read(&mm->mmap_sem);
5499 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5500 + do_group_exit(SIGKILL);
5501 + }
5502 +#endif
5503 +
5504 goto bad_area;
5505 + }
5506
5507 /*
5508 * If for any reason at all we couldn't handle the fault, make
5509 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5510 index 76069c1..c2aa816 100644
5511 --- a/arch/ia64/mm/hugetlbpage.c
5512 +++ b/arch/ia64/mm/hugetlbpage.c
5513 @@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5514 unsigned long pgoff, unsigned long flags)
5515 {
5516 struct vm_unmapped_area_info info;
5517 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5518
5519 if (len > RGN_MAP_LIMIT)
5520 return -ENOMEM;
5521 @@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5522 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5523 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5524 info.align_offset = 0;
5525 + info.threadstack_offset = offset;
5526 return vm_unmapped_area(&info);
5527 }
5528
5529 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5530 index 6b33457..88b5124 100644
5531 --- a/arch/ia64/mm/init.c
5532 +++ b/arch/ia64/mm/init.c
5533 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5534 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5535 vma->vm_end = vma->vm_start + PAGE_SIZE;
5536 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5537 +
5538 +#ifdef CONFIG_PAX_PAGEEXEC
5539 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5540 + vma->vm_flags &= ~VM_EXEC;
5541 +
5542 +#ifdef CONFIG_PAX_MPROTECT
5543 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
5544 + vma->vm_flags &= ~VM_MAYEXEC;
5545 +#endif
5546 +
5547 + }
5548 +#endif
5549 +
5550 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5551 down_write(&current->mm->mmap_sem);
5552 if (insert_vm_struct(current->mm, vma)) {
5553 @@ -286,7 +299,7 @@ static int __init gate_vma_init(void)
5554 gate_vma.vm_start = FIXADDR_USER_START;
5555 gate_vma.vm_end = FIXADDR_USER_END;
5556 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
5557 - gate_vma.vm_page_prot = __P101;
5558 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
5559
5560 return 0;
5561 }
5562 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5563 index 40b3ee9..8c2c112 100644
5564 --- a/arch/m32r/include/asm/cache.h
5565 +++ b/arch/m32r/include/asm/cache.h
5566 @@ -1,8 +1,10 @@
5567 #ifndef _ASM_M32R_CACHE_H
5568 #define _ASM_M32R_CACHE_H
5569
5570 +#include <linux/const.h>
5571 +
5572 /* L1 cache line size */
5573 #define L1_CACHE_SHIFT 4
5574 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5575 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5576
5577 #endif /* _ASM_M32R_CACHE_H */
5578 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5579 index 82abd15..d95ae5d 100644
5580 --- a/arch/m32r/lib/usercopy.c
5581 +++ b/arch/m32r/lib/usercopy.c
5582 @@ -14,6 +14,9 @@
5583 unsigned long
5584 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5585 {
5586 + if ((long)n < 0)
5587 + return n;
5588 +
5589 prefetch(from);
5590 if (access_ok(VERIFY_WRITE, to, n))
5591 __copy_user(to,from,n);
5592 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5593 unsigned long
5594 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5595 {
5596 + if ((long)n < 0)
5597 + return n;
5598 +
5599 prefetchw(to);
5600 if (access_ok(VERIFY_READ, from, n))
5601 __copy_user_zeroing(to,from,n);
5602 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5603 index 0395c51..5f26031 100644
5604 --- a/arch/m68k/include/asm/cache.h
5605 +++ b/arch/m68k/include/asm/cache.h
5606 @@ -4,9 +4,11 @@
5607 #ifndef __ARCH_M68K_CACHE_H
5608 #define __ARCH_M68K_CACHE_H
5609
5610 +#include <linux/const.h>
5611 +
5612 /* bytes per L1 cache line */
5613 #define L1_CACHE_SHIFT 4
5614 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5615 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5616
5617 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5618
5619 diff --git a/arch/metag/include/asm/barrier.h b/arch/metag/include/asm/barrier.h
5620 index c7591e8..ecef036 100644
5621 --- a/arch/metag/include/asm/barrier.h
5622 +++ b/arch/metag/include/asm/barrier.h
5623 @@ -89,7 +89,7 @@ static inline void fence(void)
5624 do { \
5625 compiletime_assert_atomic_type(*p); \
5626 smp_mb(); \
5627 - ACCESS_ONCE(*p) = (v); \
5628 + ACCESS_ONCE_RW(*p) = (v); \
5629 } while (0)
5630
5631 #define smp_load_acquire(p) \
5632 diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5633 index 3c32075..ae0ae75 100644
5634 --- a/arch/metag/mm/hugetlbpage.c
5635 +++ b/arch/metag/mm/hugetlbpage.c
5636 @@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5637 info.high_limit = TASK_SIZE;
5638 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5639 info.align_offset = 0;
5640 + info.threadstack_offset = 0;
5641 return vm_unmapped_area(&info);
5642 }
5643
5644 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5645 index 4efe96a..60e8699 100644
5646 --- a/arch/microblaze/include/asm/cache.h
5647 +++ b/arch/microblaze/include/asm/cache.h
5648 @@ -13,11 +13,12 @@
5649 #ifndef _ASM_MICROBLAZE_CACHE_H
5650 #define _ASM_MICROBLAZE_CACHE_H
5651
5652 +#include <linux/const.h>
5653 #include <asm/registers.h>
5654
5655 #define L1_CACHE_SHIFT 5
5656 /* word-granular cache in microblaze */
5657 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5658 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5659
5660 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5661
5662 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5663 index 9536ef9..9333776 100644
5664 --- a/arch/mips/Kconfig
5665 +++ b/arch/mips/Kconfig
5666 @@ -2413,6 +2413,7 @@ source "kernel/Kconfig.preempt"
5667
5668 config KEXEC
5669 bool "Kexec system call"
5670 + depends on !GRKERNSEC_KMEM
5671 help
5672 kexec is a system call that implements the ability to shutdown your
5673 current kernel, and to start another kernel. It is like a reboot
5674 diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5675 index 02f2444..506969c 100644
5676 --- a/arch/mips/cavium-octeon/dma-octeon.c
5677 +++ b/arch/mips/cavium-octeon/dma-octeon.c
5678 @@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5679 if (dma_release_from_coherent(dev, order, vaddr))
5680 return;
5681
5682 - swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5683 + swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5684 }
5685
5686 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5687 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5688 index 6dd6bfc..903b0d6 100644
5689 --- a/arch/mips/include/asm/atomic.h
5690 +++ b/arch/mips/include/asm/atomic.h
5691 @@ -21,15 +21,39 @@
5692 #include <asm/cmpxchg.h>
5693 #include <asm/war.h>
5694
5695 +#ifdef CONFIG_GENERIC_ATOMIC64
5696 +#include <asm-generic/atomic64.h>
5697 +#endif
5698 +
5699 #define ATOMIC_INIT(i) { (i) }
5700
5701 +#ifdef CONFIG_64BIT
5702 +#define _ASM_EXTABLE(from, to) \
5703 +" .section __ex_table,\"a\"\n" \
5704 +" .dword " #from ", " #to"\n" \
5705 +" .previous\n"
5706 +#else
5707 +#define _ASM_EXTABLE(from, to) \
5708 +" .section __ex_table,\"a\"\n" \
5709 +" .word " #from ", " #to"\n" \
5710 +" .previous\n"
5711 +#endif
5712 +
5713 /*
5714 * atomic_read - read atomic variable
5715 * @v: pointer of type atomic_t
5716 *
5717 * Atomically reads the value of @v.
5718 */
5719 -#define atomic_read(v) ACCESS_ONCE((v)->counter)
5720 +static inline int atomic_read(const atomic_t *v)
5721 +{
5722 + return ACCESS_ONCE(v->counter);
5723 +}
5724 +
5725 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5726 +{
5727 + return ACCESS_ONCE(v->counter);
5728 +}
5729
5730 /*
5731 * atomic_set - set atomic variable
5732 @@ -38,47 +62,77 @@
5733 *
5734 * Atomically sets the value of @v to @i.
5735 */
5736 -#define atomic_set(v, i) ((v)->counter = (i))
5737 +static inline void atomic_set(atomic_t *v, int i)
5738 +{
5739 + v->counter = i;
5740 +}
5741
5742 -#define ATOMIC_OP(op, c_op, asm_op) \
5743 -static __inline__ void atomic_##op(int i, atomic_t * v) \
5744 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5745 +{
5746 + v->counter = i;
5747 +}
5748 +
5749 +#ifdef CONFIG_PAX_REFCOUNT
5750 +#define __OVERFLOW_POST \
5751 + " b 4f \n" \
5752 + " .set noreorder \n" \
5753 + "3: b 5f \n" \
5754 + " move %0, %1 \n" \
5755 + " .set reorder \n"
5756 +#define __OVERFLOW_EXTABLE \
5757 + "3:\n" \
5758 + _ASM_EXTABLE(2b, 3b)
5759 +#else
5760 +#define __OVERFLOW_POST
5761 +#define __OVERFLOW_EXTABLE
5762 +#endif
5763 +
5764 +#define __ATOMIC_OP(op, suffix, asm_op, extable) \
5765 +static inline void atomic_##op##suffix(int i, atomic##suffix##_t * v) \
5766 { \
5767 if (kernel_uses_llsc && R10000_LLSC_WAR) { \
5768 int temp; \
5769 \
5770 __asm__ __volatile__( \
5771 - " .set arch=r4000 \n" \
5772 - "1: ll %0, %1 # atomic_" #op " \n" \
5773 - " " #asm_op " %0, %2 \n" \
5774 + " .set mips3 \n" \
5775 + "1: ll %0, %1 # atomic_" #op #suffix "\n" \
5776 + "2: " #asm_op " %0, %2 \n" \
5777 " sc %0, %1 \n" \
5778 " beqzl %0, 1b \n" \
5779 + extable \
5780 " .set mips0 \n" \
5781 : "=&r" (temp), "+m" (v->counter) \
5782 : "Ir" (i)); \
5783 } else if (kernel_uses_llsc) { \
5784 int temp; \
5785 \
5786 - do { \
5787 - __asm__ __volatile__( \
5788 - " .set arch=r4000 \n" \
5789 - " ll %0, %1 # atomic_" #op "\n" \
5790 - " " #asm_op " %0, %2 \n" \
5791 - " sc %0, %1 \n" \
5792 - " .set mips0 \n" \
5793 - : "=&r" (temp), "+m" (v->counter) \
5794 - : "Ir" (i)); \
5795 - } while (unlikely(!temp)); \
5796 + __asm__ __volatile__( \
5797 + " .set mips3 \n" \
5798 + " ll %0, %1 # atomic_" #op #suffix "\n" \
5799 + "2: " #asm_op " %0, %2 \n" \
5800 + " sc %0, %1 \n" \
5801 + " beqz %0, 1b \n" \
5802 + extable \
5803 + " .set mips0 \n" \
5804 + : "=&r" (temp), "+m" (v->counter) \
5805 + : "Ir" (i)); \
5806 } else { \
5807 unsigned long flags; \
5808 \
5809 raw_local_irq_save(flags); \
5810 - v->counter c_op i; \
5811 + __asm__ __volatile__( \
5812 + "2: " #asm_op " %0, %1 \n" \
5813 + extable \
5814 + : "+r" (v->counter) : "Ir" (i)); \
5815 raw_local_irq_restore(flags); \
5816 } \
5817 } \
5818
5819 -#define ATOMIC_OP_RETURN(op, c_op, asm_op) \
5820 -static __inline__ int atomic_##op##_return(int i, atomic_t * v) \
5821 +#define ATOMIC_OP(op, asm_op) __ATOMIC_OP(op, , asm_op##u) \
5822 + __ATOMIC_OP(op, _unchecked, asm_op)
5823 +
5824 +#define __ATOMIC_OP_RETURN(op, suffix, asm_op, post_op, extable) \
5825 +static inline int atomic_##op##_return##suffix(int i, atomic##suffix##_t * v) \
5826 { \
5827 int result; \
5828 \
5829 @@ -88,37 +142,47 @@ static __inline__ int atomic_##op##_return(int i, atomic_t * v) \
5830 int temp; \
5831 \
5832 __asm__ __volatile__( \
5833 - " .set arch=r4000 \n" \
5834 - "1: ll %1, %2 # atomic_" #op "_return \n" \
5835 - " " #asm_op " %0, %1, %3 \n" \
5836 + " .set mips3 \n" \
5837 + "1: ll %1, %2 # atomic_" #op "_return" #suffix "\n" \
5838 + "2: " #asm_op " %0, %1, %3 \n" \
5839 " sc %0, %2 \n" \
5840 " beqzl %0, 1b \n" \
5841 - " " #asm_op " %0, %1, %3 \n" \
5842 + post_op \
5843 + extable \
5844 + "4: " #asm_op " %0, %1, %3 \n" \
5845 + "5: \n" \
5846 " .set mips0 \n" \
5847 : "=&r" (result), "=&r" (temp), "+m" (v->counter) \
5848 : "Ir" (i)); \
5849 } else if (kernel_uses_llsc) { \
5850 int temp; \
5851 \
5852 - do { \
5853 - __asm__ __volatile__( \
5854 - " .set arch=r4000 \n" \
5855 - " ll %1, %2 # atomic_" #op "_return \n" \
5856 - " " #asm_op " %0, %1, %3 \n" \
5857 - " sc %0, %2 \n" \
5858 - " .set mips0 \n" \
5859 - : "=&r" (result), "=&r" (temp), "+m" (v->counter) \
5860 - : "Ir" (i)); \
5861 - } while (unlikely(!result)); \
5862 + __asm__ __volatile__( \
5863 + " .set mips3 \n" \
5864 + "1: ll %1, %2 # atomic_" #op "_return" #suffix "\n" \
5865 + "2: " #asm_op " %0, %1, %3 \n" \
5866 + " sc %0, %2 \n" \
5867 + " beqz %0, 1b \n" \
5868 + post_op \
5869 + extable \
5870 + "4: " #asm_op " %0, %1, %3 \n" \
5871 + "5: \n" \
5872 + " .set mips0 \n" \
5873 + : "=&r" (result), "=&r" (temp), "+m" (v->counter) \
5874 + : "Ir" (i)); \
5875 \
5876 result = temp; result c_op i; \
5877 } else { \
5878 unsigned long flags; \
5879 \
5880 raw_local_irq_save(flags); \
5881 - result = v->counter; \
5882 - result c_op i; \
5883 - v->counter = result; \
5884 + __asm__ __volatile__( \
5885 + " lw %0, %1 \n" \
5886 + "2: " #asm_op " %0, %1, %2 \n" \
5887 + " sw %0, %1 \n" \
5888 + "3: \n" \
5889 + extable \
5890 + : "=&r" (result), "+m" (v->counter) : "Ir" (i)); \
5891 raw_local_irq_restore(flags); \
5892 } \
5893 \
5894 @@ -127,16 +191,21 @@ static __inline__ int atomic_##op##_return(int i, atomic_t * v) \
5895 return result; \
5896 }
5897
5898 -#define ATOMIC_OPS(op, c_op, asm_op) \
5899 - ATOMIC_OP(op, c_op, asm_op) \
5900 - ATOMIC_OP_RETURN(op, c_op, asm_op)
5901 +#define ATOMIC_OP_RETURN(op, asm_op) __ATOMIC_OP_RETURN(op, , asm_op##u, , __OVERFLOW_EXTABLE) \
5902 + __ATOMIC_OP_RETURN(op, _unchecked, asm_op, __OVERFLOW_POST, __OVERFLOW_EXTABLE)
5903
5904 -ATOMIC_OPS(add, +=, addu)
5905 -ATOMIC_OPS(sub, -=, subu)
5906 +#define ATOMIC_OPS(op, asm_op) \
5907 + ATOMIC_OP(op, asm_op) \
5908 + ATOMIC_OP_RETURN(op, asm_op)
5909 +
5910 +ATOMIC_OPS(add, add)
5911 +ATOMIC_OPS(sub, sub)
5912
5913 #undef ATOMIC_OPS
5914 #undef ATOMIC_OP_RETURN
5915 +#undef __ATOMIC_OP_RETURN
5916 #undef ATOMIC_OP
5917 +#undef __ATOMIC_OP
5918
5919 /*
5920 * atomic_sub_if_positive - conditionally subtract integer from atomic variable
5921 @@ -146,7 +215,7 @@ ATOMIC_OPS(sub, -=, subu)
5922 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5923 * The function returns the old value of @v minus @i.
5924 */
5925 -static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5926 +static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5927 {
5928 int result;
5929
5930 @@ -203,8 +272,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5931 return result;
5932 }
5933
5934 -#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5935 -#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5936 +static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5937 +{
5938 + return cmpxchg(&v->counter, old, new);
5939 +}
5940 +
5941 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5942 + int new)
5943 +{
5944 + return cmpxchg(&(v->counter), old, new);
5945 +}
5946 +
5947 +static inline int atomic_xchg(atomic_t *v, int new)
5948 +{
5949 + return xchg(&v->counter, new);
5950 +}
5951 +
5952 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5953 +{
5954 + return xchg(&(v->counter), new);
5955 +}
5956
5957 /**
5958 * __atomic_add_unless - add unless the number is a given value
5959 @@ -232,6 +319,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5960
5961 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5962 #define atomic_inc_return(v) atomic_add_return(1, (v))
5963 +static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5964 +{
5965 + return atomic_add_return_unchecked(1, v);
5966 +}
5967
5968 /*
5969 * atomic_sub_and_test - subtract value from variable and test result
5970 @@ -253,6 +344,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5971 * other cases.
5972 */
5973 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5974 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5975 +{
5976 + return atomic_add_return_unchecked(1, v) == 0;
5977 +}
5978
5979 /*
5980 * atomic_dec_and_test - decrement by 1 and test
5981 @@ -277,6 +372,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5982 * Atomically increments @v by 1.
5983 */
5984 #define atomic_inc(v) atomic_add(1, (v))
5985 +static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
5986 +{
5987 + atomic_add_unchecked(1, v);
5988 +}
5989
5990 /*
5991 * atomic_dec - decrement and test
5992 @@ -285,6 +384,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5993 * Atomically decrements @v by 1.
5994 */
5995 #define atomic_dec(v) atomic_sub(1, (v))
5996 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
5997 +{
5998 + atomic_sub_unchecked(1, v);
5999 +}
6000
6001 /*
6002 * atomic_add_negative - add and test if negative
6003 @@ -306,54 +409,77 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6004 * @v: pointer of type atomic64_t
6005 *
6006 */
6007 -#define atomic64_read(v) ACCESS_ONCE((v)->counter)
6008 +static inline long atomic64_read(const atomic64_t *v)
6009 +{
6010 + return ACCESS_ONCE(v->counter);
6011 +}
6012 +
6013 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6014 +{
6015 + return ACCESS_ONCE(v->counter);
6016 +}
6017
6018 /*
6019 * atomic64_set - set atomic variable
6020 * @v: pointer of type atomic64_t
6021 * @i: required value
6022 */
6023 -#define atomic64_set(v, i) ((v)->counter = (i))
6024 +static inline void atomic64_set(atomic64_t *v, long i)
6025 +{
6026 + v->counter = i;
6027 +}
6028
6029 -#define ATOMIC64_OP(op, c_op, asm_op) \
6030 -static __inline__ void atomic64_##op(long i, atomic64_t * v) \
6031 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6032 +{
6033 + v->counter = i;
6034 +}
6035 +
6036 +#define __ATOMIC64_OP(op, suffix, asm_op, extable) \
6037 +static inline void atomic64_##op##suffix(long i, atomic64##suffix##_t * v) \
6038 { \
6039 if (kernel_uses_llsc && R10000_LLSC_WAR) { \
6040 long temp; \
6041 \
6042 __asm__ __volatile__( \
6043 - " .set arch=r4000 \n" \
6044 - "1: lld %0, %1 # atomic64_" #op " \n" \
6045 - " " #asm_op " %0, %2 \n" \
6046 + " .set mips3 \n" \
6047 + "1: lld %0, %1 # atomic64_" #op #suffix "\n" \
6048 + "2: " #asm_op " %0, %2 \n" \
6049 " scd %0, %1 \n" \
6050 " beqzl %0, 1b \n" \
6051 + extable \
6052 " .set mips0 \n" \
6053 : "=&r" (temp), "+m" (v->counter) \
6054 : "Ir" (i)); \
6055 } else if (kernel_uses_llsc) { \
6056 long temp; \
6057 \
6058 - do { \
6059 - __asm__ __volatile__( \
6060 - " .set arch=r4000 \n" \
6061 - " lld %0, %1 # atomic64_" #op "\n" \
6062 - " " #asm_op " %0, %2 \n" \
6063 - " scd %0, %1 \n" \
6064 - " .set mips0 \n" \
6065 - : "=&r" (temp), "+m" (v->counter) \
6066 - : "Ir" (i)); \
6067 - } while (unlikely(!temp)); \
6068 + __asm__ __volatile__( \
6069 + " .set mips3 \n" \
6070 + " lld %0, %1 # atomic64_" #op #suffix "\n" \
6071 + "2: " #asm_op " %0, %2 \n" \
6072 + " scd %0, %1 \n" \
6073 + " beqz %0, 1b \n" \
6074 + extable \
6075 + " .set mips0 \n" \
6076 + : "=&r" (temp), "+m" (v->counter) \
6077 + : "Ir" (i)); \
6078 } else { \
6079 unsigned long flags; \
6080 \
6081 raw_local_irq_save(flags); \
6082 - v->counter c_op i; \
6083 + __asm__ __volatile__( \
6084 + "2: " #asm_op " %0, %1 \n" \
6085 + extable \
6086 + : "+r" (v->counter) : "Ir" (i)); \
6087 raw_local_irq_restore(flags); \
6088 } \
6089 } \
6090
6091 -#define ATOMIC64_OP_RETURN(op, c_op, asm_op) \
6092 -static __inline__ long atomic64_##op##_return(long i, atomic64_t * v) \
6093 +#define ATOMIC64_OP(op, asm_op) __ATOMIC64_OP(op, , asm_op##u) \
6094 + __ATOMIC64_OP(op, _unchecked, asm_op)
6095 +
6096 +#define __ATOMIC64_OP_RETURN(op, suffix, asm_op, post_op, extable) \
6097 +static inline long atomic64_##op##_return##suffix(long i, atomic64##suffix##_t * v)\
6098 { \
6099 long result; \
6100 \
6101 @@ -363,38 +489,48 @@ static __inline__ long atomic64_##op##_return(long i, atomic64_t * v) \
6102 long temp; \
6103 \
6104 __asm__ __volatile__( \
6105 - " .set arch=r4000 \n" \
6106 + " .set mips3 \n" \
6107 "1: lld %1, %2 # atomic64_" #op "_return\n" \
6108 - " " #asm_op " %0, %1, %3 \n" \
6109 + "2: " #asm_op " %0, %1, %3 \n" \
6110 " scd %0, %2 \n" \
6111 " beqzl %0, 1b \n" \
6112 - " " #asm_op " %0, %1, %3 \n" \
6113 + post_op \
6114 + extable \
6115 + "4: " #asm_op " %0, %1, %3 \n" \
6116 + "5: \n" \
6117 " .set mips0 \n" \
6118 : "=&r" (result), "=&r" (temp), "+m" (v->counter) \
6119 : "Ir" (i)); \
6120 } else if (kernel_uses_llsc) { \
6121 long temp; \
6122 \
6123 - do { \
6124 - __asm__ __volatile__( \
6125 - " .set arch=r4000 \n" \
6126 - " lld %1, %2 # atomic64_" #op "_return\n" \
6127 - " " #asm_op " %0, %1, %3 \n" \
6128 - " scd %0, %2 \n" \
6129 - " .set mips0 \n" \
6130 - : "=&r" (result), "=&r" (temp), "=m" (v->counter) \
6131 - : "Ir" (i), "m" (v->counter) \
6132 - : "memory"); \
6133 - } while (unlikely(!result)); \
6134 + __asm__ __volatile__( \
6135 + " .set mips3 \n" \
6136 + "1: lld %1, %2 # atomic64_" #op "_return" #suffix "\n" \
6137 + "2: " #asm_op " %0, %1, %3 \n" \
6138 + " scd %0, %2 \n" \
6139 + " beqz %0, 1b \n" \
6140 + post_op \
6141 + extable \
6142 + "4: " #asm_op " %0, %1, %3 \n" \
6143 + "5: \n" \
6144 + " .set mips0 \n" \
6145 + : "=&r" (result), "=&r" (temp), "=m" (v->counter) \
6146 + : "Ir" (i), "m" (v->counter) \
6147 + : "memory"); \
6148 \
6149 result = temp; result c_op i; \
6150 } else { \
6151 unsigned long flags; \
6152 \
6153 raw_local_irq_save(flags); \
6154 - result = v->counter; \
6155 - result c_op i; \
6156 - v->counter = result; \
6157 + __asm__ __volatile__( \
6158 + " ld %0, %1 \n" \
6159 + "2: " #asm_op " %0, %1, %2 \n" \
6160 + " sd %0, %1 \n" \
6161 + "3: \n" \
6162 + extable \
6163 + : "=&r" (result), "+m" (v->counter) : "Ir" (i)); \
6164 raw_local_irq_restore(flags); \
6165 } \
6166 \
6167 @@ -403,16 +539,23 @@ static __inline__ long atomic64_##op##_return(long i, atomic64_t * v) \
6168 return result; \
6169 }
6170
6171 -#define ATOMIC64_OPS(op, c_op, asm_op) \
6172 - ATOMIC64_OP(op, c_op, asm_op) \
6173 - ATOMIC64_OP_RETURN(op, c_op, asm_op)
6174 +#define ATOMIC64_OP_RETURN(op, asm_op) __ATOMIC64_OP_RETURN(op, , asm_op##u, , __OVERFLOW_EXTABLE) \
6175 + __ATOMIC64_OP_RETURN(op, _unchecked, asm_op, __OVERFLOW_POST, __OVERFLOW_EXTABLE)
6176
6177 -ATOMIC64_OPS(add, +=, daddu)
6178 -ATOMIC64_OPS(sub, -=, dsubu)
6179 +#define ATOMIC64_OPS(op, asm_op) \
6180 + ATOMIC64_OP(op, asm_op) \
6181 + ATOMIC64_OP_RETURN(op, asm_op)
6182 +
6183 +ATOMIC64_OPS(add, dadd)
6184 +ATOMIC64_OPS(sub, dsub)
6185
6186 #undef ATOMIC64_OPS
6187 #undef ATOMIC64_OP_RETURN
6188 +#undef __ATOMIC64_OP_RETURN
6189 #undef ATOMIC64_OP
6190 +#undef __ATOMIC64_OP
6191 +#undef __OVERFLOW_EXTABLE
6192 +#undef __OVERFLOW_POST
6193
6194 /*
6195 * atomic64_sub_if_positive - conditionally subtract integer from atomic variable
6196 @@ -422,7 +565,7 @@ ATOMIC64_OPS(sub, -=, dsubu)
6197 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6198 * The function returns the old value of @v minus @i.
6199 */
6200 -static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6201 +static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6202 {
6203 long result;
6204
6205 @@ -479,9 +622,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6206 return result;
6207 }
6208
6209 -#define atomic64_cmpxchg(v, o, n) \
6210 - ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6211 -#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6212 +static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6213 +{
6214 + return cmpxchg(&v->counter, old, new);
6215 +}
6216 +
6217 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6218 + long new)
6219 +{
6220 + return cmpxchg(&(v->counter), old, new);
6221 +}
6222 +
6223 +static inline long atomic64_xchg(atomic64_t *v, long new)
6224 +{
6225 + return xchg(&v->counter, new);
6226 +}
6227 +
6228 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6229 +{
6230 + return xchg(&(v->counter), new);
6231 +}
6232
6233 /**
6234 * atomic64_add_unless - add unless the number is a given value
6235 @@ -511,6 +671,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6236
6237 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6238 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6239 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6240
6241 /*
6242 * atomic64_sub_and_test - subtract value from variable and test result
6243 @@ -532,6 +693,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6244 * other cases.
6245 */
6246 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6247 +#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6248
6249 /*
6250 * atomic64_dec_and_test - decrement by 1 and test
6251 @@ -556,6 +718,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6252 * Atomically increments @v by 1.
6253 */
6254 #define atomic64_inc(v) atomic64_add(1, (v))
6255 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6256
6257 /*
6258 * atomic64_dec - decrement and test
6259 @@ -564,6 +727,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6260 * Atomically decrements @v by 1.
6261 */
6262 #define atomic64_dec(v) atomic64_sub(1, (v))
6263 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6264
6265 /*
6266 * atomic64_add_negative - add and test if negative
6267 diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h
6268 index d0101dd..266982c 100644
6269 --- a/arch/mips/include/asm/barrier.h
6270 +++ b/arch/mips/include/asm/barrier.h
6271 @@ -184,7 +184,7 @@
6272 do { \
6273 compiletime_assert_atomic_type(*p); \
6274 smp_mb(); \
6275 - ACCESS_ONCE(*p) = (v); \
6276 + ACCESS_ONCE_RW(*p) = (v); \
6277 } while (0)
6278
6279 #define smp_load_acquire(p) \
6280 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6281 index b4db69f..8f3b093 100644
6282 --- a/arch/mips/include/asm/cache.h
6283 +++ b/arch/mips/include/asm/cache.h
6284 @@ -9,10 +9,11 @@
6285 #ifndef _ASM_CACHE_H
6286 #define _ASM_CACHE_H
6287
6288 +#include <linux/const.h>
6289 #include <kmalloc.h>
6290
6291 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6292 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6293 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6294
6295 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6296 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6297 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6298 index 1d38fe0..9beabc9 100644
6299 --- a/arch/mips/include/asm/elf.h
6300 +++ b/arch/mips/include/asm/elf.h
6301 @@ -381,13 +381,16 @@ extern const char *__elf_platform;
6302 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6303 #endif
6304
6305 +#ifdef CONFIG_PAX_ASLR
6306 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6307 +
6308 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6309 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6310 +#endif
6311 +
6312 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6313 struct linux_binprm;
6314 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6315 int uses_interp);
6316
6317 -struct mm_struct;
6318 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6319 -#define arch_randomize_brk arch_randomize_brk
6320 -
6321 #endif /* _ASM_ELF_H */
6322 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6323 index c1f6afa..38cc6e9 100644
6324 --- a/arch/mips/include/asm/exec.h
6325 +++ b/arch/mips/include/asm/exec.h
6326 @@ -12,6 +12,6 @@
6327 #ifndef _ASM_EXEC_H
6328 #define _ASM_EXEC_H
6329
6330 -extern unsigned long arch_align_stack(unsigned long sp);
6331 +#define arch_align_stack(x) ((x) & ~0xfUL)
6332
6333 #endif /* _ASM_EXEC_H */
6334 diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6335 index 9e8ef59..1139d6b 100644
6336 --- a/arch/mips/include/asm/hw_irq.h
6337 +++ b/arch/mips/include/asm/hw_irq.h
6338 @@ -10,7 +10,7 @@
6339
6340 #include <linux/atomic.h>
6341
6342 -extern atomic_t irq_err_count;
6343 +extern atomic_unchecked_t irq_err_count;
6344
6345 /*
6346 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6347 diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6348 index 46dfc3c..a16b13a 100644
6349 --- a/arch/mips/include/asm/local.h
6350 +++ b/arch/mips/include/asm/local.h
6351 @@ -12,15 +12,25 @@ typedef struct
6352 atomic_long_t a;
6353 } local_t;
6354
6355 +typedef struct {
6356 + atomic_long_unchecked_t a;
6357 +} local_unchecked_t;
6358 +
6359 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6360
6361 #define local_read(l) atomic_long_read(&(l)->a)
6362 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6363 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6364 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6365
6366 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6367 +#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6368 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6369 +#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6370 #define local_inc(l) atomic_long_inc(&(l)->a)
6371 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6372 #define local_dec(l) atomic_long_dec(&(l)->a)
6373 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6374
6375 /*
6376 * Same as above, but return the result value
6377 @@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6378 return result;
6379 }
6380
6381 +static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6382 +{
6383 + unsigned long result;
6384 +
6385 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6386 + unsigned long temp;
6387 +
6388 + __asm__ __volatile__(
6389 + " .set mips3 \n"
6390 + "1:" __LL "%1, %2 # local_add_return \n"
6391 + " addu %0, %1, %3 \n"
6392 + __SC "%0, %2 \n"
6393 + " beqzl %0, 1b \n"
6394 + " addu %0, %1, %3 \n"
6395 + " .set mips0 \n"
6396 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6397 + : "Ir" (i), "m" (l->a.counter)
6398 + : "memory");
6399 + } else if (kernel_uses_llsc) {
6400 + unsigned long temp;
6401 +
6402 + __asm__ __volatile__(
6403 + " .set mips3 \n"
6404 + "1:" __LL "%1, %2 # local_add_return \n"
6405 + " addu %0, %1, %3 \n"
6406 + __SC "%0, %2 \n"
6407 + " beqz %0, 1b \n"
6408 + " addu %0, %1, %3 \n"
6409 + " .set mips0 \n"
6410 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6411 + : "Ir" (i), "m" (l->a.counter)
6412 + : "memory");
6413 + } else {
6414 + unsigned long flags;
6415 +
6416 + local_irq_save(flags);
6417 + result = l->a.counter;
6418 + result += i;
6419 + l->a.counter = result;
6420 + local_irq_restore(flags);
6421 + }
6422 +
6423 + return result;
6424 +}
6425 +
6426 static __inline__ long local_sub_return(long i, local_t * l)
6427 {
6428 unsigned long result;
6429 @@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6430
6431 #define local_cmpxchg(l, o, n) \
6432 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6433 +#define local_cmpxchg_unchecked(l, o, n) \
6434 + ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6435 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6436
6437 /**
6438 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6439 index 3be8180..c4798d5 100644
6440 --- a/arch/mips/include/asm/page.h
6441 +++ b/arch/mips/include/asm/page.h
6442 @@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6443 #ifdef CONFIG_CPU_MIPS32
6444 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6445 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6446 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6447 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6448 #else
6449 typedef struct { unsigned long long pte; } pte_t;
6450 #define pte_val(x) ((x).pte)
6451 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6452 index b336037..5b874cc 100644
6453 --- a/arch/mips/include/asm/pgalloc.h
6454 +++ b/arch/mips/include/asm/pgalloc.h
6455 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6456 {
6457 set_pud(pud, __pud((unsigned long)pmd));
6458 }
6459 +
6460 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6461 +{
6462 + pud_populate(mm, pud, pmd);
6463 +}
6464 #endif
6465
6466 /*
6467 diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6468 index d6d1928..ce4f822 100644
6469 --- a/arch/mips/include/asm/pgtable.h
6470 +++ b/arch/mips/include/asm/pgtable.h
6471 @@ -20,6 +20,9 @@
6472 #include <asm/io.h>
6473 #include <asm/pgtable-bits.h>
6474
6475 +#define ktla_ktva(addr) (addr)
6476 +#define ktva_ktla(addr) (addr)
6477 +
6478 struct mm_struct;
6479 struct vm_area_struct;
6480
6481 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6482 index 7de8658..c109224 100644
6483 --- a/arch/mips/include/asm/thread_info.h
6484 +++ b/arch/mips/include/asm/thread_info.h
6485 @@ -105,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6486 #define TIF_SECCOMP 4 /* secure computing */
6487 #define TIF_NOTIFY_RESUME 5 /* callback before returning to user */
6488 #define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal() */
6489 +/* li takes a 32bit immediate */
6490 +#define TIF_GRSEC_SETXID 10 /* update credentials on syscall entry/exit */
6491 +
6492 #define TIF_USEDFPU 16 /* FPU was used by this task this quantum (SMP) */
6493 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
6494 #define TIF_NOHZ 19 /* in adaptive nohz mode */
6495 @@ -138,14 +141,16 @@ static inline struct thread_info *current_thread_info(void)
6496 #define _TIF_USEDMSA (1<<TIF_USEDMSA)
6497 #define _TIF_MSA_CTX_LIVE (1<<TIF_MSA_CTX_LIVE)
6498 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6499 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6500
6501 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6502 _TIF_SYSCALL_AUDIT | \
6503 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
6504 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
6505 + _TIF_GRSEC_SETXID)
6506
6507 /* work to do in syscall_trace_leave() */
6508 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6509 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6510 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6511
6512 /* work to do on interrupt/exception return */
6513 #define _TIF_WORK_MASK \
6514 @@ -153,7 +158,7 @@ static inline struct thread_info *current_thread_info(void)
6515 /* work to do on any return to u-space */
6516 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6517 _TIF_WORK_SYSCALL_EXIT | \
6518 - _TIF_SYSCALL_TRACEPOINT)
6519 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6520
6521 /*
6522 * We stash processor id into a COP0 register to retrieve it fast
6523 diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6524 index 22a5624..7c96295 100644
6525 --- a/arch/mips/include/asm/uaccess.h
6526 +++ b/arch/mips/include/asm/uaccess.h
6527 @@ -130,6 +130,7 @@ extern u64 __ua_limit;
6528 __ok == 0; \
6529 })
6530
6531 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6532 #define access_ok(type, addr, size) \
6533 likely(__access_ok((addr), (size), __access_mask))
6534
6535 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6536 index 1188e00..41cf144 100644
6537 --- a/arch/mips/kernel/binfmt_elfn32.c
6538 +++ b/arch/mips/kernel/binfmt_elfn32.c
6539 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6540 #undef ELF_ET_DYN_BASE
6541 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6542
6543 +#ifdef CONFIG_PAX_ASLR
6544 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6545 +
6546 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6547 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6548 +#endif
6549 +
6550 #include <asm/processor.h>
6551 #include <linux/module.h>
6552 #include <linux/elfcore.h>
6553 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6554 index 9287678..f870e47 100644
6555 --- a/arch/mips/kernel/binfmt_elfo32.c
6556 +++ b/arch/mips/kernel/binfmt_elfo32.c
6557 @@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6558 #undef ELF_ET_DYN_BASE
6559 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6560
6561 +#ifdef CONFIG_PAX_ASLR
6562 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6563 +
6564 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6565 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6566 +#endif
6567 +
6568 #include <asm/processor.h>
6569
6570 #include <linux/module.h>
6571 diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
6572 index 50b3648..c2f3cec 100644
6573 --- a/arch/mips/kernel/i8259.c
6574 +++ b/arch/mips/kernel/i8259.c
6575 @@ -201,7 +201,7 @@ spurious_8259A_irq:
6576 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
6577 spurious_irq_mask |= irqmask;
6578 }
6579 - atomic_inc(&irq_err_count);
6580 + atomic_inc_unchecked(&irq_err_count);
6581 /*
6582 * Theoretically we do not have to handle this IRQ,
6583 * but in Linux this does not cause problems and is
6584 diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
6585 index 44a1f79..2bd6aa3 100644
6586 --- a/arch/mips/kernel/irq-gt641xx.c
6587 +++ b/arch/mips/kernel/irq-gt641xx.c
6588 @@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
6589 }
6590 }
6591
6592 - atomic_inc(&irq_err_count);
6593 + atomic_inc_unchecked(&irq_err_count);
6594 }
6595
6596 void __init gt641xx_irq_init(void)
6597 diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6598 index d2bfbc2..a8eacd2 100644
6599 --- a/arch/mips/kernel/irq.c
6600 +++ b/arch/mips/kernel/irq.c
6601 @@ -76,17 +76,17 @@ void ack_bad_irq(unsigned int irq)
6602 printk("unexpected IRQ # %d\n", irq);
6603 }
6604
6605 -atomic_t irq_err_count;
6606 +atomic_unchecked_t irq_err_count;
6607
6608 int arch_show_interrupts(struct seq_file *p, int prec)
6609 {
6610 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6611 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6612 return 0;
6613 }
6614
6615 asmlinkage void spurious_interrupt(void)
6616 {
6617 - atomic_inc(&irq_err_count);
6618 + atomic_inc_unchecked(&irq_err_count);
6619 }
6620
6621 void __init init_IRQ(void)
6622 @@ -109,7 +109,10 @@ void __init init_IRQ(void)
6623 #endif
6624 }
6625
6626 +
6627 #ifdef DEBUG_STACKOVERFLOW
6628 +extern void gr_handle_kernel_exploit(void);
6629 +
6630 static inline void check_stack_overflow(void)
6631 {
6632 unsigned long sp;
6633 @@ -125,6 +128,7 @@ static inline void check_stack_overflow(void)
6634 printk("do_IRQ: stack overflow: %ld\n",
6635 sp - sizeof(struct thread_info));
6636 dump_stack();
6637 + gr_handle_kernel_exploit();
6638 }
6639 }
6640 #else
6641 diff --git a/arch/mips/kernel/pm-cps.c b/arch/mips/kernel/pm-cps.c
6642 index 0614717..002fa43 100644
6643 --- a/arch/mips/kernel/pm-cps.c
6644 +++ b/arch/mips/kernel/pm-cps.c
6645 @@ -172,7 +172,7 @@ int cps_pm_enter_state(enum cps_pm_state state)
6646 nc_core_ready_count = nc_addr;
6647
6648 /* Ensure ready_count is zero-initialised before the assembly runs */
6649 - ACCESS_ONCE(*nc_core_ready_count) = 0;
6650 + ACCESS_ONCE_RW(*nc_core_ready_count) = 0;
6651 coupled_barrier(&per_cpu(pm_barrier, core), online);
6652
6653 /* Run the generated entry code */
6654 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6655 index 636b074..8fbb91f 100644
6656 --- a/arch/mips/kernel/process.c
6657 +++ b/arch/mips/kernel/process.c
6658 @@ -520,15 +520,3 @@ unsigned long get_wchan(struct task_struct *task)
6659 out:
6660 return pc;
6661 }
6662 -
6663 -/*
6664 - * Don't forget that the stack pointer must be aligned on a 8 bytes
6665 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6666 - */
6667 -unsigned long arch_align_stack(unsigned long sp)
6668 -{
6669 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6670 - sp -= get_random_int() & ~PAGE_MASK;
6671 -
6672 - return sp & ALMASK;
6673 -}
6674 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6675 index 9d1487d..10c5da5 100644
6676 --- a/arch/mips/kernel/ptrace.c
6677 +++ b/arch/mips/kernel/ptrace.c
6678 @@ -761,6 +761,10 @@ long arch_ptrace(struct task_struct *child, long request,
6679 return ret;
6680 }
6681
6682 +#ifdef CONFIG_GRKERNSEC_SETXID
6683 +extern void gr_delayed_cred_worker(void);
6684 +#endif
6685 +
6686 /*
6687 * Notification of system call entry/exit
6688 * - triggered by current->work.syscall_trace
6689 @@ -777,6 +781,11 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
6690 tracehook_report_syscall_entry(regs))
6691 ret = -1;
6692
6693 +#ifdef CONFIG_GRKERNSEC_SETXID
6694 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6695 + gr_delayed_cred_worker();
6696 +#endif
6697 +
6698 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6699 trace_sys_enter(regs, regs->regs[2]);
6700
6701 diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
6702 index 07fc524..b9d7f28 100644
6703 --- a/arch/mips/kernel/reset.c
6704 +++ b/arch/mips/kernel/reset.c
6705 @@ -13,6 +13,7 @@
6706 #include <linux/reboot.h>
6707
6708 #include <asm/reboot.h>
6709 +#include <asm/bug.h>
6710
6711 /*
6712 * Urgs ... Too many MIPS machines to handle this in a generic way.
6713 @@ -29,16 +30,19 @@ void machine_restart(char *command)
6714 {
6715 if (_machine_restart)
6716 _machine_restart(command);
6717 + BUG();
6718 }
6719
6720 void machine_halt(void)
6721 {
6722 if (_machine_halt)
6723 _machine_halt();
6724 + BUG();
6725 }
6726
6727 void machine_power_off(void)
6728 {
6729 if (pm_power_off)
6730 pm_power_off();
6731 + BUG();
6732 }
6733 diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6734 index 2242bdd..b284048 100644
6735 --- a/arch/mips/kernel/sync-r4k.c
6736 +++ b/arch/mips/kernel/sync-r4k.c
6737 @@ -18,8 +18,8 @@
6738 #include <asm/mipsregs.h>
6739
6740 static atomic_t count_start_flag = ATOMIC_INIT(0);
6741 -static atomic_t count_count_start = ATOMIC_INIT(0);
6742 -static atomic_t count_count_stop = ATOMIC_INIT(0);
6743 +static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6744 +static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6745 static atomic_t count_reference = ATOMIC_INIT(0);
6746
6747 #define COUNTON 100
6748 @@ -58,13 +58,13 @@ void synchronise_count_master(int cpu)
6749
6750 for (i = 0; i < NR_LOOPS; i++) {
6751 /* slaves loop on '!= 2' */
6752 - while (atomic_read(&count_count_start) != 1)
6753 + while (atomic_read_unchecked(&count_count_start) != 1)
6754 mb();
6755 - atomic_set(&count_count_stop, 0);
6756 + atomic_set_unchecked(&count_count_stop, 0);
6757 smp_wmb();
6758
6759 /* this lets the slaves write their count register */
6760 - atomic_inc(&count_count_start);
6761 + atomic_inc_unchecked(&count_count_start);
6762
6763 /*
6764 * Everyone initialises count in the last loop:
6765 @@ -75,11 +75,11 @@ void synchronise_count_master(int cpu)
6766 /*
6767 * Wait for all slaves to leave the synchronization point:
6768 */
6769 - while (atomic_read(&count_count_stop) != 1)
6770 + while (atomic_read_unchecked(&count_count_stop) != 1)
6771 mb();
6772 - atomic_set(&count_count_start, 0);
6773 + atomic_set_unchecked(&count_count_start, 0);
6774 smp_wmb();
6775 - atomic_inc(&count_count_stop);
6776 + atomic_inc_unchecked(&count_count_stop);
6777 }
6778 /* Arrange for an interrupt in a short while */
6779 write_c0_compare(read_c0_count() + COUNTON);
6780 @@ -112,8 +112,8 @@ void synchronise_count_slave(int cpu)
6781 initcount = atomic_read(&count_reference);
6782
6783 for (i = 0; i < NR_LOOPS; i++) {
6784 - atomic_inc(&count_count_start);
6785 - while (atomic_read(&count_count_start) != 2)
6786 + atomic_inc_unchecked(&count_count_start);
6787 + while (atomic_read_unchecked(&count_count_start) != 2)
6788 mb();
6789
6790 /*
6791 @@ -122,8 +122,8 @@ void synchronise_count_slave(int cpu)
6792 if (i == NR_LOOPS-1)
6793 write_c0_count(initcount);
6794
6795 - atomic_inc(&count_count_stop);
6796 - while (atomic_read(&count_count_stop) != 2)
6797 + atomic_inc_unchecked(&count_count_stop);
6798 + while (atomic_read_unchecked(&count_count_stop) != 2)
6799 mb();
6800 }
6801 /* Arrange for an interrupt in a short while */
6802 diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
6803 index 22b19c2..c5cc8c4 100644
6804 --- a/arch/mips/kernel/traps.c
6805 +++ b/arch/mips/kernel/traps.c
6806 @@ -688,7 +688,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
6807 siginfo_t info;
6808
6809 prev_state = exception_enter();
6810 - die_if_kernel("Integer overflow", regs);
6811 + if (unlikely(!user_mode(regs))) {
6812 +
6813 +#ifdef CONFIG_PAX_REFCOUNT
6814 + if (fixup_exception(regs)) {
6815 + pax_report_refcount_overflow(regs);
6816 + exception_exit(prev_state);
6817 + return;
6818 + }
6819 +#endif
6820 +
6821 + die("Integer overflow", regs);
6822 + }
6823
6824 info.si_code = FPE_INTOVF;
6825 info.si_signo = SIGFPE;
6826 diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
6827 index e3b21e5..ea5ff7c 100644
6828 --- a/arch/mips/kvm/mips.c
6829 +++ b/arch/mips/kvm/mips.c
6830 @@ -805,7 +805,7 @@ long kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
6831 return r;
6832 }
6833
6834 -int kvm_arch_init(void *opaque)
6835 +int kvm_arch_init(const void *opaque)
6836 {
6837 if (kvm_mips_callbacks) {
6838 kvm_err("kvm: module already exists\n");
6839 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
6840 index becc42b..9e43d4b 100644
6841 --- a/arch/mips/mm/fault.c
6842 +++ b/arch/mips/mm/fault.c
6843 @@ -28,6 +28,23 @@
6844 #include <asm/highmem.h> /* For VMALLOC_END */
6845 #include <linux/kdebug.h>
6846
6847 +#ifdef CONFIG_PAX_PAGEEXEC
6848 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6849 +{
6850 + unsigned long i;
6851 +
6852 + printk(KERN_ERR "PAX: bytes at PC: ");
6853 + for (i = 0; i < 5; i++) {
6854 + unsigned int c;
6855 + if (get_user(c, (unsigned int *)pc+i))
6856 + printk(KERN_CONT "???????? ");
6857 + else
6858 + printk(KERN_CONT "%08x ", c);
6859 + }
6860 + printk("\n");
6861 +}
6862 +#endif
6863 +
6864 /*
6865 * This routine handles page faults. It determines the address,
6866 * and the problem, and then passes it off to one of the appropriate
6867 @@ -199,6 +216,14 @@ bad_area:
6868 bad_area_nosemaphore:
6869 /* User mode accesses just cause a SIGSEGV */
6870 if (user_mode(regs)) {
6871 +
6872 +#ifdef CONFIG_PAX_PAGEEXEC
6873 + if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
6874 + pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
6875 + do_group_exit(SIGKILL);
6876 + }
6877 +#endif
6878 +
6879 tsk->thread.cp0_badvaddr = address;
6880 tsk->thread.error_code = write;
6881 #if 0
6882 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
6883 index f1baadd..5472dca 100644
6884 --- a/arch/mips/mm/mmap.c
6885 +++ b/arch/mips/mm/mmap.c
6886 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6887 struct vm_area_struct *vma;
6888 unsigned long addr = addr0;
6889 int do_color_align;
6890 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6891 struct vm_unmapped_area_info info;
6892
6893 if (unlikely(len > TASK_SIZE))
6894 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6895 do_color_align = 1;
6896
6897 /* requesting a specific address */
6898 +
6899 +#ifdef CONFIG_PAX_RANDMMAP
6900 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
6901 +#endif
6902 +
6903 if (addr) {
6904 if (do_color_align)
6905 addr = COLOUR_ALIGN(addr, pgoff);
6906 @@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6907 addr = PAGE_ALIGN(addr);
6908
6909 vma = find_vma(mm, addr);
6910 - if (TASK_SIZE - len >= addr &&
6911 - (!vma || addr + len <= vma->vm_start))
6912 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6913 return addr;
6914 }
6915
6916 info.length = len;
6917 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
6918 info.align_offset = pgoff << PAGE_SHIFT;
6919 + info.threadstack_offset = offset;
6920
6921 if (dir == DOWN) {
6922 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
6923 @@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6924 {
6925 unsigned long random_factor = 0UL;
6926
6927 +#ifdef CONFIG_PAX_RANDMMAP
6928 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6929 +#endif
6930 +
6931 if (current->flags & PF_RANDOMIZE) {
6932 random_factor = get_random_int();
6933 random_factor = random_factor << PAGE_SHIFT;
6934 @@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6935
6936 if (mmap_is_legacy()) {
6937 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6938 +
6939 +#ifdef CONFIG_PAX_RANDMMAP
6940 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6941 + mm->mmap_base += mm->delta_mmap;
6942 +#endif
6943 +
6944 mm->get_unmapped_area = arch_get_unmapped_area;
6945 } else {
6946 mm->mmap_base = mmap_base(random_factor);
6947 +
6948 +#ifdef CONFIG_PAX_RANDMMAP
6949 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6950 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6951 +#endif
6952 +
6953 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6954 }
6955 }
6956
6957 -static inline unsigned long brk_rnd(void)
6958 -{
6959 - unsigned long rnd = get_random_int();
6960 -
6961 - rnd = rnd << PAGE_SHIFT;
6962 - /* 8MB for 32bit, 256MB for 64bit */
6963 - if (TASK_IS_32BIT_ADDR)
6964 - rnd = rnd & 0x7ffffful;
6965 - else
6966 - rnd = rnd & 0xffffffful;
6967 -
6968 - return rnd;
6969 -}
6970 -
6971 -unsigned long arch_randomize_brk(struct mm_struct *mm)
6972 -{
6973 - unsigned long base = mm->brk;
6974 - unsigned long ret;
6975 -
6976 - ret = PAGE_ALIGN(base + brk_rnd());
6977 -
6978 - if (ret < mm->brk)
6979 - return mm->brk;
6980 -
6981 - return ret;
6982 -}
6983 -
6984 int __virt_addr_valid(const volatile void *kaddr)
6985 {
6986 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
6987 diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
6988 index 59cccd9..f39ac2f 100644
6989 --- a/arch/mips/pci/pci-octeon.c
6990 +++ b/arch/mips/pci/pci-octeon.c
6991 @@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
6992
6993
6994 static struct pci_ops octeon_pci_ops = {
6995 - octeon_read_config,
6996 - octeon_write_config,
6997 + .read = octeon_read_config,
6998 + .write = octeon_write_config,
6999 };
7000
7001 static struct resource octeon_pci_mem_resource = {
7002 diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7003 index 5e36c33..eb4a17b 100644
7004 --- a/arch/mips/pci/pcie-octeon.c
7005 +++ b/arch/mips/pci/pcie-octeon.c
7006 @@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7007 }
7008
7009 static struct pci_ops octeon_pcie0_ops = {
7010 - octeon_pcie0_read_config,
7011 - octeon_pcie0_write_config,
7012 + .read = octeon_pcie0_read_config,
7013 + .write = octeon_pcie0_write_config,
7014 };
7015
7016 static struct resource octeon_pcie0_mem_resource = {
7017 @@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7018 };
7019
7020 static struct pci_ops octeon_pcie1_ops = {
7021 - octeon_pcie1_read_config,
7022 - octeon_pcie1_write_config,
7023 + .read = octeon_pcie1_read_config,
7024 + .write = octeon_pcie1_write_config,
7025 };
7026
7027 static struct resource octeon_pcie1_mem_resource = {
7028 @@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7029 };
7030
7031 static struct pci_ops octeon_dummy_ops = {
7032 - octeon_dummy_read_config,
7033 - octeon_dummy_write_config,
7034 + .read = octeon_dummy_read_config,
7035 + .write = octeon_dummy_write_config,
7036 };
7037
7038 static struct resource octeon_dummy_mem_resource = {
7039 diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7040 index a2358b4..7cead4f 100644
7041 --- a/arch/mips/sgi-ip27/ip27-nmi.c
7042 +++ b/arch/mips/sgi-ip27/ip27-nmi.c
7043 @@ -187,9 +187,9 @@ void
7044 cont_nmi_dump(void)
7045 {
7046 #ifndef REAL_NMI_SIGNAL
7047 - static atomic_t nmied_cpus = ATOMIC_INIT(0);
7048 + static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7049
7050 - atomic_inc(&nmied_cpus);
7051 + atomic_inc_unchecked(&nmied_cpus);
7052 #endif
7053 /*
7054 * Only allow 1 cpu to proceed
7055 @@ -233,7 +233,7 @@ cont_nmi_dump(void)
7056 udelay(10000);
7057 }
7058 #else
7059 - while (atomic_read(&nmied_cpus) != num_online_cpus());
7060 + while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7061 #endif
7062
7063 /*
7064 diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7065 index a046b30..6799527 100644
7066 --- a/arch/mips/sni/rm200.c
7067 +++ b/arch/mips/sni/rm200.c
7068 @@ -270,7 +270,7 @@ spurious_8259A_irq:
7069 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7070 spurious_irq_mask |= irqmask;
7071 }
7072 - atomic_inc(&irq_err_count);
7073 + atomic_inc_unchecked(&irq_err_count);
7074 /*
7075 * Theoretically we do not have to handle this IRQ,
7076 * but in Linux this does not cause problems and is
7077 diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7078 index 41e873b..34d33a7 100644
7079 --- a/arch/mips/vr41xx/common/icu.c
7080 +++ b/arch/mips/vr41xx/common/icu.c
7081 @@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7082
7083 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7084
7085 - atomic_inc(&irq_err_count);
7086 + atomic_inc_unchecked(&irq_err_count);
7087
7088 return -1;
7089 }
7090 diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7091 index ae0e4ee..e8f0692 100644
7092 --- a/arch/mips/vr41xx/common/irq.c
7093 +++ b/arch/mips/vr41xx/common/irq.c
7094 @@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7095 irq_cascade_t *cascade;
7096
7097 if (irq >= NR_IRQS) {
7098 - atomic_inc(&irq_err_count);
7099 + atomic_inc_unchecked(&irq_err_count);
7100 return;
7101 }
7102
7103 @@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7104 ret = cascade->get_irq(irq);
7105 irq = ret;
7106 if (ret < 0)
7107 - atomic_inc(&irq_err_count);
7108 + atomic_inc_unchecked(&irq_err_count);
7109 else
7110 irq_dispatch(irq);
7111 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7112 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7113 index 967d144..db12197 100644
7114 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7115 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7116 @@ -11,12 +11,14 @@
7117 #ifndef _ASM_PROC_CACHE_H
7118 #define _ASM_PROC_CACHE_H
7119
7120 +#include <linux/const.h>
7121 +
7122 /* L1 cache */
7123
7124 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7125 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7126 -#define L1_CACHE_BYTES 16 /* bytes per entry */
7127 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7128 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7129 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7130
7131 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7132 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7133 index bcb5df2..84fabd2 100644
7134 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7135 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7136 @@ -16,13 +16,15 @@
7137 #ifndef _ASM_PROC_CACHE_H
7138 #define _ASM_PROC_CACHE_H
7139
7140 +#include <linux/const.h>
7141 +
7142 /*
7143 * L1 cache
7144 */
7145 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7146 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7147 -#define L1_CACHE_BYTES 32 /* bytes per entry */
7148 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7149 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7150 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7151
7152 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7153 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7154 index 4ce7a01..449202a 100644
7155 --- a/arch/openrisc/include/asm/cache.h
7156 +++ b/arch/openrisc/include/asm/cache.h
7157 @@ -19,11 +19,13 @@
7158 #ifndef __ASM_OPENRISC_CACHE_H
7159 #define __ASM_OPENRISC_CACHE_H
7160
7161 +#include <linux/const.h>
7162 +
7163 /* FIXME: How can we replace these with values from the CPU...
7164 * they shouldn't be hard-coded!
7165 */
7166
7167 -#define L1_CACHE_BYTES 16
7168 #define L1_CACHE_SHIFT 4
7169 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7170
7171 #endif /* __ASM_OPENRISC_CACHE_H */
7172 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7173 index 226f8ca..9d9b87d 100644
7174 --- a/arch/parisc/include/asm/atomic.h
7175 +++ b/arch/parisc/include/asm/atomic.h
7176 @@ -273,6 +273,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7177 return dec;
7178 }
7179
7180 +#define atomic64_read_unchecked(v) atomic64_read(v)
7181 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7182 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7183 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7184 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7185 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7186 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7187 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7188 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7189 +
7190 #endif /* !CONFIG_64BIT */
7191
7192
7193 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7194 index 47f11c7..3420df2 100644
7195 --- a/arch/parisc/include/asm/cache.h
7196 +++ b/arch/parisc/include/asm/cache.h
7197 @@ -5,6 +5,7 @@
7198 #ifndef __ARCH_PARISC_CACHE_H
7199 #define __ARCH_PARISC_CACHE_H
7200
7201 +#include <linux/const.h>
7202
7203 /*
7204 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7205 @@ -15,13 +16,13 @@
7206 * just ruin performance.
7207 */
7208 #ifdef CONFIG_PA20
7209 -#define L1_CACHE_BYTES 64
7210 #define L1_CACHE_SHIFT 6
7211 #else
7212 -#define L1_CACHE_BYTES 32
7213 #define L1_CACHE_SHIFT 5
7214 #endif
7215
7216 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7217 +
7218 #ifndef __ASSEMBLY__
7219
7220 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7221 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7222 index 3391d06..c23a2cc 100644
7223 --- a/arch/parisc/include/asm/elf.h
7224 +++ b/arch/parisc/include/asm/elf.h
7225 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7226
7227 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7228
7229 +#ifdef CONFIG_PAX_ASLR
7230 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
7231 +
7232 +#define PAX_DELTA_MMAP_LEN 16
7233 +#define PAX_DELTA_STACK_LEN 16
7234 +#endif
7235 +
7236 /* This yields a mask that user programs can use to figure out what
7237 instruction set this CPU supports. This could be done in user space,
7238 but it's not easy, and we've already done it here. */
7239 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7240 index f213f5b..0af3e8e 100644
7241 --- a/arch/parisc/include/asm/pgalloc.h
7242 +++ b/arch/parisc/include/asm/pgalloc.h
7243 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7244 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7245 }
7246
7247 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7248 +{
7249 + pgd_populate(mm, pgd, pmd);
7250 +}
7251 +
7252 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7253 {
7254 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7255 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7256 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7257 #define pmd_free(mm, x) do { } while (0)
7258 #define pgd_populate(mm, pmd, pte) BUG()
7259 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
7260
7261 #endif
7262
7263 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7264 index 22b89d1..ce34230 100644
7265 --- a/arch/parisc/include/asm/pgtable.h
7266 +++ b/arch/parisc/include/asm/pgtable.h
7267 @@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7268 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7269 #define PAGE_COPY PAGE_EXECREAD
7270 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7271 +
7272 +#ifdef CONFIG_PAX_PAGEEXEC
7273 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7274 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7275 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7276 +#else
7277 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
7278 +# define PAGE_COPY_NOEXEC PAGE_COPY
7279 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
7280 +#endif
7281 +
7282 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7283 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7284 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7285 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7286 index a5cb070..8604ddc 100644
7287 --- a/arch/parisc/include/asm/uaccess.h
7288 +++ b/arch/parisc/include/asm/uaccess.h
7289 @@ -243,10 +243,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7290 const void __user *from,
7291 unsigned long n)
7292 {
7293 - int sz = __compiletime_object_size(to);
7294 + size_t sz = __compiletime_object_size(to);
7295 int ret = -EFAULT;
7296
7297 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7298 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7299 ret = __copy_from_user(to, from, n);
7300 else
7301 copy_from_user_overflow();
7302 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7303 index 50dfafc..b9fc230 100644
7304 --- a/arch/parisc/kernel/module.c
7305 +++ b/arch/parisc/kernel/module.c
7306 @@ -98,16 +98,38 @@
7307
7308 /* three functions to determine where in the module core
7309 * or init pieces the location is */
7310 +static inline int in_init_rx(struct module *me, void *loc)
7311 +{
7312 + return (loc >= me->module_init_rx &&
7313 + loc < (me->module_init_rx + me->init_size_rx));
7314 +}
7315 +
7316 +static inline int in_init_rw(struct module *me, void *loc)
7317 +{
7318 + return (loc >= me->module_init_rw &&
7319 + loc < (me->module_init_rw + me->init_size_rw));
7320 +}
7321 +
7322 static inline int in_init(struct module *me, void *loc)
7323 {
7324 - return (loc >= me->module_init &&
7325 - loc <= (me->module_init + me->init_size));
7326 + return in_init_rx(me, loc) || in_init_rw(me, loc);
7327 +}
7328 +
7329 +static inline int in_core_rx(struct module *me, void *loc)
7330 +{
7331 + return (loc >= me->module_core_rx &&
7332 + loc < (me->module_core_rx + me->core_size_rx));
7333 +}
7334 +
7335 +static inline int in_core_rw(struct module *me, void *loc)
7336 +{
7337 + return (loc >= me->module_core_rw &&
7338 + loc < (me->module_core_rw + me->core_size_rw));
7339 }
7340
7341 static inline int in_core(struct module *me, void *loc)
7342 {
7343 - return (loc >= me->module_core &&
7344 - loc <= (me->module_core + me->core_size));
7345 + return in_core_rx(me, loc) || in_core_rw(me, loc);
7346 }
7347
7348 static inline int in_local(struct module *me, void *loc)
7349 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7350 }
7351
7352 /* align things a bit */
7353 - me->core_size = ALIGN(me->core_size, 16);
7354 - me->arch.got_offset = me->core_size;
7355 - me->core_size += gots * sizeof(struct got_entry);
7356 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7357 + me->arch.got_offset = me->core_size_rw;
7358 + me->core_size_rw += gots * sizeof(struct got_entry);
7359
7360 - me->core_size = ALIGN(me->core_size, 16);
7361 - me->arch.fdesc_offset = me->core_size;
7362 - me->core_size += fdescs * sizeof(Elf_Fdesc);
7363 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7364 + me->arch.fdesc_offset = me->core_size_rw;
7365 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7366
7367 me->arch.got_max = gots;
7368 me->arch.fdesc_max = fdescs;
7369 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7370
7371 BUG_ON(value == 0);
7372
7373 - got = me->module_core + me->arch.got_offset;
7374 + got = me->module_core_rw + me->arch.got_offset;
7375 for (i = 0; got[i].addr; i++)
7376 if (got[i].addr == value)
7377 goto out;
7378 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7379 #ifdef CONFIG_64BIT
7380 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7381 {
7382 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7383 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7384
7385 if (!value) {
7386 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7387 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7388
7389 /* Create new one */
7390 fdesc->addr = value;
7391 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7392 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7393 return (Elf_Addr)fdesc;
7394 }
7395 #endif /* CONFIG_64BIT */
7396 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7397
7398 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7399 end = table + sechdrs[me->arch.unwind_section].sh_size;
7400 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7401 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7402
7403 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7404 me->arch.unwind_section, table, end, gp);
7405 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7406 index e1ffea2..46ed66e 100644
7407 --- a/arch/parisc/kernel/sys_parisc.c
7408 +++ b/arch/parisc/kernel/sys_parisc.c
7409 @@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7410 unsigned long task_size = TASK_SIZE;
7411 int do_color_align, last_mmap;
7412 struct vm_unmapped_area_info info;
7413 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7414
7415 if (len > task_size)
7416 return -ENOMEM;
7417 @@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7418 goto found_addr;
7419 }
7420
7421 +#ifdef CONFIG_PAX_RANDMMAP
7422 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7423 +#endif
7424 +
7425 if (addr) {
7426 if (do_color_align && last_mmap)
7427 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7428 @@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7429 info.high_limit = mmap_upper_limit();
7430 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7431 info.align_offset = shared_align_offset(last_mmap, pgoff);
7432 + info.threadstack_offset = offset;
7433 addr = vm_unmapped_area(&info);
7434
7435 found_addr:
7436 @@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7437 unsigned long addr = addr0;
7438 int do_color_align, last_mmap;
7439 struct vm_unmapped_area_info info;
7440 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7441
7442 #ifdef CONFIG_64BIT
7443 /* This should only ever run for 32-bit processes. */
7444 @@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7445 }
7446
7447 /* requesting a specific address */
7448 +#ifdef CONFIG_PAX_RANDMMAP
7449 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7450 +#endif
7451 +
7452 if (addr) {
7453 if (do_color_align && last_mmap)
7454 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7455 @@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7456 info.high_limit = mm->mmap_base;
7457 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7458 info.align_offset = shared_align_offset(last_mmap, pgoff);
7459 + info.threadstack_offset = offset;
7460 addr = vm_unmapped_area(&info);
7461 if (!(addr & ~PAGE_MASK))
7462 goto found_addr;
7463 @@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7464 mm->mmap_legacy_base = mmap_legacy_base();
7465 mm->mmap_base = mmap_upper_limit();
7466
7467 +#ifdef CONFIG_PAX_RANDMMAP
7468 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
7469 + mm->mmap_legacy_base += mm->delta_mmap;
7470 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7471 + }
7472 +#endif
7473 +
7474 if (mmap_is_legacy()) {
7475 mm->mmap_base = mm->mmap_legacy_base;
7476 mm->get_unmapped_area = arch_get_unmapped_area;
7477 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7478 index 47ee620..1107387 100644
7479 --- a/arch/parisc/kernel/traps.c
7480 +++ b/arch/parisc/kernel/traps.c
7481 @@ -726,9 +726,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7482
7483 down_read(&current->mm->mmap_sem);
7484 vma = find_vma(current->mm,regs->iaoq[0]);
7485 - if (vma && (regs->iaoq[0] >= vma->vm_start)
7486 - && (vma->vm_flags & VM_EXEC)) {
7487 -
7488 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7489 fault_address = regs->iaoq[0];
7490 fault_space = regs->iasq[0];
7491
7492 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7493 index 3ca9c11..d163ef7 100644
7494 --- a/arch/parisc/mm/fault.c
7495 +++ b/arch/parisc/mm/fault.c
7496 @@ -15,6 +15,7 @@
7497 #include <linux/sched.h>
7498 #include <linux/interrupt.h>
7499 #include <linux/module.h>
7500 +#include <linux/unistd.h>
7501
7502 #include <asm/uaccess.h>
7503 #include <asm/traps.h>
7504 @@ -50,7 +51,7 @@ int show_unhandled_signals = 1;
7505 static unsigned long
7506 parisc_acctyp(unsigned long code, unsigned int inst)
7507 {
7508 - if (code == 6 || code == 16)
7509 + if (code == 6 || code == 7 || code == 16)
7510 return VM_EXEC;
7511
7512 switch (inst & 0xf0000000) {
7513 @@ -136,6 +137,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7514 }
7515 #endif
7516
7517 +#ifdef CONFIG_PAX_PAGEEXEC
7518 +/*
7519 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7520 + *
7521 + * returns 1 when task should be killed
7522 + * 2 when rt_sigreturn trampoline was detected
7523 + * 3 when unpatched PLT trampoline was detected
7524 + */
7525 +static int pax_handle_fetch_fault(struct pt_regs *regs)
7526 +{
7527 +
7528 +#ifdef CONFIG_PAX_EMUPLT
7529 + int err;
7530 +
7531 + do { /* PaX: unpatched PLT emulation */
7532 + unsigned int bl, depwi;
7533 +
7534 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7535 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7536 +
7537 + if (err)
7538 + break;
7539 +
7540 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7541 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7542 +
7543 + err = get_user(ldw, (unsigned int *)addr);
7544 + err |= get_user(bv, (unsigned int *)(addr+4));
7545 + err |= get_user(ldw2, (unsigned int *)(addr+8));
7546 +
7547 + if (err)
7548 + break;
7549 +
7550 + if (ldw == 0x0E801096U &&
7551 + bv == 0xEAC0C000U &&
7552 + ldw2 == 0x0E881095U)
7553 + {
7554 + unsigned int resolver, map;
7555 +
7556 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7557 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7558 + if (err)
7559 + break;
7560 +
7561 + regs->gr[20] = instruction_pointer(regs)+8;
7562 + regs->gr[21] = map;
7563 + regs->gr[22] = resolver;
7564 + regs->iaoq[0] = resolver | 3UL;
7565 + regs->iaoq[1] = regs->iaoq[0] + 4;
7566 + return 3;
7567 + }
7568 + }
7569 + } while (0);
7570 +#endif
7571 +
7572 +#ifdef CONFIG_PAX_EMUTRAMP
7573 +
7574 +#ifndef CONFIG_PAX_EMUSIGRT
7575 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7576 + return 1;
7577 +#endif
7578 +
7579 + do { /* PaX: rt_sigreturn emulation */
7580 + unsigned int ldi1, ldi2, bel, nop;
7581 +
7582 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7583 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7584 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7585 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7586 +
7587 + if (err)
7588 + break;
7589 +
7590 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7591 + ldi2 == 0x3414015AU &&
7592 + bel == 0xE4008200U &&
7593 + nop == 0x08000240U)
7594 + {
7595 + regs->gr[25] = (ldi1 & 2) >> 1;
7596 + regs->gr[20] = __NR_rt_sigreturn;
7597 + regs->gr[31] = regs->iaoq[1] + 16;
7598 + regs->sr[0] = regs->iasq[1];
7599 + regs->iaoq[0] = 0x100UL;
7600 + regs->iaoq[1] = regs->iaoq[0] + 4;
7601 + regs->iasq[0] = regs->sr[2];
7602 + regs->iasq[1] = regs->sr[2];
7603 + return 2;
7604 + }
7605 + } while (0);
7606 +#endif
7607 +
7608 + return 1;
7609 +}
7610 +
7611 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7612 +{
7613 + unsigned long i;
7614 +
7615 + printk(KERN_ERR "PAX: bytes at PC: ");
7616 + for (i = 0; i < 5; i++) {
7617 + unsigned int c;
7618 + if (get_user(c, (unsigned int *)pc+i))
7619 + printk(KERN_CONT "???????? ");
7620 + else
7621 + printk(KERN_CONT "%08x ", c);
7622 + }
7623 + printk("\n");
7624 +}
7625 +#endif
7626 +
7627 int fixup_exception(struct pt_regs *regs)
7628 {
7629 const struct exception_table_entry *fix;
7630 @@ -234,8 +345,33 @@ retry:
7631
7632 good_area:
7633
7634 - if ((vma->vm_flags & acc_type) != acc_type)
7635 + if ((vma->vm_flags & acc_type) != acc_type) {
7636 +
7637 +#ifdef CONFIG_PAX_PAGEEXEC
7638 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7639 + (address & ~3UL) == instruction_pointer(regs))
7640 + {
7641 + up_read(&mm->mmap_sem);
7642 + switch (pax_handle_fetch_fault(regs)) {
7643 +
7644 +#ifdef CONFIG_PAX_EMUPLT
7645 + case 3:
7646 + return;
7647 +#endif
7648 +
7649 +#ifdef CONFIG_PAX_EMUTRAMP
7650 + case 2:
7651 + return;
7652 +#endif
7653 +
7654 + }
7655 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7656 + do_group_exit(SIGKILL);
7657 + }
7658 +#endif
7659 +
7660 goto bad_area;
7661 + }
7662
7663 /*
7664 * If for any reason at all we couldn't handle the fault, make
7665 diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7666 index 88eace4..4ba2591 100644
7667 --- a/arch/powerpc/Kconfig
7668 +++ b/arch/powerpc/Kconfig
7669 @@ -404,6 +404,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
7670 config KEXEC
7671 bool "kexec system call"
7672 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7673 + depends on !GRKERNSEC_KMEM
7674 help
7675 kexec is a system call that implements the ability to shutdown your
7676 current kernel, and to start another kernel. It is like a reboot
7677 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7678 index 512d278..d31fadd 100644
7679 --- a/arch/powerpc/include/asm/atomic.h
7680 +++ b/arch/powerpc/include/asm/atomic.h
7681 @@ -12,6 +12,11 @@
7682
7683 #define ATOMIC_INIT(i) { (i) }
7684
7685 +#define _ASM_EXTABLE(from, to) \
7686 +" .section __ex_table,\"a\"\n" \
7687 + PPC_LONG" " #from ", " #to"\n" \
7688 +" .previous\n"
7689 +
7690 static __inline__ int atomic_read(const atomic_t *v)
7691 {
7692 int t;
7693 @@ -21,39 +26,80 @@ static __inline__ int atomic_read(const atomic_t *v)
7694 return t;
7695 }
7696
7697 +static __inline__ int atomic_read_unchecked(const atomic_unchecked_t *v)
7698 +{
7699 + int t;
7700 +
7701 + __asm__ __volatile__("lwz%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
7702 +
7703 + return t;
7704 +}
7705 +
7706 static __inline__ void atomic_set(atomic_t *v, int i)
7707 {
7708 __asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
7709 }
7710
7711 -#define ATOMIC_OP(op, asm_op) \
7712 -static __inline__ void atomic_##op(int a, atomic_t *v) \
7713 +static __inline__ void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7714 +{
7715 + __asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
7716 +}
7717 +
7718 +#ifdef CONFIG_PAX_REFCOUNT
7719 +#define __REFCOUNT_OP(op) op##o.
7720 +#define __OVERFLOW_PRE \
7721 + " mcrxr cr0\n"
7722 +#define __OVERFLOW_POST \
7723 + " bf 4*cr0+so, 3f\n" \
7724 + "2: .long 0x00c00b00\n" \
7725 + "3:\n"
7726 +#define __OVERFLOW_EXTABLE \
7727 + "\n4:\n"
7728 + _ASM_EXTABLE(2b, 4b)
7729 +#else
7730 +#define __REFCOUNT_OP(op) op
7731 +#define __OVERFLOW_PRE
7732 +#define __OVERFLOW_POST
7733 +#define __OVERFLOW_EXTABLE
7734 +#endif
7735 +
7736 +#define __ATOMIC_OP(op, suffix, pre_op, asm_op, post_op, extable) \
7737 +static inline void atomic_##op##suffix(int a, atomic##suffix##_t *v) \
7738 { \
7739 int t; \
7740 \
7741 __asm__ __volatile__( \
7742 -"1: lwarx %0,0,%3 # atomic_" #op "\n" \
7743 +"1: lwarx %0,0,%3 # atomic_" #op #suffix "\n" \
7744 + pre_op \
7745 #asm_op " %0,%2,%0\n" \
7746 + post_op \
7747 PPC405_ERR77(0,%3) \
7748 " stwcx. %0,0,%3 \n" \
7749 " bne- 1b\n" \
7750 + extable \
7751 : "=&r" (t), "+m" (v->counter) \
7752 : "r" (a), "r" (&v->counter) \
7753 : "cc"); \
7754 } \
7755
7756 -#define ATOMIC_OP_RETURN(op, asm_op) \
7757 -static __inline__ int atomic_##op##_return(int a, atomic_t *v) \
7758 +#define ATOMIC_OP(op, asm_op) __ATOMIC_OP(op, , , asm_op, , ) \
7759 + __ATOMIC_OP(op, _unchecked, __OVERFLOW_PRE, __REFCOUNT_OP(asm_op), __OVERFLOW_POST, __OVERFLOW_EXTABLE)
7760 +
7761 +#define __ATOMIC_OP_RETURN(op, suffix, pre_op, asm_op, post_op, extable)\
7762 +static inline int atomic_##op##_return##suffix(int a, atomic##suffix##_t *v)\
7763 { \
7764 int t; \
7765 \
7766 __asm__ __volatile__( \
7767 PPC_ATOMIC_ENTRY_BARRIER \
7768 -"1: lwarx %0,0,%2 # atomic_" #op "_return\n" \
7769 +"1: lwarx %0,0,%2 # atomic_" #op "_return" #suffix "\n" \
7770 + pre_op \
7771 #asm_op " %0,%1,%0\n" \
7772 + post_op \
7773 PPC405_ERR77(0,%2) \
7774 " stwcx. %0,0,%2 \n" \
7775 " bne- 1b\n" \
7776 + extable \
7777 PPC_ATOMIC_EXIT_BARRIER \
7778 : "=&r" (t) \
7779 : "r" (a), "r" (&v->counter) \
7780 @@ -62,6 +108,9 @@ static __inline__ int atomic_##op##_return(int a, atomic_t *v) \
7781 return t; \
7782 }
7783
7784 +#define ATOMIC_OP_RETURN(op, asm_op) __ATOMIC_OP_RETURN(op, , , asm_op, , )\
7785 + __ATOMIC_OP_RETURN(op, _unchecked, __OVERFLOW_PRE, __REFCOUNT_OP(asm_op), __OVERFLOW_POST, __OVERFLOW_EXTABLE)
7786 +
7787 #define ATOMIC_OPS(op, asm_op) ATOMIC_OP(op, asm_op) ATOMIC_OP_RETURN(op, asm_op)
7788
7789 ATOMIC_OPS(add, add)
7790 @@ -69,42 +118,29 @@ ATOMIC_OPS(sub, subf)
7791
7792 #undef ATOMIC_OPS
7793 #undef ATOMIC_OP_RETURN
7794 +#undef __ATOMIC_OP_RETURN
7795 #undef ATOMIC_OP
7796 +#undef __ATOMIC_OP
7797
7798 #define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
7799
7800 -static __inline__ void atomic_inc(atomic_t *v)
7801 -{
7802 - int t;
7803 +/*
7804 + * atomic_inc - increment atomic variable
7805 + * @v: pointer of type atomic_t
7806 + *
7807 + * Automatically increments @v by 1
7808 + */
7809 +#define atomic_inc(v) atomic_add(1, (v))
7810 +#define atomic_inc_return(v) atomic_add_return(1, (v))
7811
7812 - __asm__ __volatile__(
7813 -"1: lwarx %0,0,%2 # atomic_inc\n\
7814 - addic %0,%0,1\n"
7815 - PPC405_ERR77(0,%2)
7816 -" stwcx. %0,0,%2 \n\
7817 - bne- 1b"
7818 - : "=&r" (t), "+m" (v->counter)
7819 - : "r" (&v->counter)
7820 - : "cc", "xer");
7821 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7822 +{
7823 + atomic_add_unchecked(1, v);
7824 }
7825
7826 -static __inline__ int atomic_inc_return(atomic_t *v)
7827 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7828 {
7829 - int t;
7830 -
7831 - __asm__ __volatile__(
7832 - PPC_ATOMIC_ENTRY_BARRIER
7833 -"1: lwarx %0,0,%1 # atomic_inc_return\n\
7834 - addic %0,%0,1\n"
7835 - PPC405_ERR77(0,%1)
7836 -" stwcx. %0,0,%1 \n\
7837 - bne- 1b"
7838 - PPC_ATOMIC_EXIT_BARRIER
7839 - : "=&r" (t)
7840 - : "r" (&v->counter)
7841 - : "cc", "xer", "memory");
7842 -
7843 - return t;
7844 + return atomic_add_return_unchecked(1, v);
7845 }
7846
7847 /*
7848 @@ -117,43 +153,38 @@ static __inline__ int atomic_inc_return(atomic_t *v)
7849 */
7850 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
7851
7852 -static __inline__ void atomic_dec(atomic_t *v)
7853 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7854 {
7855 - int t;
7856 -
7857 - __asm__ __volatile__(
7858 -"1: lwarx %0,0,%2 # atomic_dec\n\
7859 - addic %0,%0,-1\n"
7860 - PPC405_ERR77(0,%2)\
7861 -" stwcx. %0,0,%2\n\
7862 - bne- 1b"
7863 - : "=&r" (t), "+m" (v->counter)
7864 - : "r" (&v->counter)
7865 - : "cc", "xer");
7866 + return atomic_add_return_unchecked(1, v) == 0;
7867 }
7868
7869 -static __inline__ int atomic_dec_return(atomic_t *v)
7870 +/*
7871 + * atomic_dec - decrement atomic variable
7872 + * @v: pointer of type atomic_t
7873 + *
7874 + * Atomically decrements @v by 1
7875 + */
7876 +#define atomic_dec(v) atomic_sub(1, (v))
7877 +#define atomic_dec_return(v) atomic_sub_return(1, (v))
7878 +
7879 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
7880 {
7881 - int t;
7882 -
7883 - __asm__ __volatile__(
7884 - PPC_ATOMIC_ENTRY_BARRIER
7885 -"1: lwarx %0,0,%1 # atomic_dec_return\n\
7886 - addic %0,%0,-1\n"
7887 - PPC405_ERR77(0,%1)
7888 -" stwcx. %0,0,%1\n\
7889 - bne- 1b"
7890 - PPC_ATOMIC_EXIT_BARRIER
7891 - : "=&r" (t)
7892 - : "r" (&v->counter)
7893 - : "cc", "xer", "memory");
7894 -
7895 - return t;
7896 + atomic_sub_unchecked(1, v);
7897 }
7898
7899 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
7900 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
7901
7902 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7903 +{
7904 + return cmpxchg(&(v->counter), old, new);
7905 +}
7906 +
7907 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7908 +{
7909 + return xchg(&(v->counter), new);
7910 +}
7911 +
7912 /**
7913 * __atomic_add_unless - add unless the number is a given value
7914 * @v: pointer of type atomic_t
7915 @@ -171,11 +202,27 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
7916 PPC_ATOMIC_ENTRY_BARRIER
7917 "1: lwarx %0,0,%1 # __atomic_add_unless\n\
7918 cmpw 0,%0,%3 \n\
7919 - beq- 2f \n\
7920 - add %0,%2,%0 \n"
7921 + beq- 2f \n"
7922 +
7923 +#ifdef CONFIG_PAX_REFCOUNT
7924 +" mcrxr cr0\n"
7925 +" addo. %0,%2,%0\n"
7926 +" bf 4*cr0+so, 4f\n"
7927 +"3:.long " "0x00c00b00""\n"
7928 +"4:\n"
7929 +#else
7930 + "add %0,%2,%0 \n"
7931 +#endif
7932 +
7933 PPC405_ERR77(0,%2)
7934 " stwcx. %0,0,%1 \n\
7935 bne- 1b \n"
7936 +"5:"
7937 +
7938 +#ifdef CONFIG_PAX_REFCOUNT
7939 + _ASM_EXTABLE(3b, 5b)
7940 +#endif
7941 +
7942 PPC_ATOMIC_EXIT_BARRIER
7943 " subf %0,%2,%0 \n\
7944 2:"
7945 @@ -248,6 +295,11 @@ static __inline__ int atomic_dec_if_positive(atomic_t *v)
7946 }
7947 #define atomic_dec_if_positive atomic_dec_if_positive
7948
7949 +#define smp_mb__before_atomic_dec() smp_mb()
7950 +#define smp_mb__after_atomic_dec() smp_mb()
7951 +#define smp_mb__before_atomic_inc() smp_mb()
7952 +#define smp_mb__after_atomic_inc() smp_mb()
7953 +
7954 #ifdef __powerpc64__
7955
7956 #define ATOMIC64_INIT(i) { (i) }
7957 @@ -261,37 +313,60 @@ static __inline__ long atomic64_read(const atomic64_t *v)
7958 return t;
7959 }
7960
7961 +static __inline__ long atomic64_read_unchecked(const atomic64_unchecked_t *v)
7962 +{
7963 + long t;
7964 +
7965 + __asm__ __volatile__("ld%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
7966 +
7967 + return t;
7968 +}
7969 +
7970 static __inline__ void atomic64_set(atomic64_t *v, long i)
7971 {
7972 __asm__ __volatile__("std%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
7973 }
7974
7975 -#define ATOMIC64_OP(op, asm_op) \
7976 -static __inline__ void atomic64_##op(long a, atomic64_t *v) \
7977 +static __inline__ void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
7978 +{
7979 + __asm__ __volatile__("std%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
7980 +}
7981 +
7982 +#define __ATOMIC64_OP(op, suffix, pre_op, asm_op, post_op, extable) \
7983 +static inline void atomic64_##op##suffix(long a, atomic64##suffix##_t *v)\
7984 { \
7985 long t; \
7986 \
7987 __asm__ __volatile__( \
7988 "1: ldarx %0,0,%3 # atomic64_" #op "\n" \
7989 + pre_op \
7990 #asm_op " %0,%2,%0\n" \
7991 + post_op \
7992 " stdcx. %0,0,%3 \n" \
7993 " bne- 1b\n" \
7994 + extable \
7995 : "=&r" (t), "+m" (v->counter) \
7996 : "r" (a), "r" (&v->counter) \
7997 : "cc"); \
7998 }
7999
8000 -#define ATOMIC64_OP_RETURN(op, asm_op) \
8001 -static __inline__ long atomic64_##op##_return(long a, atomic64_t *v) \
8002 +#define ATOMIC64_OP(op, asm_op) __ATOMIC64_OP(op, , , asm_op, , ) \
8003 + __ATOMIC64_OP(op, _unchecked, __OVERFLOW_PRE, __REFCOUNT_OP(asm_op), __OVERFLOW_POST, __OVERFLOW_EXTABLE)
8004 +
8005 +#define __ATOMIC64_OP_RETURN(op, suffix, pre_op, asm_op, post_op, extable)\
8006 +static inline long atomic64_##op##_return##suffix(long a, atomic64##suffix##_t *v)\
8007 { \
8008 long t; \
8009 \
8010 __asm__ __volatile__( \
8011 PPC_ATOMIC_ENTRY_BARRIER \
8012 "1: ldarx %0,0,%2 # atomic64_" #op "_return\n" \
8013 + pre_op \
8014 #asm_op " %0,%1,%0\n" \
8015 + post_op \
8016 " stdcx. %0,0,%2 \n" \
8017 " bne- 1b\n" \
8018 + extable \
8019 PPC_ATOMIC_EXIT_BARRIER \
8020 : "=&r" (t) \
8021 : "r" (a), "r" (&v->counter) \
8022 @@ -300,6 +375,9 @@ static __inline__ long atomic64_##op##_return(long a, atomic64_t *v) \
8023 return t; \
8024 }
8025
8026 +#define ATOMIC64_OP_RETURN(op, asm_op) __ATOMIC64_OP_RETURN(op, , , asm_op, , )\
8027 + __ATOMIC64_OP_RETURN(op, _unchecked, __OVERFLOW_PRE, __REFCOUNT_OP(asm_op), __OVERFLOW_POST, __OVERFLOW_EXTABLE)
8028 +
8029 #define ATOMIC64_OPS(op, asm_op) ATOMIC64_OP(op, asm_op) ATOMIC64_OP_RETURN(op, asm_op)
8030
8031 ATOMIC64_OPS(add, add)
8032 @@ -307,40 +385,33 @@ ATOMIC64_OPS(sub, subf)
8033
8034 #undef ATOMIC64_OPS
8035 #undef ATOMIC64_OP_RETURN
8036 +#undef __ATOMIC64_OP_RETURN
8037 #undef ATOMIC64_OP
8038 +#undef __ATOMIC64_OP
8039 +#undef __OVERFLOW_EXTABLE
8040 +#undef __OVERFLOW_POST
8041 +#undef __OVERFLOW_PRE
8042 +#undef __REFCOUNT_OP
8043
8044 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
8045
8046 -static __inline__ void atomic64_inc(atomic64_t *v)
8047 -{
8048 - long t;
8049 +/*
8050 + * atomic64_inc - increment atomic variable
8051 + * @v: pointer of type atomic64_t
8052 + *
8053 + * Automatically increments @v by 1
8054 + */
8055 +#define atomic64_inc(v) atomic64_add(1, (v))
8056 +#define atomic64_inc_return(v) atomic64_add_return(1, (v))
8057
8058 - __asm__ __volatile__(
8059 -"1: ldarx %0,0,%2 # atomic64_inc\n\
8060 - addic %0,%0,1\n\
8061 - stdcx. %0,0,%2 \n\
8062 - bne- 1b"
8063 - : "=&r" (t), "+m" (v->counter)
8064 - : "r" (&v->counter)
8065 - : "cc", "xer");
8066 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8067 +{
8068 + atomic64_add_unchecked(1, v);
8069 }
8070
8071 -static __inline__ long atomic64_inc_return(atomic64_t *v)
8072 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8073 {
8074 - long t;
8075 -
8076 - __asm__ __volatile__(
8077 - PPC_ATOMIC_ENTRY_BARRIER
8078 -"1: ldarx %0,0,%1 # atomic64_inc_return\n\
8079 - addic %0,%0,1\n\
8080 - stdcx. %0,0,%1 \n\
8081 - bne- 1b"
8082 - PPC_ATOMIC_EXIT_BARRIER
8083 - : "=&r" (t)
8084 - : "r" (&v->counter)
8085 - : "cc", "xer", "memory");
8086 -
8087 - return t;
8088 + return atomic64_add_return_unchecked(1, v);
8089 }
8090
8091 /*
8092 @@ -353,36 +424,18 @@ static __inline__ long atomic64_inc_return(atomic64_t *v)
8093 */
8094 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
8095
8096 -static __inline__ void atomic64_dec(atomic64_t *v)
8097 +/*
8098 + * atomic64_dec - decrement atomic variable
8099 + * @v: pointer of type atomic64_t
8100 + *
8101 + * Atomically decrements @v by 1
8102 + */
8103 +#define atomic64_dec(v) atomic64_sub(1, (v))
8104 +#define atomic64_dec_return(v) atomic64_sub_return(1, (v))
8105 +
8106 +static __inline__ void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8107 {
8108 - long t;
8109 -
8110 - __asm__ __volatile__(
8111 -"1: ldarx %0,0,%2 # atomic64_dec\n\
8112 - addic %0,%0,-1\n\
8113 - stdcx. %0,0,%2\n\
8114 - bne- 1b"
8115 - : "=&r" (t), "+m" (v->counter)
8116 - : "r" (&v->counter)
8117 - : "cc", "xer");
8118 -}
8119 -
8120 -static __inline__ long atomic64_dec_return(atomic64_t *v)
8121 -{
8122 - long t;
8123 -
8124 - __asm__ __volatile__(
8125 - PPC_ATOMIC_ENTRY_BARRIER
8126 -"1: ldarx %0,0,%1 # atomic64_dec_return\n\
8127 - addic %0,%0,-1\n\
8128 - stdcx. %0,0,%1\n\
8129 - bne- 1b"
8130 - PPC_ATOMIC_EXIT_BARRIER
8131 - : "=&r" (t)
8132 - : "r" (&v->counter)
8133 - : "cc", "xer", "memory");
8134 -
8135 - return t;
8136 + atomic64_sub_unchecked(1, v);
8137 }
8138
8139 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
8140 @@ -415,6 +468,16 @@ static __inline__ long atomic64_dec_if_positive(atomic64_t *v)
8141 #define atomic64_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
8142 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
8143
8144 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
8145 +{
8146 + return cmpxchg(&(v->counter), old, new);
8147 +}
8148 +
8149 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
8150 +{
8151 + return xchg(&(v->counter), new);
8152 +}
8153 +
8154 /**
8155 * atomic64_add_unless - add unless the number is a given value
8156 * @v: pointer of type atomic64_t
8157 @@ -430,13 +493,29 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
8158
8159 __asm__ __volatile__ (
8160 PPC_ATOMIC_ENTRY_BARRIER
8161 -"1: ldarx %0,0,%1 # __atomic_add_unless\n\
8162 +"1: ldarx %0,0,%1 # atomic64_add_unless\n\
8163 cmpd 0,%0,%3 \n\
8164 - beq- 2f \n\
8165 - add %0,%2,%0 \n"
8166 + beq- 2f \n"
8167 +
8168 +#ifdef CONFIG_PAX_REFCOUNT
8169 +" mcrxr cr0\n"
8170 +" addo. %0,%2,%0\n"
8171 +" bf 4*cr0+so, 4f\n"
8172 +"3:.long " "0x00c00b00""\n"
8173 +"4:\n"
8174 +#else
8175 + "add %0,%2,%0 \n"
8176 +#endif
8177 +
8178 " stdcx. %0,0,%1 \n\
8179 bne- 1b \n"
8180 PPC_ATOMIC_EXIT_BARRIER
8181 +"5:"
8182 +
8183 +#ifdef CONFIG_PAX_REFCOUNT
8184 + _ASM_EXTABLE(3b, 5b)
8185 +#endif
8186 +
8187 " subf %0,%2,%0 \n\
8188 2:"
8189 : "=&r" (t)
8190 diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
8191 index bab79a1..4a3eabc 100644
8192 --- a/arch/powerpc/include/asm/barrier.h
8193 +++ b/arch/powerpc/include/asm/barrier.h
8194 @@ -73,7 +73,7 @@
8195 do { \
8196 compiletime_assert_atomic_type(*p); \
8197 __lwsync(); \
8198 - ACCESS_ONCE(*p) = (v); \
8199 + ACCESS_ONCE_RW(*p) = (v); \
8200 } while (0)
8201
8202 #define smp_load_acquire(p) \
8203 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
8204 index 34a05a1..a1f2c67 100644
8205 --- a/arch/powerpc/include/asm/cache.h
8206 +++ b/arch/powerpc/include/asm/cache.h
8207 @@ -4,6 +4,7 @@
8208 #ifdef __KERNEL__
8209
8210 #include <asm/reg.h>
8211 +#include <linux/const.h>
8212
8213 /* bytes per L1 cache line */
8214 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
8215 @@ -23,7 +24,7 @@
8216 #define L1_CACHE_SHIFT 7
8217 #endif
8218
8219 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8220 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8221
8222 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8223
8224 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
8225 index 888d8f3..66f581c 100644
8226 --- a/arch/powerpc/include/asm/elf.h
8227 +++ b/arch/powerpc/include/asm/elf.h
8228 @@ -28,8 +28,19 @@
8229 the loader. We need to make sure that it is out of the way of the program
8230 that it will "exec", and that there is sufficient room for the brk. */
8231
8232 -extern unsigned long randomize_et_dyn(unsigned long base);
8233 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
8234 +#define ELF_ET_DYN_BASE (0x20000000)
8235 +
8236 +#ifdef CONFIG_PAX_ASLR
8237 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
8238 +
8239 +#ifdef __powerpc64__
8240 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
8241 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
8242 +#else
8243 +#define PAX_DELTA_MMAP_LEN 15
8244 +#define PAX_DELTA_STACK_LEN 15
8245 +#endif
8246 +#endif
8247
8248 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
8249
8250 @@ -129,10 +140,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8251 (0x7ff >> (PAGE_SHIFT - 12)) : \
8252 (0x3ffff >> (PAGE_SHIFT - 12)))
8253
8254 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8255 -#define arch_randomize_brk arch_randomize_brk
8256 -
8257 -
8258 #ifdef CONFIG_SPU_BASE
8259 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
8260 #define NT_SPU 1
8261 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
8262 index 8196e9c..d83a9f3 100644
8263 --- a/arch/powerpc/include/asm/exec.h
8264 +++ b/arch/powerpc/include/asm/exec.h
8265 @@ -4,6 +4,6 @@
8266 #ifndef _ASM_POWERPC_EXEC_H
8267 #define _ASM_POWERPC_EXEC_H
8268
8269 -extern unsigned long arch_align_stack(unsigned long sp);
8270 +#define arch_align_stack(x) ((x) & ~0xfUL)
8271
8272 #endif /* _ASM_POWERPC_EXEC_H */
8273 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
8274 index 5acabbd..7ea14fa 100644
8275 --- a/arch/powerpc/include/asm/kmap_types.h
8276 +++ b/arch/powerpc/include/asm/kmap_types.h
8277 @@ -10,7 +10,7 @@
8278 * 2 of the License, or (at your option) any later version.
8279 */
8280
8281 -#define KM_TYPE_NR 16
8282 +#define KM_TYPE_NR 17
8283
8284 #endif /* __KERNEL__ */
8285 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8286 diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8287 index b8da913..c02b593 100644
8288 --- a/arch/powerpc/include/asm/local.h
8289 +++ b/arch/powerpc/include/asm/local.h
8290 @@ -9,21 +9,65 @@ typedef struct
8291 atomic_long_t a;
8292 } local_t;
8293
8294 +typedef struct
8295 +{
8296 + atomic_long_unchecked_t a;
8297 +} local_unchecked_t;
8298 +
8299 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8300
8301 #define local_read(l) atomic_long_read(&(l)->a)
8302 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8303 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8304 +#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8305
8306 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8307 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8308 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8309 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8310 #define local_inc(l) atomic_long_inc(&(l)->a)
8311 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8312 #define local_dec(l) atomic_long_dec(&(l)->a)
8313 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8314
8315 static __inline__ long local_add_return(long a, local_t *l)
8316 {
8317 long t;
8318
8319 __asm__ __volatile__(
8320 +"1:" PPC_LLARX(%0,0,%2,0) " # local_add_return\n"
8321 +
8322 +#ifdef CONFIG_PAX_REFCOUNT
8323 +" mcrxr cr0\n"
8324 +" addo. %0,%1,%0\n"
8325 +" bf 4*cr0+so, 3f\n"
8326 +"2:.long " "0x00c00b00""\n"
8327 +#else
8328 +" add %0,%1,%0\n"
8329 +#endif
8330 +
8331 +"3:\n"
8332 + PPC405_ERR77(0,%2)
8333 + PPC_STLCX "%0,0,%2 \n\
8334 + bne- 1b"
8335 +
8336 +#ifdef CONFIG_PAX_REFCOUNT
8337 +"\n4:\n"
8338 + _ASM_EXTABLE(2b, 4b)
8339 +#endif
8340 +
8341 + : "=&r" (t)
8342 + : "r" (a), "r" (&(l->a.counter))
8343 + : "cc", "memory");
8344 +
8345 + return t;
8346 +}
8347 +
8348 +static __inline__ long local_add_return_unchecked(long a, local_unchecked_t *l)
8349 +{
8350 + long t;
8351 +
8352 + __asm__ __volatile__(
8353 "1:" PPC_LLARX(%0,0,%2,0) " # local_add_return\n\
8354 add %0,%1,%0\n"
8355 PPC405_ERR77(0,%2)
8356 @@ -101,6 +145,8 @@ static __inline__ long local_dec_return(local_t *l)
8357
8358 #define local_cmpxchg(l, o, n) \
8359 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8360 +#define local_cmpxchg_unchecked(l, o, n) \
8361 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
8362 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8363
8364 /**
8365 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8366 index 8565c25..2865190 100644
8367 --- a/arch/powerpc/include/asm/mman.h
8368 +++ b/arch/powerpc/include/asm/mman.h
8369 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8370 }
8371 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8372
8373 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8374 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8375 {
8376 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8377 }
8378 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8379 index 26fe1ae..987ffc5 100644
8380 --- a/arch/powerpc/include/asm/page.h
8381 +++ b/arch/powerpc/include/asm/page.h
8382 @@ -227,8 +227,9 @@ extern long long virt_phys_offset;
8383 * and needs to be executable. This means the whole heap ends
8384 * up being executable.
8385 */
8386 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8387 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8388 +#define VM_DATA_DEFAULT_FLAGS32 \
8389 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8390 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8391
8392 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8393 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8394 @@ -256,6 +257,9 @@ extern long long virt_phys_offset;
8395 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8396 #endif
8397
8398 +#define ktla_ktva(addr) (addr)
8399 +#define ktva_ktla(addr) (addr)
8400 +
8401 #ifndef CONFIG_PPC_BOOK3S_64
8402 /*
8403 * Use the top bit of the higher-level page table entries to indicate whether
8404 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8405 index d908a46..3753f71 100644
8406 --- a/arch/powerpc/include/asm/page_64.h
8407 +++ b/arch/powerpc/include/asm/page_64.h
8408 @@ -172,15 +172,18 @@ do { \
8409 * stack by default, so in the absence of a PT_GNU_STACK program header
8410 * we turn execute permission off.
8411 */
8412 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8413 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8414 +#define VM_STACK_DEFAULT_FLAGS32 \
8415 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8416 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8417
8418 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8419 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8420
8421 +#ifndef CONFIG_PAX_PAGEEXEC
8422 #define VM_STACK_DEFAULT_FLAGS \
8423 (is_32bit_task() ? \
8424 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8425 +#endif
8426
8427 #include <asm-generic/getorder.h>
8428
8429 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8430 index 4b0be20..c15a27d 100644
8431 --- a/arch/powerpc/include/asm/pgalloc-64.h
8432 +++ b/arch/powerpc/include/asm/pgalloc-64.h
8433 @@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8434 #ifndef CONFIG_PPC_64K_PAGES
8435
8436 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8437 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8438
8439 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8440 {
8441 @@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8442 pud_set(pud, (unsigned long)pmd);
8443 }
8444
8445 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8446 +{
8447 + pud_populate(mm, pud, pmd);
8448 +}
8449 +
8450 #define pmd_populate(mm, pmd, pte_page) \
8451 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8452 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8453 @@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8454 #endif
8455
8456 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8457 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8458
8459 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8460 pte_t *pte)
8461 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8462 index 316f9a5..ba05c77 100644
8463 --- a/arch/powerpc/include/asm/pgtable.h
8464 +++ b/arch/powerpc/include/asm/pgtable.h
8465 @@ -2,6 +2,7 @@
8466 #define _ASM_POWERPC_PGTABLE_H
8467 #ifdef __KERNEL__
8468
8469 +#include <linux/const.h>
8470 #ifndef __ASSEMBLY__
8471 #include <linux/mmdebug.h>
8472 #include <linux/mmzone.h>
8473 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8474 index 4aad413..85d86bf 100644
8475 --- a/arch/powerpc/include/asm/pte-hash32.h
8476 +++ b/arch/powerpc/include/asm/pte-hash32.h
8477 @@ -21,6 +21,7 @@
8478 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8479 #define _PAGE_USER 0x004 /* usermode access allowed */
8480 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8481 +#define _PAGE_EXEC _PAGE_GUARDED
8482 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8483 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8484 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8485 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8486 index c998279..d13a9f8 100644
8487 --- a/arch/powerpc/include/asm/reg.h
8488 +++ b/arch/powerpc/include/asm/reg.h
8489 @@ -251,6 +251,7 @@
8490 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8491 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8492 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8493 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8494 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8495 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8496 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8497 diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8498 index 5a6614a..d89995d1 100644
8499 --- a/arch/powerpc/include/asm/smp.h
8500 +++ b/arch/powerpc/include/asm/smp.h
8501 @@ -51,7 +51,7 @@ struct smp_ops_t {
8502 int (*cpu_disable)(void);
8503 void (*cpu_die)(unsigned int nr);
8504 int (*cpu_bootable)(unsigned int nr);
8505 -};
8506 +} __no_const;
8507
8508 extern void smp_send_debugger_break(void);
8509 extern void start_secondary_resume(void);
8510 diff --git a/arch/powerpc/include/asm/spinlock.h b/arch/powerpc/include/asm/spinlock.h
8511 index 4dbe072..b803275 100644
8512 --- a/arch/powerpc/include/asm/spinlock.h
8513 +++ b/arch/powerpc/include/asm/spinlock.h
8514 @@ -204,13 +204,29 @@ static inline long __arch_read_trylock(arch_rwlock_t *rw)
8515 __asm__ __volatile__(
8516 "1: " PPC_LWARX(%0,0,%1,1) "\n"
8517 __DO_SIGN_EXTEND
8518 -" addic. %0,%0,1\n\
8519 - ble- 2f\n"
8520 +
8521 +#ifdef CONFIG_PAX_REFCOUNT
8522 +" mcrxr cr0\n"
8523 +" addico. %0,%0,1\n"
8524 +" bf 4*cr0+so, 3f\n"
8525 +"2:.long " "0x00c00b00""\n"
8526 +#else
8527 +" addic. %0,%0,1\n"
8528 +#endif
8529 +
8530 +"3:\n"
8531 + "ble- 4f\n"
8532 PPC405_ERR77(0,%1)
8533 " stwcx. %0,0,%1\n\
8534 bne- 1b\n"
8535 PPC_ACQUIRE_BARRIER
8536 -"2:" : "=&r" (tmp)
8537 +"4:"
8538 +
8539 +#ifdef CONFIG_PAX_REFCOUNT
8540 + _ASM_EXTABLE(2b,4b)
8541 +#endif
8542 +
8543 + : "=&r" (tmp)
8544 : "r" (&rw->lock)
8545 : "cr0", "xer", "memory");
8546
8547 @@ -286,11 +302,27 @@ static inline void arch_read_unlock(arch_rwlock_t *rw)
8548 __asm__ __volatile__(
8549 "# read_unlock\n\t"
8550 PPC_RELEASE_BARRIER
8551 -"1: lwarx %0,0,%1\n\
8552 - addic %0,%0,-1\n"
8553 +"1: lwarx %0,0,%1\n"
8554 +
8555 +#ifdef CONFIG_PAX_REFCOUNT
8556 +" mcrxr cr0\n"
8557 +" addico. %0,%0,-1\n"
8558 +" bf 4*cr0+so, 3f\n"
8559 +"2:.long " "0x00c00b00""\n"
8560 +#else
8561 +" addic. %0,%0,-1\n"
8562 +#endif
8563 +
8564 +"3:\n"
8565 PPC405_ERR77(0,%1)
8566 " stwcx. %0,0,%1\n\
8567 bne- 1b"
8568 +
8569 +#ifdef CONFIG_PAX_REFCOUNT
8570 +"\n4:\n"
8571 + _ASM_EXTABLE(2b, 4b)
8572 +#endif
8573 +
8574 : "=&r"(tmp)
8575 : "r"(&rw->lock)
8576 : "cr0", "xer", "memory");
8577 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8578 index b034ecd..af7e31f 100644
8579 --- a/arch/powerpc/include/asm/thread_info.h
8580 +++ b/arch/powerpc/include/asm/thread_info.h
8581 @@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8582 #if defined(CONFIG_PPC64)
8583 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8584 #endif
8585 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8586 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8587
8588 /* as above, but as bit values */
8589 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8590 @@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8591 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8592 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8593 #define _TIF_NOHZ (1<<TIF_NOHZ)
8594 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8595 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8596 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8597 - _TIF_NOHZ)
8598 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
8599
8600 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8601 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8602 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8603 index 9485b43..3bd3c16 100644
8604 --- a/arch/powerpc/include/asm/uaccess.h
8605 +++ b/arch/powerpc/include/asm/uaccess.h
8606 @@ -58,6 +58,7 @@
8607
8608 #endif
8609
8610 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8611 #define access_ok(type, addr, size) \
8612 (__chk_user_ptr(addr), \
8613 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8614 @@ -318,52 +319,6 @@ do { \
8615 extern unsigned long __copy_tofrom_user(void __user *to,
8616 const void __user *from, unsigned long size);
8617
8618 -#ifndef __powerpc64__
8619 -
8620 -static inline unsigned long copy_from_user(void *to,
8621 - const void __user *from, unsigned long n)
8622 -{
8623 - unsigned long over;
8624 -
8625 - if (access_ok(VERIFY_READ, from, n))
8626 - return __copy_tofrom_user((__force void __user *)to, from, n);
8627 - if ((unsigned long)from < TASK_SIZE) {
8628 - over = (unsigned long)from + n - TASK_SIZE;
8629 - return __copy_tofrom_user((__force void __user *)to, from,
8630 - n - over) + over;
8631 - }
8632 - return n;
8633 -}
8634 -
8635 -static inline unsigned long copy_to_user(void __user *to,
8636 - const void *from, unsigned long n)
8637 -{
8638 - unsigned long over;
8639 -
8640 - if (access_ok(VERIFY_WRITE, to, n))
8641 - return __copy_tofrom_user(to, (__force void __user *)from, n);
8642 - if ((unsigned long)to < TASK_SIZE) {
8643 - over = (unsigned long)to + n - TASK_SIZE;
8644 - return __copy_tofrom_user(to, (__force void __user *)from,
8645 - n - over) + over;
8646 - }
8647 - return n;
8648 -}
8649 -
8650 -#else /* __powerpc64__ */
8651 -
8652 -#define __copy_in_user(to, from, size) \
8653 - __copy_tofrom_user((to), (from), (size))
8654 -
8655 -extern unsigned long copy_from_user(void *to, const void __user *from,
8656 - unsigned long n);
8657 -extern unsigned long copy_to_user(void __user *to, const void *from,
8658 - unsigned long n);
8659 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
8660 - unsigned long n);
8661 -
8662 -#endif /* __powerpc64__ */
8663 -
8664 static inline unsigned long __copy_from_user_inatomic(void *to,
8665 const void __user *from, unsigned long n)
8666 {
8667 @@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8668 if (ret == 0)
8669 return 0;
8670 }
8671 +
8672 + if (!__builtin_constant_p(n))
8673 + check_object_size(to, n, false);
8674 +
8675 return __copy_tofrom_user((__force void __user *)to, from, n);
8676 }
8677
8678 @@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8679 if (ret == 0)
8680 return 0;
8681 }
8682 +
8683 + if (!__builtin_constant_p(n))
8684 + check_object_size(from, n, true);
8685 +
8686 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8687 }
8688
8689 @@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8690 return __copy_to_user_inatomic(to, from, size);
8691 }
8692
8693 +#ifndef __powerpc64__
8694 +
8695 +static inline unsigned long __must_check copy_from_user(void *to,
8696 + const void __user *from, unsigned long n)
8697 +{
8698 + unsigned long over;
8699 +
8700 + if ((long)n < 0)
8701 + return n;
8702 +
8703 + if (access_ok(VERIFY_READ, from, n)) {
8704 + if (!__builtin_constant_p(n))
8705 + check_object_size(to, n, false);
8706 + return __copy_tofrom_user((__force void __user *)to, from, n);
8707 + }
8708 + if ((unsigned long)from < TASK_SIZE) {
8709 + over = (unsigned long)from + n - TASK_SIZE;
8710 + if (!__builtin_constant_p(n - over))
8711 + check_object_size(to, n - over, false);
8712 + return __copy_tofrom_user((__force void __user *)to, from,
8713 + n - over) + over;
8714 + }
8715 + return n;
8716 +}
8717 +
8718 +static inline unsigned long __must_check copy_to_user(void __user *to,
8719 + const void *from, unsigned long n)
8720 +{
8721 + unsigned long over;
8722 +
8723 + if ((long)n < 0)
8724 + return n;
8725 +
8726 + if (access_ok(VERIFY_WRITE, to, n)) {
8727 + if (!__builtin_constant_p(n))
8728 + check_object_size(from, n, true);
8729 + return __copy_tofrom_user(to, (__force void __user *)from, n);
8730 + }
8731 + if ((unsigned long)to < TASK_SIZE) {
8732 + over = (unsigned long)to + n - TASK_SIZE;
8733 + if (!__builtin_constant_p(n))
8734 + check_object_size(from, n - over, true);
8735 + return __copy_tofrom_user(to, (__force void __user *)from,
8736 + n - over) + over;
8737 + }
8738 + return n;
8739 +}
8740 +
8741 +#else /* __powerpc64__ */
8742 +
8743 +#define __copy_in_user(to, from, size) \
8744 + __copy_tofrom_user((to), (from), (size))
8745 +
8746 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8747 +{
8748 + if ((long)n < 0 || n > INT_MAX)
8749 + return n;
8750 +
8751 + if (!__builtin_constant_p(n))
8752 + check_object_size(to, n, false);
8753 +
8754 + if (likely(access_ok(VERIFY_READ, from, n)))
8755 + n = __copy_from_user(to, from, n);
8756 + else
8757 + memset(to, 0, n);
8758 + return n;
8759 +}
8760 +
8761 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8762 +{
8763 + if ((long)n < 0 || n > INT_MAX)
8764 + return n;
8765 +
8766 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
8767 + if (!__builtin_constant_p(n))
8768 + check_object_size(from, n, true);
8769 + n = __copy_to_user(to, from, n);
8770 + }
8771 + return n;
8772 +}
8773 +
8774 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
8775 + unsigned long n);
8776 +
8777 +#endif /* __powerpc64__ */
8778 +
8779 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8780
8781 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8782 diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8783 index 502cf69..822e63b 100644
8784 --- a/arch/powerpc/kernel/Makefile
8785 +++ b/arch/powerpc/kernel/Makefile
8786 @@ -27,6 +27,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8787 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8788 endif
8789
8790 +CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8791 +
8792 obj-y := cputable.o ptrace.o syscalls.o \
8793 irq.o align.o signal_32.o pmc.o vdso.o \
8794 process.o systbl.o idle.o \
8795 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8796 index 3e68d1c..72a5ee6 100644
8797 --- a/arch/powerpc/kernel/exceptions-64e.S
8798 +++ b/arch/powerpc/kernel/exceptions-64e.S
8799 @@ -1010,6 +1010,7 @@ storage_fault_common:
8800 std r14,_DAR(r1)
8801 std r15,_DSISR(r1)
8802 addi r3,r1,STACK_FRAME_OVERHEAD
8803 + bl save_nvgprs
8804 mr r4,r14
8805 mr r5,r15
8806 ld r14,PACA_EXGEN+EX_R14(r13)
8807 @@ -1018,8 +1019,7 @@ storage_fault_common:
8808 cmpdi r3,0
8809 bne- 1f
8810 b ret_from_except_lite
8811 -1: bl save_nvgprs
8812 - mr r5,r3
8813 +1: mr r5,r3
8814 addi r3,r1,STACK_FRAME_OVERHEAD
8815 ld r4,_DAR(r1)
8816 bl bad_page_fault
8817 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8818 index 72e783e..fe058e2 100644
8819 --- a/arch/powerpc/kernel/exceptions-64s.S
8820 +++ b/arch/powerpc/kernel/exceptions-64s.S
8821 @@ -1588,10 +1588,10 @@ handle_page_fault:
8822 11: ld r4,_DAR(r1)
8823 ld r5,_DSISR(r1)
8824 addi r3,r1,STACK_FRAME_OVERHEAD
8825 + bl save_nvgprs
8826 bl do_page_fault
8827 cmpdi r3,0
8828 beq+ 12f
8829 - bl save_nvgprs
8830 mr r5,r3
8831 addi r3,r1,STACK_FRAME_OVERHEAD
8832 lwz r4,_DAR(r1)
8833 diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
8834 index c143835..5a9697f 100644
8835 --- a/arch/powerpc/kernel/irq.c
8836 +++ b/arch/powerpc/kernel/irq.c
8837 @@ -461,6 +461,8 @@ void migrate_irqs(void)
8838 }
8839 #endif
8840
8841 +extern void gr_handle_kernel_exploit(void);
8842 +
8843 static inline void check_stack_overflow(void)
8844 {
8845 #ifdef CONFIG_DEBUG_STACKOVERFLOW
8846 @@ -473,6 +475,7 @@ static inline void check_stack_overflow(void)
8847 pr_err("do_IRQ: stack overflow: %ld\n",
8848 sp - sizeof(struct thread_info));
8849 dump_stack();
8850 + gr_handle_kernel_exploit();
8851 }
8852 #endif
8853 }
8854 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8855 index c94d2e0..992a9ce 100644
8856 --- a/arch/powerpc/kernel/module_32.c
8857 +++ b/arch/powerpc/kernel/module_32.c
8858 @@ -158,7 +158,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8859 me->arch.core_plt_section = i;
8860 }
8861 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8862 - pr_err("Module doesn't contain .plt or .init.plt sections.\n");
8863 + pr_err("Module $s doesn't contain .plt or .init.plt sections.\n", me->name);
8864 return -ENOEXEC;
8865 }
8866
8867 @@ -188,11 +188,16 @@ static uint32_t do_plt_call(void *location,
8868
8869 pr_debug("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8870 /* Init, or core PLT? */
8871 - if (location >= mod->module_core
8872 - && location < mod->module_core + mod->core_size)
8873 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8874 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8875 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8876 - else
8877 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8878 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8879 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8880 + else {
8881 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8882 + return ~0UL;
8883 + }
8884
8885 /* Find this entry, or if that fails, the next avail. entry */
8886 while (entry->jump[0]) {
8887 @@ -296,7 +301,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8888 }
8889 #ifdef CONFIG_DYNAMIC_FTRACE
8890 module->arch.tramp =
8891 - do_plt_call(module->module_core,
8892 + do_plt_call(module->module_core_rx,
8893 (unsigned long)ftrace_caller,
8894 sechdrs, module);
8895 #endif
8896 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8897 index 923cd2d..ae782a9 100644
8898 --- a/arch/powerpc/kernel/process.c
8899 +++ b/arch/powerpc/kernel/process.c
8900 @@ -1040,8 +1040,8 @@ void show_regs(struct pt_regs * regs)
8901 * Lookup NIP late so we have the best change of getting the
8902 * above info out without failing
8903 */
8904 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8905 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8906 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8907 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8908 #endif
8909 show_stack(current, (unsigned long *) regs->gpr[1]);
8910 if (!user_mode(regs))
8911 @@ -1560,10 +1560,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8912 newsp = stack[0];
8913 ip = stack[STACK_FRAME_LR_SAVE];
8914 if (!firstframe || ip != lr) {
8915 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8916 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8917 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8918 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8919 - printk(" (%pS)",
8920 + printk(" (%pA)",
8921 (void *)current->ret_stack[curr_frame].ret);
8922 curr_frame--;
8923 }
8924 @@ -1583,7 +1583,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8925 struct pt_regs *regs = (struct pt_regs *)
8926 (sp + STACK_FRAME_OVERHEAD);
8927 lr = regs->link;
8928 - printk("--- interrupt: %lx at %pS\n LR = %pS\n",
8929 + printk("--- interrupt: %lx at %pA\n LR = %pA\n",
8930 regs->trap, (void *)regs->nip, (void *)lr);
8931 firstframe = 1;
8932 }
8933 @@ -1619,58 +1619,3 @@ void notrace __ppc64_runlatch_off(void)
8934 mtspr(SPRN_CTRLT, ctrl);
8935 }
8936 #endif /* CONFIG_PPC64 */
8937 -
8938 -unsigned long arch_align_stack(unsigned long sp)
8939 -{
8940 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8941 - sp -= get_random_int() & ~PAGE_MASK;
8942 - return sp & ~0xf;
8943 -}
8944 -
8945 -static inline unsigned long brk_rnd(void)
8946 -{
8947 - unsigned long rnd = 0;
8948 -
8949 - /* 8MB for 32bit, 1GB for 64bit */
8950 - if (is_32bit_task())
8951 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8952 - else
8953 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8954 -
8955 - return rnd << PAGE_SHIFT;
8956 -}
8957 -
8958 -unsigned long arch_randomize_brk(struct mm_struct *mm)
8959 -{
8960 - unsigned long base = mm->brk;
8961 - unsigned long ret;
8962 -
8963 -#ifdef CONFIG_PPC_STD_MMU_64
8964 - /*
8965 - * If we are using 1TB segments and we are allowed to randomise
8966 - * the heap, we can put it above 1TB so it is backed by a 1TB
8967 - * segment. Otherwise the heap will be in the bottom 1TB
8968 - * which always uses 256MB segments and this may result in a
8969 - * performance penalty.
8970 - */
8971 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8972 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8973 -#endif
8974 -
8975 - ret = PAGE_ALIGN(base + brk_rnd());
8976 -
8977 - if (ret < mm->brk)
8978 - return mm->brk;
8979 -
8980 - return ret;
8981 -}
8982 -
8983 -unsigned long randomize_et_dyn(unsigned long base)
8984 -{
8985 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8986 -
8987 - if (ret < base)
8988 - return base;
8989 -
8990 - return ret;
8991 -}
8992 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8993 index f21897b..28c0428 100644
8994 --- a/arch/powerpc/kernel/ptrace.c
8995 +++ b/arch/powerpc/kernel/ptrace.c
8996 @@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8997 return ret;
8998 }
8999
9000 +#ifdef CONFIG_GRKERNSEC_SETXID
9001 +extern void gr_delayed_cred_worker(void);
9002 +#endif
9003 +
9004 /*
9005 * We must return the syscall number to actually look up in the table.
9006 * This can be -1L to skip running any syscall at all.
9007 @@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
9008
9009 secure_computing_strict(regs->gpr[0]);
9010
9011 +#ifdef CONFIG_GRKERNSEC_SETXID
9012 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9013 + gr_delayed_cred_worker();
9014 +#endif
9015 +
9016 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
9017 tracehook_report_syscall_entry(regs))
9018 /*
9019 @@ -1805,6 +1814,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
9020 {
9021 int step;
9022
9023 +#ifdef CONFIG_GRKERNSEC_SETXID
9024 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9025 + gr_delayed_cred_worker();
9026 +#endif
9027 +
9028 audit_syscall_exit(regs);
9029
9030 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9031 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
9032 index b171001..4ac7ac5 100644
9033 --- a/arch/powerpc/kernel/signal_32.c
9034 +++ b/arch/powerpc/kernel/signal_32.c
9035 @@ -1011,7 +1011,7 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
9036 /* Save user registers on the stack */
9037 frame = &rt_sf->uc.uc_mcontext;
9038 addr = frame;
9039 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
9040 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9041 sigret = 0;
9042 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
9043 } else {
9044 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
9045 index 2cb0c94..c0c0bc9 100644
9046 --- a/arch/powerpc/kernel/signal_64.c
9047 +++ b/arch/powerpc/kernel/signal_64.c
9048 @@ -754,7 +754,7 @@ int handle_rt_signal64(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs
9049 current->thread.fp_state.fpscr = 0;
9050
9051 /* Set up to return from userspace. */
9052 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
9053 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9054 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
9055 } else {
9056 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
9057 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
9058 index 0dc43f9..a885d33 100644
9059 --- a/arch/powerpc/kernel/traps.c
9060 +++ b/arch/powerpc/kernel/traps.c
9061 @@ -36,6 +36,7 @@
9062 #include <linux/debugfs.h>
9063 #include <linux/ratelimit.h>
9064 #include <linux/context_tracking.h>
9065 +#include <linux/uaccess.h>
9066
9067 #include <asm/emulated_ops.h>
9068 #include <asm/pgtable.h>
9069 @@ -142,6 +143,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
9070 return flags;
9071 }
9072
9073 +extern void gr_handle_kernel_exploit(void);
9074 +
9075 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9076 int signr)
9077 {
9078 @@ -191,6 +194,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9079 panic("Fatal exception in interrupt");
9080 if (panic_on_oops)
9081 panic("Fatal exception");
9082 +
9083 + gr_handle_kernel_exploit();
9084 +
9085 do_exit(signr);
9086 }
9087
9088 @@ -1137,6 +1143,26 @@ void __kprobes program_check_exception(struct pt_regs *regs)
9089 enum ctx_state prev_state = exception_enter();
9090 unsigned int reason = get_reason(regs);
9091
9092 +#ifdef CONFIG_PAX_REFCOUNT
9093 + unsigned int bkpt;
9094 + const struct exception_table_entry *entry;
9095 +
9096 + if (reason & REASON_ILLEGAL) {
9097 + /* Check if PaX bad instruction */
9098 + if (!probe_kernel_address(regs->nip, bkpt) && bkpt == 0xc00b00) {
9099 + current->thread.trap_nr = 0;
9100 + pax_report_refcount_overflow(regs);
9101 + /* fixup_exception() for PowerPC does not exist, simulate its job */
9102 + if ((entry = search_exception_tables(regs->nip)) != NULL) {
9103 + regs->nip = entry->fixup;
9104 + return;
9105 + }
9106 + /* fixup_exception() could not handle */
9107 + goto bail;
9108 + }
9109 + }
9110 +#endif
9111 +
9112 /* We can now get here via a FP Unavailable exception if the core
9113 * has no FPU, in that case the reason flags will be 0 */
9114
9115 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
9116 index f174351..5722009 100644
9117 --- a/arch/powerpc/kernel/vdso.c
9118 +++ b/arch/powerpc/kernel/vdso.c
9119 @@ -35,6 +35,7 @@
9120 #include <asm/vdso.h>
9121 #include <asm/vdso_datapage.h>
9122 #include <asm/setup.h>
9123 +#include <asm/mman.h>
9124
9125 #undef DEBUG
9126
9127 @@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9128 vdso_base = VDSO32_MBASE;
9129 #endif
9130
9131 - current->mm->context.vdso_base = 0;
9132 + current->mm->context.vdso_base = ~0UL;
9133
9134 /* vDSO has a problem and was disabled, just don't "enable" it for the
9135 * process
9136 @@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9137 vdso_base = get_unmapped_area(NULL, vdso_base,
9138 (vdso_pages << PAGE_SHIFT) +
9139 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
9140 - 0, 0);
9141 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
9142 if (IS_ERR_VALUE(vdso_base)) {
9143 rc = vdso_base;
9144 goto fail_mmapsem;
9145 diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
9146 index c1f8f53..71a3b96 100644
9147 --- a/arch/powerpc/kvm/powerpc.c
9148 +++ b/arch/powerpc/kvm/powerpc.c
9149 @@ -1409,7 +1409,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
9150 }
9151 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
9152
9153 -int kvm_arch_init(void *opaque)
9154 +int kvm_arch_init(const void *opaque)
9155 {
9156 return 0;
9157 }
9158 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
9159 index 5eea6f3..5d10396 100644
9160 --- a/arch/powerpc/lib/usercopy_64.c
9161 +++ b/arch/powerpc/lib/usercopy_64.c
9162 @@ -9,22 +9,6 @@
9163 #include <linux/module.h>
9164 #include <asm/uaccess.h>
9165
9166 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9167 -{
9168 - if (likely(access_ok(VERIFY_READ, from, n)))
9169 - n = __copy_from_user(to, from, n);
9170 - else
9171 - memset(to, 0, n);
9172 - return n;
9173 -}
9174 -
9175 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9176 -{
9177 - if (likely(access_ok(VERIFY_WRITE, to, n)))
9178 - n = __copy_to_user(to, from, n);
9179 - return n;
9180 -}
9181 -
9182 unsigned long copy_in_user(void __user *to, const void __user *from,
9183 unsigned long n)
9184 {
9185 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
9186 return n;
9187 }
9188
9189 -EXPORT_SYMBOL(copy_from_user);
9190 -EXPORT_SYMBOL(copy_to_user);
9191 EXPORT_SYMBOL(copy_in_user);
9192
9193 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
9194 index 08d659a..ab329f4 100644
9195 --- a/arch/powerpc/mm/fault.c
9196 +++ b/arch/powerpc/mm/fault.c
9197 @@ -33,6 +33,10 @@
9198 #include <linux/ratelimit.h>
9199 #include <linux/context_tracking.h>
9200 #include <linux/hugetlb.h>
9201 +#include <linux/slab.h>
9202 +#include <linux/pagemap.h>
9203 +#include <linux/compiler.h>
9204 +#include <linux/unistd.h>
9205
9206 #include <asm/firmware.h>
9207 #include <asm/page.h>
9208 @@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
9209 }
9210 #endif
9211
9212 +#ifdef CONFIG_PAX_PAGEEXEC
9213 +/*
9214 + * PaX: decide what to do with offenders (regs->nip = fault address)
9215 + *
9216 + * returns 1 when task should be killed
9217 + */
9218 +static int pax_handle_fetch_fault(struct pt_regs *regs)
9219 +{
9220 + return 1;
9221 +}
9222 +
9223 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9224 +{
9225 + unsigned long i;
9226 +
9227 + printk(KERN_ERR "PAX: bytes at PC: ");
9228 + for (i = 0; i < 5; i++) {
9229 + unsigned int c;
9230 + if (get_user(c, (unsigned int __user *)pc+i))
9231 + printk(KERN_CONT "???????? ");
9232 + else
9233 + printk(KERN_CONT "%08x ", c);
9234 + }
9235 + printk("\n");
9236 +}
9237 +#endif
9238 +
9239 /*
9240 * Check whether the instruction at regs->nip is a store using
9241 * an update addressing form which will update r1.
9242 @@ -228,7 +259,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
9243 * indicate errors in DSISR but can validly be set in SRR1.
9244 */
9245 if (trap == 0x400)
9246 - error_code &= 0x48200000;
9247 + error_code &= 0x58200000;
9248 else
9249 is_write = error_code & DSISR_ISSTORE;
9250 #else
9251 @@ -390,7 +421,7 @@ good_area:
9252 * "undefined". Of those that can be set, this is the only
9253 * one which seems bad.
9254 */
9255 - if (error_code & 0x10000000)
9256 + if (error_code & DSISR_GUARDED)
9257 /* Guarded storage error. */
9258 goto bad_area;
9259 #endif /* CONFIG_8xx */
9260 @@ -405,7 +436,7 @@ good_area:
9261 * processors use the same I/D cache coherency mechanism
9262 * as embedded.
9263 */
9264 - if (error_code & DSISR_PROTFAULT)
9265 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
9266 goto bad_area;
9267 #endif /* CONFIG_PPC_STD_MMU */
9268
9269 @@ -495,6 +526,23 @@ bad_area:
9270 bad_area_nosemaphore:
9271 /* User mode accesses cause a SIGSEGV */
9272 if (user_mode(regs)) {
9273 +
9274 +#ifdef CONFIG_PAX_PAGEEXEC
9275 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
9276 +#ifdef CONFIG_PPC_STD_MMU
9277 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
9278 +#else
9279 + if (is_exec && regs->nip == address) {
9280 +#endif
9281 + switch (pax_handle_fetch_fault(regs)) {
9282 + }
9283 +
9284 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
9285 + do_group_exit(SIGKILL);
9286 + }
9287 + }
9288 +#endif
9289 +
9290 _exception(SIGSEGV, regs, code, address);
9291 goto bail;
9292 }
9293 diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
9294 index cb8bdbe..cde4bc7 100644
9295 --- a/arch/powerpc/mm/mmap.c
9296 +++ b/arch/powerpc/mm/mmap.c
9297 @@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
9298 return sysctl_legacy_va_layout;
9299 }
9300
9301 -static unsigned long mmap_rnd(void)
9302 +static unsigned long mmap_rnd(struct mm_struct *mm)
9303 {
9304 unsigned long rnd = 0;
9305
9306 +#ifdef CONFIG_PAX_RANDMMAP
9307 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9308 +#endif
9309 +
9310 if (current->flags & PF_RANDOMIZE) {
9311 /* 8MB for 32bit, 1GB for 64bit */
9312 if (is_32bit_task())
9313 @@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
9314 return rnd << PAGE_SHIFT;
9315 }
9316
9317 -static inline unsigned long mmap_base(void)
9318 +static inline unsigned long mmap_base(struct mm_struct *mm)
9319 {
9320 unsigned long gap = rlimit(RLIMIT_STACK);
9321
9322 @@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
9323 else if (gap > MAX_GAP)
9324 gap = MAX_GAP;
9325
9326 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
9327 + return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
9328 }
9329
9330 /*
9331 @@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9332 */
9333 if (mmap_is_legacy()) {
9334 mm->mmap_base = TASK_UNMAPPED_BASE;
9335 +
9336 +#ifdef CONFIG_PAX_RANDMMAP
9337 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9338 + mm->mmap_base += mm->delta_mmap;
9339 +#endif
9340 +
9341 mm->get_unmapped_area = arch_get_unmapped_area;
9342 } else {
9343 - mm->mmap_base = mmap_base();
9344 + mm->mmap_base = mmap_base(mm);
9345 +
9346 +#ifdef CONFIG_PAX_RANDMMAP
9347 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9348 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9349 +#endif
9350 +
9351 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9352 }
9353 }
9354 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
9355 index ded0ea1..f213a9b 100644
9356 --- a/arch/powerpc/mm/slice.c
9357 +++ b/arch/powerpc/mm/slice.c
9358 @@ -105,7 +105,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
9359 if ((mm->task_size - len) < addr)
9360 return 0;
9361 vma = find_vma(mm, addr);
9362 - return (!vma || (addr + len) <= vma->vm_start);
9363 + return check_heap_stack_gap(vma, addr, len, 0);
9364 }
9365
9366 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
9367 @@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
9368 info.align_offset = 0;
9369
9370 addr = TASK_UNMAPPED_BASE;
9371 +
9372 +#ifdef CONFIG_PAX_RANDMMAP
9373 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9374 + addr += mm->delta_mmap;
9375 +#endif
9376 +
9377 while (addr < TASK_SIZE) {
9378 info.low_limit = addr;
9379 if (!slice_scan_available(addr, available, 1, &addr))
9380 @@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
9381 if (fixed && addr > (mm->task_size - len))
9382 return -ENOMEM;
9383
9384 +#ifdef CONFIG_PAX_RANDMMAP
9385 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
9386 + addr = 0;
9387 +#endif
9388 +
9389 /* If hint, make sure it matches our alignment restrictions */
9390 if (!fixed && addr) {
9391 addr = _ALIGN_UP(addr, 1ul << pshift);
9392 diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9393 index 4278acf..67fd0e6 100644
9394 --- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9395 +++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9396 @@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
9397 }
9398
9399 static struct pci_ops scc_pciex_pci_ops = {
9400 - scc_pciex_read_config,
9401 - scc_pciex_write_config,
9402 + .read = scc_pciex_read_config,
9403 + .write = scc_pciex_write_config,
9404 };
9405
9406 static void pciex_clear_intr_all(unsigned int __iomem *base)
9407 diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
9408 index d966bbe..372124a 100644
9409 --- a/arch/powerpc/platforms/cell/spufs/file.c
9410 +++ b/arch/powerpc/platforms/cell/spufs/file.c
9411 @@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9412 return VM_FAULT_NOPAGE;
9413 }
9414
9415 -static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9416 +static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9417 unsigned long address,
9418 - void *buf, int len, int write)
9419 + void *buf, size_t len, int write)
9420 {
9421 struct spu_context *ctx = vma->vm_file->private_data;
9422 unsigned long offset = address - vma->vm_start;
9423 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9424 index fa934fe..c296056 100644
9425 --- a/arch/s390/include/asm/atomic.h
9426 +++ b/arch/s390/include/asm/atomic.h
9427 @@ -412,4 +412,14 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9428 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9429 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9430
9431 +#define atomic64_read_unchecked(v) atomic64_read(v)
9432 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9433 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9434 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9435 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9436 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
9437 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9438 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
9439 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9440 +
9441 #endif /* __ARCH_S390_ATOMIC__ */
9442 diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
9443 index b5dce65..8aca09a 100644
9444 --- a/arch/s390/include/asm/barrier.h
9445 +++ b/arch/s390/include/asm/barrier.h
9446 @@ -39,7 +39,7 @@
9447 do { \
9448 compiletime_assert_atomic_type(*p); \
9449 barrier(); \
9450 - ACCESS_ONCE(*p) = (v); \
9451 + ACCESS_ONCE_RW(*p) = (v); \
9452 } while (0)
9453
9454 #define smp_load_acquire(p) \
9455 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9456 index 4d7ccac..d03d0ad 100644
9457 --- a/arch/s390/include/asm/cache.h
9458 +++ b/arch/s390/include/asm/cache.h
9459 @@ -9,8 +9,10 @@
9460 #ifndef __ARCH_S390_CACHE_H
9461 #define __ARCH_S390_CACHE_H
9462
9463 -#define L1_CACHE_BYTES 256
9464 +#include <linux/const.h>
9465 +
9466 #define L1_CACHE_SHIFT 8
9467 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9468 #define NET_SKB_PAD 32
9469
9470 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9471 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9472 index f6e43d3..5f57681 100644
9473 --- a/arch/s390/include/asm/elf.h
9474 +++ b/arch/s390/include/asm/elf.h
9475 @@ -163,8 +163,14 @@ extern unsigned int vdso_enabled;
9476 the loader. We need to make sure that it is out of the way of the program
9477 that it will "exec", and that there is sufficient room for the brk. */
9478
9479 -extern unsigned long randomize_et_dyn(unsigned long base);
9480 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9481 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9482 +
9483 +#ifdef CONFIG_PAX_ASLR
9484 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9485 +
9486 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9487 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9488 +#endif
9489
9490 /* This yields a mask that user programs can use to figure out what
9491 instruction set this CPU supports. */
9492 @@ -223,9 +229,6 @@ struct linux_binprm;
9493 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9494 int arch_setup_additional_pages(struct linux_binprm *, int);
9495
9496 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9497 -#define arch_randomize_brk arch_randomize_brk
9498 -
9499 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa, __vector128 *vxrs);
9500
9501 #endif
9502 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9503 index c4a93d6..4d2a9b4 100644
9504 --- a/arch/s390/include/asm/exec.h
9505 +++ b/arch/s390/include/asm/exec.h
9506 @@ -7,6 +7,6 @@
9507 #ifndef __ASM_EXEC_H
9508 #define __ASM_EXEC_H
9509
9510 -extern unsigned long arch_align_stack(unsigned long sp);
9511 +#define arch_align_stack(x) ((x) & ~0xfUL)
9512
9513 #endif /* __ASM_EXEC_H */
9514 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9515 index cd4c68e..6764641 100644
9516 --- a/arch/s390/include/asm/uaccess.h
9517 +++ b/arch/s390/include/asm/uaccess.h
9518 @@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9519 __range_ok((unsigned long)(addr), (size)); \
9520 })
9521
9522 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9523 #define access_ok(type, addr, size) __access_ok(addr, size)
9524
9525 /*
9526 @@ -275,6 +276,10 @@ static inline unsigned long __must_check
9527 copy_to_user(void __user *to, const void *from, unsigned long n)
9528 {
9529 might_fault();
9530 +
9531 + if ((long)n < 0)
9532 + return n;
9533 +
9534 return __copy_to_user(to, from, n);
9535 }
9536
9537 @@ -303,10 +308,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9538 static inline unsigned long __must_check
9539 copy_from_user(void *to, const void __user *from, unsigned long n)
9540 {
9541 - unsigned int sz = __compiletime_object_size(to);
9542 + size_t sz = __compiletime_object_size(to);
9543
9544 might_fault();
9545 - if (unlikely(sz != -1 && sz < n)) {
9546 +
9547 + if ((long)n < 0)
9548 + return n;
9549 +
9550 + if (unlikely(sz != (size_t)-1 && sz < n)) {
9551 copy_from_user_overflow();
9552 return n;
9553 }
9554 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9555 index b89b591..fd9609d 100644
9556 --- a/arch/s390/kernel/module.c
9557 +++ b/arch/s390/kernel/module.c
9558 @@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9559
9560 /* Increase core size by size of got & plt and set start
9561 offsets for got and plt. */
9562 - me->core_size = ALIGN(me->core_size, 4);
9563 - me->arch.got_offset = me->core_size;
9564 - me->core_size += me->arch.got_size;
9565 - me->arch.plt_offset = me->core_size;
9566 - me->core_size += me->arch.plt_size;
9567 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
9568 + me->arch.got_offset = me->core_size_rw;
9569 + me->core_size_rw += me->arch.got_size;
9570 + me->arch.plt_offset = me->core_size_rx;
9571 + me->core_size_rx += me->arch.plt_size;
9572 return 0;
9573 }
9574
9575 @@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9576 if (info->got_initialized == 0) {
9577 Elf_Addr *gotent;
9578
9579 - gotent = me->module_core + me->arch.got_offset +
9580 + gotent = me->module_core_rw + me->arch.got_offset +
9581 info->got_offset;
9582 *gotent = val;
9583 info->got_initialized = 1;
9584 @@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9585 rc = apply_rela_bits(loc, val, 0, 64, 0);
9586 else if (r_type == R_390_GOTENT ||
9587 r_type == R_390_GOTPLTENT) {
9588 - val += (Elf_Addr) me->module_core - loc;
9589 + val += (Elf_Addr) me->module_core_rw - loc;
9590 rc = apply_rela_bits(loc, val, 1, 32, 1);
9591 }
9592 break;
9593 @@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9594 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9595 if (info->plt_initialized == 0) {
9596 unsigned int *ip;
9597 - ip = me->module_core + me->arch.plt_offset +
9598 + ip = me->module_core_rx + me->arch.plt_offset +
9599 info->plt_offset;
9600 #ifndef CONFIG_64BIT
9601 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9602 @@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9603 val - loc + 0xffffUL < 0x1ffffeUL) ||
9604 (r_type == R_390_PLT32DBL &&
9605 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9606 - val = (Elf_Addr) me->module_core +
9607 + val = (Elf_Addr) me->module_core_rx +
9608 me->arch.plt_offset +
9609 info->plt_offset;
9610 val += rela->r_addend - loc;
9611 @@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9612 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9613 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9614 val = val + rela->r_addend -
9615 - ((Elf_Addr) me->module_core + me->arch.got_offset);
9616 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9617 if (r_type == R_390_GOTOFF16)
9618 rc = apply_rela_bits(loc, val, 0, 16, 0);
9619 else if (r_type == R_390_GOTOFF32)
9620 @@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9621 break;
9622 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9623 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9624 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
9625 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9626 rela->r_addend - loc;
9627 if (r_type == R_390_GOTPC)
9628 rc = apply_rela_bits(loc, val, 1, 32, 0);
9629 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9630 index ed84cc2..c05a9d2 100644
9631 --- a/arch/s390/kernel/process.c
9632 +++ b/arch/s390/kernel/process.c
9633 @@ -218,37 +218,3 @@ unsigned long get_wchan(struct task_struct *p)
9634 }
9635 return 0;
9636 }
9637 -
9638 -unsigned long arch_align_stack(unsigned long sp)
9639 -{
9640 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9641 - sp -= get_random_int() & ~PAGE_MASK;
9642 - return sp & ~0xf;
9643 -}
9644 -
9645 -static inline unsigned long brk_rnd(void)
9646 -{
9647 - /* 8MB for 32bit, 1GB for 64bit */
9648 - if (is_32bit_task())
9649 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9650 - else
9651 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9652 -}
9653 -
9654 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9655 -{
9656 - unsigned long ret;
9657 -
9658 - ret = PAGE_ALIGN(mm->brk + brk_rnd());
9659 - return (ret > mm->brk) ? ret : mm->brk;
9660 -}
9661 -
9662 -unsigned long randomize_et_dyn(unsigned long base)
9663 -{
9664 - unsigned long ret;
9665 -
9666 - if (!(current->flags & PF_RANDOMIZE))
9667 - return base;
9668 - ret = PAGE_ALIGN(base + brk_rnd());
9669 - return (ret > base) ? ret : base;
9670 -}
9671 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9672 index 9b436c2..54fbf0a 100644
9673 --- a/arch/s390/mm/mmap.c
9674 +++ b/arch/s390/mm/mmap.c
9675 @@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9676 */
9677 if (mmap_is_legacy()) {
9678 mm->mmap_base = mmap_base_legacy();
9679 +
9680 +#ifdef CONFIG_PAX_RANDMMAP
9681 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9682 + mm->mmap_base += mm->delta_mmap;
9683 +#endif
9684 +
9685 mm->get_unmapped_area = arch_get_unmapped_area;
9686 } else {
9687 mm->mmap_base = mmap_base();
9688 +
9689 +#ifdef CONFIG_PAX_RANDMMAP
9690 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9691 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9692 +#endif
9693 +
9694 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9695 }
9696 }
9697 @@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9698 */
9699 if (mmap_is_legacy()) {
9700 mm->mmap_base = mmap_base_legacy();
9701 +
9702 +#ifdef CONFIG_PAX_RANDMMAP
9703 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9704 + mm->mmap_base += mm->delta_mmap;
9705 +#endif
9706 +
9707 mm->get_unmapped_area = s390_get_unmapped_area;
9708 } else {
9709 mm->mmap_base = mmap_base();
9710 +
9711 +#ifdef CONFIG_PAX_RANDMMAP
9712 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9713 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9714 +#endif
9715 +
9716 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9717 }
9718 }
9719 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9720 index ae3d59f..f65f075 100644
9721 --- a/arch/score/include/asm/cache.h
9722 +++ b/arch/score/include/asm/cache.h
9723 @@ -1,7 +1,9 @@
9724 #ifndef _ASM_SCORE_CACHE_H
9725 #define _ASM_SCORE_CACHE_H
9726
9727 +#include <linux/const.h>
9728 +
9729 #define L1_CACHE_SHIFT 4
9730 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9731 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9732
9733 #endif /* _ASM_SCORE_CACHE_H */
9734 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9735 index f9f3cd5..58ff438 100644
9736 --- a/arch/score/include/asm/exec.h
9737 +++ b/arch/score/include/asm/exec.h
9738 @@ -1,6 +1,6 @@
9739 #ifndef _ASM_SCORE_EXEC_H
9740 #define _ASM_SCORE_EXEC_H
9741
9742 -extern unsigned long arch_align_stack(unsigned long sp);
9743 +#define arch_align_stack(x) (x)
9744
9745 #endif /* _ASM_SCORE_EXEC_H */
9746 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9747 index a1519ad3..e8ac1ff 100644
9748 --- a/arch/score/kernel/process.c
9749 +++ b/arch/score/kernel/process.c
9750 @@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9751
9752 return task_pt_regs(task)->cp0_epc;
9753 }
9754 -
9755 -unsigned long arch_align_stack(unsigned long sp)
9756 -{
9757 - return sp;
9758 -}
9759 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9760 index ef9e555..331bd29 100644
9761 --- a/arch/sh/include/asm/cache.h
9762 +++ b/arch/sh/include/asm/cache.h
9763 @@ -9,10 +9,11 @@
9764 #define __ASM_SH_CACHE_H
9765 #ifdef __KERNEL__
9766
9767 +#include <linux/const.h>
9768 #include <linux/init.h>
9769 #include <cpu/cache.h>
9770
9771 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9772 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9773
9774 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9775
9776 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9777 index 6777177..cb5e44f 100644
9778 --- a/arch/sh/mm/mmap.c
9779 +++ b/arch/sh/mm/mmap.c
9780 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9781 struct mm_struct *mm = current->mm;
9782 struct vm_area_struct *vma;
9783 int do_colour_align;
9784 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9785 struct vm_unmapped_area_info info;
9786
9787 if (flags & MAP_FIXED) {
9788 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9789 if (filp || (flags & MAP_SHARED))
9790 do_colour_align = 1;
9791
9792 +#ifdef CONFIG_PAX_RANDMMAP
9793 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9794 +#endif
9795 +
9796 if (addr) {
9797 if (do_colour_align)
9798 addr = COLOUR_ALIGN(addr, pgoff);
9799 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9800 addr = PAGE_ALIGN(addr);
9801
9802 vma = find_vma(mm, addr);
9803 - if (TASK_SIZE - len >= addr &&
9804 - (!vma || addr + len <= vma->vm_start))
9805 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9806 return addr;
9807 }
9808
9809 info.flags = 0;
9810 info.length = len;
9811 - info.low_limit = TASK_UNMAPPED_BASE;
9812 + info.low_limit = mm->mmap_base;
9813 info.high_limit = TASK_SIZE;
9814 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9815 info.align_offset = pgoff << PAGE_SHIFT;
9816 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9817 struct mm_struct *mm = current->mm;
9818 unsigned long addr = addr0;
9819 int do_colour_align;
9820 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9821 struct vm_unmapped_area_info info;
9822
9823 if (flags & MAP_FIXED) {
9824 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9825 if (filp || (flags & MAP_SHARED))
9826 do_colour_align = 1;
9827
9828 +#ifdef CONFIG_PAX_RANDMMAP
9829 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9830 +#endif
9831 +
9832 /* requesting a specific address */
9833 if (addr) {
9834 if (do_colour_align)
9835 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9836 addr = PAGE_ALIGN(addr);
9837
9838 vma = find_vma(mm, addr);
9839 - if (TASK_SIZE - len >= addr &&
9840 - (!vma || addr + len <= vma->vm_start))
9841 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9842 return addr;
9843 }
9844
9845 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9846 VM_BUG_ON(addr != -ENOMEM);
9847 info.flags = 0;
9848 info.low_limit = TASK_UNMAPPED_BASE;
9849 +
9850 +#ifdef CONFIG_PAX_RANDMMAP
9851 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9852 + info.low_limit += mm->delta_mmap;
9853 +#endif
9854 +
9855 info.high_limit = TASK_SIZE;
9856 addr = vm_unmapped_area(&info);
9857 }
9858 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9859 index 4082749..fd97781 100644
9860 --- a/arch/sparc/include/asm/atomic_64.h
9861 +++ b/arch/sparc/include/asm/atomic_64.h
9862 @@ -15,18 +15,38 @@
9863 #define ATOMIC64_INIT(i) { (i) }
9864
9865 #define atomic_read(v) ACCESS_ONCE((v)->counter)
9866 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9867 +{
9868 + return ACCESS_ONCE(v->counter);
9869 +}
9870 #define atomic64_read(v) ACCESS_ONCE((v)->counter)
9871 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9872 +{
9873 + return ACCESS_ONCE(v->counter);
9874 +}
9875
9876 #define atomic_set(v, i) (((v)->counter) = i)
9877 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9878 +{
9879 + v->counter = i;
9880 +}
9881 #define atomic64_set(v, i) (((v)->counter) = i)
9882 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9883 +{
9884 + v->counter = i;
9885 +}
9886
9887 -#define ATOMIC_OP(op) \
9888 -void atomic_##op(int, atomic_t *); \
9889 -void atomic64_##op(long, atomic64_t *);
9890 +#define __ATOMIC_OP(op, suffix) \
9891 +void atomic_##op##suffix(int, atomic##suffix##_t *); \
9892 +void atomic64_##op##suffix(long, atomic64##suffix##_t *);
9893
9894 -#define ATOMIC_OP_RETURN(op) \
9895 -int atomic_##op##_return(int, atomic_t *); \
9896 -long atomic64_##op##_return(long, atomic64_t *);
9897 +#define ATOMIC_OP(op) __ATOMIC_OP(op, ) __ATOMIC_OP(op, _unchecked)
9898 +
9899 +#define __ATOMIC_OP_RETURN(op, suffix) \
9900 +int atomic_##op##_return##suffix(int, atomic##suffix##_t *); \
9901 +long atomic64_##op##_return##suffix(long, atomic64##suffix##_t *);
9902 +
9903 +#define ATOMIC_OP_RETURN(op) __ATOMIC_OP_RETURN(op, ) __ATOMIC_OP_RETURN(op, _unchecked)
9904
9905 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op)
9906
9907 @@ -35,13 +55,23 @@ ATOMIC_OPS(sub)
9908
9909 #undef ATOMIC_OPS
9910 #undef ATOMIC_OP_RETURN
9911 +#undef __ATOMIC_OP_RETURN
9912 #undef ATOMIC_OP
9913 +#undef __ATOMIC_OP
9914
9915 #define atomic_dec_return(v) atomic_sub_return(1, v)
9916 #define atomic64_dec_return(v) atomic64_sub_return(1, v)
9917
9918 #define atomic_inc_return(v) atomic_add_return(1, v)
9919 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9920 +{
9921 + return atomic_add_return_unchecked(1, v);
9922 +}
9923 #define atomic64_inc_return(v) atomic64_add_return(1, v)
9924 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9925 +{
9926 + return atomic64_add_return_unchecked(1, v);
9927 +}
9928
9929 /*
9930 * atomic_inc_and_test - increment and test
9931 @@ -52,6 +82,10 @@ ATOMIC_OPS(sub)
9932 * other cases.
9933 */
9934 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9935 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9936 +{
9937 + return atomic_inc_return_unchecked(v) == 0;
9938 +}
9939 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9940
9941 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
9942 @@ -61,25 +95,60 @@ ATOMIC_OPS(sub)
9943 #define atomic64_dec_and_test(v) (atomic64_sub_return(1, v) == 0)
9944
9945 #define atomic_inc(v) atomic_add(1, v)
9946 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9947 +{
9948 + atomic_add_unchecked(1, v);
9949 +}
9950 #define atomic64_inc(v) atomic64_add(1, v)
9951 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9952 +{
9953 + atomic64_add_unchecked(1, v);
9954 +}
9955
9956 #define atomic_dec(v) atomic_sub(1, v)
9957 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9958 +{
9959 + atomic_sub_unchecked(1, v);
9960 +}
9961 #define atomic64_dec(v) atomic64_sub(1, v)
9962 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9963 +{
9964 + atomic64_sub_unchecked(1, v);
9965 +}
9966
9967 #define atomic_add_negative(i, v) (atomic_add_return(i, v) < 0)
9968 #define atomic64_add_negative(i, v) (atomic64_add_return(i, v) < 0)
9969
9970 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9971 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9972 +{
9973 + return cmpxchg(&v->counter, old, new);
9974 +}
9975 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9976 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9977 +{
9978 + return xchg(&v->counter, new);
9979 +}
9980
9981 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9982 {
9983 - int c, old;
9984 + int c, old, new;
9985 c = atomic_read(v);
9986 for (;;) {
9987 - if (unlikely(c == (u)))
9988 + if (unlikely(c == u))
9989 break;
9990 - old = atomic_cmpxchg((v), c, c + (a));
9991 +
9992 + asm volatile("addcc %2, %0, %0\n"
9993 +
9994 +#ifdef CONFIG_PAX_REFCOUNT
9995 + "tvs %%icc, 6\n"
9996 +#endif
9997 +
9998 + : "=r" (new)
9999 + : "0" (c), "ir" (a)
10000 + : "cc");
10001 +
10002 + old = atomic_cmpxchg(v, c, new);
10003 if (likely(old == c))
10004 break;
10005 c = old;
10006 @@ -90,20 +159,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10007 #define atomic64_cmpxchg(v, o, n) \
10008 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
10009 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
10010 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
10011 +{
10012 + return xchg(&v->counter, new);
10013 +}
10014
10015 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
10016 {
10017 - long c, old;
10018 + long c, old, new;
10019 c = atomic64_read(v);
10020 for (;;) {
10021 - if (unlikely(c == (u)))
10022 + if (unlikely(c == u))
10023 break;
10024 - old = atomic64_cmpxchg((v), c, c + (a));
10025 +
10026 + asm volatile("addcc %2, %0, %0\n"
10027 +
10028 +#ifdef CONFIG_PAX_REFCOUNT
10029 + "tvs %%xcc, 6\n"
10030 +#endif
10031 +
10032 + : "=r" (new)
10033 + : "0" (c), "ir" (a)
10034 + : "cc");
10035 +
10036 + old = atomic64_cmpxchg(v, c, new);
10037 if (likely(old == c))
10038 break;
10039 c = old;
10040 }
10041 - return c != (u);
10042 + return c != u;
10043 }
10044
10045 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10046 diff --git a/arch/sparc/include/asm/barrier_64.h b/arch/sparc/include/asm/barrier_64.h
10047 index 305dcc3..7835030 100644
10048 --- a/arch/sparc/include/asm/barrier_64.h
10049 +++ b/arch/sparc/include/asm/barrier_64.h
10050 @@ -57,7 +57,7 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
10051 do { \
10052 compiletime_assert_atomic_type(*p); \
10053 barrier(); \
10054 - ACCESS_ONCE(*p) = (v); \
10055 + ACCESS_ONCE_RW(*p) = (v); \
10056 } while (0)
10057
10058 #define smp_load_acquire(p) \
10059 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
10060 index 5bb6991..5c2132e 100644
10061 --- a/arch/sparc/include/asm/cache.h
10062 +++ b/arch/sparc/include/asm/cache.h
10063 @@ -7,10 +7,12 @@
10064 #ifndef _SPARC_CACHE_H
10065 #define _SPARC_CACHE_H
10066
10067 +#include <linux/const.h>
10068 +
10069 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
10070
10071 #define L1_CACHE_SHIFT 5
10072 -#define L1_CACHE_BYTES 32
10073 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10074
10075 #ifdef CONFIG_SPARC32
10076 #define SMP_CACHE_BYTES_SHIFT 5
10077 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
10078 index a24e41f..47677ff 100644
10079 --- a/arch/sparc/include/asm/elf_32.h
10080 +++ b/arch/sparc/include/asm/elf_32.h
10081 @@ -114,6 +114,13 @@ typedef struct {
10082
10083 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
10084
10085 +#ifdef CONFIG_PAX_ASLR
10086 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
10087 +
10088 +#define PAX_DELTA_MMAP_LEN 16
10089 +#define PAX_DELTA_STACK_LEN 16
10090 +#endif
10091 +
10092 /* This yields a mask that user programs can use to figure out what
10093 instruction set this cpu supports. This can NOT be done in userspace
10094 on Sparc. */
10095 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
10096 index 370ca1e..d4f4a98 100644
10097 --- a/arch/sparc/include/asm/elf_64.h
10098 +++ b/arch/sparc/include/asm/elf_64.h
10099 @@ -189,6 +189,13 @@ typedef struct {
10100 #define ELF_ET_DYN_BASE 0x0000010000000000UL
10101 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
10102
10103 +#ifdef CONFIG_PAX_ASLR
10104 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
10105 +
10106 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
10107 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
10108 +#endif
10109 +
10110 extern unsigned long sparc64_elf_hwcap;
10111 #define ELF_HWCAP sparc64_elf_hwcap
10112
10113 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
10114 index a3890da..f6a408e 100644
10115 --- a/arch/sparc/include/asm/pgalloc_32.h
10116 +++ b/arch/sparc/include/asm/pgalloc_32.h
10117 @@ -35,6 +35,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
10118 }
10119
10120 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
10121 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
10122
10123 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
10124 unsigned long address)
10125 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
10126 index 5e31871..13469c6 100644
10127 --- a/arch/sparc/include/asm/pgalloc_64.h
10128 +++ b/arch/sparc/include/asm/pgalloc_64.h
10129 @@ -21,6 +21,7 @@ static inline void __pgd_populate(pgd_t *pgd, pud_t *pud)
10130 }
10131
10132 #define pgd_populate(MM, PGD, PUD) __pgd_populate(PGD, PUD)
10133 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
10134
10135 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
10136 {
10137 @@ -38,6 +39,7 @@ static inline void __pud_populate(pud_t *pud, pmd_t *pmd)
10138 }
10139
10140 #define pud_populate(MM, PUD, PMD) __pud_populate(PUD, PMD)
10141 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
10142
10143 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
10144 {
10145 diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
10146 index 59ba6f6..4518128 100644
10147 --- a/arch/sparc/include/asm/pgtable.h
10148 +++ b/arch/sparc/include/asm/pgtable.h
10149 @@ -5,4 +5,8 @@
10150 #else
10151 #include <asm/pgtable_32.h>
10152 #endif
10153 +
10154 +#define ktla_ktva(addr) (addr)
10155 +#define ktva_ktla(addr) (addr)
10156 +
10157 #endif
10158 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
10159 index b9b91ae..950b91e 100644
10160 --- a/arch/sparc/include/asm/pgtable_32.h
10161 +++ b/arch/sparc/include/asm/pgtable_32.h
10162 @@ -51,6 +51,9 @@ unsigned long __init bootmem_init(unsigned long *pages_avail);
10163 #define PAGE_SHARED SRMMU_PAGE_SHARED
10164 #define PAGE_COPY SRMMU_PAGE_COPY
10165 #define PAGE_READONLY SRMMU_PAGE_RDONLY
10166 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
10167 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
10168 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
10169 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
10170
10171 /* Top-level page directory - dummy used by init-mm.
10172 @@ -63,18 +66,18 @@ extern unsigned long ptr_in_current_pgd;
10173
10174 /* xwr */
10175 #define __P000 PAGE_NONE
10176 -#define __P001 PAGE_READONLY
10177 -#define __P010 PAGE_COPY
10178 -#define __P011 PAGE_COPY
10179 +#define __P001 PAGE_READONLY_NOEXEC
10180 +#define __P010 PAGE_COPY_NOEXEC
10181 +#define __P011 PAGE_COPY_NOEXEC
10182 #define __P100 PAGE_READONLY
10183 #define __P101 PAGE_READONLY
10184 #define __P110 PAGE_COPY
10185 #define __P111 PAGE_COPY
10186
10187 #define __S000 PAGE_NONE
10188 -#define __S001 PAGE_READONLY
10189 -#define __S010 PAGE_SHARED
10190 -#define __S011 PAGE_SHARED
10191 +#define __S001 PAGE_READONLY_NOEXEC
10192 +#define __S010 PAGE_SHARED_NOEXEC
10193 +#define __S011 PAGE_SHARED_NOEXEC
10194 #define __S100 PAGE_READONLY
10195 #define __S101 PAGE_READONLY
10196 #define __S110 PAGE_SHARED
10197 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
10198 index 79da178..c2eede8 100644
10199 --- a/arch/sparc/include/asm/pgtsrmmu.h
10200 +++ b/arch/sparc/include/asm/pgtsrmmu.h
10201 @@ -115,6 +115,11 @@
10202 SRMMU_EXEC | SRMMU_REF)
10203 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
10204 SRMMU_EXEC | SRMMU_REF)
10205 +
10206 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
10207 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10208 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10209 +
10210 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
10211 SRMMU_DIRTY | SRMMU_REF)
10212
10213 diff --git a/arch/sparc/include/asm/setup.h b/arch/sparc/include/asm/setup.h
10214 index 29d64b1..4272fe8 100644
10215 --- a/arch/sparc/include/asm/setup.h
10216 +++ b/arch/sparc/include/asm/setup.h
10217 @@ -55,8 +55,8 @@ int handle_ldf_stq(u32 insn, struct pt_regs *regs);
10218 void handle_ld_nf(u32 insn, struct pt_regs *regs);
10219
10220 /* init_64.c */
10221 -extern atomic_t dcpage_flushes;
10222 -extern atomic_t dcpage_flushes_xcall;
10223 +extern atomic_unchecked_t dcpage_flushes;
10224 +extern atomic_unchecked_t dcpage_flushes_xcall;
10225
10226 extern int sysctl_tsb_ratio;
10227 #endif
10228 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
10229 index 9689176..63c18ea 100644
10230 --- a/arch/sparc/include/asm/spinlock_64.h
10231 +++ b/arch/sparc/include/asm/spinlock_64.h
10232 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
10233
10234 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
10235
10236 -static void inline arch_read_lock(arch_rwlock_t *lock)
10237 +static inline void arch_read_lock(arch_rwlock_t *lock)
10238 {
10239 unsigned long tmp1, tmp2;
10240
10241 __asm__ __volatile__ (
10242 "1: ldsw [%2], %0\n"
10243 " brlz,pn %0, 2f\n"
10244 -"4: add %0, 1, %1\n"
10245 +"4: addcc %0, 1, %1\n"
10246 +
10247 +#ifdef CONFIG_PAX_REFCOUNT
10248 +" tvs %%icc, 6\n"
10249 +#endif
10250 +
10251 " cas [%2], %0, %1\n"
10252 " cmp %0, %1\n"
10253 " bne,pn %%icc, 1b\n"
10254 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
10255 " .previous"
10256 : "=&r" (tmp1), "=&r" (tmp2)
10257 : "r" (lock)
10258 - : "memory");
10259 + : "memory", "cc");
10260 }
10261
10262 -static int inline arch_read_trylock(arch_rwlock_t *lock)
10263 +static inline int arch_read_trylock(arch_rwlock_t *lock)
10264 {
10265 int tmp1, tmp2;
10266
10267 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10268 "1: ldsw [%2], %0\n"
10269 " brlz,a,pn %0, 2f\n"
10270 " mov 0, %0\n"
10271 -" add %0, 1, %1\n"
10272 +" addcc %0, 1, %1\n"
10273 +
10274 +#ifdef CONFIG_PAX_REFCOUNT
10275 +" tvs %%icc, 6\n"
10276 +#endif
10277 +
10278 " cas [%2], %0, %1\n"
10279 " cmp %0, %1\n"
10280 " bne,pn %%icc, 1b\n"
10281 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10282 return tmp1;
10283 }
10284
10285 -static void inline arch_read_unlock(arch_rwlock_t *lock)
10286 +static inline void arch_read_unlock(arch_rwlock_t *lock)
10287 {
10288 unsigned long tmp1, tmp2;
10289
10290 __asm__ __volatile__(
10291 "1: lduw [%2], %0\n"
10292 -" sub %0, 1, %1\n"
10293 +" subcc %0, 1, %1\n"
10294 +
10295 +#ifdef CONFIG_PAX_REFCOUNT
10296 +" tvs %%icc, 6\n"
10297 +#endif
10298 +
10299 " cas [%2], %0, %1\n"
10300 " cmp %0, %1\n"
10301 " bne,pn %%xcc, 1b\n"
10302 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
10303 : "memory");
10304 }
10305
10306 -static void inline arch_write_lock(arch_rwlock_t *lock)
10307 +static inline void arch_write_lock(arch_rwlock_t *lock)
10308 {
10309 unsigned long mask, tmp1, tmp2;
10310
10311 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
10312 : "memory");
10313 }
10314
10315 -static void inline arch_write_unlock(arch_rwlock_t *lock)
10316 +static inline void arch_write_unlock(arch_rwlock_t *lock)
10317 {
10318 __asm__ __volatile__(
10319 " stw %%g0, [%0]"
10320 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
10321 : "memory");
10322 }
10323
10324 -static int inline arch_write_trylock(arch_rwlock_t *lock)
10325 +static inline int arch_write_trylock(arch_rwlock_t *lock)
10326 {
10327 unsigned long mask, tmp1, tmp2, result;
10328
10329 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
10330 index 025c984..a216504 100644
10331 --- a/arch/sparc/include/asm/thread_info_32.h
10332 +++ b/arch/sparc/include/asm/thread_info_32.h
10333 @@ -49,6 +49,8 @@ struct thread_info {
10334 unsigned long w_saved;
10335
10336 struct restart_block restart_block;
10337 +
10338 + unsigned long lowest_stack;
10339 };
10340
10341 /*
10342 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
10343 index 798f027..b009941 100644
10344 --- a/arch/sparc/include/asm/thread_info_64.h
10345 +++ b/arch/sparc/include/asm/thread_info_64.h
10346 @@ -63,6 +63,8 @@ struct thread_info {
10347 struct pt_regs *kern_una_regs;
10348 unsigned int kern_una_insn;
10349
10350 + unsigned long lowest_stack;
10351 +
10352 unsigned long fpregs[(7 * 256) / sizeof(unsigned long)]
10353 __attribute__ ((aligned(64)));
10354 };
10355 @@ -190,12 +192,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
10356 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
10357 /* flag bit 4 is available */
10358 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
10359 -/* flag bit 6 is available */
10360 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
10361 #define TIF_32BIT 7 /* 32-bit binary */
10362 #define TIF_NOHZ 8 /* in adaptive nohz mode */
10363 #define TIF_SECCOMP 9 /* secure computing */
10364 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
10365 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
10366 +
10367 /* NOTE: Thread flags >= 12 should be ones we have no interest
10368 * in using in assembly, else we can't use the mask as
10369 * an immediate value in instructions such as andcc.
10370 @@ -215,12 +218,17 @@ register struct thread_info *current_thread_info_reg asm("g6");
10371 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
10372 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
10373 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
10374 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
10375
10376 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
10377 _TIF_DO_NOTIFY_RESUME_MASK | \
10378 _TIF_NEED_RESCHED)
10379 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
10380
10381 +#define _TIF_WORK_SYSCALL \
10382 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
10383 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
10384 +
10385 #define is_32bit_task() (test_thread_flag(TIF_32BIT))
10386
10387 /*
10388 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
10389 index bd56c28..4b63d83 100644
10390 --- a/arch/sparc/include/asm/uaccess.h
10391 +++ b/arch/sparc/include/asm/uaccess.h
10392 @@ -1,5 +1,6 @@
10393 #ifndef ___ASM_SPARC_UACCESS_H
10394 #define ___ASM_SPARC_UACCESS_H
10395 +
10396 #if defined(__sparc__) && defined(__arch64__)
10397 #include <asm/uaccess_64.h>
10398 #else
10399 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
10400 index 9634d08..f55fe4f 100644
10401 --- a/arch/sparc/include/asm/uaccess_32.h
10402 +++ b/arch/sparc/include/asm/uaccess_32.h
10403 @@ -250,27 +250,46 @@ unsigned long __copy_user(void __user *to, const void __user *from, unsigned lon
10404
10405 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
10406 {
10407 - if (n && __access_ok((unsigned long) to, n))
10408 + if ((long)n < 0)
10409 + return n;
10410 +
10411 + if (n && __access_ok((unsigned long) to, n)) {
10412 + if (!__builtin_constant_p(n))
10413 + check_object_size(from, n, true);
10414 return __copy_user(to, (__force void __user *) from, n);
10415 - else
10416 + } else
10417 return n;
10418 }
10419
10420 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
10421 {
10422 + if ((long)n < 0)
10423 + return n;
10424 +
10425 + if (!__builtin_constant_p(n))
10426 + check_object_size(from, n, true);
10427 +
10428 return __copy_user(to, (__force void __user *) from, n);
10429 }
10430
10431 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
10432 {
10433 - if (n && __access_ok((unsigned long) from, n))
10434 + if ((long)n < 0)
10435 + return n;
10436 +
10437 + if (n && __access_ok((unsigned long) from, n)) {
10438 + if (!__builtin_constant_p(n))
10439 + check_object_size(to, n, false);
10440 return __copy_user((__force void __user *) to, from, n);
10441 - else
10442 + } else
10443 return n;
10444 }
10445
10446 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10447 {
10448 + if ((long)n < 0)
10449 + return n;
10450 +
10451 return __copy_user((__force void __user *) to, from, n);
10452 }
10453
10454 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10455 index c990a5e..f17b9c1 100644
10456 --- a/arch/sparc/include/asm/uaccess_64.h
10457 +++ b/arch/sparc/include/asm/uaccess_64.h
10458 @@ -10,6 +10,7 @@
10459 #include <linux/compiler.h>
10460 #include <linux/string.h>
10461 #include <linux/thread_info.h>
10462 +#include <linux/kernel.h>
10463 #include <asm/asi.h>
10464 #include <asm/spitfire.h>
10465 #include <asm-generic/uaccess-unaligned.h>
10466 @@ -214,8 +215,15 @@ unsigned long copy_from_user_fixup(void *to, const void __user *from,
10467 static inline unsigned long __must_check
10468 copy_from_user(void *to, const void __user *from, unsigned long size)
10469 {
10470 - unsigned long ret = ___copy_from_user(to, from, size);
10471 + unsigned long ret;
10472
10473 + if ((long)size < 0 || size > INT_MAX)
10474 + return size;
10475 +
10476 + if (!__builtin_constant_p(size))
10477 + check_object_size(to, size, false);
10478 +
10479 + ret = ___copy_from_user(to, from, size);
10480 if (unlikely(ret))
10481 ret = copy_from_user_fixup(to, from, size);
10482
10483 @@ -231,8 +239,15 @@ unsigned long copy_to_user_fixup(void __user *to, const void *from,
10484 static inline unsigned long __must_check
10485 copy_to_user(void __user *to, const void *from, unsigned long size)
10486 {
10487 - unsigned long ret = ___copy_to_user(to, from, size);
10488 + unsigned long ret;
10489
10490 + if ((long)size < 0 || size > INT_MAX)
10491 + return size;
10492 +
10493 + if (!__builtin_constant_p(size))
10494 + check_object_size(from, size, true);
10495 +
10496 + ret = ___copy_to_user(to, from, size);
10497 if (unlikely(ret))
10498 ret = copy_to_user_fixup(to, from, size);
10499 return ret;
10500 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10501 index 7cf9c6e..6206648 100644
10502 --- a/arch/sparc/kernel/Makefile
10503 +++ b/arch/sparc/kernel/Makefile
10504 @@ -4,7 +4,7 @@
10505 #
10506
10507 asflags-y := -ansi
10508 -ccflags-y := -Werror
10509 +#ccflags-y := -Werror
10510
10511 extra-y := head_$(BITS).o
10512
10513 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10514 index 50e7b62..79fae35 100644
10515 --- a/arch/sparc/kernel/process_32.c
10516 +++ b/arch/sparc/kernel/process_32.c
10517 @@ -123,14 +123,14 @@ void show_regs(struct pt_regs *r)
10518
10519 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10520 r->psr, r->pc, r->npc, r->y, print_tainted());
10521 - printk("PC: <%pS>\n", (void *) r->pc);
10522 + printk("PC: <%pA>\n", (void *) r->pc);
10523 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10524 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10525 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10526 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10527 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10528 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10529 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10530 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10531
10532 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10533 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10534 @@ -167,7 +167,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10535 rw = (struct reg_window32 *) fp;
10536 pc = rw->ins[7];
10537 printk("[%08lx : ", pc);
10538 - printk("%pS ] ", (void *) pc);
10539 + printk("%pA ] ", (void *) pc);
10540 fp = rw->ins[6];
10541 } while (++count < 16);
10542 printk("\n");
10543 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10544 index 0be7bf9..2b1cba8 100644
10545 --- a/arch/sparc/kernel/process_64.c
10546 +++ b/arch/sparc/kernel/process_64.c
10547 @@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10548 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10549 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10550 if (regs->tstate & TSTATE_PRIV)
10551 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10552 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10553 }
10554
10555 void show_regs(struct pt_regs *regs)
10556 @@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10557
10558 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10559 regs->tpc, regs->tnpc, regs->y, print_tainted());
10560 - printk("TPC: <%pS>\n", (void *) regs->tpc);
10561 + printk("TPC: <%pA>\n", (void *) regs->tpc);
10562 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10563 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10564 regs->u_regs[3]);
10565 @@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10566 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10567 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10568 regs->u_regs[15]);
10569 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10570 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10571 show_regwindow(regs);
10572 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10573 }
10574 @@ -278,7 +278,7 @@ void arch_trigger_all_cpu_backtrace(bool include_self)
10575 ((tp && tp->task) ? tp->task->pid : -1));
10576
10577 if (gp->tstate & TSTATE_PRIV) {
10578 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10579 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10580 (void *) gp->tpc,
10581 (void *) gp->o7,
10582 (void *) gp->i7,
10583 diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10584 index 79cc0d1..ec62734 100644
10585 --- a/arch/sparc/kernel/prom_common.c
10586 +++ b/arch/sparc/kernel/prom_common.c
10587 @@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10588
10589 unsigned int prom_early_allocated __initdata;
10590
10591 -static struct of_pdt_ops prom_sparc_ops __initdata = {
10592 +static struct of_pdt_ops prom_sparc_ops __initconst = {
10593 .nextprop = prom_common_nextprop,
10594 .getproplen = prom_getproplen,
10595 .getproperty = prom_getproperty,
10596 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10597 index 9ddc492..27a5619 100644
10598 --- a/arch/sparc/kernel/ptrace_64.c
10599 +++ b/arch/sparc/kernel/ptrace_64.c
10600 @@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10601 return ret;
10602 }
10603
10604 +#ifdef CONFIG_GRKERNSEC_SETXID
10605 +extern void gr_delayed_cred_worker(void);
10606 +#endif
10607 +
10608 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10609 {
10610 int ret = 0;
10611 @@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10612 if (test_thread_flag(TIF_NOHZ))
10613 user_exit();
10614
10615 +#ifdef CONFIG_GRKERNSEC_SETXID
10616 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10617 + gr_delayed_cred_worker();
10618 +#endif
10619 +
10620 if (test_thread_flag(TIF_SYSCALL_TRACE))
10621 ret = tracehook_report_syscall_entry(regs);
10622
10623 @@ -1088,6 +1097,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10624 if (test_thread_flag(TIF_NOHZ))
10625 user_exit();
10626
10627 +#ifdef CONFIG_GRKERNSEC_SETXID
10628 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10629 + gr_delayed_cred_worker();
10630 +#endif
10631 +
10632 audit_syscall_exit(regs);
10633
10634 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10635 diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10636 index da6f1a7..e5dea8f 100644
10637 --- a/arch/sparc/kernel/smp_64.c
10638 +++ b/arch/sparc/kernel/smp_64.c
10639 @@ -887,7 +887,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10640 return;
10641
10642 #ifdef CONFIG_DEBUG_DCFLUSH
10643 - atomic_inc(&dcpage_flushes);
10644 + atomic_inc_unchecked(&dcpage_flushes);
10645 #endif
10646
10647 this_cpu = get_cpu();
10648 @@ -911,7 +911,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10649 xcall_deliver(data0, __pa(pg_addr),
10650 (u64) pg_addr, cpumask_of(cpu));
10651 #ifdef CONFIG_DEBUG_DCFLUSH
10652 - atomic_inc(&dcpage_flushes_xcall);
10653 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10654 #endif
10655 }
10656 }
10657 @@ -930,7 +930,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10658 preempt_disable();
10659
10660 #ifdef CONFIG_DEBUG_DCFLUSH
10661 - atomic_inc(&dcpage_flushes);
10662 + atomic_inc_unchecked(&dcpage_flushes);
10663 #endif
10664 data0 = 0;
10665 pg_addr = page_address(page);
10666 @@ -947,7 +947,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10667 xcall_deliver(data0, __pa(pg_addr),
10668 (u64) pg_addr, cpu_online_mask);
10669 #ifdef CONFIG_DEBUG_DCFLUSH
10670 - atomic_inc(&dcpage_flushes_xcall);
10671 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10672 #endif
10673 }
10674 __local_flush_dcache_page(page);
10675 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10676 index 646988d..b88905f 100644
10677 --- a/arch/sparc/kernel/sys_sparc_32.c
10678 +++ b/arch/sparc/kernel/sys_sparc_32.c
10679 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10680 if (len > TASK_SIZE - PAGE_SIZE)
10681 return -ENOMEM;
10682 if (!addr)
10683 - addr = TASK_UNMAPPED_BASE;
10684 + addr = current->mm->mmap_base;
10685
10686 info.flags = 0;
10687 info.length = len;
10688 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10689 index c85403d..6af95c9 100644
10690 --- a/arch/sparc/kernel/sys_sparc_64.c
10691 +++ b/arch/sparc/kernel/sys_sparc_64.c
10692 @@ -89,13 +89,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10693 struct vm_area_struct * vma;
10694 unsigned long task_size = TASK_SIZE;
10695 int do_color_align;
10696 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10697 struct vm_unmapped_area_info info;
10698
10699 if (flags & MAP_FIXED) {
10700 /* We do not accept a shared mapping if it would violate
10701 * cache aliasing constraints.
10702 */
10703 - if ((flags & MAP_SHARED) &&
10704 + if ((filp || (flags & MAP_SHARED)) &&
10705 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10706 return -EINVAL;
10707 return addr;
10708 @@ -110,6 +111,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10709 if (filp || (flags & MAP_SHARED))
10710 do_color_align = 1;
10711
10712 +#ifdef CONFIG_PAX_RANDMMAP
10713 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10714 +#endif
10715 +
10716 if (addr) {
10717 if (do_color_align)
10718 addr = COLOR_ALIGN(addr, pgoff);
10719 @@ -117,22 +122,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10720 addr = PAGE_ALIGN(addr);
10721
10722 vma = find_vma(mm, addr);
10723 - if (task_size - len >= addr &&
10724 - (!vma || addr + len <= vma->vm_start))
10725 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10726 return addr;
10727 }
10728
10729 info.flags = 0;
10730 info.length = len;
10731 - info.low_limit = TASK_UNMAPPED_BASE;
10732 + info.low_limit = mm->mmap_base;
10733 info.high_limit = min(task_size, VA_EXCLUDE_START);
10734 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10735 info.align_offset = pgoff << PAGE_SHIFT;
10736 + info.threadstack_offset = offset;
10737 addr = vm_unmapped_area(&info);
10738
10739 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10740 VM_BUG_ON(addr != -ENOMEM);
10741 info.low_limit = VA_EXCLUDE_END;
10742 +
10743 +#ifdef CONFIG_PAX_RANDMMAP
10744 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10745 + info.low_limit += mm->delta_mmap;
10746 +#endif
10747 +
10748 info.high_limit = task_size;
10749 addr = vm_unmapped_area(&info);
10750 }
10751 @@ -150,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10752 unsigned long task_size = STACK_TOP32;
10753 unsigned long addr = addr0;
10754 int do_color_align;
10755 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10756 struct vm_unmapped_area_info info;
10757
10758 /* This should only ever run for 32-bit processes. */
10759 @@ -159,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10760 /* We do not accept a shared mapping if it would violate
10761 * cache aliasing constraints.
10762 */
10763 - if ((flags & MAP_SHARED) &&
10764 + if ((filp || (flags & MAP_SHARED)) &&
10765 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10766 return -EINVAL;
10767 return addr;
10768 @@ -172,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10769 if (filp || (flags & MAP_SHARED))
10770 do_color_align = 1;
10771
10772 +#ifdef CONFIG_PAX_RANDMMAP
10773 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10774 +#endif
10775 +
10776 /* requesting a specific address */
10777 if (addr) {
10778 if (do_color_align)
10779 @@ -180,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10780 addr = PAGE_ALIGN(addr);
10781
10782 vma = find_vma(mm, addr);
10783 - if (task_size - len >= addr &&
10784 - (!vma || addr + len <= vma->vm_start))
10785 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10786 return addr;
10787 }
10788
10789 @@ -191,6 +206,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10790 info.high_limit = mm->mmap_base;
10791 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10792 info.align_offset = pgoff << PAGE_SHIFT;
10793 + info.threadstack_offset = offset;
10794 addr = vm_unmapped_area(&info);
10795
10796 /*
10797 @@ -203,6 +219,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10798 VM_BUG_ON(addr != -ENOMEM);
10799 info.flags = 0;
10800 info.low_limit = TASK_UNMAPPED_BASE;
10801 +
10802 +#ifdef CONFIG_PAX_RANDMMAP
10803 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10804 + info.low_limit += mm->delta_mmap;
10805 +#endif
10806 +
10807 info.high_limit = STACK_TOP32;
10808 addr = vm_unmapped_area(&info);
10809 }
10810 @@ -259,10 +281,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10811 EXPORT_SYMBOL(get_fb_unmapped_area);
10812
10813 /* Essentially the same as PowerPC. */
10814 -static unsigned long mmap_rnd(void)
10815 +static unsigned long mmap_rnd(struct mm_struct *mm)
10816 {
10817 unsigned long rnd = 0UL;
10818
10819 +#ifdef CONFIG_PAX_RANDMMAP
10820 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10821 +#endif
10822 +
10823 if (current->flags & PF_RANDOMIZE) {
10824 unsigned long val = get_random_int();
10825 if (test_thread_flag(TIF_32BIT))
10826 @@ -275,7 +301,7 @@ static unsigned long mmap_rnd(void)
10827
10828 void arch_pick_mmap_layout(struct mm_struct *mm)
10829 {
10830 - unsigned long random_factor = mmap_rnd();
10831 + unsigned long random_factor = mmap_rnd(mm);
10832 unsigned long gap;
10833
10834 /*
10835 @@ -288,6 +314,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10836 gap == RLIM_INFINITY ||
10837 sysctl_legacy_va_layout) {
10838 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10839 +
10840 +#ifdef CONFIG_PAX_RANDMMAP
10841 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10842 + mm->mmap_base += mm->delta_mmap;
10843 +#endif
10844 +
10845 mm->get_unmapped_area = arch_get_unmapped_area;
10846 } else {
10847 /* We know it's 32-bit */
10848 @@ -299,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10849 gap = (task_size / 6 * 5);
10850
10851 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10852 +
10853 +#ifdef CONFIG_PAX_RANDMMAP
10854 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10855 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10856 +#endif
10857 +
10858 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10859 }
10860 }
10861 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10862 index 33a17e7..d87fb1f 100644
10863 --- a/arch/sparc/kernel/syscalls.S
10864 +++ b/arch/sparc/kernel/syscalls.S
10865 @@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10866 #endif
10867 .align 32
10868 1: ldx [%g6 + TI_FLAGS], %l5
10869 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10870 + andcc %l5, _TIF_WORK_SYSCALL, %g0
10871 be,pt %icc, rtrap
10872 nop
10873 call syscall_trace_leave
10874 @@ -184,7 +184,7 @@ linux_sparc_syscall32:
10875
10876 srl %i3, 0, %o3 ! IEU0
10877 srl %i2, 0, %o2 ! IEU0 Group
10878 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10879 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10880 bne,pn %icc, linux_syscall_trace32 ! CTI
10881 mov %i0, %l5 ! IEU1
10882 5: call %l7 ! CTI Group brk forced
10883 @@ -208,7 +208,7 @@ linux_sparc_syscall:
10884
10885 mov %i3, %o3 ! IEU1
10886 mov %i4, %o4 ! IEU0 Group
10887 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10888 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10889 bne,pn %icc, linux_syscall_trace ! CTI Group
10890 mov %i0, %l5 ! IEU0
10891 2: call %l7 ! CTI Group brk forced
10892 @@ -223,7 +223,7 @@ ret_sys_call:
10893
10894 cmp %o0, -ERESTART_RESTARTBLOCK
10895 bgeu,pn %xcc, 1f
10896 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10897 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10898 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10899
10900 2:
10901 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10902 index 6fd386c5..6907d81 100644
10903 --- a/arch/sparc/kernel/traps_32.c
10904 +++ b/arch/sparc/kernel/traps_32.c
10905 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10906 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10907 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10908
10909 +extern void gr_handle_kernel_exploit(void);
10910 +
10911 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
10912 {
10913 static int die_counter;
10914 @@ -76,15 +78,17 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
10915 count++ < 30 &&
10916 (((unsigned long) rw) >= PAGE_OFFSET) &&
10917 !(((unsigned long) rw) & 0x7)) {
10918 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
10919 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
10920 (void *) rw->ins[7]);
10921 rw = (struct reg_window32 *)rw->ins[6];
10922 }
10923 }
10924 printk("Instruction DUMP:");
10925 instruction_dump ((unsigned long *) regs->pc);
10926 - if(regs->psr & PSR_PS)
10927 + if(regs->psr & PSR_PS) {
10928 + gr_handle_kernel_exploit();
10929 do_exit(SIGKILL);
10930 + }
10931 do_exit(SIGSEGV);
10932 }
10933
10934 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10935 index 981a769..d906eda 100644
10936 --- a/arch/sparc/kernel/traps_64.c
10937 +++ b/arch/sparc/kernel/traps_64.c
10938 @@ -79,7 +79,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10939 i + 1,
10940 p->trapstack[i].tstate, p->trapstack[i].tpc,
10941 p->trapstack[i].tnpc, p->trapstack[i].tt);
10942 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10943 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10944 }
10945 }
10946
10947 @@ -99,6 +99,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10948
10949 lvl -= 0x100;
10950 if (regs->tstate & TSTATE_PRIV) {
10951 +
10952 +#ifdef CONFIG_PAX_REFCOUNT
10953 + if (lvl == 6)
10954 + pax_report_refcount_overflow(regs);
10955 +#endif
10956 +
10957 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10958 die_if_kernel(buffer, regs);
10959 }
10960 @@ -117,11 +123,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10961 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10962 {
10963 char buffer[32];
10964 -
10965 +
10966 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10967 0, lvl, SIGTRAP) == NOTIFY_STOP)
10968 return;
10969
10970 +#ifdef CONFIG_PAX_REFCOUNT
10971 + if (lvl == 6)
10972 + pax_report_refcount_overflow(regs);
10973 +#endif
10974 +
10975 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10976
10977 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10978 @@ -1151,7 +1162,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10979 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10980 printk("%s" "ERROR(%d): ",
10981 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10982 - printk("TPC<%pS>\n", (void *) regs->tpc);
10983 + printk("TPC<%pA>\n", (void *) regs->tpc);
10984 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10985 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10986 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10987 @@ -1758,7 +1769,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10988 smp_processor_id(),
10989 (type & 0x1) ? 'I' : 'D',
10990 regs->tpc);
10991 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10992 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10993 panic("Irrecoverable Cheetah+ parity error.");
10994 }
10995
10996 @@ -1766,7 +1777,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10997 smp_processor_id(),
10998 (type & 0x1) ? 'I' : 'D',
10999 regs->tpc);
11000 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
11001 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
11002 }
11003
11004 struct sun4v_error_entry {
11005 @@ -1839,8 +1850,8 @@ struct sun4v_error_entry {
11006 /*0x38*/u64 reserved_5;
11007 };
11008
11009 -static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11010 -static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11011 +static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11012 +static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11013
11014 static const char *sun4v_err_type_to_str(u8 type)
11015 {
11016 @@ -1932,7 +1943,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
11017 }
11018
11019 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11020 - int cpu, const char *pfx, atomic_t *ocnt)
11021 + int cpu, const char *pfx, atomic_unchecked_t *ocnt)
11022 {
11023 u64 *raw_ptr = (u64 *) ent;
11024 u32 attrs;
11025 @@ -1990,8 +2001,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11026
11027 show_regs(regs);
11028
11029 - if ((cnt = atomic_read(ocnt)) != 0) {
11030 - atomic_set(ocnt, 0);
11031 + if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
11032 + atomic_set_unchecked(ocnt, 0);
11033 wmb();
11034 printk("%s: Queue overflowed %d times.\n",
11035 pfx, cnt);
11036 @@ -2048,7 +2059,7 @@ out:
11037 */
11038 void sun4v_resum_overflow(struct pt_regs *regs)
11039 {
11040 - atomic_inc(&sun4v_resum_oflow_cnt);
11041 + atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
11042 }
11043
11044 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
11045 @@ -2101,7 +2112,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
11046 /* XXX Actually even this can make not that much sense. Perhaps
11047 * XXX we should just pull the plug and panic directly from here?
11048 */
11049 - atomic_inc(&sun4v_nonresum_oflow_cnt);
11050 + atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
11051 }
11052
11053 static void sun4v_tlb_error(struct pt_regs *regs)
11054 @@ -2120,9 +2131,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
11055
11056 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
11057 regs->tpc, tl);
11058 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
11059 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
11060 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11061 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
11062 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
11063 (void *) regs->u_regs[UREG_I7]);
11064 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
11065 "pte[%lx] error[%lx]\n",
11066 @@ -2143,9 +2154,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
11067
11068 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
11069 regs->tpc, tl);
11070 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
11071 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
11072 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11073 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
11074 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
11075 (void *) regs->u_regs[UREG_I7]);
11076 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
11077 "pte[%lx] error[%lx]\n",
11078 @@ -2362,13 +2373,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
11079 fp = (unsigned long)sf->fp + STACK_BIAS;
11080 }
11081
11082 - printk(" [%016lx] %pS\n", pc, (void *) pc);
11083 + printk(" [%016lx] %pA\n", pc, (void *) pc);
11084 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
11085 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
11086 int index = tsk->curr_ret_stack;
11087 if (tsk->ret_stack && index >= graph) {
11088 pc = tsk->ret_stack[index - graph].ret;
11089 - printk(" [%016lx] %pS\n", pc, (void *) pc);
11090 + printk(" [%016lx] %pA\n", pc, (void *) pc);
11091 graph++;
11092 }
11093 }
11094 @@ -2386,6 +2397,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
11095 return (struct reg_window *) (fp + STACK_BIAS);
11096 }
11097
11098 +extern void gr_handle_kernel_exploit(void);
11099 +
11100 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11101 {
11102 static int die_counter;
11103 @@ -2414,7 +2427,7 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11104 while (rw &&
11105 count++ < 30 &&
11106 kstack_valid(tp, (unsigned long) rw)) {
11107 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
11108 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
11109 (void *) rw->ins[7]);
11110
11111 rw = kernel_stack_up(rw);
11112 @@ -2427,8 +2440,10 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11113 }
11114 user_instruction_dump ((unsigned int __user *) regs->tpc);
11115 }
11116 - if (regs->tstate & TSTATE_PRIV)
11117 + if (regs->tstate & TSTATE_PRIV) {
11118 + gr_handle_kernel_exploit();
11119 do_exit(SIGKILL);
11120 + }
11121 do_exit(SIGSEGV);
11122 }
11123 EXPORT_SYMBOL(die_if_kernel);
11124 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
11125 index 62098a8..547ab2c 100644
11126 --- a/arch/sparc/kernel/unaligned_64.c
11127 +++ b/arch/sparc/kernel/unaligned_64.c
11128 @@ -297,7 +297,7 @@ static void log_unaligned(struct pt_regs *regs)
11129 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
11130
11131 if (__ratelimit(&ratelimit)) {
11132 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
11133 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
11134 regs->tpc, (void *) regs->tpc);
11135 }
11136 }
11137 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
11138 index 3269b02..64f5231 100644
11139 --- a/arch/sparc/lib/Makefile
11140 +++ b/arch/sparc/lib/Makefile
11141 @@ -2,7 +2,7 @@
11142 #
11143
11144 asflags-y := -ansi -DST_DIV0=0x02
11145 -ccflags-y := -Werror
11146 +#ccflags-y := -Werror
11147
11148 lib-$(CONFIG_SPARC32) += ashrdi3.o
11149 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
11150 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
11151 index 05dac43..76f8ed4 100644
11152 --- a/arch/sparc/lib/atomic_64.S
11153 +++ b/arch/sparc/lib/atomic_64.S
11154 @@ -15,11 +15,22 @@
11155 * a value and does the barriers.
11156 */
11157
11158 -#define ATOMIC_OP(op) \
11159 -ENTRY(atomic_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11160 +#ifdef CONFIG_PAX_REFCOUNT
11161 +#define __REFCOUNT_OP(op) op##cc
11162 +#define __OVERFLOW_IOP tvs %icc, 6;
11163 +#define __OVERFLOW_XOP tvs %xcc, 6;
11164 +#else
11165 +#define __REFCOUNT_OP(op) op
11166 +#define __OVERFLOW_IOP
11167 +#define __OVERFLOW_XOP
11168 +#endif
11169 +
11170 +#define __ATOMIC_OP(op, suffix, asm_op, post_op) \
11171 +ENTRY(atomic_##op##suffix) /* %o0 = increment, %o1 = atomic_ptr */ \
11172 BACKOFF_SETUP(%o2); \
11173 1: lduw [%o1], %g1; \
11174 - op %g1, %o0, %g7; \
11175 + asm_op %g1, %o0, %g7; \
11176 + post_op \
11177 cas [%o1], %g1, %g7; \
11178 cmp %g1, %g7; \
11179 bne,pn %icc, BACKOFF_LABEL(2f, 1b); \
11180 @@ -29,11 +40,15 @@ ENTRY(atomic_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11181 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11182 ENDPROC(atomic_##op); \
11183
11184 -#define ATOMIC_OP_RETURN(op) \
11185 -ENTRY(atomic_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11186 +#define ATOMIC_OP(op) __ATOMIC_OP(op, , op, ) \
11187 + __ATOMIC_OP(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_IOP)
11188 +
11189 +#define __ATOMIC_OP_RETURN(op, suffix, asm_op, post_op) \
11190 +ENTRY(atomic_##op##_return##suffix) /* %o0 = increment, %o1 = atomic_ptr */\
11191 BACKOFF_SETUP(%o2); \
11192 1: lduw [%o1], %g1; \
11193 - op %g1, %o0, %g7; \
11194 + asm_op %g1, %o0, %g7; \
11195 + post_op \
11196 cas [%o1], %g1, %g7; \
11197 cmp %g1, %g7; \
11198 bne,pn %icc, BACKOFF_LABEL(2f, 1b); \
11199 @@ -43,6 +58,9 @@ ENTRY(atomic_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11200 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11201 ENDPROC(atomic_##op##_return);
11202
11203 +#define ATOMIC_OP_RETURN(op) __ATOMIC_OP_RETURN(op, , op, ) \
11204 + __ATOMIC_OP_RETURN(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_IOP)
11205 +
11206 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op)
11207
11208 ATOMIC_OPS(add)
11209 @@ -50,13 +68,16 @@ ATOMIC_OPS(sub)
11210
11211 #undef ATOMIC_OPS
11212 #undef ATOMIC_OP_RETURN
11213 +#undef __ATOMIC_OP_RETURN
11214 #undef ATOMIC_OP
11215 +#undef __ATOMIC_OP
11216
11217 -#define ATOMIC64_OP(op) \
11218 -ENTRY(atomic64_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11219 +#define __ATOMIC64_OP(op, suffix, asm_op, post_op) \
11220 +ENTRY(atomic64_##op##suffix) /* %o0 = increment, %o1 = atomic_ptr */ \
11221 BACKOFF_SETUP(%o2); \
11222 1: ldx [%o1], %g1; \
11223 - op %g1, %o0, %g7; \
11224 + asm_op %g1, %o0, %g7; \
11225 + post_op \
11226 casx [%o1], %g1, %g7; \
11227 cmp %g1, %g7; \
11228 bne,pn %xcc, BACKOFF_LABEL(2f, 1b); \
11229 @@ -66,11 +87,15 @@ ENTRY(atomic64_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11230 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11231 ENDPROC(atomic64_##op); \
11232
11233 -#define ATOMIC64_OP_RETURN(op) \
11234 -ENTRY(atomic64_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11235 +#define ATOMIC64_OP(op) __ATOMIC64_OP(op, , op, ) \
11236 + __ATOMIC64_OP(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_XOP)
11237 +
11238 +#define __ATOMIC64_OP_RETURN(op, suffix, asm_op, post_op) \
11239 +ENTRY(atomic64_##op##_return##suffix) /* %o0 = increment, %o1 = atomic_ptr */\
11240 BACKOFF_SETUP(%o2); \
11241 1: ldx [%o1], %g1; \
11242 - op %g1, %o0, %g7; \
11243 + asm_op %g1, %o0, %g7; \
11244 + post_op \
11245 casx [%o1], %g1, %g7; \
11246 cmp %g1, %g7; \
11247 bne,pn %xcc, BACKOFF_LABEL(2f, 1b); \
11248 @@ -80,6 +105,9 @@ ENTRY(atomic64_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11249 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11250 ENDPROC(atomic64_##op##_return);
11251
11252 +#define ATOMIC64_OP_RETURN(op) __ATOMIC64_OP_RETURN(op, , op, ) \
11253 +i __ATOMIC64_OP_RETURN(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_XOP)
11254 +
11255 #define ATOMIC64_OPS(op) ATOMIC64_OP(op) ATOMIC64_OP_RETURN(op)
11256
11257 ATOMIC64_OPS(add)
11258 @@ -87,7 +115,12 @@ ATOMIC64_OPS(sub)
11259
11260 #undef ATOMIC64_OPS
11261 #undef ATOMIC64_OP_RETURN
11262 +#undef __ATOMIC64_OP_RETURN
11263 #undef ATOMIC64_OP
11264 +#undef __ATOMIC64_OP
11265 +#undef __OVERFLOW_XOP
11266 +#undef __OVERFLOW_IOP
11267 +#undef __REFCOUNT_OP
11268
11269 ENTRY(atomic64_dec_if_positive) /* %o0 = atomic_ptr */
11270 BACKOFF_SETUP(%o2)
11271 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
11272 index 1d649a9..fbc5bfc 100644
11273 --- a/arch/sparc/lib/ksyms.c
11274 +++ b/arch/sparc/lib/ksyms.c
11275 @@ -101,7 +101,9 @@ EXPORT_SYMBOL(__clear_user);
11276 /* Atomic counter implementation. */
11277 #define ATOMIC_OP(op) \
11278 EXPORT_SYMBOL(atomic_##op); \
11279 -EXPORT_SYMBOL(atomic64_##op);
11280 +EXPORT_SYMBOL(atomic_##op##_unchecked); \
11281 +EXPORT_SYMBOL(atomic64_##op); \
11282 +EXPORT_SYMBOL(atomic64_##op##_unchecked);
11283
11284 #define ATOMIC_OP_RETURN(op) \
11285 EXPORT_SYMBOL(atomic_##op##_return); \
11286 @@ -110,6 +112,8 @@ EXPORT_SYMBOL(atomic64_##op##_return);
11287 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op)
11288
11289 ATOMIC_OPS(add)
11290 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
11291 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
11292 ATOMIC_OPS(sub)
11293
11294 #undef ATOMIC_OPS
11295 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
11296 index 30c3ecc..736f015 100644
11297 --- a/arch/sparc/mm/Makefile
11298 +++ b/arch/sparc/mm/Makefile
11299 @@ -2,7 +2,7 @@
11300 #
11301
11302 asflags-y := -ansi
11303 -ccflags-y := -Werror
11304 +#ccflags-y := -Werror
11305
11306 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
11307 obj-y += fault_$(BITS).o
11308 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
11309 index 908e8c1..1524793 100644
11310 --- a/arch/sparc/mm/fault_32.c
11311 +++ b/arch/sparc/mm/fault_32.c
11312 @@ -21,6 +21,9 @@
11313 #include <linux/perf_event.h>
11314 #include <linux/interrupt.h>
11315 #include <linux/kdebug.h>
11316 +#include <linux/slab.h>
11317 +#include <linux/pagemap.h>
11318 +#include <linux/compiler.h>
11319
11320 #include <asm/page.h>
11321 #include <asm/pgtable.h>
11322 @@ -156,6 +159,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
11323 return safe_compute_effective_address(regs, insn);
11324 }
11325
11326 +#ifdef CONFIG_PAX_PAGEEXEC
11327 +#ifdef CONFIG_PAX_DLRESOLVE
11328 +static void pax_emuplt_close(struct vm_area_struct *vma)
11329 +{
11330 + vma->vm_mm->call_dl_resolve = 0UL;
11331 +}
11332 +
11333 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11334 +{
11335 + unsigned int *kaddr;
11336 +
11337 + vmf->page = alloc_page(GFP_HIGHUSER);
11338 + if (!vmf->page)
11339 + return VM_FAULT_OOM;
11340 +
11341 + kaddr = kmap(vmf->page);
11342 + memset(kaddr, 0, PAGE_SIZE);
11343 + kaddr[0] = 0x9DE3BFA8U; /* save */
11344 + flush_dcache_page(vmf->page);
11345 + kunmap(vmf->page);
11346 + return VM_FAULT_MAJOR;
11347 +}
11348 +
11349 +static const struct vm_operations_struct pax_vm_ops = {
11350 + .close = pax_emuplt_close,
11351 + .fault = pax_emuplt_fault
11352 +};
11353 +
11354 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11355 +{
11356 + int ret;
11357 +
11358 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11359 + vma->vm_mm = current->mm;
11360 + vma->vm_start = addr;
11361 + vma->vm_end = addr + PAGE_SIZE;
11362 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11363 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11364 + vma->vm_ops = &pax_vm_ops;
11365 +
11366 + ret = insert_vm_struct(current->mm, vma);
11367 + if (ret)
11368 + return ret;
11369 +
11370 + ++current->mm->total_vm;
11371 + return 0;
11372 +}
11373 +#endif
11374 +
11375 +/*
11376 + * PaX: decide what to do with offenders (regs->pc = fault address)
11377 + *
11378 + * returns 1 when task should be killed
11379 + * 2 when patched PLT trampoline was detected
11380 + * 3 when unpatched PLT trampoline was detected
11381 + */
11382 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11383 +{
11384 +
11385 +#ifdef CONFIG_PAX_EMUPLT
11386 + int err;
11387 +
11388 + do { /* PaX: patched PLT emulation #1 */
11389 + unsigned int sethi1, sethi2, jmpl;
11390 +
11391 + err = get_user(sethi1, (unsigned int *)regs->pc);
11392 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11393 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11394 +
11395 + if (err)
11396 + break;
11397 +
11398 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11399 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11400 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11401 + {
11402 + unsigned int addr;
11403 +
11404 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11405 + addr = regs->u_regs[UREG_G1];
11406 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11407 + regs->pc = addr;
11408 + regs->npc = addr+4;
11409 + return 2;
11410 + }
11411 + } while (0);
11412 +
11413 + do { /* PaX: patched PLT emulation #2 */
11414 + unsigned int ba;
11415 +
11416 + err = get_user(ba, (unsigned int *)regs->pc);
11417 +
11418 + if (err)
11419 + break;
11420 +
11421 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11422 + unsigned int addr;
11423 +
11424 + if ((ba & 0xFFC00000U) == 0x30800000U)
11425 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11426 + else
11427 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11428 + regs->pc = addr;
11429 + regs->npc = addr+4;
11430 + return 2;
11431 + }
11432 + } while (0);
11433 +
11434 + do { /* PaX: patched PLT emulation #3 */
11435 + unsigned int sethi, bajmpl, nop;
11436 +
11437 + err = get_user(sethi, (unsigned int *)regs->pc);
11438 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11439 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11440 +
11441 + if (err)
11442 + break;
11443 +
11444 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11445 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11446 + nop == 0x01000000U)
11447 + {
11448 + unsigned int addr;
11449 +
11450 + addr = (sethi & 0x003FFFFFU) << 10;
11451 + regs->u_regs[UREG_G1] = addr;
11452 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11453 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11454 + else
11455 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11456 + regs->pc = addr;
11457 + regs->npc = addr+4;
11458 + return 2;
11459 + }
11460 + } while (0);
11461 +
11462 + do { /* PaX: unpatched PLT emulation step 1 */
11463 + unsigned int sethi, ba, nop;
11464 +
11465 + err = get_user(sethi, (unsigned int *)regs->pc);
11466 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
11467 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11468 +
11469 + if (err)
11470 + break;
11471 +
11472 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11473 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11474 + nop == 0x01000000U)
11475 + {
11476 + unsigned int addr, save, call;
11477 +
11478 + if ((ba & 0xFFC00000U) == 0x30800000U)
11479 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11480 + else
11481 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11482 +
11483 + err = get_user(save, (unsigned int *)addr);
11484 + err |= get_user(call, (unsigned int *)(addr+4));
11485 + err |= get_user(nop, (unsigned int *)(addr+8));
11486 + if (err)
11487 + break;
11488 +
11489 +#ifdef CONFIG_PAX_DLRESOLVE
11490 + if (save == 0x9DE3BFA8U &&
11491 + (call & 0xC0000000U) == 0x40000000U &&
11492 + nop == 0x01000000U)
11493 + {
11494 + struct vm_area_struct *vma;
11495 + unsigned long call_dl_resolve;
11496 +
11497 + down_read(&current->mm->mmap_sem);
11498 + call_dl_resolve = current->mm->call_dl_resolve;
11499 + up_read(&current->mm->mmap_sem);
11500 + if (likely(call_dl_resolve))
11501 + goto emulate;
11502 +
11503 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11504 +
11505 + down_write(&current->mm->mmap_sem);
11506 + if (current->mm->call_dl_resolve) {
11507 + call_dl_resolve = current->mm->call_dl_resolve;
11508 + up_write(&current->mm->mmap_sem);
11509 + if (vma)
11510 + kmem_cache_free(vm_area_cachep, vma);
11511 + goto emulate;
11512 + }
11513 +
11514 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11515 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11516 + up_write(&current->mm->mmap_sem);
11517 + if (vma)
11518 + kmem_cache_free(vm_area_cachep, vma);
11519 + return 1;
11520 + }
11521 +
11522 + if (pax_insert_vma(vma, call_dl_resolve)) {
11523 + up_write(&current->mm->mmap_sem);
11524 + kmem_cache_free(vm_area_cachep, vma);
11525 + return 1;
11526 + }
11527 +
11528 + current->mm->call_dl_resolve = call_dl_resolve;
11529 + up_write(&current->mm->mmap_sem);
11530 +
11531 +emulate:
11532 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11533 + regs->pc = call_dl_resolve;
11534 + regs->npc = addr+4;
11535 + return 3;
11536 + }
11537 +#endif
11538 +
11539 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11540 + if ((save & 0xFFC00000U) == 0x05000000U &&
11541 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11542 + nop == 0x01000000U)
11543 + {
11544 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11545 + regs->u_regs[UREG_G2] = addr + 4;
11546 + addr = (save & 0x003FFFFFU) << 10;
11547 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11548 + regs->pc = addr;
11549 + regs->npc = addr+4;
11550 + return 3;
11551 + }
11552 + }
11553 + } while (0);
11554 +
11555 + do { /* PaX: unpatched PLT emulation step 2 */
11556 + unsigned int save, call, nop;
11557 +
11558 + err = get_user(save, (unsigned int *)(regs->pc-4));
11559 + err |= get_user(call, (unsigned int *)regs->pc);
11560 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
11561 + if (err)
11562 + break;
11563 +
11564 + if (save == 0x9DE3BFA8U &&
11565 + (call & 0xC0000000U) == 0x40000000U &&
11566 + nop == 0x01000000U)
11567 + {
11568 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11569 +
11570 + regs->u_regs[UREG_RETPC] = regs->pc;
11571 + regs->pc = dl_resolve;
11572 + regs->npc = dl_resolve+4;
11573 + return 3;
11574 + }
11575 + } while (0);
11576 +#endif
11577 +
11578 + return 1;
11579 +}
11580 +
11581 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11582 +{
11583 + unsigned long i;
11584 +
11585 + printk(KERN_ERR "PAX: bytes at PC: ");
11586 + for (i = 0; i < 8; i++) {
11587 + unsigned int c;
11588 + if (get_user(c, (unsigned int *)pc+i))
11589 + printk(KERN_CONT "???????? ");
11590 + else
11591 + printk(KERN_CONT "%08x ", c);
11592 + }
11593 + printk("\n");
11594 +}
11595 +#endif
11596 +
11597 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11598 int text_fault)
11599 {
11600 @@ -226,6 +500,24 @@ good_area:
11601 if (!(vma->vm_flags & VM_WRITE))
11602 goto bad_area;
11603 } else {
11604 +
11605 +#ifdef CONFIG_PAX_PAGEEXEC
11606 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11607 + up_read(&mm->mmap_sem);
11608 + switch (pax_handle_fetch_fault(regs)) {
11609 +
11610 +#ifdef CONFIG_PAX_EMUPLT
11611 + case 2:
11612 + case 3:
11613 + return;
11614 +#endif
11615 +
11616 + }
11617 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11618 + do_group_exit(SIGKILL);
11619 + }
11620 +#endif
11621 +
11622 /* Allow reads even for write-only mappings */
11623 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11624 goto bad_area;
11625 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11626 index 18fcd71..e4fe821 100644
11627 --- a/arch/sparc/mm/fault_64.c
11628 +++ b/arch/sparc/mm/fault_64.c
11629 @@ -22,6 +22,9 @@
11630 #include <linux/kdebug.h>
11631 #include <linux/percpu.h>
11632 #include <linux/context_tracking.h>
11633 +#include <linux/slab.h>
11634 +#include <linux/pagemap.h>
11635 +#include <linux/compiler.h>
11636
11637 #include <asm/page.h>
11638 #include <asm/pgtable.h>
11639 @@ -76,7 +79,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11640 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11641 regs->tpc);
11642 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11643 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11644 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11645 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11646 dump_stack();
11647 unhandled_fault(regs->tpc, current, regs);
11648 @@ -279,6 +282,466 @@ static void noinline __kprobes bogus_32bit_fault_tpc(struct pt_regs *regs)
11649 show_regs(regs);
11650 }
11651
11652 +#ifdef CONFIG_PAX_PAGEEXEC
11653 +#ifdef CONFIG_PAX_DLRESOLVE
11654 +static void pax_emuplt_close(struct vm_area_struct *vma)
11655 +{
11656 + vma->vm_mm->call_dl_resolve = 0UL;
11657 +}
11658 +
11659 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11660 +{
11661 + unsigned int *kaddr;
11662 +
11663 + vmf->page = alloc_page(GFP_HIGHUSER);
11664 + if (!vmf->page)
11665 + return VM_FAULT_OOM;
11666 +
11667 + kaddr = kmap(vmf->page);
11668 + memset(kaddr, 0, PAGE_SIZE);
11669 + kaddr[0] = 0x9DE3BFA8U; /* save */
11670 + flush_dcache_page(vmf->page);
11671 + kunmap(vmf->page);
11672 + return VM_FAULT_MAJOR;
11673 +}
11674 +
11675 +static const struct vm_operations_struct pax_vm_ops = {
11676 + .close = pax_emuplt_close,
11677 + .fault = pax_emuplt_fault
11678 +};
11679 +
11680 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11681 +{
11682 + int ret;
11683 +
11684 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11685 + vma->vm_mm = current->mm;
11686 + vma->vm_start = addr;
11687 + vma->vm_end = addr + PAGE_SIZE;
11688 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11689 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11690 + vma->vm_ops = &pax_vm_ops;
11691 +
11692 + ret = insert_vm_struct(current->mm, vma);
11693 + if (ret)
11694 + return ret;
11695 +
11696 + ++current->mm->total_vm;
11697 + return 0;
11698 +}
11699 +#endif
11700 +
11701 +/*
11702 + * PaX: decide what to do with offenders (regs->tpc = fault address)
11703 + *
11704 + * returns 1 when task should be killed
11705 + * 2 when patched PLT trampoline was detected
11706 + * 3 when unpatched PLT trampoline was detected
11707 + */
11708 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11709 +{
11710 +
11711 +#ifdef CONFIG_PAX_EMUPLT
11712 + int err;
11713 +
11714 + do { /* PaX: patched PLT emulation #1 */
11715 + unsigned int sethi1, sethi2, jmpl;
11716 +
11717 + err = get_user(sethi1, (unsigned int *)regs->tpc);
11718 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11719 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11720 +
11721 + if (err)
11722 + break;
11723 +
11724 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11725 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11726 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11727 + {
11728 + unsigned long addr;
11729 +
11730 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11731 + addr = regs->u_regs[UREG_G1];
11732 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11733 +
11734 + if (test_thread_flag(TIF_32BIT))
11735 + addr &= 0xFFFFFFFFUL;
11736 +
11737 + regs->tpc = addr;
11738 + regs->tnpc = addr+4;
11739 + return 2;
11740 + }
11741 + } while (0);
11742 +
11743 + do { /* PaX: patched PLT emulation #2 */
11744 + unsigned int ba;
11745 +
11746 + err = get_user(ba, (unsigned int *)regs->tpc);
11747 +
11748 + if (err)
11749 + break;
11750 +
11751 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11752 + unsigned long addr;
11753 +
11754 + if ((ba & 0xFFC00000U) == 0x30800000U)
11755 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11756 + else
11757 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11758 +
11759 + if (test_thread_flag(TIF_32BIT))
11760 + addr &= 0xFFFFFFFFUL;
11761 +
11762 + regs->tpc = addr;
11763 + regs->tnpc = addr+4;
11764 + return 2;
11765 + }
11766 + } while (0);
11767 +
11768 + do { /* PaX: patched PLT emulation #3 */
11769 + unsigned int sethi, bajmpl, nop;
11770 +
11771 + err = get_user(sethi, (unsigned int *)regs->tpc);
11772 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11773 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11774 +
11775 + if (err)
11776 + break;
11777 +
11778 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11779 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11780 + nop == 0x01000000U)
11781 + {
11782 + unsigned long addr;
11783 +
11784 + addr = (sethi & 0x003FFFFFU) << 10;
11785 + regs->u_regs[UREG_G1] = addr;
11786 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11787 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11788 + else
11789 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11790 +
11791 + if (test_thread_flag(TIF_32BIT))
11792 + addr &= 0xFFFFFFFFUL;
11793 +
11794 + regs->tpc = addr;
11795 + regs->tnpc = addr+4;
11796 + return 2;
11797 + }
11798 + } while (0);
11799 +
11800 + do { /* PaX: patched PLT emulation #4 */
11801 + unsigned int sethi, mov1, call, mov2;
11802 +
11803 + err = get_user(sethi, (unsigned int *)regs->tpc);
11804 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11805 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
11806 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11807 +
11808 + if (err)
11809 + break;
11810 +
11811 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11812 + mov1 == 0x8210000FU &&
11813 + (call & 0xC0000000U) == 0x40000000U &&
11814 + mov2 == 0x9E100001U)
11815 + {
11816 + unsigned long addr;
11817 +
11818 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11819 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11820 +
11821 + if (test_thread_flag(TIF_32BIT))
11822 + addr &= 0xFFFFFFFFUL;
11823 +
11824 + regs->tpc = addr;
11825 + regs->tnpc = addr+4;
11826 + return 2;
11827 + }
11828 + } while (0);
11829 +
11830 + do { /* PaX: patched PLT emulation #5 */
11831 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11832 +
11833 + err = get_user(sethi, (unsigned int *)regs->tpc);
11834 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11835 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11836 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11837 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11838 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11839 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11840 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11841 +
11842 + if (err)
11843 + break;
11844 +
11845 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11846 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11847 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11848 + (or1 & 0xFFFFE000U) == 0x82106000U &&
11849 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11850 + sllx == 0x83287020U &&
11851 + jmpl == 0x81C04005U &&
11852 + nop == 0x01000000U)
11853 + {
11854 + unsigned long addr;
11855 +
11856 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11857 + regs->u_regs[UREG_G1] <<= 32;
11858 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11859 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11860 + regs->tpc = addr;
11861 + regs->tnpc = addr+4;
11862 + return 2;
11863 + }
11864 + } while (0);
11865 +
11866 + do { /* PaX: patched PLT emulation #6 */
11867 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11868 +
11869 + err = get_user(sethi, (unsigned int *)regs->tpc);
11870 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11871 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11872 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11873 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
11874 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11875 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11876 +
11877 + if (err)
11878 + break;
11879 +
11880 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11881 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11882 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11883 + sllx == 0x83287020U &&
11884 + (or & 0xFFFFE000U) == 0x8A116000U &&
11885 + jmpl == 0x81C04005U &&
11886 + nop == 0x01000000U)
11887 + {
11888 + unsigned long addr;
11889 +
11890 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11891 + regs->u_regs[UREG_G1] <<= 32;
11892 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11893 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11894 + regs->tpc = addr;
11895 + regs->tnpc = addr+4;
11896 + return 2;
11897 + }
11898 + } while (0);
11899 +
11900 + do { /* PaX: unpatched PLT emulation step 1 */
11901 + unsigned int sethi, ba, nop;
11902 +
11903 + err = get_user(sethi, (unsigned int *)regs->tpc);
11904 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11905 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11906 +
11907 + if (err)
11908 + break;
11909 +
11910 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11911 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11912 + nop == 0x01000000U)
11913 + {
11914 + unsigned long addr;
11915 + unsigned int save, call;
11916 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11917 +
11918 + if ((ba & 0xFFC00000U) == 0x30800000U)
11919 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11920 + else
11921 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11922 +
11923 + if (test_thread_flag(TIF_32BIT))
11924 + addr &= 0xFFFFFFFFUL;
11925 +
11926 + err = get_user(save, (unsigned int *)addr);
11927 + err |= get_user(call, (unsigned int *)(addr+4));
11928 + err |= get_user(nop, (unsigned int *)(addr+8));
11929 + if (err)
11930 + break;
11931 +
11932 +#ifdef CONFIG_PAX_DLRESOLVE
11933 + if (save == 0x9DE3BFA8U &&
11934 + (call & 0xC0000000U) == 0x40000000U &&
11935 + nop == 0x01000000U)
11936 + {
11937 + struct vm_area_struct *vma;
11938 + unsigned long call_dl_resolve;
11939 +
11940 + down_read(&current->mm->mmap_sem);
11941 + call_dl_resolve = current->mm->call_dl_resolve;
11942 + up_read(&current->mm->mmap_sem);
11943 + if (likely(call_dl_resolve))
11944 + goto emulate;
11945 +
11946 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11947 +
11948 + down_write(&current->mm->mmap_sem);
11949 + if (current->mm->call_dl_resolve) {
11950 + call_dl_resolve = current->mm->call_dl_resolve;
11951 + up_write(&current->mm->mmap_sem);
11952 + if (vma)
11953 + kmem_cache_free(vm_area_cachep, vma);
11954 + goto emulate;
11955 + }
11956 +
11957 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11958 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11959 + up_write(&current->mm->mmap_sem);
11960 + if (vma)
11961 + kmem_cache_free(vm_area_cachep, vma);
11962 + return 1;
11963 + }
11964 +
11965 + if (pax_insert_vma(vma, call_dl_resolve)) {
11966 + up_write(&current->mm->mmap_sem);
11967 + kmem_cache_free(vm_area_cachep, vma);
11968 + return 1;
11969 + }
11970 +
11971 + current->mm->call_dl_resolve = call_dl_resolve;
11972 + up_write(&current->mm->mmap_sem);
11973 +
11974 +emulate:
11975 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11976 + regs->tpc = call_dl_resolve;
11977 + regs->tnpc = addr+4;
11978 + return 3;
11979 + }
11980 +#endif
11981 +
11982 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11983 + if ((save & 0xFFC00000U) == 0x05000000U &&
11984 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11985 + nop == 0x01000000U)
11986 + {
11987 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11988 + regs->u_regs[UREG_G2] = addr + 4;
11989 + addr = (save & 0x003FFFFFU) << 10;
11990 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11991 +
11992 + if (test_thread_flag(TIF_32BIT))
11993 + addr &= 0xFFFFFFFFUL;
11994 +
11995 + regs->tpc = addr;
11996 + regs->tnpc = addr+4;
11997 + return 3;
11998 + }
11999 +
12000 + /* PaX: 64-bit PLT stub */
12001 + err = get_user(sethi1, (unsigned int *)addr);
12002 + err |= get_user(sethi2, (unsigned int *)(addr+4));
12003 + err |= get_user(or1, (unsigned int *)(addr+8));
12004 + err |= get_user(or2, (unsigned int *)(addr+12));
12005 + err |= get_user(sllx, (unsigned int *)(addr+16));
12006 + err |= get_user(add, (unsigned int *)(addr+20));
12007 + err |= get_user(jmpl, (unsigned int *)(addr+24));
12008 + err |= get_user(nop, (unsigned int *)(addr+28));
12009 + if (err)
12010 + break;
12011 +
12012 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
12013 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12014 + (or1 & 0xFFFFE000U) == 0x88112000U &&
12015 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
12016 + sllx == 0x89293020U &&
12017 + add == 0x8A010005U &&
12018 + jmpl == 0x89C14000U &&
12019 + nop == 0x01000000U)
12020 + {
12021 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12022 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12023 + regs->u_regs[UREG_G4] <<= 32;
12024 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12025 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
12026 + regs->u_regs[UREG_G4] = addr + 24;
12027 + addr = regs->u_regs[UREG_G5];
12028 + regs->tpc = addr;
12029 + regs->tnpc = addr+4;
12030 + return 3;
12031 + }
12032 + }
12033 + } while (0);
12034 +
12035 +#ifdef CONFIG_PAX_DLRESOLVE
12036 + do { /* PaX: unpatched PLT emulation step 2 */
12037 + unsigned int save, call, nop;
12038 +
12039 + err = get_user(save, (unsigned int *)(regs->tpc-4));
12040 + err |= get_user(call, (unsigned int *)regs->tpc);
12041 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
12042 + if (err)
12043 + break;
12044 +
12045 + if (save == 0x9DE3BFA8U &&
12046 + (call & 0xC0000000U) == 0x40000000U &&
12047 + nop == 0x01000000U)
12048 + {
12049 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12050 +
12051 + if (test_thread_flag(TIF_32BIT))
12052 + dl_resolve &= 0xFFFFFFFFUL;
12053 +
12054 + regs->u_regs[UREG_RETPC] = regs->tpc;
12055 + regs->tpc = dl_resolve;
12056 + regs->tnpc = dl_resolve+4;
12057 + return 3;
12058 + }
12059 + } while (0);
12060 +#endif
12061 +
12062 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
12063 + unsigned int sethi, ba, nop;
12064 +
12065 + err = get_user(sethi, (unsigned int *)regs->tpc);
12066 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12067 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12068 +
12069 + if (err)
12070 + break;
12071 +
12072 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12073 + (ba & 0xFFF00000U) == 0x30600000U &&
12074 + nop == 0x01000000U)
12075 + {
12076 + unsigned long addr;
12077 +
12078 + addr = (sethi & 0x003FFFFFU) << 10;
12079 + regs->u_regs[UREG_G1] = addr;
12080 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12081 +
12082 + if (test_thread_flag(TIF_32BIT))
12083 + addr &= 0xFFFFFFFFUL;
12084 +
12085 + regs->tpc = addr;
12086 + regs->tnpc = addr+4;
12087 + return 2;
12088 + }
12089 + } while (0);
12090 +
12091 +#endif
12092 +
12093 + return 1;
12094 +}
12095 +
12096 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12097 +{
12098 + unsigned long i;
12099 +
12100 + printk(KERN_ERR "PAX: bytes at PC: ");
12101 + for (i = 0; i < 8; i++) {
12102 + unsigned int c;
12103 + if (get_user(c, (unsigned int *)pc+i))
12104 + printk(KERN_CONT "???????? ");
12105 + else
12106 + printk(KERN_CONT "%08x ", c);
12107 + }
12108 + printk("\n");
12109 +}
12110 +#endif
12111 +
12112 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
12113 {
12114 enum ctx_state prev_state = exception_enter();
12115 @@ -353,6 +816,29 @@ retry:
12116 if (!vma)
12117 goto bad_area;
12118
12119 +#ifdef CONFIG_PAX_PAGEEXEC
12120 + /* PaX: detect ITLB misses on non-exec pages */
12121 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
12122 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
12123 + {
12124 + if (address != regs->tpc)
12125 + goto good_area;
12126 +
12127 + up_read(&mm->mmap_sem);
12128 + switch (pax_handle_fetch_fault(regs)) {
12129 +
12130 +#ifdef CONFIG_PAX_EMUPLT
12131 + case 2:
12132 + case 3:
12133 + return;
12134 +#endif
12135 +
12136 + }
12137 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
12138 + do_group_exit(SIGKILL);
12139 + }
12140 +#endif
12141 +
12142 /* Pure DTLB misses do not tell us whether the fault causing
12143 * load/store/atomic was a write or not, it only says that there
12144 * was no match. So in such a case we (carefully) read the
12145 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
12146 index d329537..2c3746a 100644
12147 --- a/arch/sparc/mm/hugetlbpage.c
12148 +++ b/arch/sparc/mm/hugetlbpage.c
12149 @@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12150 unsigned long addr,
12151 unsigned long len,
12152 unsigned long pgoff,
12153 - unsigned long flags)
12154 + unsigned long flags,
12155 + unsigned long offset)
12156 {
12157 + struct mm_struct *mm = current->mm;
12158 unsigned long task_size = TASK_SIZE;
12159 struct vm_unmapped_area_info info;
12160
12161 @@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12162
12163 info.flags = 0;
12164 info.length = len;
12165 - info.low_limit = TASK_UNMAPPED_BASE;
12166 + info.low_limit = mm->mmap_base;
12167 info.high_limit = min(task_size, VA_EXCLUDE_START);
12168 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12169 info.align_offset = 0;
12170 + info.threadstack_offset = offset;
12171 addr = vm_unmapped_area(&info);
12172
12173 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
12174 VM_BUG_ON(addr != -ENOMEM);
12175 info.low_limit = VA_EXCLUDE_END;
12176 +
12177 +#ifdef CONFIG_PAX_RANDMMAP
12178 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12179 + info.low_limit += mm->delta_mmap;
12180 +#endif
12181 +
12182 info.high_limit = task_size;
12183 addr = vm_unmapped_area(&info);
12184 }
12185 @@ -55,7 +64,8 @@ static unsigned long
12186 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12187 const unsigned long len,
12188 const unsigned long pgoff,
12189 - const unsigned long flags)
12190 + const unsigned long flags,
12191 + const unsigned long offset)
12192 {
12193 struct mm_struct *mm = current->mm;
12194 unsigned long addr = addr0;
12195 @@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12196 info.high_limit = mm->mmap_base;
12197 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12198 info.align_offset = 0;
12199 + info.threadstack_offset = offset;
12200 addr = vm_unmapped_area(&info);
12201
12202 /*
12203 @@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12204 VM_BUG_ON(addr != -ENOMEM);
12205 info.flags = 0;
12206 info.low_limit = TASK_UNMAPPED_BASE;
12207 +
12208 +#ifdef CONFIG_PAX_RANDMMAP
12209 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12210 + info.low_limit += mm->delta_mmap;
12211 +#endif
12212 +
12213 info.high_limit = STACK_TOP32;
12214 addr = vm_unmapped_area(&info);
12215 }
12216 @@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12217 struct mm_struct *mm = current->mm;
12218 struct vm_area_struct *vma;
12219 unsigned long task_size = TASK_SIZE;
12220 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
12221
12222 if (test_thread_flag(TIF_32BIT))
12223 task_size = STACK_TOP32;
12224 @@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12225 return addr;
12226 }
12227
12228 +#ifdef CONFIG_PAX_RANDMMAP
12229 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
12230 +#endif
12231 +
12232 if (addr) {
12233 addr = ALIGN(addr, HPAGE_SIZE);
12234 vma = find_vma(mm, addr);
12235 - if (task_size - len >= addr &&
12236 - (!vma || addr + len <= vma->vm_start))
12237 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
12238 return addr;
12239 }
12240 if (mm->get_unmapped_area == arch_get_unmapped_area)
12241 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
12242 - pgoff, flags);
12243 + pgoff, flags, offset);
12244 else
12245 return hugetlb_get_unmapped_area_topdown(file, addr, len,
12246 - pgoff, flags);
12247 + pgoff, flags, offset);
12248 }
12249
12250 pte_t *huge_pte_alloc(struct mm_struct *mm,
12251 diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
12252 index 2d91c62..17a8fff 100644
12253 --- a/arch/sparc/mm/init_64.c
12254 +++ b/arch/sparc/mm/init_64.c
12255 @@ -186,9 +186,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
12256 int num_kernel_image_mappings;
12257
12258 #ifdef CONFIG_DEBUG_DCFLUSH
12259 -atomic_t dcpage_flushes = ATOMIC_INIT(0);
12260 +atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
12261 #ifdef CONFIG_SMP
12262 -atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12263 +atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12264 #endif
12265 #endif
12266
12267 @@ -196,7 +196,7 @@ inline void flush_dcache_page_impl(struct page *page)
12268 {
12269 BUG_ON(tlb_type == hypervisor);
12270 #ifdef CONFIG_DEBUG_DCFLUSH
12271 - atomic_inc(&dcpage_flushes);
12272 + atomic_inc_unchecked(&dcpage_flushes);
12273 #endif
12274
12275 #ifdef DCACHE_ALIASING_POSSIBLE
12276 @@ -468,10 +468,10 @@ void mmu_info(struct seq_file *m)
12277
12278 #ifdef CONFIG_DEBUG_DCFLUSH
12279 seq_printf(m, "DCPageFlushes\t: %d\n",
12280 - atomic_read(&dcpage_flushes));
12281 + atomic_read_unchecked(&dcpage_flushes));
12282 #ifdef CONFIG_SMP
12283 seq_printf(m, "DCPageFlushesXC\t: %d\n",
12284 - atomic_read(&dcpage_flushes_xcall));
12285 + atomic_read_unchecked(&dcpage_flushes_xcall));
12286 #endif /* CONFIG_SMP */
12287 #endif /* CONFIG_DEBUG_DCFLUSH */
12288 }
12289 diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
12290 index 7cca418..53fc030 100644
12291 --- a/arch/tile/Kconfig
12292 +++ b/arch/tile/Kconfig
12293 @@ -192,6 +192,7 @@ source "kernel/Kconfig.hz"
12294
12295 config KEXEC
12296 bool "kexec system call"
12297 + depends on !GRKERNSEC_KMEM
12298 ---help---
12299 kexec is a system call that implements the ability to shutdown your
12300 current kernel, and to start another kernel. It is like a reboot
12301 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
12302 index 7b11c5f..755a026 100644
12303 --- a/arch/tile/include/asm/atomic_64.h
12304 +++ b/arch/tile/include/asm/atomic_64.h
12305 @@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
12306
12307 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12308
12309 +#define atomic64_read_unchecked(v) atomic64_read(v)
12310 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
12311 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
12312 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
12313 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
12314 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
12315 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
12316 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
12317 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
12318 +
12319 /* Define this to indicate that cmpxchg is an efficient operation. */
12320 #define __HAVE_ARCH_CMPXCHG
12321
12322 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
12323 index 6160761..00cac88 100644
12324 --- a/arch/tile/include/asm/cache.h
12325 +++ b/arch/tile/include/asm/cache.h
12326 @@ -15,11 +15,12 @@
12327 #ifndef _ASM_TILE_CACHE_H
12328 #define _ASM_TILE_CACHE_H
12329
12330 +#include <linux/const.h>
12331 #include <arch/chip.h>
12332
12333 /* bytes per L1 data cache line */
12334 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
12335 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12336 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12337
12338 /* bytes per L2 cache line */
12339 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12340 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12341 index b6cde32..c0cb736 100644
12342 --- a/arch/tile/include/asm/uaccess.h
12343 +++ b/arch/tile/include/asm/uaccess.h
12344 @@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12345 const void __user *from,
12346 unsigned long n)
12347 {
12348 - int sz = __compiletime_object_size(to);
12349 + size_t sz = __compiletime_object_size(to);
12350
12351 - if (likely(sz == -1 || sz >= n))
12352 + if (likely(sz == (size_t)-1 || sz >= n))
12353 n = _copy_from_user(to, from, n);
12354 else
12355 copy_from_user_overflow();
12356 diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12357 index e514899..f8743c4 100644
12358 --- a/arch/tile/mm/hugetlbpage.c
12359 +++ b/arch/tile/mm/hugetlbpage.c
12360 @@ -207,6 +207,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12361 info.high_limit = TASK_SIZE;
12362 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12363 info.align_offset = 0;
12364 + info.threadstack_offset = 0;
12365 return vm_unmapped_area(&info);
12366 }
12367
12368 @@ -224,6 +225,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12369 info.high_limit = current->mm->mmap_base;
12370 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12371 info.align_offset = 0;
12372 + info.threadstack_offset = 0;
12373 addr = vm_unmapped_area(&info);
12374
12375 /*
12376 diff --git a/arch/um/Makefile b/arch/um/Makefile
12377 index e4b1a96..16162f8 100644
12378 --- a/arch/um/Makefile
12379 +++ b/arch/um/Makefile
12380 @@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12381 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12382 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12383
12384 +ifdef CONSTIFY_PLUGIN
12385 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12386 +endif
12387 +
12388 #This will adjust *FLAGS accordingly to the platform.
12389 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12390
12391 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12392 index 19e1bdd..3665b77 100644
12393 --- a/arch/um/include/asm/cache.h
12394 +++ b/arch/um/include/asm/cache.h
12395 @@ -1,6 +1,7 @@
12396 #ifndef __UM_CACHE_H
12397 #define __UM_CACHE_H
12398
12399 +#include <linux/const.h>
12400
12401 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12402 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12403 @@ -12,6 +13,6 @@
12404 # define L1_CACHE_SHIFT 5
12405 #endif
12406
12407 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12408 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12409
12410 #endif
12411 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12412 index 2e0a6b1..a64d0f5 100644
12413 --- a/arch/um/include/asm/kmap_types.h
12414 +++ b/arch/um/include/asm/kmap_types.h
12415 @@ -8,6 +8,6 @@
12416
12417 /* No more #include "asm/arch/kmap_types.h" ! */
12418
12419 -#define KM_TYPE_NR 14
12420 +#define KM_TYPE_NR 15
12421
12422 #endif
12423 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12424 index 71c5d13..4c7b9f1 100644
12425 --- a/arch/um/include/asm/page.h
12426 +++ b/arch/um/include/asm/page.h
12427 @@ -14,6 +14,9 @@
12428 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12429 #define PAGE_MASK (~(PAGE_SIZE-1))
12430
12431 +#define ktla_ktva(addr) (addr)
12432 +#define ktva_ktla(addr) (addr)
12433 +
12434 #ifndef __ASSEMBLY__
12435
12436 struct page;
12437 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12438 index 0032f92..cd151e0 100644
12439 --- a/arch/um/include/asm/pgtable-3level.h
12440 +++ b/arch/um/include/asm/pgtable-3level.h
12441 @@ -58,6 +58,7 @@
12442 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12443 #define pud_populate(mm, pud, pmd) \
12444 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12445 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12446
12447 #ifdef CONFIG_64BIT
12448 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12449 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12450 index f17bca8..48adb87 100644
12451 --- a/arch/um/kernel/process.c
12452 +++ b/arch/um/kernel/process.c
12453 @@ -356,22 +356,6 @@ int singlestepping(void * t)
12454 return 2;
12455 }
12456
12457 -/*
12458 - * Only x86 and x86_64 have an arch_align_stack().
12459 - * All other arches have "#define arch_align_stack(x) (x)"
12460 - * in their asm/exec.h
12461 - * As this is included in UML from asm-um/system-generic.h,
12462 - * we can use it to behave as the subarch does.
12463 - */
12464 -#ifndef arch_align_stack
12465 -unsigned long arch_align_stack(unsigned long sp)
12466 -{
12467 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12468 - sp -= get_random_int() % 8192;
12469 - return sp & ~0xf;
12470 -}
12471 -#endif
12472 -
12473 unsigned long get_wchan(struct task_struct *p)
12474 {
12475 unsigned long stack_page, sp, ip;
12476 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12477 index ad8f795..2c7eec6 100644
12478 --- a/arch/unicore32/include/asm/cache.h
12479 +++ b/arch/unicore32/include/asm/cache.h
12480 @@ -12,8 +12,10 @@
12481 #ifndef __UNICORE_CACHE_H__
12482 #define __UNICORE_CACHE_H__
12483
12484 -#define L1_CACHE_SHIFT (5)
12485 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12486 +#include <linux/const.h>
12487 +
12488 +#define L1_CACHE_SHIFT 5
12489 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12490
12491 /*
12492 * Memory returned by kmalloc() may be used for DMA, so we must make
12493 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12494 index 41a503c..cf98b04 100644
12495 --- a/arch/x86/Kconfig
12496 +++ b/arch/x86/Kconfig
12497 @@ -129,7 +129,7 @@ config X86
12498 select RTC_LIB
12499 select HAVE_DEBUG_STACKOVERFLOW
12500 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12501 - select HAVE_CC_STACKPROTECTOR
12502 + select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12503 select GENERIC_CPU_AUTOPROBE
12504 select HAVE_ARCH_AUDITSYSCALL
12505 select ARCH_SUPPORTS_ATOMIC_RMW
12506 @@ -262,7 +262,7 @@ config X86_HT
12507
12508 config X86_32_LAZY_GS
12509 def_bool y
12510 - depends on X86_32 && !CC_STACKPROTECTOR
12511 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12512
12513 config ARCH_HWEIGHT_CFLAGS
12514 string
12515 @@ -600,6 +600,7 @@ config SCHED_OMIT_FRAME_POINTER
12516
12517 menuconfig HYPERVISOR_GUEST
12518 bool "Linux guest support"
12519 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12520 ---help---
12521 Say Y here to enable options for running Linux under various hyper-
12522 visors. This option enables basic hypervisor detection and platform
12523 @@ -973,6 +974,7 @@ config VM86
12524
12525 config X86_16BIT
12526 bool "Enable support for 16-bit segments" if EXPERT
12527 + depends on !GRKERNSEC
12528 default y
12529 ---help---
12530 This option is required by programs like Wine to run 16-bit
12531 @@ -1128,6 +1130,7 @@ choice
12532
12533 config NOHIGHMEM
12534 bool "off"
12535 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12536 ---help---
12537 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12538 However, the address space of 32-bit x86 processors is only 4
12539 @@ -1164,6 +1167,7 @@ config NOHIGHMEM
12540
12541 config HIGHMEM4G
12542 bool "4GB"
12543 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12544 ---help---
12545 Select this if you have a 32-bit processor and between 1 and 4
12546 gigabytes of physical RAM.
12547 @@ -1216,7 +1220,7 @@ config PAGE_OFFSET
12548 hex
12549 default 0xB0000000 if VMSPLIT_3G_OPT
12550 default 0x80000000 if VMSPLIT_2G
12551 - default 0x78000000 if VMSPLIT_2G_OPT
12552 + default 0x70000000 if VMSPLIT_2G_OPT
12553 default 0x40000000 if VMSPLIT_1G
12554 default 0xC0000000
12555 depends on X86_32
12556 @@ -1631,6 +1635,7 @@ source kernel/Kconfig.hz
12557
12558 config KEXEC
12559 bool "kexec system call"
12560 + depends on !GRKERNSEC_KMEM
12561 ---help---
12562 kexec is a system call that implements the ability to shutdown your
12563 current kernel, and to start another kernel. It is like a reboot
12564 @@ -1816,7 +1821,9 @@ config X86_NEED_RELOCS
12565
12566 config PHYSICAL_ALIGN
12567 hex "Alignment value to which kernel should be aligned"
12568 - default "0x200000"
12569 + default "0x1000000"
12570 + range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12571 + range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12572 range 0x2000 0x1000000 if X86_32
12573 range 0x200000 0x1000000 if X86_64
12574 ---help---
12575 @@ -1899,6 +1906,7 @@ config COMPAT_VDSO
12576 def_bool n
12577 prompt "Disable the 32-bit vDSO (needed for glibc 2.3.3)"
12578 depends on X86_32 || IA32_EMULATION
12579 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12580 ---help---
12581 Certain buggy versions of glibc will crash if they are
12582 presented with a 32-bit vDSO that is not mapped at the address
12583 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12584 index 6983314..54ad7e8 100644
12585 --- a/arch/x86/Kconfig.cpu
12586 +++ b/arch/x86/Kconfig.cpu
12587 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12588
12589 config X86_F00F_BUG
12590 def_bool y
12591 - depends on M586MMX || M586TSC || M586 || M486
12592 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12593
12594 config X86_INVD_BUG
12595 def_bool y
12596 @@ -327,7 +327,7 @@ config X86_INVD_BUG
12597
12598 config X86_ALIGNMENT_16
12599 def_bool y
12600 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12601 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12602
12603 config X86_INTEL_USERCOPY
12604 def_bool y
12605 @@ -369,7 +369,7 @@ config X86_CMPXCHG64
12606 # generates cmov.
12607 config X86_CMOV
12608 def_bool y
12609 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12610 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12611
12612 config X86_MINIMUM_CPU_FAMILY
12613 int
12614 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12615 index 61bd2ad..50b625d 100644
12616 --- a/arch/x86/Kconfig.debug
12617 +++ b/arch/x86/Kconfig.debug
12618 @@ -93,7 +93,7 @@ config EFI_PGT_DUMP
12619 config DEBUG_RODATA
12620 bool "Write protect kernel read-only data structures"
12621 default y
12622 - depends on DEBUG_KERNEL
12623 + depends on DEBUG_KERNEL && BROKEN
12624 ---help---
12625 Mark the kernel read-only data as write-protected in the pagetables,
12626 in order to catch accidental (and incorrect) writes to such const
12627 @@ -111,7 +111,7 @@ config DEBUG_RODATA_TEST
12628
12629 config DEBUG_SET_MODULE_RONX
12630 bool "Set loadable kernel module data as NX and text as RO"
12631 - depends on MODULES
12632 + depends on MODULES && BROKEN
12633 ---help---
12634 This option helps catch unintended modifications to loadable
12635 kernel module's text and read-only data. It also prevents execution
12636 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12637 index 920e616..ac3d4df 100644
12638 --- a/arch/x86/Makefile
12639 +++ b/arch/x86/Makefile
12640 @@ -65,9 +65,6 @@ ifeq ($(CONFIG_X86_32),y)
12641 # CPU-specific tuning. Anything which can be shared with UML should go here.
12642 include $(srctree)/arch/x86/Makefile_32.cpu
12643 KBUILD_CFLAGS += $(cflags-y)
12644 -
12645 - # temporary until string.h is fixed
12646 - KBUILD_CFLAGS += -ffreestanding
12647 else
12648 BITS := 64
12649 UTS_MACHINE := x86_64
12650 @@ -107,6 +104,9 @@ else
12651 KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
12652 endif
12653
12654 +# temporary until string.h is fixed
12655 +KBUILD_CFLAGS += -ffreestanding
12656 +
12657 # Make sure compiler does not have buggy stack-protector support.
12658 ifdef CONFIG_CC_STACKPROTECTOR
12659 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12660 @@ -180,6 +180,7 @@ archheaders:
12661 $(Q)$(MAKE) $(build)=arch/x86/syscalls all
12662
12663 archprepare:
12664 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12665 ifeq ($(CONFIG_KEXEC_FILE),y)
12666 $(Q)$(MAKE) $(build)=arch/x86/purgatory arch/x86/purgatory/kexec-purgatory.c
12667 endif
12668 @@ -263,3 +264,9 @@ define archhelp
12669 echo ' FDARGS="..." arguments for the booted kernel'
12670 echo ' FDINITRD=file initrd for the booted kernel'
12671 endef
12672 +
12673 +define OLD_LD
12674 +
12675 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12676 +*** Please upgrade your binutils to 2.18 or newer
12677 +endef
12678 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12679 index 5b016e2..04ef69c 100644
12680 --- a/arch/x86/boot/Makefile
12681 +++ b/arch/x86/boot/Makefile
12682 @@ -55,6 +55,9 @@ endif
12683 # ---------------------------------------------------------------------------
12684
12685 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12686 +ifdef CONSTIFY_PLUGIN
12687 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12688 +endif
12689 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12690 GCOV_PROFILE := n
12691
12692 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12693 index 878e4b9..20537ab 100644
12694 --- a/arch/x86/boot/bitops.h
12695 +++ b/arch/x86/boot/bitops.h
12696 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12697 u8 v;
12698 const u32 *p = (const u32 *)addr;
12699
12700 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12701 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12702 return v;
12703 }
12704
12705 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12706
12707 static inline void set_bit(int nr, void *addr)
12708 {
12709 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12710 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12711 }
12712
12713 #endif /* BOOT_BITOPS_H */
12714 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12715 index bd49ec6..94c7f58 100644
12716 --- a/arch/x86/boot/boot.h
12717 +++ b/arch/x86/boot/boot.h
12718 @@ -84,7 +84,7 @@ static inline void io_delay(void)
12719 static inline u16 ds(void)
12720 {
12721 u16 seg;
12722 - asm("movw %%ds,%0" : "=rm" (seg));
12723 + asm volatile("movw %%ds,%0" : "=rm" (seg));
12724 return seg;
12725 }
12726
12727 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12728 index 45abc36..97bea2d 100644
12729 --- a/arch/x86/boot/compressed/Makefile
12730 +++ b/arch/x86/boot/compressed/Makefile
12731 @@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12732 KBUILD_CFLAGS += -mno-mmx -mno-sse
12733 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12734 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12735 +ifdef CONSTIFY_PLUGIN
12736 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12737 +endif
12738
12739 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12740 GCOV_PROFILE := n
12741 diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12742 index a53440e..c3dbf1e 100644
12743 --- a/arch/x86/boot/compressed/efi_stub_32.S
12744 +++ b/arch/x86/boot/compressed/efi_stub_32.S
12745 @@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12746 * parameter 2, ..., param n. To make things easy, we save the return
12747 * address of efi_call_phys in a global variable.
12748 */
12749 - popl %ecx
12750 - movl %ecx, saved_return_addr(%edx)
12751 - /* get the function pointer into ECX*/
12752 - popl %ecx
12753 - movl %ecx, efi_rt_function_ptr(%edx)
12754 + popl saved_return_addr(%edx)
12755 + popl efi_rt_function_ptr(%edx)
12756
12757 /*
12758 * 3. Call the physical function.
12759 */
12760 - call *%ecx
12761 + call *efi_rt_function_ptr(%edx)
12762
12763 /*
12764 * 4. Balance the stack. And because EAX contain the return value,
12765 @@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12766 1: popl %edx
12767 subl $1b, %edx
12768
12769 - movl efi_rt_function_ptr(%edx), %ecx
12770 - pushl %ecx
12771 + pushl efi_rt_function_ptr(%edx)
12772
12773 /*
12774 * 10. Push the saved return address onto the stack and return.
12775 */
12776 - movl saved_return_addr(%edx), %ecx
12777 - pushl %ecx
12778 - ret
12779 + jmpl *saved_return_addr(%edx)
12780 ENDPROC(efi_call_phys)
12781 .previous
12782
12783 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12784 index 1d7fbbc..36ecd58 100644
12785 --- a/arch/x86/boot/compressed/head_32.S
12786 +++ b/arch/x86/boot/compressed/head_32.S
12787 @@ -140,10 +140,10 @@ preferred_addr:
12788 addl %eax, %ebx
12789 notl %eax
12790 andl %eax, %ebx
12791 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
12792 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12793 jge 1f
12794 #endif
12795 - movl $LOAD_PHYSICAL_ADDR, %ebx
12796 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12797 1:
12798
12799 /* Target address to relocate to for decompression */
12800 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12801 index 6b1766c..ad465c9 100644
12802 --- a/arch/x86/boot/compressed/head_64.S
12803 +++ b/arch/x86/boot/compressed/head_64.S
12804 @@ -94,10 +94,10 @@ ENTRY(startup_32)
12805 addl %eax, %ebx
12806 notl %eax
12807 andl %eax, %ebx
12808 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
12809 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12810 jge 1f
12811 #endif
12812 - movl $LOAD_PHYSICAL_ADDR, %ebx
12813 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12814 1:
12815
12816 /* Target address to relocate to for decompression */
12817 @@ -322,10 +322,10 @@ preferred_addr:
12818 addq %rax, %rbp
12819 notq %rax
12820 andq %rax, %rbp
12821 - cmpq $LOAD_PHYSICAL_ADDR, %rbp
12822 + cmpq $____LOAD_PHYSICAL_ADDR, %rbp
12823 jge 1f
12824 #endif
12825 - movq $LOAD_PHYSICAL_ADDR, %rbp
12826 + movq $____LOAD_PHYSICAL_ADDR, %rbp
12827 1:
12828
12829 /* Target address to relocate to for decompression */
12830 @@ -434,8 +434,8 @@ gdt:
12831 .long gdt
12832 .word 0
12833 .quad 0x0000000000000000 /* NULL descriptor */
12834 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
12835 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
12836 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
12837 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
12838 .quad 0x0080890000000000 /* TS descriptor */
12839 .quad 0x0000000000000000 /* TS continued */
12840 gdt_end:
12841 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12842 index 30dd59a..cd9edc3 100644
12843 --- a/arch/x86/boot/compressed/misc.c
12844 +++ b/arch/x86/boot/compressed/misc.c
12845 @@ -242,7 +242,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12846 * Calculate the delta between where vmlinux was linked to load
12847 * and where it was actually loaded.
12848 */
12849 - delta = min_addr - LOAD_PHYSICAL_ADDR;
12850 + delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12851 if (!delta) {
12852 debug_putstr("No relocation needed... ");
12853 return;
12854 @@ -312,7 +312,7 @@ static void parse_elf(void *output)
12855 Elf32_Ehdr ehdr;
12856 Elf32_Phdr *phdrs, *phdr;
12857 #endif
12858 - void *dest;
12859 + void *dest, *prev;
12860 int i;
12861
12862 memcpy(&ehdr, output, sizeof(ehdr));
12863 @@ -339,13 +339,16 @@ static void parse_elf(void *output)
12864 case PT_LOAD:
12865 #ifdef CONFIG_RELOCATABLE
12866 dest = output;
12867 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12868 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12869 #else
12870 dest = (void *)(phdr->p_paddr);
12871 #endif
12872 memcpy(dest,
12873 output + phdr->p_offset,
12874 phdr->p_filesz);
12875 + if (i)
12876 + memset(prev, 0xff, dest - prev);
12877 + prev = dest + phdr->p_filesz;
12878 break;
12879 default: /* Ignore other PT_* */ break;
12880 }
12881 @@ -402,7 +405,7 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
12882 error("Destination address too large");
12883 #endif
12884 #ifndef CONFIG_RELOCATABLE
12885 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12886 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12887 error("Wrong destination address");
12888 #endif
12889
12890 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12891 index 1fd7d57..0f7d096 100644
12892 --- a/arch/x86/boot/cpucheck.c
12893 +++ b/arch/x86/boot/cpucheck.c
12894 @@ -125,9 +125,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12895 u32 ecx = MSR_K7_HWCR;
12896 u32 eax, edx;
12897
12898 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12899 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12900 eax &= ~(1 << 15);
12901 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12902 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12903
12904 get_cpuflags(); /* Make sure it really did something */
12905 err = check_cpuflags();
12906 @@ -140,9 +140,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12907 u32 ecx = MSR_VIA_FCR;
12908 u32 eax, edx;
12909
12910 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12911 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12912 eax |= (1<<1)|(1<<7);
12913 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12914 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12915
12916 set_bit(X86_FEATURE_CX8, cpu.flags);
12917 err = check_cpuflags();
12918 @@ -153,12 +153,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12919 u32 eax, edx;
12920 u32 level = 1;
12921
12922 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12923 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12924 - asm("cpuid"
12925 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12926 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12927 + asm volatile("cpuid"
12928 : "+a" (level), "=d" (cpu.flags[0])
12929 : : "ecx", "ebx");
12930 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12931 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12932
12933 err = check_cpuflags();
12934 } else if (err == 0x01 &&
12935 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12936 index 16ef025..91e033b 100644
12937 --- a/arch/x86/boot/header.S
12938 +++ b/arch/x86/boot/header.S
12939 @@ -438,10 +438,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12940 # single linked list of
12941 # struct setup_data
12942
12943 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12944 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12945
12946 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12947 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12948 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12949 +#else
12950 #define VO_INIT_SIZE (VO__end - VO__text)
12951 +#endif
12952 #if ZO_INIT_SIZE > VO_INIT_SIZE
12953 #define INIT_SIZE ZO_INIT_SIZE
12954 #else
12955 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12956 index db75d07..8e6d0af 100644
12957 --- a/arch/x86/boot/memory.c
12958 +++ b/arch/x86/boot/memory.c
12959 @@ -19,7 +19,7 @@
12960
12961 static int detect_memory_e820(void)
12962 {
12963 - int count = 0;
12964 + unsigned int count = 0;
12965 struct biosregs ireg, oreg;
12966 struct e820entry *desc = boot_params.e820_map;
12967 static struct e820entry buf; /* static so it is zeroed */
12968 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12969 index ba3e100..6501b8f 100644
12970 --- a/arch/x86/boot/video-vesa.c
12971 +++ b/arch/x86/boot/video-vesa.c
12972 @@ -201,6 +201,7 @@ static void vesa_store_pm_info(void)
12973
12974 boot_params.screen_info.vesapm_seg = oreg.es;
12975 boot_params.screen_info.vesapm_off = oreg.di;
12976 + boot_params.screen_info.vesapm_size = oreg.cx;
12977 }
12978
12979 /*
12980 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12981 index 43eda28..5ab5fdb 100644
12982 --- a/arch/x86/boot/video.c
12983 +++ b/arch/x86/boot/video.c
12984 @@ -96,7 +96,7 @@ static void store_mode_params(void)
12985 static unsigned int get_entry(void)
12986 {
12987 char entry_buf[4];
12988 - int i, len = 0;
12989 + unsigned int i, len = 0;
12990 int key;
12991 unsigned int v;
12992
12993 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12994 index 9105655..41779c1 100644
12995 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
12996 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12997 @@ -8,6 +8,8 @@
12998 * including this sentence is retained in full.
12999 */
13000
13001 +#include <asm/alternative-asm.h>
13002 +
13003 .extern crypto_ft_tab
13004 .extern crypto_it_tab
13005 .extern crypto_fl_tab
13006 @@ -70,6 +72,8 @@
13007 je B192; \
13008 leaq 32(r9),r9;
13009
13010 +#define ret pax_force_retaddr; ret
13011 +
13012 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
13013 movq r1,r2; \
13014 movq r3,r4; \
13015 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
13016 index 477e9d7..c92c7d8 100644
13017 --- a/arch/x86/crypto/aesni-intel_asm.S
13018 +++ b/arch/x86/crypto/aesni-intel_asm.S
13019 @@ -31,6 +31,7 @@
13020
13021 #include <linux/linkage.h>
13022 #include <asm/inst.h>
13023 +#include <asm/alternative-asm.h>
13024
13025 #ifdef __x86_64__
13026 .data
13027 @@ -205,7 +206,7 @@ enc: .octa 0x2
13028 * num_initial_blocks = b mod 4
13029 * encrypt the initial num_initial_blocks blocks and apply ghash on
13030 * the ciphertext
13031 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13032 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13033 * are clobbered
13034 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13035 */
13036 @@ -214,8 +215,8 @@ enc: .octa 0x2
13037 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13038 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13039 mov arg7, %r10 # %r10 = AAD
13040 - mov arg8, %r12 # %r12 = aadLen
13041 - mov %r12, %r11
13042 + mov arg8, %r15 # %r15 = aadLen
13043 + mov %r15, %r11
13044 pxor %xmm\i, %xmm\i
13045 _get_AAD_loop\num_initial_blocks\operation:
13046 movd (%r10), \TMP1
13047 @@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13048 psrldq $4, %xmm\i
13049 pxor \TMP1, %xmm\i
13050 add $4, %r10
13051 - sub $4, %r12
13052 + sub $4, %r15
13053 jne _get_AAD_loop\num_initial_blocks\operation
13054 cmp $16, %r11
13055 je _get_AAD_loop2_done\num_initial_blocks\operation
13056 - mov $16, %r12
13057 + mov $16, %r15
13058 _get_AAD_loop2\num_initial_blocks\operation:
13059 psrldq $4, %xmm\i
13060 - sub $4, %r12
13061 - cmp %r11, %r12
13062 + sub $4, %r15
13063 + cmp %r11, %r15
13064 jne _get_AAD_loop2\num_initial_blocks\operation
13065 _get_AAD_loop2_done\num_initial_blocks\operation:
13066 movdqa SHUF_MASK(%rip), %xmm14
13067 @@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
13068 * num_initial_blocks = b mod 4
13069 * encrypt the initial num_initial_blocks blocks and apply ghash on
13070 * the ciphertext
13071 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13072 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13073 * are clobbered
13074 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13075 */
13076 @@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
13077 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13078 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13079 mov arg7, %r10 # %r10 = AAD
13080 - mov arg8, %r12 # %r12 = aadLen
13081 - mov %r12, %r11
13082 + mov arg8, %r15 # %r15 = aadLen
13083 + mov %r15, %r11
13084 pxor %xmm\i, %xmm\i
13085 _get_AAD_loop\num_initial_blocks\operation:
13086 movd (%r10), \TMP1
13087 @@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13088 psrldq $4, %xmm\i
13089 pxor \TMP1, %xmm\i
13090 add $4, %r10
13091 - sub $4, %r12
13092 + sub $4, %r15
13093 jne _get_AAD_loop\num_initial_blocks\operation
13094 cmp $16, %r11
13095 je _get_AAD_loop2_done\num_initial_blocks\operation
13096 - mov $16, %r12
13097 + mov $16, %r15
13098 _get_AAD_loop2\num_initial_blocks\operation:
13099 psrldq $4, %xmm\i
13100 - sub $4, %r12
13101 - cmp %r11, %r12
13102 + sub $4, %r15
13103 + cmp %r11, %r15
13104 jne _get_AAD_loop2\num_initial_blocks\operation
13105 _get_AAD_loop2_done\num_initial_blocks\operation:
13106 movdqa SHUF_MASK(%rip), %xmm14
13107 @@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
13108 *
13109 *****************************************************************************/
13110 ENTRY(aesni_gcm_dec)
13111 - push %r12
13112 + push %r15
13113 push %r13
13114 push %r14
13115 mov %rsp, %r14
13116 @@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
13117 */
13118 sub $VARIABLE_OFFSET, %rsp
13119 and $~63, %rsp # align rsp to 64 bytes
13120 - mov %arg6, %r12
13121 - movdqu (%r12), %xmm13 # %xmm13 = HashKey
13122 + mov %arg6, %r15
13123 + movdqu (%r15), %xmm13 # %xmm13 = HashKey
13124 movdqa SHUF_MASK(%rip), %xmm2
13125 PSHUFB_XMM %xmm2, %xmm13
13126
13127 @@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
13128 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
13129 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
13130 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
13131 - mov %r13, %r12
13132 - and $(3<<4), %r12
13133 + mov %r13, %r15
13134 + and $(3<<4), %r15
13135 jz _initial_num_blocks_is_0_decrypt
13136 - cmp $(2<<4), %r12
13137 + cmp $(2<<4), %r15
13138 jb _initial_num_blocks_is_1_decrypt
13139 je _initial_num_blocks_is_2_decrypt
13140 _initial_num_blocks_is_3_decrypt:
13141 @@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
13142 sub $16, %r11
13143 add %r13, %r11
13144 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
13145 - lea SHIFT_MASK+16(%rip), %r12
13146 - sub %r13, %r12
13147 + lea SHIFT_MASK+16(%rip), %r15
13148 + sub %r13, %r15
13149 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
13150 # (%r13 is the number of bytes in plaintext mod 16)
13151 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13152 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13153 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
13154
13155 movdqa %xmm1, %xmm2
13156 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
13157 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13158 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13159 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
13160 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
13161 pand %xmm1, %xmm2
13162 @@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
13163 sub $1, %r13
13164 jne _less_than_8_bytes_left_decrypt
13165 _multiple_of_16_bytes_decrypt:
13166 - mov arg8, %r12 # %r13 = aadLen (number of bytes)
13167 - shl $3, %r12 # convert into number of bits
13168 - movd %r12d, %xmm15 # len(A) in %xmm15
13169 + mov arg8, %r15 # %r13 = aadLen (number of bytes)
13170 + shl $3, %r15 # convert into number of bits
13171 + movd %r15d, %xmm15 # len(A) in %xmm15
13172 shl $3, %arg4 # len(C) in bits (*128)
13173 MOVQ_R64_XMM %arg4, %xmm1
13174 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13175 @@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
13176 mov %r14, %rsp
13177 pop %r14
13178 pop %r13
13179 - pop %r12
13180 + pop %r15
13181 + pax_force_retaddr
13182 ret
13183 ENDPROC(aesni_gcm_dec)
13184
13185 @@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
13186 * poly = x^128 + x^127 + x^126 + x^121 + 1
13187 ***************************************************************************/
13188 ENTRY(aesni_gcm_enc)
13189 - push %r12
13190 + push %r15
13191 push %r13
13192 push %r14
13193 mov %rsp, %r14
13194 @@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
13195 #
13196 sub $VARIABLE_OFFSET, %rsp
13197 and $~63, %rsp
13198 - mov %arg6, %r12
13199 - movdqu (%r12), %xmm13
13200 + mov %arg6, %r15
13201 + movdqu (%r15), %xmm13
13202 movdqa SHUF_MASK(%rip), %xmm2
13203 PSHUFB_XMM %xmm2, %xmm13
13204
13205 @@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
13206 movdqa %xmm13, HashKey(%rsp)
13207 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
13208 and $-16, %r13
13209 - mov %r13, %r12
13210 + mov %r13, %r15
13211
13212 # Encrypt first few blocks
13213
13214 - and $(3<<4), %r12
13215 + and $(3<<4), %r15
13216 jz _initial_num_blocks_is_0_encrypt
13217 - cmp $(2<<4), %r12
13218 + cmp $(2<<4), %r15
13219 jb _initial_num_blocks_is_1_encrypt
13220 je _initial_num_blocks_is_2_encrypt
13221 _initial_num_blocks_is_3_encrypt:
13222 @@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
13223 sub $16, %r11
13224 add %r13, %r11
13225 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
13226 - lea SHIFT_MASK+16(%rip), %r12
13227 - sub %r13, %r12
13228 + lea SHIFT_MASK+16(%rip), %r15
13229 + sub %r13, %r15
13230 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
13231 # (%r13 is the number of bytes in plaintext mod 16)
13232 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13233 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13234 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
13235 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
13236 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13237 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13238 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
13239 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
13240 movdqa SHUF_MASK(%rip), %xmm10
13241 @@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
13242 sub $1, %r13
13243 jne _less_than_8_bytes_left_encrypt
13244 _multiple_of_16_bytes_encrypt:
13245 - mov arg8, %r12 # %r12 = addLen (number of bytes)
13246 - shl $3, %r12
13247 - movd %r12d, %xmm15 # len(A) in %xmm15
13248 + mov arg8, %r15 # %r15 = addLen (number of bytes)
13249 + shl $3, %r15
13250 + movd %r15d, %xmm15 # len(A) in %xmm15
13251 shl $3, %arg4 # len(C) in bits (*128)
13252 MOVQ_R64_XMM %arg4, %xmm1
13253 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13254 @@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
13255 mov %r14, %rsp
13256 pop %r14
13257 pop %r13
13258 - pop %r12
13259 + pop %r15
13260 + pax_force_retaddr
13261 ret
13262 ENDPROC(aesni_gcm_enc)
13263
13264 @@ -1722,6 +1725,7 @@ _key_expansion_256a:
13265 pxor %xmm1, %xmm0
13266 movaps %xmm0, (TKEYP)
13267 add $0x10, TKEYP
13268 + pax_force_retaddr
13269 ret
13270 ENDPROC(_key_expansion_128)
13271 ENDPROC(_key_expansion_256a)
13272 @@ -1748,6 +1752,7 @@ _key_expansion_192a:
13273 shufps $0b01001110, %xmm2, %xmm1
13274 movaps %xmm1, 0x10(TKEYP)
13275 add $0x20, TKEYP
13276 + pax_force_retaddr
13277 ret
13278 ENDPROC(_key_expansion_192a)
13279
13280 @@ -1768,6 +1773,7 @@ _key_expansion_192b:
13281
13282 movaps %xmm0, (TKEYP)
13283 add $0x10, TKEYP
13284 + pax_force_retaddr
13285 ret
13286 ENDPROC(_key_expansion_192b)
13287
13288 @@ -1781,6 +1787,7 @@ _key_expansion_256b:
13289 pxor %xmm1, %xmm2
13290 movaps %xmm2, (TKEYP)
13291 add $0x10, TKEYP
13292 + pax_force_retaddr
13293 ret
13294 ENDPROC(_key_expansion_256b)
13295
13296 @@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13297 #ifndef __x86_64__
13298 popl KEYP
13299 #endif
13300 + pax_force_retaddr
13301 ret
13302 ENDPROC(aesni_set_key)
13303
13304 @@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13305 popl KLEN
13306 popl KEYP
13307 #endif
13308 + pax_force_retaddr
13309 ret
13310 ENDPROC(aesni_enc)
13311
13312 @@ -1974,6 +1983,7 @@ _aesni_enc1:
13313 AESENC KEY STATE
13314 movaps 0x70(TKEYP), KEY
13315 AESENCLAST KEY STATE
13316 + pax_force_retaddr
13317 ret
13318 ENDPROC(_aesni_enc1)
13319
13320 @@ -2083,6 +2093,7 @@ _aesni_enc4:
13321 AESENCLAST KEY STATE2
13322 AESENCLAST KEY STATE3
13323 AESENCLAST KEY STATE4
13324 + pax_force_retaddr
13325 ret
13326 ENDPROC(_aesni_enc4)
13327
13328 @@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13329 popl KLEN
13330 popl KEYP
13331 #endif
13332 + pax_force_retaddr
13333 ret
13334 ENDPROC(aesni_dec)
13335
13336 @@ -2164,6 +2176,7 @@ _aesni_dec1:
13337 AESDEC KEY STATE
13338 movaps 0x70(TKEYP), KEY
13339 AESDECLAST KEY STATE
13340 + pax_force_retaddr
13341 ret
13342 ENDPROC(_aesni_dec1)
13343
13344 @@ -2273,6 +2286,7 @@ _aesni_dec4:
13345 AESDECLAST KEY STATE2
13346 AESDECLAST KEY STATE3
13347 AESDECLAST KEY STATE4
13348 + pax_force_retaddr
13349 ret
13350 ENDPROC(_aesni_dec4)
13351
13352 @@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13353 popl KEYP
13354 popl LEN
13355 #endif
13356 + pax_force_retaddr
13357 ret
13358 ENDPROC(aesni_ecb_enc)
13359
13360 @@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13361 popl KEYP
13362 popl LEN
13363 #endif
13364 + pax_force_retaddr
13365 ret
13366 ENDPROC(aesni_ecb_dec)
13367
13368 @@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13369 popl LEN
13370 popl IVP
13371 #endif
13372 + pax_force_retaddr
13373 ret
13374 ENDPROC(aesni_cbc_enc)
13375
13376 @@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13377 popl LEN
13378 popl IVP
13379 #endif
13380 + pax_force_retaddr
13381 ret
13382 ENDPROC(aesni_cbc_dec)
13383
13384 @@ -2550,6 +2568,7 @@ _aesni_inc_init:
13385 mov $1, TCTR_LOW
13386 MOVQ_R64_XMM TCTR_LOW INC
13387 MOVQ_R64_XMM CTR TCTR_LOW
13388 + pax_force_retaddr
13389 ret
13390 ENDPROC(_aesni_inc_init)
13391
13392 @@ -2579,6 +2598,7 @@ _aesni_inc:
13393 .Linc_low:
13394 movaps CTR, IV
13395 PSHUFB_XMM BSWAP_MASK IV
13396 + pax_force_retaddr
13397 ret
13398 ENDPROC(_aesni_inc)
13399
13400 @@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13401 .Lctr_enc_ret:
13402 movups IV, (IVP)
13403 .Lctr_enc_just_ret:
13404 + pax_force_retaddr
13405 ret
13406 ENDPROC(aesni_ctr_enc)
13407
13408 @@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13409 pxor INC, STATE4
13410 movdqu STATE4, 0x70(OUTP)
13411
13412 + pax_force_retaddr
13413 ret
13414 ENDPROC(aesni_xts_crypt8)
13415
13416 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13417 index 246c670..466e2d6 100644
13418 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13419 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13420 @@ -21,6 +21,7 @@
13421 */
13422
13423 #include <linux/linkage.h>
13424 +#include <asm/alternative-asm.h>
13425
13426 .file "blowfish-x86_64-asm.S"
13427 .text
13428 @@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13429 jnz .L__enc_xor;
13430
13431 write_block();
13432 + pax_force_retaddr
13433 ret;
13434 .L__enc_xor:
13435 xor_block();
13436 + pax_force_retaddr
13437 ret;
13438 ENDPROC(__blowfish_enc_blk)
13439
13440 @@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13441
13442 movq %r11, %rbp;
13443
13444 + pax_force_retaddr
13445 ret;
13446 ENDPROC(blowfish_dec_blk)
13447
13448 @@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13449
13450 popq %rbx;
13451 popq %rbp;
13452 + pax_force_retaddr
13453 ret;
13454
13455 .L__enc_xor4:
13456 @@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13457
13458 popq %rbx;
13459 popq %rbp;
13460 + pax_force_retaddr
13461 ret;
13462 ENDPROC(__blowfish_enc_blk_4way)
13463
13464 @@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13465 popq %rbx;
13466 popq %rbp;
13467
13468 + pax_force_retaddr
13469 ret;
13470 ENDPROC(blowfish_dec_blk_4way)
13471 diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13472 index ce71f92..1dce7ec 100644
13473 --- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13474 +++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13475 @@ -16,6 +16,7 @@
13476 */
13477
13478 #include <linux/linkage.h>
13479 +#include <asm/alternative-asm.h>
13480
13481 #define CAMELLIA_TABLE_BYTE_LEN 272
13482
13483 @@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13484 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13485 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13486 %rcx, (%r9));
13487 + pax_force_retaddr
13488 ret;
13489 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13490
13491 @@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13492 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13493 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13494 %rax, (%r9));
13495 + pax_force_retaddr
13496 ret;
13497 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13498
13499 @@ -780,6 +783,7 @@ __camellia_enc_blk16:
13500 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13501 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13502
13503 + pax_force_retaddr
13504 ret;
13505
13506 .align 8
13507 @@ -865,6 +869,7 @@ __camellia_dec_blk16:
13508 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13509 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13510
13511 + pax_force_retaddr
13512 ret;
13513
13514 .align 8
13515 @@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13516 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13517 %xmm8, %rsi);
13518
13519 + pax_force_retaddr
13520 ret;
13521 ENDPROC(camellia_ecb_enc_16way)
13522
13523 @@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13524 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13525 %xmm8, %rsi);
13526
13527 + pax_force_retaddr
13528 ret;
13529 ENDPROC(camellia_ecb_dec_16way)
13530
13531 @@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13532 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13533 %xmm8, %rsi);
13534
13535 + pax_force_retaddr
13536 ret;
13537 ENDPROC(camellia_cbc_dec_16way)
13538
13539 @@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13540 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13541 %xmm8, %rsi);
13542
13543 + pax_force_retaddr
13544 ret;
13545 ENDPROC(camellia_ctr_16way)
13546
13547 @@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13548 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13549 %xmm8, %rsi);
13550
13551 + pax_force_retaddr
13552 ret;
13553 ENDPROC(camellia_xts_crypt_16way)
13554
13555 diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13556 index 0e0b886..5a3123c 100644
13557 --- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13558 +++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13559 @@ -11,6 +11,7 @@
13560 */
13561
13562 #include <linux/linkage.h>
13563 +#include <asm/alternative-asm.h>
13564
13565 #define CAMELLIA_TABLE_BYTE_LEN 272
13566
13567 @@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13568 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13569 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13570 %rcx, (%r9));
13571 + pax_force_retaddr
13572 ret;
13573 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13574
13575 @@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13576 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13577 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13578 %rax, (%r9));
13579 + pax_force_retaddr
13580 ret;
13581 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13582
13583 @@ -820,6 +823,7 @@ __camellia_enc_blk32:
13584 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13585 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13586
13587 + pax_force_retaddr
13588 ret;
13589
13590 .align 8
13591 @@ -905,6 +909,7 @@ __camellia_dec_blk32:
13592 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13593 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13594
13595 + pax_force_retaddr
13596 ret;
13597
13598 .align 8
13599 @@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13600
13601 vzeroupper;
13602
13603 + pax_force_retaddr
13604 ret;
13605 ENDPROC(camellia_ecb_enc_32way)
13606
13607 @@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13608
13609 vzeroupper;
13610
13611 + pax_force_retaddr
13612 ret;
13613 ENDPROC(camellia_ecb_dec_32way)
13614
13615 @@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13616
13617 vzeroupper;
13618
13619 + pax_force_retaddr
13620 ret;
13621 ENDPROC(camellia_cbc_dec_32way)
13622
13623 @@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13624
13625 vzeroupper;
13626
13627 + pax_force_retaddr
13628 ret;
13629 ENDPROC(camellia_ctr_32way)
13630
13631 @@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13632
13633 vzeroupper;
13634
13635 + pax_force_retaddr
13636 ret;
13637 ENDPROC(camellia_xts_crypt_32way)
13638
13639 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13640 index 310319c..db3d7b5 100644
13641 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13642 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13643 @@ -21,6 +21,7 @@
13644 */
13645
13646 #include <linux/linkage.h>
13647 +#include <asm/alternative-asm.h>
13648
13649 .file "camellia-x86_64-asm_64.S"
13650 .text
13651 @@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13652 enc_outunpack(mov, RT1);
13653
13654 movq RRBP, %rbp;
13655 + pax_force_retaddr
13656 ret;
13657
13658 .L__enc_xor:
13659 enc_outunpack(xor, RT1);
13660
13661 movq RRBP, %rbp;
13662 + pax_force_retaddr
13663 ret;
13664 ENDPROC(__camellia_enc_blk)
13665
13666 @@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13667 dec_outunpack();
13668
13669 movq RRBP, %rbp;
13670 + pax_force_retaddr
13671 ret;
13672 ENDPROC(camellia_dec_blk)
13673
13674 @@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13675
13676 movq RRBP, %rbp;
13677 popq %rbx;
13678 + pax_force_retaddr
13679 ret;
13680
13681 .L__enc2_xor:
13682 @@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13683
13684 movq RRBP, %rbp;
13685 popq %rbx;
13686 + pax_force_retaddr
13687 ret;
13688 ENDPROC(__camellia_enc_blk_2way)
13689
13690 @@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13691
13692 movq RRBP, %rbp;
13693 movq RXOR, %rbx;
13694 + pax_force_retaddr
13695 ret;
13696 ENDPROC(camellia_dec_blk_2way)
13697 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13698 index c35fd5d..2d8c7db 100644
13699 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13700 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13701 @@ -24,6 +24,7 @@
13702 */
13703
13704 #include <linux/linkage.h>
13705 +#include <asm/alternative-asm.h>
13706
13707 .file "cast5-avx-x86_64-asm_64.S"
13708
13709 @@ -281,6 +282,7 @@ __cast5_enc_blk16:
13710 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13711 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13712
13713 + pax_force_retaddr
13714 ret;
13715 ENDPROC(__cast5_enc_blk16)
13716
13717 @@ -352,6 +354,7 @@ __cast5_dec_blk16:
13718 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13719 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13720
13721 + pax_force_retaddr
13722 ret;
13723
13724 .L__skip_dec:
13725 @@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13726 vmovdqu RR4, (6*4*4)(%r11);
13727 vmovdqu RL4, (7*4*4)(%r11);
13728
13729 + pax_force_retaddr
13730 ret;
13731 ENDPROC(cast5_ecb_enc_16way)
13732
13733 @@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13734 vmovdqu RR4, (6*4*4)(%r11);
13735 vmovdqu RL4, (7*4*4)(%r11);
13736
13737 + pax_force_retaddr
13738 ret;
13739 ENDPROC(cast5_ecb_dec_16way)
13740
13741 @@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13742 * %rdx: src
13743 */
13744
13745 - pushq %r12;
13746 + pushq %r14;
13747
13748 movq %rsi, %r11;
13749 - movq %rdx, %r12;
13750 + movq %rdx, %r14;
13751
13752 vmovdqu (0*16)(%rdx), RL1;
13753 vmovdqu (1*16)(%rdx), RR1;
13754 @@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13755 call __cast5_dec_blk16;
13756
13757 /* xor with src */
13758 - vmovq (%r12), RX;
13759 + vmovq (%r14), RX;
13760 vpshufd $0x4f, RX, RX;
13761 vpxor RX, RR1, RR1;
13762 - vpxor 0*16+8(%r12), RL1, RL1;
13763 - vpxor 1*16+8(%r12), RR2, RR2;
13764 - vpxor 2*16+8(%r12), RL2, RL2;
13765 - vpxor 3*16+8(%r12), RR3, RR3;
13766 - vpxor 4*16+8(%r12), RL3, RL3;
13767 - vpxor 5*16+8(%r12), RR4, RR4;
13768 - vpxor 6*16+8(%r12), RL4, RL4;
13769 + vpxor 0*16+8(%r14), RL1, RL1;
13770 + vpxor 1*16+8(%r14), RR2, RR2;
13771 + vpxor 2*16+8(%r14), RL2, RL2;
13772 + vpxor 3*16+8(%r14), RR3, RR3;
13773 + vpxor 4*16+8(%r14), RL3, RL3;
13774 + vpxor 5*16+8(%r14), RR4, RR4;
13775 + vpxor 6*16+8(%r14), RL4, RL4;
13776
13777 vmovdqu RR1, (0*16)(%r11);
13778 vmovdqu RL1, (1*16)(%r11);
13779 @@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13780 vmovdqu RR4, (6*16)(%r11);
13781 vmovdqu RL4, (7*16)(%r11);
13782
13783 - popq %r12;
13784 + popq %r14;
13785
13786 + pax_force_retaddr
13787 ret;
13788 ENDPROC(cast5_cbc_dec_16way)
13789
13790 @@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13791 * %rcx: iv (big endian, 64bit)
13792 */
13793
13794 - pushq %r12;
13795 + pushq %r14;
13796
13797 movq %rsi, %r11;
13798 - movq %rdx, %r12;
13799 + movq %rdx, %r14;
13800
13801 vpcmpeqd RTMP, RTMP, RTMP;
13802 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13803 @@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13804 call __cast5_enc_blk16;
13805
13806 /* dst = src ^ iv */
13807 - vpxor (0*16)(%r12), RR1, RR1;
13808 - vpxor (1*16)(%r12), RL1, RL1;
13809 - vpxor (2*16)(%r12), RR2, RR2;
13810 - vpxor (3*16)(%r12), RL2, RL2;
13811 - vpxor (4*16)(%r12), RR3, RR3;
13812 - vpxor (5*16)(%r12), RL3, RL3;
13813 - vpxor (6*16)(%r12), RR4, RR4;
13814 - vpxor (7*16)(%r12), RL4, RL4;
13815 + vpxor (0*16)(%r14), RR1, RR1;
13816 + vpxor (1*16)(%r14), RL1, RL1;
13817 + vpxor (2*16)(%r14), RR2, RR2;
13818 + vpxor (3*16)(%r14), RL2, RL2;
13819 + vpxor (4*16)(%r14), RR3, RR3;
13820 + vpxor (5*16)(%r14), RL3, RL3;
13821 + vpxor (6*16)(%r14), RR4, RR4;
13822 + vpxor (7*16)(%r14), RL4, RL4;
13823 vmovdqu RR1, (0*16)(%r11);
13824 vmovdqu RL1, (1*16)(%r11);
13825 vmovdqu RR2, (2*16)(%r11);
13826 @@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13827 vmovdqu RR4, (6*16)(%r11);
13828 vmovdqu RL4, (7*16)(%r11);
13829
13830 - popq %r12;
13831 + popq %r14;
13832
13833 + pax_force_retaddr
13834 ret;
13835 ENDPROC(cast5_ctr_16way)
13836 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13837 index e3531f8..e123f35 100644
13838 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13839 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13840 @@ -24,6 +24,7 @@
13841 */
13842
13843 #include <linux/linkage.h>
13844 +#include <asm/alternative-asm.h>
13845 #include "glue_helper-asm-avx.S"
13846
13847 .file "cast6-avx-x86_64-asm_64.S"
13848 @@ -295,6 +296,7 @@ __cast6_enc_blk8:
13849 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13850 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13851
13852 + pax_force_retaddr
13853 ret;
13854 ENDPROC(__cast6_enc_blk8)
13855
13856 @@ -340,6 +342,7 @@ __cast6_dec_blk8:
13857 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13858 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13859
13860 + pax_force_retaddr
13861 ret;
13862 ENDPROC(__cast6_dec_blk8)
13863
13864 @@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13865
13866 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13867
13868 + pax_force_retaddr
13869 ret;
13870 ENDPROC(cast6_ecb_enc_8way)
13871
13872 @@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13873
13874 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13875
13876 + pax_force_retaddr
13877 ret;
13878 ENDPROC(cast6_ecb_dec_8way)
13879
13880 @@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13881 * %rdx: src
13882 */
13883
13884 - pushq %r12;
13885 + pushq %r14;
13886
13887 movq %rsi, %r11;
13888 - movq %rdx, %r12;
13889 + movq %rdx, %r14;
13890
13891 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13892
13893 call __cast6_dec_blk8;
13894
13895 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13896 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13897
13898 - popq %r12;
13899 + popq %r14;
13900
13901 + pax_force_retaddr
13902 ret;
13903 ENDPROC(cast6_cbc_dec_8way)
13904
13905 @@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13906 * %rcx: iv (little endian, 128bit)
13907 */
13908
13909 - pushq %r12;
13910 + pushq %r14;
13911
13912 movq %rsi, %r11;
13913 - movq %rdx, %r12;
13914 + movq %rdx, %r14;
13915
13916 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13917 RD2, RX, RKR, RKM);
13918
13919 call __cast6_enc_blk8;
13920
13921 - store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13922 + store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13923
13924 - popq %r12;
13925 + popq %r14;
13926
13927 + pax_force_retaddr
13928 ret;
13929 ENDPROC(cast6_ctr_8way)
13930
13931 @@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13932 /* dst <= regs xor IVs(in dst) */
13933 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13934
13935 + pax_force_retaddr
13936 ret;
13937 ENDPROC(cast6_xts_enc_8way)
13938
13939 @@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13940 /* dst <= regs xor IVs(in dst) */
13941 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13942
13943 + pax_force_retaddr
13944 ret;
13945 ENDPROC(cast6_xts_dec_8way)
13946 diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13947 index 26d49eb..c0a8c84 100644
13948 --- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13949 +++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13950 @@ -45,6 +45,7 @@
13951
13952 #include <asm/inst.h>
13953 #include <linux/linkage.h>
13954 +#include <asm/alternative-asm.h>
13955
13956 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
13957
13958 @@ -309,6 +310,7 @@ do_return:
13959 popq %rsi
13960 popq %rdi
13961 popq %rbx
13962 + pax_force_retaddr
13963 ret
13964
13965 ################################################################
13966 diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13967 index 5d1e007..098cb4f 100644
13968 --- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
13969 +++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13970 @@ -18,6 +18,7 @@
13971
13972 #include <linux/linkage.h>
13973 #include <asm/inst.h>
13974 +#include <asm/alternative-asm.h>
13975
13976 .data
13977
13978 @@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
13979 psrlq $1, T2
13980 pxor T2, T1
13981 pxor T1, DATA
13982 + pax_force_retaddr
13983 ret
13984 ENDPROC(__clmul_gf128mul_ble)
13985
13986 @@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
13987 call __clmul_gf128mul_ble
13988 PSHUFB_XMM BSWAP DATA
13989 movups DATA, (%rdi)
13990 + pax_force_retaddr
13991 ret
13992 ENDPROC(clmul_ghash_mul)
13993
13994 @@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
13995 PSHUFB_XMM BSWAP DATA
13996 movups DATA, (%rdi)
13997 .Lupdate_just_ret:
13998 + pax_force_retaddr
13999 ret
14000 ENDPROC(clmul_ghash_update)
14001 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14002 index 9279e0b..c4b3d2c 100644
14003 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
14004 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14005 @@ -1,4 +1,5 @@
14006 #include <linux/linkage.h>
14007 +#include <asm/alternative-asm.h>
14008
14009 # enter salsa20_encrypt_bytes
14010 ENTRY(salsa20_encrypt_bytes)
14011 @@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
14012 add %r11,%rsp
14013 mov %rdi,%rax
14014 mov %rsi,%rdx
14015 + pax_force_retaddr
14016 ret
14017 # bytesatleast65:
14018 ._bytesatleast65:
14019 @@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
14020 add %r11,%rsp
14021 mov %rdi,%rax
14022 mov %rsi,%rdx
14023 + pax_force_retaddr
14024 ret
14025 ENDPROC(salsa20_keysetup)
14026
14027 @@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
14028 add %r11,%rsp
14029 mov %rdi,%rax
14030 mov %rsi,%rdx
14031 + pax_force_retaddr
14032 ret
14033 ENDPROC(salsa20_ivsetup)
14034 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14035 index 2f202f4..d9164d6 100644
14036 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14037 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14038 @@ -24,6 +24,7 @@
14039 */
14040
14041 #include <linux/linkage.h>
14042 +#include <asm/alternative-asm.h>
14043 #include "glue_helper-asm-avx.S"
14044
14045 .file "serpent-avx-x86_64-asm_64.S"
14046 @@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
14047 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14048 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14049
14050 + pax_force_retaddr
14051 ret;
14052 ENDPROC(__serpent_enc_blk8_avx)
14053
14054 @@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
14055 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14056 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14057
14058 + pax_force_retaddr
14059 ret;
14060 ENDPROC(__serpent_dec_blk8_avx)
14061
14062 @@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
14063
14064 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14065
14066 + pax_force_retaddr
14067 ret;
14068 ENDPROC(serpent_ecb_enc_8way_avx)
14069
14070 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
14071
14072 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14073
14074 + pax_force_retaddr
14075 ret;
14076 ENDPROC(serpent_ecb_dec_8way_avx)
14077
14078 @@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
14079
14080 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14081
14082 + pax_force_retaddr
14083 ret;
14084 ENDPROC(serpent_cbc_dec_8way_avx)
14085
14086 @@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
14087
14088 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14089
14090 + pax_force_retaddr
14091 ret;
14092 ENDPROC(serpent_ctr_8way_avx)
14093
14094 @@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
14095 /* dst <= regs xor IVs(in dst) */
14096 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14097
14098 + pax_force_retaddr
14099 ret;
14100 ENDPROC(serpent_xts_enc_8way_avx)
14101
14102 @@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
14103 /* dst <= regs xor IVs(in dst) */
14104 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14105
14106 + pax_force_retaddr
14107 ret;
14108 ENDPROC(serpent_xts_dec_8way_avx)
14109 diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
14110 index b222085..abd483c 100644
14111 --- a/arch/x86/crypto/serpent-avx2-asm_64.S
14112 +++ b/arch/x86/crypto/serpent-avx2-asm_64.S
14113 @@ -15,6 +15,7 @@
14114 */
14115
14116 #include <linux/linkage.h>
14117 +#include <asm/alternative-asm.h>
14118 #include "glue_helper-asm-avx2.S"
14119
14120 .file "serpent-avx2-asm_64.S"
14121 @@ -610,6 +611,7 @@ __serpent_enc_blk16:
14122 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14123 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14124
14125 + pax_force_retaddr
14126 ret;
14127 ENDPROC(__serpent_enc_blk16)
14128
14129 @@ -664,6 +666,7 @@ __serpent_dec_blk16:
14130 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14131 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14132
14133 + pax_force_retaddr
14134 ret;
14135 ENDPROC(__serpent_dec_blk16)
14136
14137 @@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
14138
14139 vzeroupper;
14140
14141 + pax_force_retaddr
14142 ret;
14143 ENDPROC(serpent_ecb_enc_16way)
14144
14145 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
14146
14147 vzeroupper;
14148
14149 + pax_force_retaddr
14150 ret;
14151 ENDPROC(serpent_ecb_dec_16way)
14152
14153 @@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
14154
14155 vzeroupper;
14156
14157 + pax_force_retaddr
14158 ret;
14159 ENDPROC(serpent_cbc_dec_16way)
14160
14161 @@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
14162
14163 vzeroupper;
14164
14165 + pax_force_retaddr
14166 ret;
14167 ENDPROC(serpent_ctr_16way)
14168
14169 @@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
14170
14171 vzeroupper;
14172
14173 + pax_force_retaddr
14174 ret;
14175 ENDPROC(serpent_xts_enc_16way)
14176
14177 @@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
14178
14179 vzeroupper;
14180
14181 + pax_force_retaddr
14182 ret;
14183 ENDPROC(serpent_xts_dec_16way)
14184 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14185 index acc066c..1559cc4 100644
14186 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14187 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14188 @@ -25,6 +25,7 @@
14189 */
14190
14191 #include <linux/linkage.h>
14192 +#include <asm/alternative-asm.h>
14193
14194 .file "serpent-sse2-x86_64-asm_64.S"
14195 .text
14196 @@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
14197 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14198 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14199
14200 + pax_force_retaddr
14201 ret;
14202
14203 .L__enc_xor8:
14204 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14205 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14206
14207 + pax_force_retaddr
14208 ret;
14209 ENDPROC(__serpent_enc_blk_8way)
14210
14211 @@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
14212 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14213 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14214
14215 + pax_force_retaddr
14216 ret;
14217 ENDPROC(serpent_dec_blk_8way)
14218 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
14219 index a410950..9dfe7ad 100644
14220 --- a/arch/x86/crypto/sha1_ssse3_asm.S
14221 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
14222 @@ -29,6 +29,7 @@
14223 */
14224
14225 #include <linux/linkage.h>
14226 +#include <asm/alternative-asm.h>
14227
14228 #define CTX %rdi // arg1
14229 #define BUF %rsi // arg2
14230 @@ -75,9 +76,9 @@
14231
14232 push %rbx
14233 push %rbp
14234 - push %r12
14235 + push %r14
14236
14237 - mov %rsp, %r12
14238 + mov %rsp, %r14
14239 sub $64, %rsp # allocate workspace
14240 and $~15, %rsp # align stack
14241
14242 @@ -99,11 +100,12 @@
14243 xor %rax, %rax
14244 rep stosq
14245
14246 - mov %r12, %rsp # deallocate workspace
14247 + mov %r14, %rsp # deallocate workspace
14248
14249 - pop %r12
14250 + pop %r14
14251 pop %rbp
14252 pop %rbx
14253 + pax_force_retaddr
14254 ret
14255
14256 ENDPROC(\name)
14257 diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
14258 index 642f156..51a513c 100644
14259 --- a/arch/x86/crypto/sha256-avx-asm.S
14260 +++ b/arch/x86/crypto/sha256-avx-asm.S
14261 @@ -49,6 +49,7 @@
14262
14263 #ifdef CONFIG_AS_AVX
14264 #include <linux/linkage.h>
14265 +#include <asm/alternative-asm.h>
14266
14267 ## assume buffers not aligned
14268 #define VMOVDQ vmovdqu
14269 @@ -460,6 +461,7 @@ done_hash:
14270 popq %r13
14271 popq %rbp
14272 popq %rbx
14273 + pax_force_retaddr
14274 ret
14275 ENDPROC(sha256_transform_avx)
14276
14277 diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14278 index 9e86944..3795e6a 100644
14279 --- a/arch/x86/crypto/sha256-avx2-asm.S
14280 +++ b/arch/x86/crypto/sha256-avx2-asm.S
14281 @@ -50,6 +50,7 @@
14282
14283 #ifdef CONFIG_AS_AVX2
14284 #include <linux/linkage.h>
14285 +#include <asm/alternative-asm.h>
14286
14287 ## assume buffers not aligned
14288 #define VMOVDQ vmovdqu
14289 @@ -720,6 +721,7 @@ done_hash:
14290 popq %r12
14291 popq %rbp
14292 popq %rbx
14293 + pax_force_retaddr
14294 ret
14295 ENDPROC(sha256_transform_rorx)
14296
14297 diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14298 index f833b74..8c62a9e 100644
14299 --- a/arch/x86/crypto/sha256-ssse3-asm.S
14300 +++ b/arch/x86/crypto/sha256-ssse3-asm.S
14301 @@ -47,6 +47,7 @@
14302 ########################################################################
14303
14304 #include <linux/linkage.h>
14305 +#include <asm/alternative-asm.h>
14306
14307 ## assume buffers not aligned
14308 #define MOVDQ movdqu
14309 @@ -471,6 +472,7 @@ done_hash:
14310 popq %rbp
14311 popq %rbx
14312
14313 + pax_force_retaddr
14314 ret
14315 ENDPROC(sha256_transform_ssse3)
14316
14317 diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14318 index 974dde9..a823ff9 100644
14319 --- a/arch/x86/crypto/sha512-avx-asm.S
14320 +++ b/arch/x86/crypto/sha512-avx-asm.S
14321 @@ -49,6 +49,7 @@
14322
14323 #ifdef CONFIG_AS_AVX
14324 #include <linux/linkage.h>
14325 +#include <asm/alternative-asm.h>
14326
14327 .text
14328
14329 @@ -364,6 +365,7 @@ updateblock:
14330 mov frame_RSPSAVE(%rsp), %rsp
14331
14332 nowork:
14333 + pax_force_retaddr
14334 ret
14335 ENDPROC(sha512_transform_avx)
14336
14337 diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14338 index 568b961..ed20c37 100644
14339 --- a/arch/x86/crypto/sha512-avx2-asm.S
14340 +++ b/arch/x86/crypto/sha512-avx2-asm.S
14341 @@ -51,6 +51,7 @@
14342
14343 #ifdef CONFIG_AS_AVX2
14344 #include <linux/linkage.h>
14345 +#include <asm/alternative-asm.h>
14346
14347 .text
14348
14349 @@ -678,6 +679,7 @@ done_hash:
14350
14351 # Restore Stack Pointer
14352 mov frame_RSPSAVE(%rsp), %rsp
14353 + pax_force_retaddr
14354 ret
14355 ENDPROC(sha512_transform_rorx)
14356
14357 diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14358 index fb56855..6edd768 100644
14359 --- a/arch/x86/crypto/sha512-ssse3-asm.S
14360 +++ b/arch/x86/crypto/sha512-ssse3-asm.S
14361 @@ -48,6 +48,7 @@
14362 ########################################################################
14363
14364 #include <linux/linkage.h>
14365 +#include <asm/alternative-asm.h>
14366
14367 .text
14368
14369 @@ -363,6 +364,7 @@ updateblock:
14370 mov frame_RSPSAVE(%rsp), %rsp
14371
14372 nowork:
14373 + pax_force_retaddr
14374 ret
14375 ENDPROC(sha512_transform_ssse3)
14376
14377 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14378 index 0505813..b067311 100644
14379 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14380 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14381 @@ -24,6 +24,7 @@
14382 */
14383
14384 #include <linux/linkage.h>
14385 +#include <asm/alternative-asm.h>
14386 #include "glue_helper-asm-avx.S"
14387
14388 .file "twofish-avx-x86_64-asm_64.S"
14389 @@ -284,6 +285,7 @@ __twofish_enc_blk8:
14390 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14391 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14392
14393 + pax_force_retaddr
14394 ret;
14395 ENDPROC(__twofish_enc_blk8)
14396
14397 @@ -324,6 +326,7 @@ __twofish_dec_blk8:
14398 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14399 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14400
14401 + pax_force_retaddr
14402 ret;
14403 ENDPROC(__twofish_dec_blk8)
14404
14405 @@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14406
14407 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14408
14409 + pax_force_retaddr
14410 ret;
14411 ENDPROC(twofish_ecb_enc_8way)
14412
14413 @@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14414
14415 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14416
14417 + pax_force_retaddr
14418 ret;
14419 ENDPROC(twofish_ecb_dec_8way)
14420
14421 @@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14422 * %rdx: src
14423 */
14424
14425 - pushq %r12;
14426 + pushq %r14;
14427
14428 movq %rsi, %r11;
14429 - movq %rdx, %r12;
14430 + movq %rdx, %r14;
14431
14432 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14433
14434 call __twofish_dec_blk8;
14435
14436 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14437 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14438
14439 - popq %r12;
14440 + popq %r14;
14441
14442 + pax_force_retaddr
14443 ret;
14444 ENDPROC(twofish_cbc_dec_8way)
14445
14446 @@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14447 * %rcx: iv (little endian, 128bit)
14448 */
14449
14450 - pushq %r12;
14451 + pushq %r14;
14452
14453 movq %rsi, %r11;
14454 - movq %rdx, %r12;
14455 + movq %rdx, %r14;
14456
14457 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14458 RD2, RX0, RX1, RY0);
14459
14460 call __twofish_enc_blk8;
14461
14462 - store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14463 + store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14464
14465 - popq %r12;
14466 + popq %r14;
14467
14468 + pax_force_retaddr
14469 ret;
14470 ENDPROC(twofish_ctr_8way)
14471
14472 @@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14473 /* dst <= regs xor IVs(in dst) */
14474 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14475
14476 + pax_force_retaddr
14477 ret;
14478 ENDPROC(twofish_xts_enc_8way)
14479
14480 @@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14481 /* dst <= regs xor IVs(in dst) */
14482 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14483
14484 + pax_force_retaddr
14485 ret;
14486 ENDPROC(twofish_xts_dec_8way)
14487 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14488 index 1c3b7ce..02f578d 100644
14489 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14490 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14491 @@ -21,6 +21,7 @@
14492 */
14493
14494 #include <linux/linkage.h>
14495 +#include <asm/alternative-asm.h>
14496
14497 .file "twofish-x86_64-asm-3way.S"
14498 .text
14499 @@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14500 popq %r13;
14501 popq %r14;
14502 popq %r15;
14503 + pax_force_retaddr
14504 ret;
14505
14506 .L__enc_xor3:
14507 @@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14508 popq %r13;
14509 popq %r14;
14510 popq %r15;
14511 + pax_force_retaddr
14512 ret;
14513 ENDPROC(__twofish_enc_blk_3way)
14514
14515 @@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14516 popq %r13;
14517 popq %r14;
14518 popq %r15;
14519 + pax_force_retaddr
14520 ret;
14521 ENDPROC(twofish_dec_blk_3way)
14522 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14523 index a039d21..524b8b2 100644
14524 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14525 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14526 @@ -22,6 +22,7 @@
14527
14528 #include <linux/linkage.h>
14529 #include <asm/asm-offsets.h>
14530 +#include <asm/alternative-asm.h>
14531
14532 #define a_offset 0
14533 #define b_offset 4
14534 @@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14535
14536 popq R1
14537 movq $1,%rax
14538 + pax_force_retaddr
14539 ret
14540 ENDPROC(twofish_enc_blk)
14541
14542 @@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14543
14544 popq R1
14545 movq $1,%rax
14546 + pax_force_retaddr
14547 ret
14548 ENDPROC(twofish_dec_blk)
14549 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14550 index df91466..74b31cb 100644
14551 --- a/arch/x86/ia32/ia32_aout.c
14552 +++ b/arch/x86/ia32/ia32_aout.c
14553 @@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14554 unsigned long dump_start, dump_size;
14555 struct user32 dump;
14556
14557 + memset(&dump, 0, sizeof(dump));
14558 +
14559 fs = get_fs();
14560 set_fs(KERNEL_DS);
14561 has_dumped = 1;
14562 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14563 index f9e181a..300544c 100644
14564 --- a/arch/x86/ia32/ia32_signal.c
14565 +++ b/arch/x86/ia32/ia32_signal.c
14566 @@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14567 if (__get_user(set.sig[0], &frame->sc.oldmask)
14568 || (_COMPAT_NSIG_WORDS > 1
14569 && __copy_from_user((((char *) &set.sig) + 4),
14570 - &frame->extramask,
14571 + frame->extramask,
14572 sizeof(frame->extramask))))
14573 goto badframe;
14574
14575 @@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14576 sp -= frame_size;
14577 /* Align the stack pointer according to the i386 ABI,
14578 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14579 - sp = ((sp + 4) & -16ul) - 4;
14580 + sp = ((sp - 12) & -16ul) - 4;
14581 return (void __user *) sp;
14582 }
14583
14584 @@ -383,10 +383,10 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14585 } else {
14586 /* Return stub is in 32bit vsyscall page */
14587 if (current->mm->context.vdso)
14588 - restorer = current->mm->context.vdso +
14589 - selected_vdso32->sym___kernel_sigreturn;
14590 + restorer = (void __force_user *)(current->mm->context.vdso +
14591 + selected_vdso32->sym___kernel_sigreturn);
14592 else
14593 - restorer = &frame->retcode;
14594 + restorer = frame->retcode;
14595 }
14596
14597 put_user_try {
14598 @@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14599 * These are actually not used anymore, but left because some
14600 * gdb versions depend on them as a marker.
14601 */
14602 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14603 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14604 } put_user_catch(err);
14605
14606 if (err)
14607 @@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14608 0xb8,
14609 __NR_ia32_rt_sigreturn,
14610 0x80cd,
14611 - 0,
14612 + 0
14613 };
14614
14615 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14616 @@ -461,16 +461,19 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14617
14618 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14619 restorer = ksig->ka.sa.sa_restorer;
14620 + else if (current->mm->context.vdso)
14621 + /* Return stub is in 32bit vsyscall page */
14622 + restorer = (void __force_user *)(current->mm->context.vdso +
14623 + selected_vdso32->sym___kernel_rt_sigreturn);
14624 else
14625 - restorer = current->mm->context.vdso +
14626 - selected_vdso32->sym___kernel_rt_sigreturn;
14627 + restorer = frame->retcode;
14628 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14629
14630 /*
14631 * Not actually used anymore, but left because some gdb
14632 * versions need it.
14633 */
14634 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14635 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14636 } put_user_catch(err);
14637
14638 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14639 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14640 index ffe7122..899bad3 100644
14641 --- a/arch/x86/ia32/ia32entry.S
14642 +++ b/arch/x86/ia32/ia32entry.S
14643 @@ -15,8 +15,10 @@
14644 #include <asm/irqflags.h>
14645 #include <asm/asm.h>
14646 #include <asm/smap.h>
14647 +#include <asm/pgtable.h>
14648 #include <linux/linkage.h>
14649 #include <linux/err.h>
14650 +#include <asm/alternative-asm.h>
14651
14652 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14653 #include <linux/elf-em.h>
14654 @@ -62,12 +64,12 @@
14655 */
14656 .macro LOAD_ARGS32 offset, _r9=0
14657 .if \_r9
14658 - movl \offset+16(%rsp),%r9d
14659 + movl \offset+R9(%rsp),%r9d
14660 .endif
14661 - movl \offset+40(%rsp),%ecx
14662 - movl \offset+48(%rsp),%edx
14663 - movl \offset+56(%rsp),%esi
14664 - movl \offset+64(%rsp),%edi
14665 + movl \offset+RCX(%rsp),%ecx
14666 + movl \offset+RDX(%rsp),%edx
14667 + movl \offset+RSI(%rsp),%esi
14668 + movl \offset+RDI(%rsp),%edi
14669 movl %eax,%eax /* zero extension */
14670 .endm
14671
14672 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14673 ENDPROC(native_irq_enable_sysexit)
14674 #endif
14675
14676 + .macro pax_enter_kernel_user
14677 + pax_set_fptr_mask
14678 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14679 + call pax_enter_kernel_user
14680 +#endif
14681 + .endm
14682 +
14683 + .macro pax_exit_kernel_user
14684 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14685 + call pax_exit_kernel_user
14686 +#endif
14687 +#ifdef CONFIG_PAX_RANDKSTACK
14688 + pushq %rax
14689 + pushq %r11
14690 + call pax_randomize_kstack
14691 + popq %r11
14692 + popq %rax
14693 +#endif
14694 + .endm
14695 +
14696 + .macro pax_erase_kstack
14697 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14698 + call pax_erase_kstack
14699 +#endif
14700 + .endm
14701 +
14702 /*
14703 * 32bit SYSENTER instruction entry.
14704 *
14705 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14706 CFI_REGISTER rsp,rbp
14707 SWAPGS_UNSAFE_STACK
14708 movq PER_CPU_VAR(kernel_stack), %rsp
14709 - addq $(KERNEL_STACK_OFFSET),%rsp
14710 - /*
14711 - * No need to follow this irqs on/off section: the syscall
14712 - * disabled irqs, here we enable it straight after entry:
14713 - */
14714 - ENABLE_INTERRUPTS(CLBR_NONE)
14715 movl %ebp,%ebp /* zero extension */
14716 pushq_cfi $__USER32_DS
14717 /*CFI_REL_OFFSET ss,0*/
14718 @@ -135,23 +157,46 @@ ENTRY(ia32_sysenter_target)
14719 CFI_REL_OFFSET rsp,0
14720 pushfq_cfi
14721 /*CFI_REL_OFFSET rflags,0*/
14722 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14723 - CFI_REGISTER rip,r10
14724 + orl $X86_EFLAGS_IF,(%rsp)
14725 + GET_THREAD_INFO(%r11)
14726 + movl TI_sysenter_return(%r11), %r11d
14727 + CFI_REGISTER rip,r11
14728 pushq_cfi $__USER32_CS
14729 /*CFI_REL_OFFSET cs,0*/
14730 movl %eax, %eax
14731 - pushq_cfi %r10
14732 + pushq_cfi %r11
14733 CFI_REL_OFFSET rip,0
14734 pushq_cfi %rax
14735 cld
14736 SAVE_ARGS 0,1,0
14737 + pax_enter_kernel_user
14738 +
14739 +#ifdef CONFIG_PAX_RANDKSTACK
14740 + pax_erase_kstack
14741 +#endif
14742 +
14743 + /*
14744 + * No need to follow this irqs on/off section: the syscall
14745 + * disabled irqs, here we enable it straight after entry:
14746 + */
14747 + ENABLE_INTERRUPTS(CLBR_NONE)
14748 /* no need to do an access_ok check here because rbp has been
14749 32bit zero extended */
14750 +
14751 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14752 + addq pax_user_shadow_base,%rbp
14753 + ASM_PAX_OPEN_USERLAND
14754 +#endif
14755 +
14756 ASM_STAC
14757 1: movl (%rbp),%ebp
14758 _ASM_EXTABLE(1b,ia32_badarg)
14759 ASM_CLAC
14760
14761 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14762 + ASM_PAX_CLOSE_USERLAND
14763 +#endif
14764 +
14765 /*
14766 * Sysenter doesn't filter flags, so we need to clear NT
14767 * ourselves. To save a few cycles, we can check whether
14768 @@ -161,8 +206,9 @@ ENTRY(ia32_sysenter_target)
14769 jnz sysenter_fix_flags
14770 sysenter_flags_fixed:
14771
14772 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14773 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14774 + GET_THREAD_INFO(%r11)
14775 + orl $TS_COMPAT,TI_status(%r11)
14776 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14777 CFI_REMEMBER_STATE
14778 jnz sysenter_tracesys
14779 cmpq $(IA32_NR_syscalls-1),%rax
14780 @@ -172,15 +218,18 @@ sysenter_do_call:
14781 sysenter_dispatch:
14782 call *ia32_sys_call_table(,%rax,8)
14783 movq %rax,RAX-ARGOFFSET(%rsp)
14784 + GET_THREAD_INFO(%r11)
14785 DISABLE_INTERRUPTS(CLBR_NONE)
14786 TRACE_IRQS_OFF
14787 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14788 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14789 jnz sysexit_audit
14790 sysexit_from_sys_call:
14791 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14792 + pax_exit_kernel_user
14793 + pax_erase_kstack
14794 + andl $~TS_COMPAT,TI_status(%r11)
14795 /* clear IF, that popfq doesn't enable interrupts early */
14796 - andl $~0x200,EFLAGS-R11(%rsp)
14797 - movl RIP-R11(%rsp),%edx /* User %eip */
14798 + andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14799 + movl RIP(%rsp),%edx /* User %eip */
14800 CFI_REGISTER rip,rdx
14801 RESTORE_ARGS 0,24,0,0,0,0
14802 xorq %r8,%r8
14803 @@ -205,6 +254,9 @@ sysexit_from_sys_call:
14804 movl %ebx,%esi /* 2nd arg: 1st syscall arg */
14805 movl %eax,%edi /* 1st arg: syscall number */
14806 call __audit_syscall_entry
14807 +
14808 + pax_erase_kstack
14809 +
14810 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14811 cmpq $(IA32_NR_syscalls-1),%rax
14812 ja ia32_badsys
14813 @@ -216,7 +268,7 @@ sysexit_from_sys_call:
14814 .endm
14815
14816 .macro auditsys_exit exit
14817 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14818 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14819 jnz ia32_ret_from_sys_call
14820 TRACE_IRQS_ON
14821 ENABLE_INTERRUPTS(CLBR_NONE)
14822 @@ -227,11 +279,12 @@ sysexit_from_sys_call:
14823 1: setbe %al /* 1 if error, 0 if not */
14824 movzbl %al,%edi /* zero-extend that into %edi */
14825 call __audit_syscall_exit
14826 + GET_THREAD_INFO(%r11)
14827 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14828 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14829 DISABLE_INTERRUPTS(CLBR_NONE)
14830 TRACE_IRQS_OFF
14831 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14832 + testl %edi,TI_flags(%r11)
14833 jz \exit
14834 CLEAR_RREGS -ARGOFFSET
14835 jmp int_with_check
14836 @@ -253,7 +306,7 @@ sysenter_fix_flags:
14837
14838 sysenter_tracesys:
14839 #ifdef CONFIG_AUDITSYSCALL
14840 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14841 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14842 jz sysenter_auditsys
14843 #endif
14844 SAVE_REST
14845 @@ -265,6 +318,9 @@ sysenter_tracesys:
14846 RESTORE_REST
14847 cmpq $(IA32_NR_syscalls-1),%rax
14848 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14849 +
14850 + pax_erase_kstack
14851 +
14852 jmp sysenter_do_call
14853 CFI_ENDPROC
14854 ENDPROC(ia32_sysenter_target)
14855 @@ -292,19 +348,25 @@ ENDPROC(ia32_sysenter_target)
14856 ENTRY(ia32_cstar_target)
14857 CFI_STARTPROC32 simple
14858 CFI_SIGNAL_FRAME
14859 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14860 + CFI_DEF_CFA rsp,0
14861 CFI_REGISTER rip,rcx
14862 /*CFI_REGISTER rflags,r11*/
14863 SWAPGS_UNSAFE_STACK
14864 movl %esp,%r8d
14865 CFI_REGISTER rsp,r8
14866 movq PER_CPU_VAR(kernel_stack),%rsp
14867 + SAVE_ARGS 8*6,0,0
14868 + pax_enter_kernel_user
14869 +
14870 +#ifdef CONFIG_PAX_RANDKSTACK
14871 + pax_erase_kstack
14872 +#endif
14873 +
14874 /*
14875 * No need to follow this irqs on/off section: the syscall
14876 * disabled irqs and here we enable it straight after entry:
14877 */
14878 ENABLE_INTERRUPTS(CLBR_NONE)
14879 - SAVE_ARGS 8,0,0
14880 movl %eax,%eax /* zero extension */
14881 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14882 movq %rcx,RIP-ARGOFFSET(%rsp)
14883 @@ -320,12 +382,25 @@ ENTRY(ia32_cstar_target)
14884 /* no need to do an access_ok check here because r8 has been
14885 32bit zero extended */
14886 /* hardware stack frame is complete now */
14887 +
14888 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14889 + ASM_PAX_OPEN_USERLAND
14890 + movq pax_user_shadow_base,%r8
14891 + addq RSP-ARGOFFSET(%rsp),%r8
14892 +#endif
14893 +
14894 ASM_STAC
14895 1: movl (%r8),%r9d
14896 _ASM_EXTABLE(1b,ia32_badarg)
14897 ASM_CLAC
14898 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14899 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14900 +
14901 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14902 + ASM_PAX_CLOSE_USERLAND
14903 +#endif
14904 +
14905 + GET_THREAD_INFO(%r11)
14906 + orl $TS_COMPAT,TI_status(%r11)
14907 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14908 CFI_REMEMBER_STATE
14909 jnz cstar_tracesys
14910 cmpq $IA32_NR_syscalls-1,%rax
14911 @@ -335,13 +410,16 @@ cstar_do_call:
14912 cstar_dispatch:
14913 call *ia32_sys_call_table(,%rax,8)
14914 movq %rax,RAX-ARGOFFSET(%rsp)
14915 + GET_THREAD_INFO(%r11)
14916 DISABLE_INTERRUPTS(CLBR_NONE)
14917 TRACE_IRQS_OFF
14918 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14919 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14920 jnz sysretl_audit
14921 sysretl_from_sys_call:
14922 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14923 - RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14924 + pax_exit_kernel_user
14925 + pax_erase_kstack
14926 + andl $~TS_COMPAT,TI_status(%r11)
14927 + RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14928 movl RIP-ARGOFFSET(%rsp),%ecx
14929 CFI_REGISTER rip,rcx
14930 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14931 @@ -368,7 +446,7 @@ sysretl_audit:
14932
14933 cstar_tracesys:
14934 #ifdef CONFIG_AUDITSYSCALL
14935 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14936 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14937 jz cstar_auditsys
14938 #endif
14939 xchgl %r9d,%ebp
14940 @@ -382,11 +460,19 @@ cstar_tracesys:
14941 xchgl %ebp,%r9d
14942 cmpq $(IA32_NR_syscalls-1),%rax
14943 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14944 +
14945 + pax_erase_kstack
14946 +
14947 jmp cstar_do_call
14948 END(ia32_cstar_target)
14949
14950 ia32_badarg:
14951 ASM_CLAC
14952 +
14953 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14954 + ASM_PAX_CLOSE_USERLAND
14955 +#endif
14956 +
14957 movq $-EFAULT,%rax
14958 jmp ia32_sysret
14959 CFI_ENDPROC
14960 @@ -423,19 +509,26 @@ ENTRY(ia32_syscall)
14961 CFI_REL_OFFSET rip,RIP-RIP
14962 PARAVIRT_ADJUST_EXCEPTION_FRAME
14963 SWAPGS
14964 - /*
14965 - * No need to follow this irqs on/off section: the syscall
14966 - * disabled irqs and here we enable it straight after entry:
14967 - */
14968 - ENABLE_INTERRUPTS(CLBR_NONE)
14969 movl %eax,%eax
14970 pushq_cfi %rax
14971 cld
14972 /* note the registers are not zero extended to the sf.
14973 this could be a problem. */
14974 SAVE_ARGS 0,1,0
14975 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14976 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14977 + pax_enter_kernel_user
14978 +
14979 +#ifdef CONFIG_PAX_RANDKSTACK
14980 + pax_erase_kstack
14981 +#endif
14982 +
14983 + /*
14984 + * No need to follow this irqs on/off section: the syscall
14985 + * disabled irqs and here we enable it straight after entry:
14986 + */
14987 + ENABLE_INTERRUPTS(CLBR_NONE)
14988 + GET_THREAD_INFO(%r11)
14989 + orl $TS_COMPAT,TI_status(%r11)
14990 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14991 jnz ia32_tracesys
14992 cmpq $(IA32_NR_syscalls-1),%rax
14993 ja ia32_badsys
14994 @@ -458,6 +551,9 @@ ia32_tracesys:
14995 RESTORE_REST
14996 cmpq $(IA32_NR_syscalls-1),%rax
14997 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
14998 +
14999 + pax_erase_kstack
15000 +
15001 jmp ia32_do_call
15002 END(ia32_syscall)
15003
15004 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
15005 index 8e0ceec..af13504 100644
15006 --- a/arch/x86/ia32/sys_ia32.c
15007 +++ b/arch/x86/ia32/sys_ia32.c
15008 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
15009 */
15010 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
15011 {
15012 - typeof(ubuf->st_uid) uid = 0;
15013 - typeof(ubuf->st_gid) gid = 0;
15014 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
15015 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
15016 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
15017 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
15018 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
15019 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
15020 index 372231c..51b537d 100644
15021 --- a/arch/x86/include/asm/alternative-asm.h
15022 +++ b/arch/x86/include/asm/alternative-asm.h
15023 @@ -18,6 +18,45 @@
15024 .endm
15025 #endif
15026
15027 +#ifdef KERNEXEC_PLUGIN
15028 + .macro pax_force_retaddr_bts rip=0
15029 + btsq $63,\rip(%rsp)
15030 + .endm
15031 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15032 + .macro pax_force_retaddr rip=0, reload=0
15033 + btsq $63,\rip(%rsp)
15034 + .endm
15035 + .macro pax_force_fptr ptr
15036 + btsq $63,\ptr
15037 + .endm
15038 + .macro pax_set_fptr_mask
15039 + .endm
15040 +#endif
15041 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15042 + .macro pax_force_retaddr rip=0, reload=0
15043 + .if \reload
15044 + pax_set_fptr_mask
15045 + .endif
15046 + orq %r12,\rip(%rsp)
15047 + .endm
15048 + .macro pax_force_fptr ptr
15049 + orq %r12,\ptr
15050 + .endm
15051 + .macro pax_set_fptr_mask
15052 + movabs $0x8000000000000000,%r12
15053 + .endm
15054 +#endif
15055 +#else
15056 + .macro pax_force_retaddr rip=0, reload=0
15057 + .endm
15058 + .macro pax_force_fptr ptr
15059 + .endm
15060 + .macro pax_force_retaddr_bts rip=0
15061 + .endm
15062 + .macro pax_set_fptr_mask
15063 + .endm
15064 +#endif
15065 +
15066 .macro altinstruction_entry orig alt feature orig_len alt_len
15067 .long \orig - .
15068 .long \alt - .
15069 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
15070 index 473bdbe..b1e3377 100644
15071 --- a/arch/x86/include/asm/alternative.h
15072 +++ b/arch/x86/include/asm/alternative.h
15073 @@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15074 ".pushsection .discard,\"aw\",@progbits\n" \
15075 DISCARD_ENTRY(1) \
15076 ".popsection\n" \
15077 - ".pushsection .altinstr_replacement, \"ax\"\n" \
15078 + ".pushsection .altinstr_replacement, \"a\"\n" \
15079 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
15080 ".popsection"
15081
15082 @@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15083 DISCARD_ENTRY(1) \
15084 DISCARD_ENTRY(2) \
15085 ".popsection\n" \
15086 - ".pushsection .altinstr_replacement, \"ax\"\n" \
15087 + ".pushsection .altinstr_replacement, \"a\"\n" \
15088 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
15089 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
15090 ".popsection"
15091 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
15092 index 465b309..ab7e51f 100644
15093 --- a/arch/x86/include/asm/apic.h
15094 +++ b/arch/x86/include/asm/apic.h
15095 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
15096
15097 #ifdef CONFIG_X86_LOCAL_APIC
15098
15099 -extern unsigned int apic_verbosity;
15100 +extern int apic_verbosity;
15101 extern int local_apic_timer_c2_ok;
15102
15103 extern int disable_apic;
15104 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
15105 index 20370c6..a2eb9b0 100644
15106 --- a/arch/x86/include/asm/apm.h
15107 +++ b/arch/x86/include/asm/apm.h
15108 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
15109 __asm__ __volatile__(APM_DO_ZERO_SEGS
15110 "pushl %%edi\n\t"
15111 "pushl %%ebp\n\t"
15112 - "lcall *%%cs:apm_bios_entry\n\t"
15113 + "lcall *%%ss:apm_bios_entry\n\t"
15114 "setc %%al\n\t"
15115 "popl %%ebp\n\t"
15116 "popl %%edi\n\t"
15117 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
15118 __asm__ __volatile__(APM_DO_ZERO_SEGS
15119 "pushl %%edi\n\t"
15120 "pushl %%ebp\n\t"
15121 - "lcall *%%cs:apm_bios_entry\n\t"
15122 + "lcall *%%ss:apm_bios_entry\n\t"
15123 "setc %%bl\n\t"
15124 "popl %%ebp\n\t"
15125 "popl %%edi\n\t"
15126 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
15127 index 5e5cd12..3d18208 100644
15128 --- a/arch/x86/include/asm/atomic.h
15129 +++ b/arch/x86/include/asm/atomic.h
15130 @@ -28,6 +28,17 @@ static inline int atomic_read(const atomic_t *v)
15131 }
15132
15133 /**
15134 + * atomic_read_unchecked - read atomic variable
15135 + * @v: pointer of type atomic_unchecked_t
15136 + *
15137 + * Atomically reads the value of @v.
15138 + */
15139 +static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
15140 +{
15141 + return ACCESS_ONCE((v)->counter);
15142 +}
15143 +
15144 +/**
15145 * atomic_set - set atomic variable
15146 * @v: pointer of type atomic_t
15147 * @i: required value
15148 @@ -40,6 +51,18 @@ static inline void atomic_set(atomic_t *v, int i)
15149 }
15150
15151 /**
15152 + * atomic_set_unchecked - set atomic variable
15153 + * @v: pointer of type atomic_unchecked_t
15154 + * @i: required value
15155 + *
15156 + * Atomically sets the value of @v to @i.
15157 + */
15158 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
15159 +{
15160 + v->counter = i;
15161 +}
15162 +
15163 +/**
15164 * atomic_add - add integer to atomic variable
15165 * @i: integer value to add
15166 * @v: pointer of type atomic_t
15167 @@ -48,7 +71,29 @@ static inline void atomic_set(atomic_t *v, int i)
15168 */
15169 static inline void atomic_add(int i, atomic_t *v)
15170 {
15171 - asm volatile(LOCK_PREFIX "addl %1,%0"
15172 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
15173 +
15174 +#ifdef CONFIG_PAX_REFCOUNT
15175 + "jno 0f\n"
15176 + LOCK_PREFIX "subl %1,%0\n"
15177 + "int $4\n0:\n"
15178 + _ASM_EXTABLE(0b, 0b)
15179 +#endif
15180 +
15181 + : "+m" (v->counter)
15182 + : "ir" (i));
15183 +}
15184 +
15185 +/**
15186 + * atomic_add_unchecked - add integer to atomic variable
15187 + * @i: integer value to add
15188 + * @v: pointer of type atomic_unchecked_t
15189 + *
15190 + * Atomically adds @i to @v.
15191 + */
15192 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
15193 +{
15194 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
15195 : "+m" (v->counter)
15196 : "ir" (i));
15197 }
15198 @@ -62,7 +107,29 @@ static inline void atomic_add(int i, atomic_t *v)
15199 */
15200 static inline void atomic_sub(int i, atomic_t *v)
15201 {
15202 - asm volatile(LOCK_PREFIX "subl %1,%0"
15203 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
15204 +
15205 +#ifdef CONFIG_PAX_REFCOUNT
15206 + "jno 0f\n"
15207 + LOCK_PREFIX "addl %1,%0\n"
15208 + "int $4\n0:\n"
15209 + _ASM_EXTABLE(0b, 0b)
15210 +#endif
15211 +
15212 + : "+m" (v->counter)
15213 + : "ir" (i));
15214 +}
15215 +
15216 +/**
15217 + * atomic_sub_unchecked - subtract integer from atomic variable
15218 + * @i: integer value to subtract
15219 + * @v: pointer of type atomic_unchecked_t
15220 + *
15221 + * Atomically subtracts @i from @v.
15222 + */
15223 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
15224 +{
15225 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
15226 : "+m" (v->counter)
15227 : "ir" (i));
15228 }
15229 @@ -78,7 +145,7 @@ static inline void atomic_sub(int i, atomic_t *v)
15230 */
15231 static inline int atomic_sub_and_test(int i, atomic_t *v)
15232 {
15233 - GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
15234 + GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
15235 }
15236
15237 /**
15238 @@ -89,7 +156,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
15239 */
15240 static inline void atomic_inc(atomic_t *v)
15241 {
15242 - asm volatile(LOCK_PREFIX "incl %0"
15243 + asm volatile(LOCK_PREFIX "incl %0\n"
15244 +
15245 +#ifdef CONFIG_PAX_REFCOUNT
15246 + "jno 0f\n"
15247 + LOCK_PREFIX "decl %0\n"
15248 + "int $4\n0:\n"
15249 + _ASM_EXTABLE(0b, 0b)
15250 +#endif
15251 +
15252 + : "+m" (v->counter));
15253 +}
15254 +
15255 +/**
15256 + * atomic_inc_unchecked - increment atomic variable
15257 + * @v: pointer of type atomic_unchecked_t
15258 + *
15259 + * Atomically increments @v by 1.
15260 + */
15261 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
15262 +{
15263 + asm volatile(LOCK_PREFIX "incl %0\n"
15264 : "+m" (v->counter));
15265 }
15266
15267 @@ -101,7 +188,27 @@ static inline void atomic_inc(atomic_t *v)
15268 */
15269 static inline void atomic_dec(atomic_t *v)
15270 {
15271 - asm volatile(LOCK_PREFIX "decl %0"
15272 + asm volatile(LOCK_PREFIX "decl %0\n"
15273 +
15274 +#ifdef CONFIG_PAX_REFCOUNT
15275 + "jno 0f\n"
15276 + LOCK_PREFIX "incl %0\n"
15277 + "int $4\n0:\n"
15278 + _ASM_EXTABLE(0b, 0b)
15279 +#endif
15280 +
15281 + : "+m" (v->counter));
15282 +}
15283 +
15284 +/**
15285 + * atomic_dec_unchecked - decrement atomic variable
15286 + * @v: pointer of type atomic_unchecked_t
15287 + *
15288 + * Atomically decrements @v by 1.
15289 + */
15290 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15291 +{
15292 + asm volatile(LOCK_PREFIX "decl %0\n"
15293 : "+m" (v->counter));
15294 }
15295
15296 @@ -115,7 +222,7 @@ static inline void atomic_dec(atomic_t *v)
15297 */
15298 static inline int atomic_dec_and_test(atomic_t *v)
15299 {
15300 - GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15301 + GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15302 }
15303
15304 /**
15305 @@ -128,7 +235,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15306 */
15307 static inline int atomic_inc_and_test(atomic_t *v)
15308 {
15309 - GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15310 + GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15311 +}
15312 +
15313 +/**
15314 + * atomic_inc_and_test_unchecked - increment and test
15315 + * @v: pointer of type atomic_unchecked_t
15316 + *
15317 + * Atomically increments @v by 1
15318 + * and returns true if the result is zero, or false for all
15319 + * other cases.
15320 + */
15321 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15322 +{
15323 + GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15324 }
15325
15326 /**
15327 @@ -142,7 +262,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15328 */
15329 static inline int atomic_add_negative(int i, atomic_t *v)
15330 {
15331 - GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15332 + GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15333 }
15334
15335 /**
15336 @@ -152,7 +272,19 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15337 *
15338 * Atomically adds @i to @v and returns @i + @v
15339 */
15340 -static inline int atomic_add_return(int i, atomic_t *v)
15341 +static inline int __intentional_overflow(-1) atomic_add_return(int i, atomic_t *v)
15342 +{
15343 + return i + xadd_check_overflow(&v->counter, i);
15344 +}
15345 +
15346 +/**
15347 + * atomic_add_return_unchecked - add integer and return
15348 + * @i: integer value to add
15349 + * @v: pointer of type atomic_unchecked_t
15350 + *
15351 + * Atomically adds @i to @v and returns @i + @v
15352 + */
15353 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15354 {
15355 return i + xadd(&v->counter, i);
15356 }
15357 @@ -164,15 +296,24 @@ static inline int atomic_add_return(int i, atomic_t *v)
15358 *
15359 * Atomically subtracts @i from @v and returns @v - @i
15360 */
15361 -static inline int atomic_sub_return(int i, atomic_t *v)
15362 +static inline int __intentional_overflow(-1) atomic_sub_return(int i, atomic_t *v)
15363 {
15364 return atomic_add_return(-i, v);
15365 }
15366
15367 #define atomic_inc_return(v) (atomic_add_return(1, v))
15368 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15369 +{
15370 + return atomic_add_return_unchecked(1, v);
15371 +}
15372 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15373
15374 -static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15375 +static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15376 +{
15377 + return cmpxchg(&v->counter, old, new);
15378 +}
15379 +
15380 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15381 {
15382 return cmpxchg(&v->counter, old, new);
15383 }
15384 @@ -182,6 +323,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15385 return xchg(&v->counter, new);
15386 }
15387
15388 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15389 +{
15390 + return xchg(&v->counter, new);
15391 +}
15392 +
15393 /**
15394 * __atomic_add_unless - add unless the number is already a given value
15395 * @v: pointer of type atomic_t
15396 @@ -191,14 +337,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15397 * Atomically adds @a to @v, so long as @v was not already @u.
15398 * Returns the old value of @v.
15399 */
15400 -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15401 +static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15402 {
15403 - int c, old;
15404 + int c, old, new;
15405 c = atomic_read(v);
15406 for (;;) {
15407 - if (unlikely(c == (u)))
15408 + if (unlikely(c == u))
15409 break;
15410 - old = atomic_cmpxchg((v), c, c + (a));
15411 +
15412 + asm volatile("addl %2,%0\n"
15413 +
15414 +#ifdef CONFIG_PAX_REFCOUNT
15415 + "jno 0f\n"
15416 + "subl %2,%0\n"
15417 + "int $4\n0:\n"
15418 + _ASM_EXTABLE(0b, 0b)
15419 +#endif
15420 +
15421 + : "=r" (new)
15422 + : "0" (c), "ir" (a));
15423 +
15424 + old = atomic_cmpxchg(v, c, new);
15425 if (likely(old == c))
15426 break;
15427 c = old;
15428 @@ -207,6 +366,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15429 }
15430
15431 /**
15432 + * atomic_inc_not_zero_hint - increment if not null
15433 + * @v: pointer of type atomic_t
15434 + * @hint: probable value of the atomic before the increment
15435 + *
15436 + * This version of atomic_inc_not_zero() gives a hint of probable
15437 + * value of the atomic. This helps processor to not read the memory
15438 + * before doing the atomic read/modify/write cycle, lowering
15439 + * number of bus transactions on some arches.
15440 + *
15441 + * Returns: 0 if increment was not done, 1 otherwise.
15442 + */
15443 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15444 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15445 +{
15446 + int val, c = hint, new;
15447 +
15448 + /* sanity test, should be removed by compiler if hint is a constant */
15449 + if (!hint)
15450 + return __atomic_add_unless(v, 1, 0);
15451 +
15452 + do {
15453 + asm volatile("incl %0\n"
15454 +
15455 +#ifdef CONFIG_PAX_REFCOUNT
15456 + "jno 0f\n"
15457 + "decl %0\n"
15458 + "int $4\n0:\n"
15459 + _ASM_EXTABLE(0b, 0b)
15460 +#endif
15461 +
15462 + : "=r" (new)
15463 + : "0" (c));
15464 +
15465 + val = atomic_cmpxchg(v, c, new);
15466 + if (val == c)
15467 + return 1;
15468 + c = val;
15469 + } while (c);
15470 +
15471 + return 0;
15472 +}
15473 +
15474 +/**
15475 * atomic_inc_short - increment of a short integer
15476 * @v: pointer to type int
15477 *
15478 @@ -220,14 +422,37 @@ static inline short int atomic_inc_short(short int *v)
15479 }
15480
15481 /* These are x86-specific, used by some header files */
15482 -#define atomic_clear_mask(mask, addr) \
15483 - asm volatile(LOCK_PREFIX "andl %0,%1" \
15484 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
15485 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15486 +{
15487 + asm volatile(LOCK_PREFIX "andl %1,%0"
15488 + : "+m" (v->counter)
15489 + : "r" (~(mask))
15490 + : "memory");
15491 +}
15492
15493 -#define atomic_set_mask(mask, addr) \
15494 - asm volatile(LOCK_PREFIX "orl %0,%1" \
15495 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15496 - : "memory")
15497 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15498 +{
15499 + asm volatile(LOCK_PREFIX "andl %1,%0"
15500 + : "+m" (v->counter)
15501 + : "r" (~(mask))
15502 + : "memory");
15503 +}
15504 +
15505 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15506 +{
15507 + asm volatile(LOCK_PREFIX "orl %1,%0"
15508 + : "+m" (v->counter)
15509 + : "r" (mask)
15510 + : "memory");
15511 +}
15512 +
15513 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15514 +{
15515 + asm volatile(LOCK_PREFIX "orl %1,%0"
15516 + : "+m" (v->counter)
15517 + : "r" (mask)
15518 + : "memory");
15519 +}
15520
15521 #ifdef CONFIG_X86_32
15522 # include <asm/atomic64_32.h>
15523 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15524 index b154de7..bf18a5a 100644
15525 --- a/arch/x86/include/asm/atomic64_32.h
15526 +++ b/arch/x86/include/asm/atomic64_32.h
15527 @@ -12,6 +12,14 @@ typedef struct {
15528 u64 __aligned(8) counter;
15529 } atomic64_t;
15530
15531 +#ifdef CONFIG_PAX_REFCOUNT
15532 +typedef struct {
15533 + u64 __aligned(8) counter;
15534 +} atomic64_unchecked_t;
15535 +#else
15536 +typedef atomic64_t atomic64_unchecked_t;
15537 +#endif
15538 +
15539 #define ATOMIC64_INIT(val) { (val) }
15540
15541 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15542 @@ -37,21 +45,31 @@ typedef struct {
15543 ATOMIC64_DECL_ONE(sym##_386)
15544
15545 ATOMIC64_DECL_ONE(add_386);
15546 +ATOMIC64_DECL_ONE(add_unchecked_386);
15547 ATOMIC64_DECL_ONE(sub_386);
15548 +ATOMIC64_DECL_ONE(sub_unchecked_386);
15549 ATOMIC64_DECL_ONE(inc_386);
15550 +ATOMIC64_DECL_ONE(inc_unchecked_386);
15551 ATOMIC64_DECL_ONE(dec_386);
15552 +ATOMIC64_DECL_ONE(dec_unchecked_386);
15553 #endif
15554
15555 #define alternative_atomic64(f, out, in...) \
15556 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15557
15558 ATOMIC64_DECL(read);
15559 +ATOMIC64_DECL(read_unchecked);
15560 ATOMIC64_DECL(set);
15561 +ATOMIC64_DECL(set_unchecked);
15562 ATOMIC64_DECL(xchg);
15563 ATOMIC64_DECL(add_return);
15564 +ATOMIC64_DECL(add_return_unchecked);
15565 ATOMIC64_DECL(sub_return);
15566 +ATOMIC64_DECL(sub_return_unchecked);
15567 ATOMIC64_DECL(inc_return);
15568 +ATOMIC64_DECL(inc_return_unchecked);
15569 ATOMIC64_DECL(dec_return);
15570 +ATOMIC64_DECL(dec_return_unchecked);
15571 ATOMIC64_DECL(dec_if_positive);
15572 ATOMIC64_DECL(inc_not_zero);
15573 ATOMIC64_DECL(add_unless);
15574 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15575 }
15576
15577 /**
15578 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15579 + * @p: pointer to type atomic64_unchecked_t
15580 + * @o: expected value
15581 + * @n: new value
15582 + *
15583 + * Atomically sets @v to @n if it was equal to @o and returns
15584 + * the old value.
15585 + */
15586 +
15587 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15588 +{
15589 + return cmpxchg64(&v->counter, o, n);
15590 +}
15591 +
15592 +/**
15593 * atomic64_xchg - xchg atomic64 variable
15594 * @v: pointer to type atomic64_t
15595 * @n: value to assign
15596 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15597 }
15598
15599 /**
15600 + * atomic64_set_unchecked - set atomic64 variable
15601 + * @v: pointer to type atomic64_unchecked_t
15602 + * @n: value to assign
15603 + *
15604 + * Atomically sets the value of @v to @n.
15605 + */
15606 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15607 +{
15608 + unsigned high = (unsigned)(i >> 32);
15609 + unsigned low = (unsigned)i;
15610 + alternative_atomic64(set, /* no output */,
15611 + "S" (v), "b" (low), "c" (high)
15612 + : "eax", "edx", "memory");
15613 +}
15614 +
15615 +/**
15616 * atomic64_read - read atomic64 variable
15617 * @v: pointer to type atomic64_t
15618 *
15619 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15620 }
15621
15622 /**
15623 + * atomic64_read_unchecked - read atomic64 variable
15624 + * @v: pointer to type atomic64_unchecked_t
15625 + *
15626 + * Atomically reads the value of @v and returns it.
15627 + */
15628 +static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15629 +{
15630 + long long r;
15631 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15632 + return r;
15633 + }
15634 +
15635 +/**
15636 * atomic64_add_return - add and return
15637 * @i: integer value to add
15638 * @v: pointer to type atomic64_t
15639 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15640 return i;
15641 }
15642
15643 +/**
15644 + * atomic64_add_return_unchecked - add and return
15645 + * @i: integer value to add
15646 + * @v: pointer to type atomic64_unchecked_t
15647 + *
15648 + * Atomically adds @i to @v and returns @i + *@v
15649 + */
15650 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15651 +{
15652 + alternative_atomic64(add_return_unchecked,
15653 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15654 + ASM_NO_INPUT_CLOBBER("memory"));
15655 + return i;
15656 +}
15657 +
15658 /*
15659 * Other variants with different arithmetic operators:
15660 */
15661 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15662 return a;
15663 }
15664
15665 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15666 +{
15667 + long long a;
15668 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
15669 + "S" (v) : "memory", "ecx");
15670 + return a;
15671 +}
15672 +
15673 static inline long long atomic64_dec_return(atomic64_t *v)
15674 {
15675 long long a;
15676 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15677 }
15678
15679 /**
15680 + * atomic64_add_unchecked - add integer to atomic64 variable
15681 + * @i: integer value to add
15682 + * @v: pointer to type atomic64_unchecked_t
15683 + *
15684 + * Atomically adds @i to @v.
15685 + */
15686 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15687 +{
15688 + __alternative_atomic64(add_unchecked, add_return_unchecked,
15689 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15690 + ASM_NO_INPUT_CLOBBER("memory"));
15691 + return i;
15692 +}
15693 +
15694 +/**
15695 * atomic64_sub - subtract the atomic64 variable
15696 * @i: integer value to subtract
15697 * @v: pointer to type atomic64_t
15698 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15699 index f8d273e..02f39f3 100644
15700 --- a/arch/x86/include/asm/atomic64_64.h
15701 +++ b/arch/x86/include/asm/atomic64_64.h
15702 @@ -22,6 +22,18 @@ static inline long atomic64_read(const atomic64_t *v)
15703 }
15704
15705 /**
15706 + * atomic64_read_unchecked - read atomic64 variable
15707 + * @v: pointer of type atomic64_unchecked_t
15708 + *
15709 + * Atomically reads the value of @v.
15710 + * Doesn't imply a read memory barrier.
15711 + */
15712 +static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15713 +{
15714 + return ACCESS_ONCE((v)->counter);
15715 +}
15716 +
15717 +/**
15718 * atomic64_set - set atomic64 variable
15719 * @v: pointer to type atomic64_t
15720 * @i: required value
15721 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15722 }
15723
15724 /**
15725 + * atomic64_set_unchecked - set atomic64 variable
15726 + * @v: pointer to type atomic64_unchecked_t
15727 + * @i: required value
15728 + *
15729 + * Atomically sets the value of @v to @i.
15730 + */
15731 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15732 +{
15733 + v->counter = i;
15734 +}
15735 +
15736 +/**
15737 * atomic64_add - add integer to atomic64 variable
15738 * @i: integer value to add
15739 * @v: pointer to type atomic64_t
15740 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15741 */
15742 static inline void atomic64_add(long i, atomic64_t *v)
15743 {
15744 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
15745 +
15746 +#ifdef CONFIG_PAX_REFCOUNT
15747 + "jno 0f\n"
15748 + LOCK_PREFIX "subq %1,%0\n"
15749 + "int $4\n0:\n"
15750 + _ASM_EXTABLE(0b, 0b)
15751 +#endif
15752 +
15753 + : "=m" (v->counter)
15754 + : "er" (i), "m" (v->counter));
15755 +}
15756 +
15757 +/**
15758 + * atomic64_add_unchecked - add integer to atomic64 variable
15759 + * @i: integer value to add
15760 + * @v: pointer to type atomic64_unchecked_t
15761 + *
15762 + * Atomically adds @i to @v.
15763 + */
15764 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15765 +{
15766 asm volatile(LOCK_PREFIX "addq %1,%0"
15767 : "=m" (v->counter)
15768 : "er" (i), "m" (v->counter));
15769 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15770 */
15771 static inline void atomic64_sub(long i, atomic64_t *v)
15772 {
15773 - asm volatile(LOCK_PREFIX "subq %1,%0"
15774 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15775 +
15776 +#ifdef CONFIG_PAX_REFCOUNT
15777 + "jno 0f\n"
15778 + LOCK_PREFIX "addq %1,%0\n"
15779 + "int $4\n0:\n"
15780 + _ASM_EXTABLE(0b, 0b)
15781 +#endif
15782 +
15783 + : "=m" (v->counter)
15784 + : "er" (i), "m" (v->counter));
15785 +}
15786 +
15787 +/**
15788 + * atomic64_sub_unchecked - subtract the atomic64 variable
15789 + * @i: integer value to subtract
15790 + * @v: pointer to type atomic64_unchecked_t
15791 + *
15792 + * Atomically subtracts @i from @v.
15793 + */
15794 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15795 +{
15796 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15797 : "=m" (v->counter)
15798 : "er" (i), "m" (v->counter));
15799 }
15800 @@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15801 */
15802 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15803 {
15804 - GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15805 + GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15806 }
15807
15808 /**
15809 @@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15810 */
15811 static inline void atomic64_inc(atomic64_t *v)
15812 {
15813 + asm volatile(LOCK_PREFIX "incq %0\n"
15814 +
15815 +#ifdef CONFIG_PAX_REFCOUNT
15816 + "jno 0f\n"
15817 + LOCK_PREFIX "decq %0\n"
15818 + "int $4\n0:\n"
15819 + _ASM_EXTABLE(0b, 0b)
15820 +#endif
15821 +
15822 + : "=m" (v->counter)
15823 + : "m" (v->counter));
15824 +}
15825 +
15826 +/**
15827 + * atomic64_inc_unchecked - increment atomic64 variable
15828 + * @v: pointer to type atomic64_unchecked_t
15829 + *
15830 + * Atomically increments @v by 1.
15831 + */
15832 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15833 +{
15834 asm volatile(LOCK_PREFIX "incq %0"
15835 : "=m" (v->counter)
15836 : "m" (v->counter));
15837 @@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15838 */
15839 static inline void atomic64_dec(atomic64_t *v)
15840 {
15841 - asm volatile(LOCK_PREFIX "decq %0"
15842 + asm volatile(LOCK_PREFIX "decq %0\n"
15843 +
15844 +#ifdef CONFIG_PAX_REFCOUNT
15845 + "jno 0f\n"
15846 + LOCK_PREFIX "incq %0\n"
15847 + "int $4\n0:\n"
15848 + _ASM_EXTABLE(0b, 0b)
15849 +#endif
15850 +
15851 + : "=m" (v->counter)
15852 + : "m" (v->counter));
15853 +}
15854 +
15855 +/**
15856 + * atomic64_dec_unchecked - decrement atomic64 variable
15857 + * @v: pointer to type atomic64_t
15858 + *
15859 + * Atomically decrements @v by 1.
15860 + */
15861 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15862 +{
15863 + asm volatile(LOCK_PREFIX "decq %0\n"
15864 : "=m" (v->counter)
15865 : "m" (v->counter));
15866 }
15867 @@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15868 */
15869 static inline int atomic64_dec_and_test(atomic64_t *v)
15870 {
15871 - GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15872 + GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15873 }
15874
15875 /**
15876 @@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15877 */
15878 static inline int atomic64_inc_and_test(atomic64_t *v)
15879 {
15880 - GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15881 + GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15882 }
15883
15884 /**
15885 @@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15886 */
15887 static inline int atomic64_add_negative(long i, atomic64_t *v)
15888 {
15889 - GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15890 + GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15891 }
15892
15893 /**
15894 @@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15895 */
15896 static inline long atomic64_add_return(long i, atomic64_t *v)
15897 {
15898 + return i + xadd_check_overflow(&v->counter, i);
15899 +}
15900 +
15901 +/**
15902 + * atomic64_add_return_unchecked - add and return
15903 + * @i: integer value to add
15904 + * @v: pointer to type atomic64_unchecked_t
15905 + *
15906 + * Atomically adds @i to @v and returns @i + @v
15907 + */
15908 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15909 +{
15910 return i + xadd(&v->counter, i);
15911 }
15912
15913 @@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15914 }
15915
15916 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15917 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15918 +{
15919 + return atomic64_add_return_unchecked(1, v);
15920 +}
15921 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15922
15923 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15924 @@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15925 return cmpxchg(&v->counter, old, new);
15926 }
15927
15928 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15929 +{
15930 + return cmpxchg(&v->counter, old, new);
15931 +}
15932 +
15933 static inline long atomic64_xchg(atomic64_t *v, long new)
15934 {
15935 return xchg(&v->counter, new);
15936 @@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15937 */
15938 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15939 {
15940 - long c, old;
15941 + long c, old, new;
15942 c = atomic64_read(v);
15943 for (;;) {
15944 - if (unlikely(c == (u)))
15945 + if (unlikely(c == u))
15946 break;
15947 - old = atomic64_cmpxchg((v), c, c + (a));
15948 +
15949 + asm volatile("add %2,%0\n"
15950 +
15951 +#ifdef CONFIG_PAX_REFCOUNT
15952 + "jno 0f\n"
15953 + "sub %2,%0\n"
15954 + "int $4\n0:\n"
15955 + _ASM_EXTABLE(0b, 0b)
15956 +#endif
15957 +
15958 + : "=r" (new)
15959 + : "0" (c), "ir" (a));
15960 +
15961 + old = atomic64_cmpxchg(v, c, new);
15962 if (likely(old == c))
15963 break;
15964 c = old;
15965 }
15966 - return c != (u);
15967 + return c != u;
15968 }
15969
15970 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15971 diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
15972 index 0f4460b..fa1ee19 100644
15973 --- a/arch/x86/include/asm/barrier.h
15974 +++ b/arch/x86/include/asm/barrier.h
15975 @@ -107,7 +107,7 @@
15976 do { \
15977 compiletime_assert_atomic_type(*p); \
15978 smp_mb(); \
15979 - ACCESS_ONCE(*p) = (v); \
15980 + ACCESS_ONCE_RW(*p) = (v); \
15981 } while (0)
15982
15983 #define smp_load_acquire(p) \
15984 @@ -124,7 +124,7 @@ do { \
15985 do { \
15986 compiletime_assert_atomic_type(*p); \
15987 barrier(); \
15988 - ACCESS_ONCE(*p) = (v); \
15989 + ACCESS_ONCE_RW(*p) = (v); \
15990 } while (0)
15991
15992 #define smp_load_acquire(p) \
15993 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
15994 index cfe3b95..d01b118 100644
15995 --- a/arch/x86/include/asm/bitops.h
15996 +++ b/arch/x86/include/asm/bitops.h
15997 @@ -50,7 +50,7 @@
15998 * a mask operation on a byte.
15999 */
16000 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
16001 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
16002 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
16003 #define CONST_MASK(nr) (1 << ((nr) & 7))
16004
16005 /**
16006 @@ -203,7 +203,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
16007 */
16008 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
16009 {
16010 - GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16011 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16012 }
16013
16014 /**
16015 @@ -249,7 +249,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
16016 */
16017 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
16018 {
16019 - GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16020 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16021 }
16022
16023 /**
16024 @@ -302,7 +302,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
16025 */
16026 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
16027 {
16028 - GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16029 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16030 }
16031
16032 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
16033 @@ -343,7 +343,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
16034 *
16035 * Undefined if no bit exists, so code should check against 0 first.
16036 */
16037 -static inline unsigned long __ffs(unsigned long word)
16038 +static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
16039 {
16040 asm("rep; bsf %1,%0"
16041 : "=r" (word)
16042 @@ -357,7 +357,7 @@ static inline unsigned long __ffs(unsigned long word)
16043 *
16044 * Undefined if no zero exists, so code should check against ~0UL first.
16045 */
16046 -static inline unsigned long ffz(unsigned long word)
16047 +static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
16048 {
16049 asm("rep; bsf %1,%0"
16050 : "=r" (word)
16051 @@ -371,7 +371,7 @@ static inline unsigned long ffz(unsigned long word)
16052 *
16053 * Undefined if no set bit exists, so code should check against 0 first.
16054 */
16055 -static inline unsigned long __fls(unsigned long word)
16056 +static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
16057 {
16058 asm("bsr %1,%0"
16059 : "=r" (word)
16060 @@ -434,7 +434,7 @@ static inline int ffs(int x)
16061 * set bit if value is nonzero. The last (most significant) bit is
16062 * at position 32.
16063 */
16064 -static inline int fls(int x)
16065 +static inline int __intentional_overflow(-1) fls(int x)
16066 {
16067 int r;
16068
16069 @@ -476,7 +476,7 @@ static inline int fls(int x)
16070 * at position 64.
16071 */
16072 #ifdef CONFIG_X86_64
16073 -static __always_inline int fls64(__u64 x)
16074 +static __always_inline __intentional_overflow(-1) int fls64(__u64 x)
16075 {
16076 int bitpos = -1;
16077 /*
16078 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
16079 index 4fa687a..60f2d39 100644
16080 --- a/arch/x86/include/asm/boot.h
16081 +++ b/arch/x86/include/asm/boot.h
16082 @@ -6,10 +6,15 @@
16083 #include <uapi/asm/boot.h>
16084
16085 /* Physical address where kernel should be loaded. */
16086 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16087 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16088 + (CONFIG_PHYSICAL_ALIGN - 1)) \
16089 & ~(CONFIG_PHYSICAL_ALIGN - 1))
16090
16091 +#ifndef __ASSEMBLY__
16092 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
16093 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
16094 +#endif
16095 +
16096 /* Minimum kernel alignment, as a power of two */
16097 #ifdef CONFIG_X86_64
16098 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
16099 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
16100 index 48f99f1..d78ebf9 100644
16101 --- a/arch/x86/include/asm/cache.h
16102 +++ b/arch/x86/include/asm/cache.h
16103 @@ -5,12 +5,13 @@
16104
16105 /* L1 cache line size */
16106 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
16107 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
16108 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
16109
16110 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
16111 +#define __read_only __attribute__((__section__(".data..read_only")))
16112
16113 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
16114 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
16115 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
16116
16117 #ifdef CONFIG_X86_VSMP
16118 #ifdef CONFIG_SMP
16119 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
16120 index 9863ee3..4a1f8e1 100644
16121 --- a/arch/x86/include/asm/cacheflush.h
16122 +++ b/arch/x86/include/asm/cacheflush.h
16123 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
16124 unsigned long pg_flags = pg->flags & _PGMT_MASK;
16125
16126 if (pg_flags == _PGMT_DEFAULT)
16127 - return -1;
16128 + return ~0UL;
16129 else if (pg_flags == _PGMT_WC)
16130 return _PAGE_CACHE_WC;
16131 else if (pg_flags == _PGMT_UC_MINUS)
16132 diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
16133 index 76659b6..6e0b30a 100644
16134 --- a/arch/x86/include/asm/calling.h
16135 +++ b/arch/x86/include/asm/calling.h
16136 @@ -82,107 +82,117 @@ For 32-bit we have the following conventions - kernel is built with
16137 #define RSP 152
16138 #define SS 160
16139
16140 -#define ARGOFFSET R11
16141 -#define SWFRAME ORIG_RAX
16142 +#define ARGOFFSET R15
16143
16144 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1, rax_enosys=0
16145 - subq $9*8+\addskip, %rsp
16146 - CFI_ADJUST_CFA_OFFSET 9*8+\addskip
16147 - movq_cfi rdi, 8*8
16148 - movq_cfi rsi, 7*8
16149 - movq_cfi rdx, 6*8
16150 + subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
16151 + CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
16152 + movq_cfi rdi, RDI
16153 + movq_cfi rsi, RSI
16154 + movq_cfi rdx, RDX
16155
16156 .if \save_rcx
16157 - movq_cfi rcx, 5*8
16158 + movq_cfi rcx, RCX
16159 .endif
16160
16161 .if \rax_enosys
16162 - movq $-ENOSYS, 4*8(%rsp)
16163 + movq $-ENOSYS, RAX(%rsp)
16164 .else
16165 - movq_cfi rax, 4*8
16166 + movq_cfi rax, RAX
16167 .endif
16168
16169 .if \save_r891011
16170 - movq_cfi r8, 3*8
16171 - movq_cfi r9, 2*8
16172 - movq_cfi r10, 1*8
16173 - movq_cfi r11, 0*8
16174 + movq_cfi r8, R8
16175 + movq_cfi r9, R9
16176 + movq_cfi r10, R10
16177 + movq_cfi r11, R11
16178 .endif
16179
16180 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16181 + movq_cfi r12, R12
16182 +#endif
16183 +
16184 .endm
16185
16186 -#define ARG_SKIP (9*8)
16187 +#define ARG_SKIP ORIG_RAX
16188
16189 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
16190 rstor_r8910=1, rstor_rdx=1
16191 +
16192 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16193 + movq_cfi_restore R12, r12
16194 +#endif
16195 +
16196 .if \rstor_r11
16197 - movq_cfi_restore 0*8, r11
16198 + movq_cfi_restore R11, r11
16199 .endif
16200
16201 .if \rstor_r8910
16202 - movq_cfi_restore 1*8, r10
16203 - movq_cfi_restore 2*8, r9
16204 - movq_cfi_restore 3*8, r8
16205 + movq_cfi_restore R10, r10
16206 + movq_cfi_restore R9, r9
16207 + movq_cfi_restore R8, r8
16208 .endif
16209
16210 .if \rstor_rax
16211 - movq_cfi_restore 4*8, rax
16212 + movq_cfi_restore RAX, rax
16213 .endif
16214
16215 .if \rstor_rcx
16216 - movq_cfi_restore 5*8, rcx
16217 + movq_cfi_restore RCX, rcx
16218 .endif
16219
16220 .if \rstor_rdx
16221 - movq_cfi_restore 6*8, rdx
16222 + movq_cfi_restore RDX, rdx
16223 .endif
16224
16225 - movq_cfi_restore 7*8, rsi
16226 - movq_cfi_restore 8*8, rdi
16227 + movq_cfi_restore RSI, rsi
16228 + movq_cfi_restore RDI, rdi
16229
16230 - .if ARG_SKIP+\addskip > 0
16231 - addq $ARG_SKIP+\addskip, %rsp
16232 - CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
16233 + .if ORIG_RAX+\addskip > 0
16234 + addq $ORIG_RAX+\addskip, %rsp
16235 + CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
16236 .endif
16237 .endm
16238
16239 - .macro LOAD_ARGS offset, skiprax=0
16240 - movq \offset(%rsp), %r11
16241 - movq \offset+8(%rsp), %r10
16242 - movq \offset+16(%rsp), %r9
16243 - movq \offset+24(%rsp), %r8
16244 - movq \offset+40(%rsp), %rcx
16245 - movq \offset+48(%rsp), %rdx
16246 - movq \offset+56(%rsp), %rsi
16247 - movq \offset+64(%rsp), %rdi
16248 + .macro LOAD_ARGS skiprax=0
16249 + movq R11(%rsp), %r11
16250 + movq R10(%rsp), %r10
16251 + movq R9(%rsp), %r9
16252 + movq R8(%rsp), %r8
16253 + movq RCX(%rsp), %rcx
16254 + movq RDX(%rsp), %rdx
16255 + movq RSI(%rsp), %rsi
16256 + movq RDI(%rsp), %rdi
16257 .if \skiprax
16258 .else
16259 - movq \offset+72(%rsp), %rax
16260 + movq RAX(%rsp), %rax
16261 .endif
16262 .endm
16263
16264 -#define REST_SKIP (6*8)
16265 -
16266 .macro SAVE_REST
16267 - subq $REST_SKIP, %rsp
16268 - CFI_ADJUST_CFA_OFFSET REST_SKIP
16269 - movq_cfi rbx, 5*8
16270 - movq_cfi rbp, 4*8
16271 - movq_cfi r12, 3*8
16272 - movq_cfi r13, 2*8
16273 - movq_cfi r14, 1*8
16274 - movq_cfi r15, 0*8
16275 + movq_cfi rbx, RBX
16276 + movq_cfi rbp, RBP
16277 +
16278 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16279 + movq_cfi r12, R12
16280 +#endif
16281 +
16282 + movq_cfi r13, R13
16283 + movq_cfi r14, R14
16284 + movq_cfi r15, R15
16285 .endm
16286
16287 .macro RESTORE_REST
16288 - movq_cfi_restore 0*8, r15
16289 - movq_cfi_restore 1*8, r14
16290 - movq_cfi_restore 2*8, r13
16291 - movq_cfi_restore 3*8, r12
16292 - movq_cfi_restore 4*8, rbp
16293 - movq_cfi_restore 5*8, rbx
16294 - addq $REST_SKIP, %rsp
16295 - CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
16296 + movq_cfi_restore R15, r15
16297 + movq_cfi_restore R14, r14
16298 + movq_cfi_restore R13, r13
16299 +
16300 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16301 + movq_cfi_restore R12, r12
16302 +#endif
16303 +
16304 + movq_cfi_restore RBP, rbp
16305 + movq_cfi_restore RBX, rbx
16306 .endm
16307
16308 .macro SAVE_ALL
16309 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
16310 index f50de69..2b0a458 100644
16311 --- a/arch/x86/include/asm/checksum_32.h
16312 +++ b/arch/x86/include/asm/checksum_32.h
16313 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
16314 int len, __wsum sum,
16315 int *src_err_ptr, int *dst_err_ptr);
16316
16317 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
16318 + int len, __wsum sum,
16319 + int *src_err_ptr, int *dst_err_ptr);
16320 +
16321 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16322 + int len, __wsum sum,
16323 + int *src_err_ptr, int *dst_err_ptr);
16324 +
16325 /*
16326 * Note: when you get a NULL pointer exception here this means someone
16327 * passed in an incorrect kernel address to one of these functions.
16328 @@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16329
16330 might_sleep();
16331 stac();
16332 - ret = csum_partial_copy_generic((__force void *)src, dst,
16333 + ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16334 len, sum, err_ptr, NULL);
16335 clac();
16336
16337 @@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16338 might_sleep();
16339 if (access_ok(VERIFY_WRITE, dst, len)) {
16340 stac();
16341 - ret = csum_partial_copy_generic(src, (__force void *)dst,
16342 + ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16343 len, sum, NULL, err_ptr);
16344 clac();
16345 return ret;
16346 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16347 index 99c105d7..2f667ac 100644
16348 --- a/arch/x86/include/asm/cmpxchg.h
16349 +++ b/arch/x86/include/asm/cmpxchg.h
16350 @@ -16,8 +16,12 @@ extern void __cmpxchg_wrong_size(void)
16351 __compiletime_error("Bad argument size for cmpxchg");
16352 extern void __xadd_wrong_size(void)
16353 __compiletime_error("Bad argument size for xadd");
16354 +extern void __xadd_check_overflow_wrong_size(void)
16355 + __compiletime_error("Bad argument size for xadd_check_overflow");
16356 extern void __add_wrong_size(void)
16357 __compiletime_error("Bad argument size for add");
16358 +extern void __add_check_overflow_wrong_size(void)
16359 + __compiletime_error("Bad argument size for add_check_overflow");
16360
16361 /*
16362 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16363 @@ -69,6 +73,38 @@ extern void __add_wrong_size(void)
16364 __ret; \
16365 })
16366
16367 +#ifdef CONFIG_PAX_REFCOUNT
16368 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16369 + ({ \
16370 + __typeof__ (*(ptr)) __ret = (arg); \
16371 + switch (sizeof(*(ptr))) { \
16372 + case __X86_CASE_L: \
16373 + asm volatile (lock #op "l %0, %1\n" \
16374 + "jno 0f\n" \
16375 + "mov %0,%1\n" \
16376 + "int $4\n0:\n" \
16377 + _ASM_EXTABLE(0b, 0b) \
16378 + : "+r" (__ret), "+m" (*(ptr)) \
16379 + : : "memory", "cc"); \
16380 + break; \
16381 + case __X86_CASE_Q: \
16382 + asm volatile (lock #op "q %q0, %1\n" \
16383 + "jno 0f\n" \
16384 + "mov %0,%1\n" \
16385 + "int $4\n0:\n" \
16386 + _ASM_EXTABLE(0b, 0b) \
16387 + : "+r" (__ret), "+m" (*(ptr)) \
16388 + : : "memory", "cc"); \
16389 + break; \
16390 + default: \
16391 + __ ## op ## _check_overflow_wrong_size(); \
16392 + } \
16393 + __ret; \
16394 + })
16395 +#else
16396 +#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
16397 +#endif
16398 +
16399 /*
16400 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16401 * Since this is generally used to protect other memory information, we
16402 @@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
16403 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16404 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16405
16406 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16407 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16408 +
16409 #define __add(ptr, inc, lock) \
16410 ({ \
16411 __typeof__ (*(ptr)) __ret = (inc); \
16412 diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16413 index 59c6c40..5e0b22c 100644
16414 --- a/arch/x86/include/asm/compat.h
16415 +++ b/arch/x86/include/asm/compat.h
16416 @@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16417 typedef u32 compat_uint_t;
16418 typedef u32 compat_ulong_t;
16419 typedef u64 __attribute__((aligned(4))) compat_u64;
16420 -typedef u32 compat_uptr_t;
16421 +typedef u32 __user compat_uptr_t;
16422
16423 struct compat_timespec {
16424 compat_time_t tv_sec;
16425 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16426 index 0bb1335..8f1aec7 100644
16427 --- a/arch/x86/include/asm/cpufeature.h
16428 +++ b/arch/x86/include/asm/cpufeature.h
16429 @@ -207,7 +207,7 @@
16430 #define X86_FEATURE_PAUSEFILTER ( 8*32+13) /* AMD filtered pause intercept */
16431 #define X86_FEATURE_PFTHRESHOLD ( 8*32+14) /* AMD pause filter threshold */
16432 #define X86_FEATURE_VMMCALL ( 8*32+15) /* Prefer vmmcall to vmcall */
16433 -
16434 +#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16435
16436 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16437 #define X86_FEATURE_FSGSBASE ( 9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16438 @@ -215,7 +215,7 @@
16439 #define X86_FEATURE_BMI1 ( 9*32+ 3) /* 1st group bit manipulation extensions */
16440 #define X86_FEATURE_HLE ( 9*32+ 4) /* Hardware Lock Elision */
16441 #define X86_FEATURE_AVX2 ( 9*32+ 5) /* AVX2 instructions */
16442 -#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Protection */
16443 +#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Prevention */
16444 #define X86_FEATURE_BMI2 ( 9*32+ 8) /* 2nd group bit manipulation extensions */
16445 #define X86_FEATURE_ERMS ( 9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16446 #define X86_FEATURE_INVPCID ( 9*32+10) /* Invalidate Processor Context ID */
16447 @@ -383,6 +383,7 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
16448 #define cpu_has_cx16 boot_cpu_has(X86_FEATURE_CX16)
16449 #define cpu_has_eager_fpu boot_cpu_has(X86_FEATURE_EAGER_FPU)
16450 #define cpu_has_topoext boot_cpu_has(X86_FEATURE_TOPOEXT)
16451 +#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16452
16453 #if __GNUC__ >= 4
16454 extern void warn_pre_alternatives(void);
16455 @@ -434,7 +435,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16456
16457 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16458 t_warn:
16459 - warn_pre_alternatives();
16460 + if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16461 + warn_pre_alternatives();
16462 return false;
16463 #endif
16464
16465 @@ -454,7 +456,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16466 ".section .discard,\"aw\",@progbits\n"
16467 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16468 ".previous\n"
16469 - ".section .altinstr_replacement,\"ax\"\n"
16470 + ".section .altinstr_replacement,\"a\"\n"
16471 "3: movb $1,%0\n"
16472 "4:\n"
16473 ".previous\n"
16474 @@ -491,7 +493,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16475 " .byte 2b - 1b\n" /* src len */
16476 " .byte 4f - 3f\n" /* repl len */
16477 ".previous\n"
16478 - ".section .altinstr_replacement,\"ax\"\n"
16479 + ".section .altinstr_replacement,\"a\"\n"
16480 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16481 "4:\n"
16482 ".previous\n"
16483 @@ -524,7 +526,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16484 ".section .discard,\"aw\",@progbits\n"
16485 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16486 ".previous\n"
16487 - ".section .altinstr_replacement,\"ax\"\n"
16488 + ".section .altinstr_replacement,\"a\"\n"
16489 "3: movb $0,%0\n"
16490 "4:\n"
16491 ".previous\n"
16492 @@ -538,7 +540,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16493 ".section .discard,\"aw\",@progbits\n"
16494 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16495 ".previous\n"
16496 - ".section .altinstr_replacement,\"ax\"\n"
16497 + ".section .altinstr_replacement,\"a\"\n"
16498 "5: movb $1,%0\n"
16499 "6:\n"
16500 ".previous\n"
16501 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16502 index 50d033a..37deb26 100644
16503 --- a/arch/x86/include/asm/desc.h
16504 +++ b/arch/x86/include/asm/desc.h
16505 @@ -4,6 +4,7 @@
16506 #include <asm/desc_defs.h>
16507 #include <asm/ldt.h>
16508 #include <asm/mmu.h>
16509 +#include <asm/pgtable.h>
16510
16511 #include <linux/smp.h>
16512 #include <linux/percpu.h>
16513 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16514
16515 desc->type = (info->read_exec_only ^ 1) << 1;
16516 desc->type |= info->contents << 2;
16517 + desc->type |= info->seg_not_present ^ 1;
16518
16519 desc->s = 1;
16520 desc->dpl = 0x3;
16521 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16522 }
16523
16524 extern struct desc_ptr idt_descr;
16525 -extern gate_desc idt_table[];
16526 -extern struct desc_ptr debug_idt_descr;
16527 -extern gate_desc debug_idt_table[];
16528 -
16529 -struct gdt_page {
16530 - struct desc_struct gdt[GDT_ENTRIES];
16531 -} __attribute__((aligned(PAGE_SIZE)));
16532 -
16533 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16534 +extern gate_desc idt_table[IDT_ENTRIES];
16535 +extern const struct desc_ptr debug_idt_descr;
16536 +extern gate_desc debug_idt_table[IDT_ENTRIES];
16537
16538 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16539 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16540 {
16541 - return per_cpu(gdt_page, cpu).gdt;
16542 + return cpu_gdt_table[cpu];
16543 }
16544
16545 #ifdef CONFIG_X86_64
16546 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16547 unsigned long base, unsigned dpl, unsigned flags,
16548 unsigned short seg)
16549 {
16550 - gate->a = (seg << 16) | (base & 0xffff);
16551 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16552 + gate->gate.offset_low = base;
16553 + gate->gate.seg = seg;
16554 + gate->gate.reserved = 0;
16555 + gate->gate.type = type;
16556 + gate->gate.s = 0;
16557 + gate->gate.dpl = dpl;
16558 + gate->gate.p = 1;
16559 + gate->gate.offset_high = base >> 16;
16560 }
16561
16562 #endif
16563 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16564
16565 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16566 {
16567 + pax_open_kernel();
16568 memcpy(&idt[entry], gate, sizeof(*gate));
16569 + pax_close_kernel();
16570 }
16571
16572 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16573 {
16574 + pax_open_kernel();
16575 memcpy(&ldt[entry], desc, 8);
16576 + pax_close_kernel();
16577 }
16578
16579 static inline void
16580 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16581 default: size = sizeof(*gdt); break;
16582 }
16583
16584 + pax_open_kernel();
16585 memcpy(&gdt[entry], desc, size);
16586 + pax_close_kernel();
16587 }
16588
16589 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16590 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16591
16592 static inline void native_load_tr_desc(void)
16593 {
16594 + pax_open_kernel();
16595 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16596 + pax_close_kernel();
16597 }
16598
16599 static inline void native_load_gdt(const struct desc_ptr *dtr)
16600 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16601 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16602 unsigned int i;
16603
16604 + pax_open_kernel();
16605 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16606 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16607 + pax_close_kernel();
16608 }
16609
16610 #define _LDT_empty(info) \
16611 @@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16612 preempt_enable();
16613 }
16614
16615 -static inline unsigned long get_desc_base(const struct desc_struct *desc)
16616 +static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16617 {
16618 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16619 }
16620 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16621 }
16622
16623 #ifdef CONFIG_X86_64
16624 -static inline void set_nmi_gate(int gate, void *addr)
16625 +static inline void set_nmi_gate(int gate, const void *addr)
16626 {
16627 gate_desc s;
16628
16629 @@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16630 #endif
16631
16632 #ifdef CONFIG_TRACING
16633 -extern struct desc_ptr trace_idt_descr;
16634 -extern gate_desc trace_idt_table[];
16635 +extern const struct desc_ptr trace_idt_descr;
16636 +extern gate_desc trace_idt_table[IDT_ENTRIES];
16637 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16638 {
16639 write_idt_entry(trace_idt_table, entry, gate);
16640 }
16641
16642 -static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16643 +static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16644 unsigned dpl, unsigned ist, unsigned seg)
16645 {
16646 gate_desc s;
16647 @@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16648 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16649 #endif
16650
16651 -static inline void _set_gate(int gate, unsigned type, void *addr,
16652 +static inline void _set_gate(int gate, unsigned type, const void *addr,
16653 unsigned dpl, unsigned ist, unsigned seg)
16654 {
16655 gate_desc s;
16656 @@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16657 #define set_intr_gate(n, addr) \
16658 do { \
16659 BUG_ON((unsigned)n > 0xFF); \
16660 - _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16661 + _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16662 __KERNEL_CS); \
16663 - _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16664 + _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16665 0, 0, __KERNEL_CS); \
16666 } while (0)
16667
16668 @@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16669 /*
16670 * This routine sets up an interrupt gate at directory privilege level 3.
16671 */
16672 -static inline void set_system_intr_gate(unsigned int n, void *addr)
16673 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
16674 {
16675 BUG_ON((unsigned)n > 0xFF);
16676 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16677 }
16678
16679 -static inline void set_system_trap_gate(unsigned int n, void *addr)
16680 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
16681 {
16682 BUG_ON((unsigned)n > 0xFF);
16683 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16684 }
16685
16686 -static inline void set_trap_gate(unsigned int n, void *addr)
16687 +static inline void set_trap_gate(unsigned int n, const void *addr)
16688 {
16689 BUG_ON((unsigned)n > 0xFF);
16690 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16691 @@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16692 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16693 {
16694 BUG_ON((unsigned)n > 0xFF);
16695 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16696 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16697 }
16698
16699 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16700 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16701 {
16702 BUG_ON((unsigned)n > 0xFF);
16703 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16704 }
16705
16706 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16707 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16708 {
16709 BUG_ON((unsigned)n > 0xFF);
16710 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16711 @@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16712 else
16713 load_idt((const struct desc_ptr *)&idt_descr);
16714 }
16715 +
16716 +#ifdef CONFIG_X86_32
16717 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16718 +{
16719 + struct desc_struct d;
16720 +
16721 + if (likely(limit))
16722 + limit = (limit - 1UL) >> PAGE_SHIFT;
16723 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
16724 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16725 +}
16726 +#endif
16727 +
16728 #endif /* _ASM_X86_DESC_H */
16729 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16730 index 278441f..b95a174 100644
16731 --- a/arch/x86/include/asm/desc_defs.h
16732 +++ b/arch/x86/include/asm/desc_defs.h
16733 @@ -31,6 +31,12 @@ struct desc_struct {
16734 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16735 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16736 };
16737 + struct {
16738 + u16 offset_low;
16739 + u16 seg;
16740 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16741 + unsigned offset_high: 16;
16742 + } gate;
16743 };
16744 } __attribute__((packed));
16745
16746 diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16747 index ced283a..ffe04cc 100644
16748 --- a/arch/x86/include/asm/div64.h
16749 +++ b/arch/x86/include/asm/div64.h
16750 @@ -39,7 +39,7 @@
16751 __mod; \
16752 })
16753
16754 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16755 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16756 {
16757 union {
16758 u64 v64;
16759 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16760 index ca3347a..1a5082a 100644
16761 --- a/arch/x86/include/asm/elf.h
16762 +++ b/arch/x86/include/asm/elf.h
16763 @@ -75,9 +75,6 @@ typedef struct user_fxsr_struct elf_fpxregset_t;
16764
16765 #include <asm/vdso.h>
16766
16767 -#ifdef CONFIG_X86_64
16768 -extern unsigned int vdso64_enabled;
16769 -#endif
16770 #if defined(CONFIG_X86_32) || defined(CONFIG_COMPAT)
16771 extern unsigned int vdso32_enabled;
16772 #endif
16773 @@ -249,7 +246,25 @@ extern int force_personality32;
16774 the loader. We need to make sure that it is out of the way of the program
16775 that it will "exec", and that there is sufficient room for the brk. */
16776
16777 +#ifdef CONFIG_PAX_SEGMEXEC
16778 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16779 +#else
16780 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16781 +#endif
16782 +
16783 +#ifdef CONFIG_PAX_ASLR
16784 +#ifdef CONFIG_X86_32
16785 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16786 +
16787 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16788 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16789 +#else
16790 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
16791 +
16792 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16793 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16794 +#endif
16795 +#endif
16796
16797 /* This yields a mask that user programs can use to figure out what
16798 instruction set this CPU supports. This could be done in user space,
16799 @@ -298,17 +313,13 @@ do { \
16800
16801 #define ARCH_DLINFO \
16802 do { \
16803 - if (vdso64_enabled) \
16804 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16805 - (unsigned long __force)current->mm->context.vdso); \
16806 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16807 } while (0)
16808
16809 /* As a historical oddity, the x32 and x86_64 vDSOs are controlled together. */
16810 #define ARCH_DLINFO_X32 \
16811 do { \
16812 - if (vdso64_enabled) \
16813 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16814 - (unsigned long __force)current->mm->context.vdso); \
16815 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16816 } while (0)
16817
16818 #define AT_SYSINFO 32
16819 @@ -323,10 +334,10 @@ else \
16820
16821 #endif /* !CONFIG_X86_32 */
16822
16823 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16824 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16825
16826 #define VDSO_ENTRY \
16827 - ((unsigned long)current->mm->context.vdso + \
16828 + (current->mm->context.vdso + \
16829 selected_vdso32->sym___kernel_vsyscall)
16830
16831 struct linux_binprm;
16832 @@ -338,9 +349,6 @@ extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
16833 int uses_interp);
16834 #define compat_arch_setup_additional_pages compat_arch_setup_additional_pages
16835
16836 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16837 -#define arch_randomize_brk arch_randomize_brk
16838 -
16839 /*
16840 * True on X86_32 or when emulating IA32 on X86_64
16841 */
16842 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16843 index 77a99ac..39ff7f5 100644
16844 --- a/arch/x86/include/asm/emergency-restart.h
16845 +++ b/arch/x86/include/asm/emergency-restart.h
16846 @@ -1,6 +1,6 @@
16847 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16848 #define _ASM_X86_EMERGENCY_RESTART_H
16849
16850 -extern void machine_emergency_restart(void);
16851 +extern void machine_emergency_restart(void) __noreturn;
16852
16853 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16854 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16855 index 1c7eefe..d0e4702 100644
16856 --- a/arch/x86/include/asm/floppy.h
16857 +++ b/arch/x86/include/asm/floppy.h
16858 @@ -229,18 +229,18 @@ static struct fd_routine_l {
16859 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16860 } fd_routine[] = {
16861 {
16862 - request_dma,
16863 - free_dma,
16864 - get_dma_residue,
16865 - dma_mem_alloc,
16866 - hard_dma_setup
16867 + ._request_dma = request_dma,
16868 + ._free_dma = free_dma,
16869 + ._get_dma_residue = get_dma_residue,
16870 + ._dma_mem_alloc = dma_mem_alloc,
16871 + ._dma_setup = hard_dma_setup
16872 },
16873 {
16874 - vdma_request_dma,
16875 - vdma_nop,
16876 - vdma_get_dma_residue,
16877 - vdma_mem_alloc,
16878 - vdma_dma_setup
16879 + ._request_dma = vdma_request_dma,
16880 + ._free_dma = vdma_nop,
16881 + ._get_dma_residue = vdma_get_dma_residue,
16882 + ._dma_mem_alloc = vdma_mem_alloc,
16883 + ._dma_setup = vdma_dma_setup
16884 }
16885 };
16886
16887 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16888 index e97622f..d0ba77a 100644
16889 --- a/arch/x86/include/asm/fpu-internal.h
16890 +++ b/arch/x86/include/asm/fpu-internal.h
16891 @@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16892 #define user_insn(insn, output, input...) \
16893 ({ \
16894 int err; \
16895 + pax_open_userland(); \
16896 asm volatile(ASM_STAC "\n" \
16897 - "1:" #insn "\n\t" \
16898 + "1:" \
16899 + __copyuser_seg \
16900 + #insn "\n\t" \
16901 "2: " ASM_CLAC "\n" \
16902 ".section .fixup,\"ax\"\n" \
16903 "3: movl $-1,%[err]\n" \
16904 @@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16905 _ASM_EXTABLE(1b, 3b) \
16906 : [err] "=r" (err), output \
16907 : "0"(0), input); \
16908 + pax_close_userland(); \
16909 err; \
16910 })
16911
16912 @@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16913 "fnclex\n\t"
16914 "emms\n\t"
16915 "fildl %P[addr]" /* set F?P to defined value */
16916 - : : [addr] "m" (tsk->thread.fpu.has_fpu));
16917 + : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16918 }
16919
16920 return fpu_restore_checking(&tsk->thread.fpu);
16921 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16922 index b4c1f54..e290c08 100644
16923 --- a/arch/x86/include/asm/futex.h
16924 +++ b/arch/x86/include/asm/futex.h
16925 @@ -12,6 +12,7 @@
16926 #include <asm/smap.h>
16927
16928 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16929 + typecheck(u32 __user *, uaddr); \
16930 asm volatile("\t" ASM_STAC "\n" \
16931 "1:\t" insn "\n" \
16932 "2:\t" ASM_CLAC "\n" \
16933 @@ -20,15 +21,16 @@
16934 "\tjmp\t2b\n" \
16935 "\t.previous\n" \
16936 _ASM_EXTABLE(1b, 3b) \
16937 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16938 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16939 : "i" (-EFAULT), "0" (oparg), "1" (0))
16940
16941 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16942 + typecheck(u32 __user *, uaddr); \
16943 asm volatile("\t" ASM_STAC "\n" \
16944 "1:\tmovl %2, %0\n" \
16945 "\tmovl\t%0, %3\n" \
16946 "\t" insn "\n" \
16947 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16948 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16949 "\tjnz\t1b\n" \
16950 "3:\t" ASM_CLAC "\n" \
16951 "\t.section .fixup,\"ax\"\n" \
16952 @@ -38,7 +40,7 @@
16953 _ASM_EXTABLE(1b, 4b) \
16954 _ASM_EXTABLE(2b, 4b) \
16955 : "=&a" (oldval), "=&r" (ret), \
16956 - "+m" (*uaddr), "=&r" (tem) \
16957 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16958 : "r" (oparg), "i" (-EFAULT), "1" (0))
16959
16960 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16961 @@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16962
16963 pagefault_disable();
16964
16965 + pax_open_userland();
16966 switch (op) {
16967 case FUTEX_OP_SET:
16968 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16969 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16970 break;
16971 case FUTEX_OP_ADD:
16972 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16973 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16974 uaddr, oparg);
16975 break;
16976 case FUTEX_OP_OR:
16977 @@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16978 default:
16979 ret = -ENOSYS;
16980 }
16981 + pax_close_userland();
16982
16983 pagefault_enable();
16984
16985 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16986 index 4615906..788c817 100644
16987 --- a/arch/x86/include/asm/hw_irq.h
16988 +++ b/arch/x86/include/asm/hw_irq.h
16989 @@ -164,8 +164,8 @@ extern void setup_ioapic_dest(void);
16990 extern void enable_IO_APIC(void);
16991
16992 /* Statistics */
16993 -extern atomic_t irq_err_count;
16994 -extern atomic_t irq_mis_count;
16995 +extern atomic_unchecked_t irq_err_count;
16996 +extern atomic_unchecked_t irq_mis_count;
16997
16998 /* EISA */
16999 extern void eisa_set_level_irq(unsigned int irq);
17000 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
17001 index ccffa53..3c90c87 100644
17002 --- a/arch/x86/include/asm/i8259.h
17003 +++ b/arch/x86/include/asm/i8259.h
17004 @@ -62,7 +62,7 @@ struct legacy_pic {
17005 void (*init)(int auto_eoi);
17006 int (*irq_pending)(unsigned int irq);
17007 void (*make_irq)(unsigned int irq);
17008 -};
17009 +} __do_const;
17010
17011 extern struct legacy_pic *legacy_pic;
17012 extern struct legacy_pic null_legacy_pic;
17013 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
17014 index b8237d8..3e8864e 100644
17015 --- a/arch/x86/include/asm/io.h
17016 +++ b/arch/x86/include/asm/io.h
17017 @@ -52,12 +52,12 @@ static inline void name(type val, volatile void __iomem *addr) \
17018 "m" (*(volatile type __force *)addr) barrier); }
17019
17020 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
17021 -build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
17022 -build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
17023 +build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
17024 +build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
17025
17026 build_mmio_read(__readb, "b", unsigned char, "=q", )
17027 -build_mmio_read(__readw, "w", unsigned short, "=r", )
17028 -build_mmio_read(__readl, "l", unsigned int, "=r", )
17029 +build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
17030 +build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
17031
17032 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
17033 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
17034 @@ -109,7 +109,7 @@ build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
17035 * this function
17036 */
17037
17038 -static inline phys_addr_t virt_to_phys(volatile void *address)
17039 +static inline phys_addr_t __intentional_overflow(-1) virt_to_phys(volatile void *address)
17040 {
17041 return __pa(address);
17042 }
17043 @@ -185,7 +185,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
17044 return ioremap_nocache(offset, size);
17045 }
17046
17047 -extern void iounmap(volatile void __iomem *addr);
17048 +extern void iounmap(const volatile void __iomem *addr);
17049
17050 extern void set_iounmap_nonlazy(void);
17051
17052 @@ -195,6 +195,17 @@ extern void set_iounmap_nonlazy(void);
17053
17054 #include <linux/vmalloc.h>
17055
17056 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
17057 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
17058 +{
17059 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17060 +}
17061 +
17062 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
17063 +{
17064 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17065 +}
17066 +
17067 /*
17068 * Convert a virtual cached pointer to an uncached pointer
17069 */
17070 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
17071 index 0a8b519..80e7d5b 100644
17072 --- a/arch/x86/include/asm/irqflags.h
17073 +++ b/arch/x86/include/asm/irqflags.h
17074 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
17075 sti; \
17076 sysexit
17077
17078 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
17079 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
17080 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
17081 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
17082 +
17083 #else
17084 #define INTERRUPT_RETURN iret
17085 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
17086 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
17087 index 4421b5d..8543006 100644
17088 --- a/arch/x86/include/asm/kprobes.h
17089 +++ b/arch/x86/include/asm/kprobes.h
17090 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
17091 #define RELATIVEJUMP_SIZE 5
17092 #define RELATIVECALL_OPCODE 0xe8
17093 #define RELATIVE_ADDR_SIZE 4
17094 -#define MAX_STACK_SIZE 64
17095 -#define MIN_STACK_SIZE(ADDR) \
17096 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
17097 - THREAD_SIZE - (unsigned long)(ADDR))) \
17098 - ? (MAX_STACK_SIZE) \
17099 - : (((unsigned long)current_thread_info()) + \
17100 - THREAD_SIZE - (unsigned long)(ADDR)))
17101 +#define MAX_STACK_SIZE 64UL
17102 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
17103
17104 #define flush_insn_slot(p) do { } while (0)
17105
17106 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
17107 index 6ed0c30..74fb6c3 100644
17108 --- a/arch/x86/include/asm/kvm_host.h
17109 +++ b/arch/x86/include/asm/kvm_host.h
17110 @@ -51,6 +51,7 @@
17111 | X86_CR0_NW | X86_CR0_CD | X86_CR0_PG))
17112
17113 #define CR3_L_MODE_RESERVED_BITS 0xFFFFFF0000000000ULL
17114 +#define CR3_PCID_INVD (1UL << 63)
17115 #define CR4_RESERVED_BITS \
17116 (~(unsigned long)(X86_CR4_VME | X86_CR4_PVI | X86_CR4_TSD | X86_CR4_DE\
17117 | X86_CR4_PSE | X86_CR4_PAE | X86_CR4_MCE \
17118 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
17119 index 4ad6560..75c7bdd 100644
17120 --- a/arch/x86/include/asm/local.h
17121 +++ b/arch/x86/include/asm/local.h
17122 @@ -10,33 +10,97 @@ typedef struct {
17123 atomic_long_t a;
17124 } local_t;
17125
17126 +typedef struct {
17127 + atomic_long_unchecked_t a;
17128 +} local_unchecked_t;
17129 +
17130 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
17131
17132 #define local_read(l) atomic_long_read(&(l)->a)
17133 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
17134 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
17135 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
17136
17137 static inline void local_inc(local_t *l)
17138 {
17139 - asm volatile(_ASM_INC "%0"
17140 + asm volatile(_ASM_INC "%0\n"
17141 +
17142 +#ifdef CONFIG_PAX_REFCOUNT
17143 + "jno 0f\n"
17144 + _ASM_DEC "%0\n"
17145 + "int $4\n0:\n"
17146 + _ASM_EXTABLE(0b, 0b)
17147 +#endif
17148 +
17149 + : "+m" (l->a.counter));
17150 +}
17151 +
17152 +static inline void local_inc_unchecked(local_unchecked_t *l)
17153 +{
17154 + asm volatile(_ASM_INC "%0\n"
17155 : "+m" (l->a.counter));
17156 }
17157
17158 static inline void local_dec(local_t *l)
17159 {
17160 - asm volatile(_ASM_DEC "%0"
17161 + asm volatile(_ASM_DEC "%0\n"
17162 +
17163 +#ifdef CONFIG_PAX_REFCOUNT
17164 + "jno 0f\n"
17165 + _ASM_INC "%0\n"
17166 + "int $4\n0:\n"
17167 + _ASM_EXTABLE(0b, 0b)
17168 +#endif
17169 +
17170 + : "+m" (l->a.counter));
17171 +}
17172 +
17173 +static inline void local_dec_unchecked(local_unchecked_t *l)
17174 +{
17175 + asm volatile(_ASM_DEC "%0\n"
17176 : "+m" (l->a.counter));
17177 }
17178
17179 static inline void local_add(long i, local_t *l)
17180 {
17181 - asm volatile(_ASM_ADD "%1,%0"
17182 + asm volatile(_ASM_ADD "%1,%0\n"
17183 +
17184 +#ifdef CONFIG_PAX_REFCOUNT
17185 + "jno 0f\n"
17186 + _ASM_SUB "%1,%0\n"
17187 + "int $4\n0:\n"
17188 + _ASM_EXTABLE(0b, 0b)
17189 +#endif
17190 +
17191 + : "+m" (l->a.counter)
17192 + : "ir" (i));
17193 +}
17194 +
17195 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
17196 +{
17197 + asm volatile(_ASM_ADD "%1,%0\n"
17198 : "+m" (l->a.counter)
17199 : "ir" (i));
17200 }
17201
17202 static inline void local_sub(long i, local_t *l)
17203 {
17204 - asm volatile(_ASM_SUB "%1,%0"
17205 + asm volatile(_ASM_SUB "%1,%0\n"
17206 +
17207 +#ifdef CONFIG_PAX_REFCOUNT
17208 + "jno 0f\n"
17209 + _ASM_ADD "%1,%0\n"
17210 + "int $4\n0:\n"
17211 + _ASM_EXTABLE(0b, 0b)
17212 +#endif
17213 +
17214 + : "+m" (l->a.counter)
17215 + : "ir" (i));
17216 +}
17217 +
17218 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
17219 +{
17220 + asm volatile(_ASM_SUB "%1,%0\n"
17221 : "+m" (l->a.counter)
17222 : "ir" (i));
17223 }
17224 @@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
17225 */
17226 static inline int local_sub_and_test(long i, local_t *l)
17227 {
17228 - GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
17229 + GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
17230 }
17231
17232 /**
17233 @@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
17234 */
17235 static inline int local_dec_and_test(local_t *l)
17236 {
17237 - GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
17238 + GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
17239 }
17240
17241 /**
17242 @@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
17243 */
17244 static inline int local_inc_and_test(local_t *l)
17245 {
17246 - GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
17247 + GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
17248 }
17249
17250 /**
17251 @@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
17252 */
17253 static inline int local_add_negative(long i, local_t *l)
17254 {
17255 - GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
17256 + GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
17257 }
17258
17259 /**
17260 @@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
17261 static inline long local_add_return(long i, local_t *l)
17262 {
17263 long __i = i;
17264 + asm volatile(_ASM_XADD "%0, %1\n"
17265 +
17266 +#ifdef CONFIG_PAX_REFCOUNT
17267 + "jno 0f\n"
17268 + _ASM_MOV "%0,%1\n"
17269 + "int $4\n0:\n"
17270 + _ASM_EXTABLE(0b, 0b)
17271 +#endif
17272 +
17273 + : "+r" (i), "+m" (l->a.counter)
17274 + : : "memory");
17275 + return i + __i;
17276 +}
17277 +
17278 +/**
17279 + * local_add_return_unchecked - add and return
17280 + * @i: integer value to add
17281 + * @l: pointer to type local_unchecked_t
17282 + *
17283 + * Atomically adds @i to @l and returns @i + @l
17284 + */
17285 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
17286 +{
17287 + long __i = i;
17288 asm volatile(_ASM_XADD "%0, %1;"
17289 : "+r" (i), "+m" (l->a.counter)
17290 : : "memory");
17291 @@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
17292
17293 #define local_cmpxchg(l, o, n) \
17294 (cmpxchg_local(&((l)->a.counter), (o), (n)))
17295 +#define local_cmpxchg_unchecked(l, o, n) \
17296 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
17297 /* Always has a lock prefix */
17298 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
17299
17300 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
17301 new file mode 100644
17302 index 0000000..2bfd3ba
17303 --- /dev/null
17304 +++ b/arch/x86/include/asm/mman.h
17305 @@ -0,0 +1,15 @@
17306 +#ifndef _X86_MMAN_H
17307 +#define _X86_MMAN_H
17308 +
17309 +#include <uapi/asm/mman.h>
17310 +
17311 +#ifdef __KERNEL__
17312 +#ifndef __ASSEMBLY__
17313 +#ifdef CONFIG_X86_32
17314 +#define arch_mmap_check i386_mmap_check
17315 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
17316 +#endif
17317 +#endif
17318 +#endif
17319 +
17320 +#endif /* X86_MMAN_H */
17321 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
17322 index 876e74e..e20bfb1 100644
17323 --- a/arch/x86/include/asm/mmu.h
17324 +++ b/arch/x86/include/asm/mmu.h
17325 @@ -9,7 +9,7 @@
17326 * we put the segment information here.
17327 */
17328 typedef struct {
17329 - void *ldt;
17330 + struct desc_struct *ldt;
17331 int size;
17332
17333 #ifdef CONFIG_X86_64
17334 @@ -18,7 +18,19 @@ typedef struct {
17335 #endif
17336
17337 struct mutex lock;
17338 - void __user *vdso;
17339 + unsigned long vdso;
17340 +
17341 +#ifdef CONFIG_X86_32
17342 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17343 + unsigned long user_cs_base;
17344 + unsigned long user_cs_limit;
17345 +
17346 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17347 + cpumask_t cpu_user_cs_mask;
17348 +#endif
17349 +
17350 +#endif
17351 +#endif
17352 } mm_context_t;
17353
17354 #ifdef CONFIG_SMP
17355 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17356 index 166af2a..648c200 100644
17357 --- a/arch/x86/include/asm/mmu_context.h
17358 +++ b/arch/x86/include/asm/mmu_context.h
17359 @@ -28,6 +28,20 @@ void destroy_context(struct mm_struct *mm);
17360
17361 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17362 {
17363 +
17364 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17365 + if (!(static_cpu_has(X86_FEATURE_PCID))) {
17366 + unsigned int i;
17367 + pgd_t *pgd;
17368 +
17369 + pax_open_kernel();
17370 + pgd = get_cpu_pgd(smp_processor_id(), kernel);
17371 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17372 + set_pgd_batched(pgd+i, native_make_pgd(0));
17373 + pax_close_kernel();
17374 + }
17375 +#endif
17376 +
17377 #ifdef CONFIG_SMP
17378 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17379 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17380 @@ -38,16 +52,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17381 struct task_struct *tsk)
17382 {
17383 unsigned cpu = smp_processor_id();
17384 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17385 + int tlbstate = TLBSTATE_OK;
17386 +#endif
17387
17388 if (likely(prev != next)) {
17389 #ifdef CONFIG_SMP
17390 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17391 + tlbstate = this_cpu_read(cpu_tlbstate.state);
17392 +#endif
17393 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17394 this_cpu_write(cpu_tlbstate.active_mm, next);
17395 #endif
17396 cpumask_set_cpu(cpu, mm_cpumask(next));
17397
17398 /* Re-load page tables */
17399 +#ifdef CONFIG_PAX_PER_CPU_PGD
17400 + pax_open_kernel();
17401 +
17402 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17403 + if (static_cpu_has(X86_FEATURE_PCID))
17404 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17405 + else
17406 +#endif
17407 +
17408 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17409 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17410 + pax_close_kernel();
17411 + 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));
17412 +
17413 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17414 + if (static_cpu_has(X86_FEATURE_PCID)) {
17415 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17416 + u64 descriptor[2];
17417 + descriptor[0] = PCID_USER;
17418 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17419 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17420 + descriptor[0] = PCID_KERNEL;
17421 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17422 + }
17423 + } else {
17424 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17425 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17426 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17427 + else
17428 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17429 + }
17430 + } else
17431 +#endif
17432 +
17433 + load_cr3(get_cpu_pgd(cpu, kernel));
17434 +#else
17435 load_cr3(next->pgd);
17436 +#endif
17437 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
17438
17439 /* Stop flush ipis for the previous mm */
17440 @@ -56,9 +113,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17441 /* Load the LDT, if the LDT is different: */
17442 if (unlikely(prev->context.ldt != next->context.ldt))
17443 load_LDT_nolock(&next->context);
17444 +
17445 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17446 + if (!(__supported_pte_mask & _PAGE_NX)) {
17447 + smp_mb__before_atomic();
17448 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17449 + smp_mb__after_atomic();
17450 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17451 + }
17452 +#endif
17453 +
17454 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17455 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17456 + prev->context.user_cs_limit != next->context.user_cs_limit))
17457 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17458 +#ifdef CONFIG_SMP
17459 + else if (unlikely(tlbstate != TLBSTATE_OK))
17460 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17461 +#endif
17462 +#endif
17463 +
17464 }
17465 + else {
17466 +
17467 +#ifdef CONFIG_PAX_PER_CPU_PGD
17468 + pax_open_kernel();
17469 +
17470 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17471 + if (static_cpu_has(X86_FEATURE_PCID))
17472 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17473 + else
17474 +#endif
17475 +
17476 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17477 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17478 + pax_close_kernel();
17479 + 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));
17480 +
17481 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17482 + if (static_cpu_has(X86_FEATURE_PCID)) {
17483 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17484 + u64 descriptor[2];
17485 + descriptor[0] = PCID_USER;
17486 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17487 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17488 + descriptor[0] = PCID_KERNEL;
17489 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17490 + }
17491 + } else {
17492 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17493 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17494 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17495 + else
17496 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17497 + }
17498 + } else
17499 +#endif
17500 +
17501 + load_cr3(get_cpu_pgd(cpu, kernel));
17502 +#endif
17503 +
17504 #ifdef CONFIG_SMP
17505 - else {
17506 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17507 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17508
17509 @@ -75,12 +190,29 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17510 * tlb flush IPI delivery. We must reload CR3
17511 * to make sure to use no freed page tables.
17512 */
17513 +
17514 +#ifndef CONFIG_PAX_PER_CPU_PGD
17515 load_cr3(next->pgd);
17516 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
17517 +#endif
17518 +
17519 load_LDT_nolock(&next->context);
17520 +
17521 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17522 + if (!(__supported_pte_mask & _PAGE_NX))
17523 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17524 +#endif
17525 +
17526 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17527 +#ifdef CONFIG_PAX_PAGEEXEC
17528 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17529 +#endif
17530 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17531 +#endif
17532 +
17533 }
17534 +#endif
17535 }
17536 -#endif
17537 }
17538
17539 #define activate_mm(prev, next) \
17540 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17541 index e3b7819..b257c64 100644
17542 --- a/arch/x86/include/asm/module.h
17543 +++ b/arch/x86/include/asm/module.h
17544 @@ -5,6 +5,7 @@
17545
17546 #ifdef CONFIG_X86_64
17547 /* X86_64 does not define MODULE_PROC_FAMILY */
17548 +#define MODULE_PROC_FAMILY ""
17549 #elif defined CONFIG_M486
17550 #define MODULE_PROC_FAMILY "486 "
17551 #elif defined CONFIG_M586
17552 @@ -57,8 +58,20 @@
17553 #error unknown processor family
17554 #endif
17555
17556 -#ifdef CONFIG_X86_32
17557 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17558 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17559 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17560 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17561 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17562 +#else
17563 +#define MODULE_PAX_KERNEXEC ""
17564 #endif
17565
17566 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17567 +#define MODULE_PAX_UDEREF "UDEREF "
17568 +#else
17569 +#define MODULE_PAX_UDEREF ""
17570 +#endif
17571 +
17572 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17573 +
17574 #endif /* _ASM_X86_MODULE_H */
17575 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17576 index 5f2fc44..106caa6 100644
17577 --- a/arch/x86/include/asm/nmi.h
17578 +++ b/arch/x86/include/asm/nmi.h
17579 @@ -36,26 +36,35 @@ enum {
17580
17581 typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
17582
17583 +struct nmiaction;
17584 +
17585 +struct nmiwork {
17586 + const struct nmiaction *action;
17587 + u64 max_duration;
17588 + struct irq_work irq_work;
17589 +};
17590 +
17591 struct nmiaction {
17592 struct list_head list;
17593 nmi_handler_t handler;
17594 - u64 max_duration;
17595 - struct irq_work irq_work;
17596 unsigned long flags;
17597 const char *name;
17598 -};
17599 + struct nmiwork *work;
17600 +} __do_const;
17601
17602 #define register_nmi_handler(t, fn, fg, n, init...) \
17603 ({ \
17604 - static struct nmiaction init fn##_na = { \
17605 + static struct nmiwork fn##_nw; \
17606 + static const struct nmiaction init fn##_na = { \
17607 .handler = (fn), \
17608 .name = (n), \
17609 .flags = (fg), \
17610 + .work = &fn##_nw, \
17611 }; \
17612 __register_nmi_handler((t), &fn##_na); \
17613 })
17614
17615 -int __register_nmi_handler(unsigned int, struct nmiaction *);
17616 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
17617
17618 void unregister_nmi_handler(unsigned int, const char *);
17619
17620 diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17621 index 802dde3..9183e68 100644
17622 --- a/arch/x86/include/asm/page.h
17623 +++ b/arch/x86/include/asm/page.h
17624 @@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17625 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17626
17627 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17628 +#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17629
17630 #define __boot_va(x) __va(x)
17631 #define __boot_pa(x) __pa(x)
17632 @@ -60,11 +61,21 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17633 * virt_to_page(kaddr) returns a valid pointer if and only if
17634 * virt_addr_valid(kaddr) returns true.
17635 */
17636 -#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17637 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
17638 extern bool __virt_addr_valid(unsigned long kaddr);
17639 #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr))
17640
17641 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
17642 +#define virt_to_page(kaddr) \
17643 + ({ \
17644 + const void *__kaddr = (const void *)(kaddr); \
17645 + BUG_ON(!virt_addr_valid(__kaddr)); \
17646 + pfn_to_page(__pa(__kaddr) >> PAGE_SHIFT); \
17647 + })
17648 +#else
17649 +#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17650 +#endif
17651 +
17652 #endif /* __ASSEMBLY__ */
17653
17654 #include <asm-generic/memory_model.h>
17655 diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17656 index f408caf..4a0455e 100644
17657 --- a/arch/x86/include/asm/page_64.h
17658 +++ b/arch/x86/include/asm/page_64.h
17659 @@ -7,9 +7,9 @@
17660
17661 /* duplicated to the one in bootmem.h */
17662 extern unsigned long max_pfn;
17663 -extern unsigned long phys_base;
17664 +extern const unsigned long phys_base;
17665
17666 -static inline unsigned long __phys_addr_nodebug(unsigned long x)
17667 +static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17668 {
17669 unsigned long y = x - __START_KERNEL_map;
17670
17671 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17672 index cd6e1610..70f4418 100644
17673 --- a/arch/x86/include/asm/paravirt.h
17674 +++ b/arch/x86/include/asm/paravirt.h
17675 @@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17676 return (pmd_t) { ret };
17677 }
17678
17679 -static inline pmdval_t pmd_val(pmd_t pmd)
17680 +static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17681 {
17682 pmdval_t ret;
17683
17684 @@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17685 val);
17686 }
17687
17688 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17689 +{
17690 + pgdval_t val = native_pgd_val(pgd);
17691 +
17692 + if (sizeof(pgdval_t) > sizeof(long))
17693 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17694 + val, (u64)val >> 32);
17695 + else
17696 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17697 + val);
17698 +}
17699 +
17700 static inline void pgd_clear(pgd_t *pgdp)
17701 {
17702 set_pgd(pgdp, __pgd(0));
17703 @@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17704 pv_mmu_ops.set_fixmap(idx, phys, flags);
17705 }
17706
17707 +#ifdef CONFIG_PAX_KERNEXEC
17708 +static inline unsigned long pax_open_kernel(void)
17709 +{
17710 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17711 +}
17712 +
17713 +static inline unsigned long pax_close_kernel(void)
17714 +{
17715 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17716 +}
17717 +#else
17718 +static inline unsigned long pax_open_kernel(void) { return 0; }
17719 +static inline unsigned long pax_close_kernel(void) { return 0; }
17720 +#endif
17721 +
17722 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17723
17724 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17725 @@ -906,7 +933,7 @@ extern void default_banner(void);
17726
17727 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17728 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17729 -#define PARA_INDIRECT(addr) *%cs:addr
17730 +#define PARA_INDIRECT(addr) *%ss:addr
17731 #endif
17732
17733 #define INTERRUPT_RETURN \
17734 @@ -981,6 +1008,21 @@ extern void default_banner(void);
17735 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17736 CLBR_NONE, \
17737 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17738 +
17739 +#define GET_CR0_INTO_RDI \
17740 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17741 + mov %rax,%rdi
17742 +
17743 +#define SET_RDI_INTO_CR0 \
17744 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17745 +
17746 +#define GET_CR3_INTO_RDI \
17747 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17748 + mov %rax,%rdi
17749 +
17750 +#define SET_RDI_INTO_CR3 \
17751 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17752 +
17753 #endif /* CONFIG_X86_32 */
17754
17755 #endif /* __ASSEMBLY__ */
17756 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17757 index 7549b8b..f0edfda 100644
17758 --- a/arch/x86/include/asm/paravirt_types.h
17759 +++ b/arch/x86/include/asm/paravirt_types.h
17760 @@ -84,7 +84,7 @@ struct pv_init_ops {
17761 */
17762 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17763 unsigned long addr, unsigned len);
17764 -};
17765 +} __no_const __no_randomize_layout;
17766
17767
17768 struct pv_lazy_ops {
17769 @@ -92,13 +92,13 @@ struct pv_lazy_ops {
17770 void (*enter)(void);
17771 void (*leave)(void);
17772 void (*flush)(void);
17773 -};
17774 +} __no_randomize_layout;
17775
17776 struct pv_time_ops {
17777 unsigned long long (*sched_clock)(void);
17778 unsigned long long (*steal_clock)(int cpu);
17779 unsigned long (*get_tsc_khz)(void);
17780 -};
17781 +} __no_const __no_randomize_layout;
17782
17783 struct pv_cpu_ops {
17784 /* hooks for various privileged instructions */
17785 @@ -192,7 +192,7 @@ struct pv_cpu_ops {
17786
17787 void (*start_context_switch)(struct task_struct *prev);
17788 void (*end_context_switch)(struct task_struct *next);
17789 -};
17790 +} __no_const __no_randomize_layout;
17791
17792 struct pv_irq_ops {
17793 /*
17794 @@ -215,7 +215,7 @@ struct pv_irq_ops {
17795 #ifdef CONFIG_X86_64
17796 void (*adjust_exception_frame)(void);
17797 #endif
17798 -};
17799 +} __no_randomize_layout;
17800
17801 struct pv_apic_ops {
17802 #ifdef CONFIG_X86_LOCAL_APIC
17803 @@ -223,7 +223,7 @@ struct pv_apic_ops {
17804 unsigned long start_eip,
17805 unsigned long start_esp);
17806 #endif
17807 -};
17808 +} __no_const __no_randomize_layout;
17809
17810 struct pv_mmu_ops {
17811 unsigned long (*read_cr2)(void);
17812 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
17813 struct paravirt_callee_save make_pud;
17814
17815 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17816 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17817 #endif /* PAGETABLE_LEVELS == 4 */
17818 #endif /* PAGETABLE_LEVELS >= 3 */
17819
17820 @@ -324,7 +325,13 @@ struct pv_mmu_ops {
17821 an mfn. We can tell which is which from the index. */
17822 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17823 phys_addr_t phys, pgprot_t flags);
17824 -};
17825 +
17826 +#ifdef CONFIG_PAX_KERNEXEC
17827 + unsigned long (*pax_open_kernel)(void);
17828 + unsigned long (*pax_close_kernel)(void);
17829 +#endif
17830 +
17831 +} __no_randomize_layout;
17832
17833 struct arch_spinlock;
17834 #ifdef CONFIG_SMP
17835 @@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17836 struct pv_lock_ops {
17837 struct paravirt_callee_save lock_spinning;
17838 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17839 -};
17840 +} __no_randomize_layout;
17841
17842 /* This contains all the paravirt structures: we get a convenient
17843 * number for each function using the offset which we use to indicate
17844 - * what to patch. */
17845 + * what to patch.
17846 + * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17847 + */
17848 +
17849 struct paravirt_patch_template {
17850 struct pv_init_ops pv_init_ops;
17851 struct pv_time_ops pv_time_ops;
17852 @@ -349,7 +359,7 @@ struct paravirt_patch_template {
17853 struct pv_apic_ops pv_apic_ops;
17854 struct pv_mmu_ops pv_mmu_ops;
17855 struct pv_lock_ops pv_lock_ops;
17856 -};
17857 +} __no_randomize_layout;
17858
17859 extern struct pv_info pv_info;
17860 extern struct pv_init_ops pv_init_ops;
17861 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17862 index c4412e9..90e88c5 100644
17863 --- a/arch/x86/include/asm/pgalloc.h
17864 +++ b/arch/x86/include/asm/pgalloc.h
17865 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17866 pmd_t *pmd, pte_t *pte)
17867 {
17868 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17869 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17870 +}
17871 +
17872 +static inline void pmd_populate_user(struct mm_struct *mm,
17873 + pmd_t *pmd, pte_t *pte)
17874 +{
17875 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17876 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17877 }
17878
17879 @@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17880
17881 #ifdef CONFIG_X86_PAE
17882 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17883 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17884 +{
17885 + pud_populate(mm, pudp, pmd);
17886 +}
17887 #else /* !CONFIG_X86_PAE */
17888 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17889 {
17890 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17891 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17892 }
17893 +
17894 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17895 +{
17896 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17897 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17898 +}
17899 #endif /* CONFIG_X86_PAE */
17900
17901 #if PAGETABLE_LEVELS > 3
17902 @@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17903 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17904 }
17905
17906 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17907 +{
17908 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17909 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17910 +}
17911 +
17912 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17913 {
17914 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17915 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17916 index 206a87f..1623b06 100644
17917 --- a/arch/x86/include/asm/pgtable-2level.h
17918 +++ b/arch/x86/include/asm/pgtable-2level.h
17919 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17920
17921 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17922 {
17923 + pax_open_kernel();
17924 *pmdp = pmd;
17925 + pax_close_kernel();
17926 }
17927
17928 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17929 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17930 index 81bb91b..9392125 100644
17931 --- a/arch/x86/include/asm/pgtable-3level.h
17932 +++ b/arch/x86/include/asm/pgtable-3level.h
17933 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17934
17935 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17936 {
17937 + pax_open_kernel();
17938 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17939 + pax_close_kernel();
17940 }
17941
17942 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17943 {
17944 + pax_open_kernel();
17945 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17946 + pax_close_kernel();
17947 }
17948
17949 /*
17950 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17951 index aa97a07..5c53c32 100644
17952 --- a/arch/x86/include/asm/pgtable.h
17953 +++ b/arch/x86/include/asm/pgtable.h
17954 @@ -46,6 +46,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17955
17956 #ifndef __PAGETABLE_PUD_FOLDED
17957 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17958 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17959 #define pgd_clear(pgd) native_pgd_clear(pgd)
17960 #endif
17961
17962 @@ -83,12 +84,53 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17963
17964 #define arch_end_context_switch(prev) do {} while(0)
17965
17966 +#define pax_open_kernel() native_pax_open_kernel()
17967 +#define pax_close_kernel() native_pax_close_kernel()
17968 #endif /* CONFIG_PARAVIRT */
17969
17970 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
17971 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17972 +
17973 +#ifdef CONFIG_PAX_KERNEXEC
17974 +static inline unsigned long native_pax_open_kernel(void)
17975 +{
17976 + unsigned long cr0;
17977 +
17978 + preempt_disable();
17979 + barrier();
17980 + cr0 = read_cr0() ^ X86_CR0_WP;
17981 + BUG_ON(cr0 & X86_CR0_WP);
17982 + write_cr0(cr0);
17983 + barrier();
17984 + return cr0 ^ X86_CR0_WP;
17985 +}
17986 +
17987 +static inline unsigned long native_pax_close_kernel(void)
17988 +{
17989 + unsigned long cr0;
17990 +
17991 + barrier();
17992 + cr0 = read_cr0() ^ X86_CR0_WP;
17993 + BUG_ON(!(cr0 & X86_CR0_WP));
17994 + write_cr0(cr0);
17995 + barrier();
17996 + preempt_enable_no_resched();
17997 + return cr0 ^ X86_CR0_WP;
17998 +}
17999 +#else
18000 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
18001 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
18002 +#endif
18003 +
18004 /*
18005 * The following only work if pte_present() is true.
18006 * Undefined behaviour if not..
18007 */
18008 +static inline int pte_user(pte_t pte)
18009 +{
18010 + return pte_val(pte) & _PAGE_USER;
18011 +}
18012 +
18013 static inline int pte_dirty(pte_t pte)
18014 {
18015 return pte_flags(pte) & _PAGE_DIRTY;
18016 @@ -155,6 +197,11 @@ static inline unsigned long pud_pfn(pud_t pud)
18017 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
18018 }
18019
18020 +static inline unsigned long pgd_pfn(pgd_t pgd)
18021 +{
18022 + return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
18023 +}
18024 +
18025 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
18026
18027 static inline int pmd_large(pmd_t pte)
18028 @@ -208,9 +255,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
18029 return pte_clear_flags(pte, _PAGE_RW);
18030 }
18031
18032 +static inline pte_t pte_mkread(pte_t pte)
18033 +{
18034 + return __pte(pte_val(pte) | _PAGE_USER);
18035 +}
18036 +
18037 static inline pte_t pte_mkexec(pte_t pte)
18038 {
18039 - return pte_clear_flags(pte, _PAGE_NX);
18040 +#ifdef CONFIG_X86_PAE
18041 + if (__supported_pte_mask & _PAGE_NX)
18042 + return pte_clear_flags(pte, _PAGE_NX);
18043 + else
18044 +#endif
18045 + return pte_set_flags(pte, _PAGE_USER);
18046 +}
18047 +
18048 +static inline pte_t pte_exprotect(pte_t pte)
18049 +{
18050 +#ifdef CONFIG_X86_PAE
18051 + if (__supported_pte_mask & _PAGE_NX)
18052 + return pte_set_flags(pte, _PAGE_NX);
18053 + else
18054 +#endif
18055 + return pte_clear_flags(pte, _PAGE_USER);
18056 }
18057
18058 static inline pte_t pte_mkdirty(pte_t pte)
18059 @@ -440,6 +507,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
18060 #endif
18061
18062 #ifndef __ASSEMBLY__
18063 +
18064 +#ifdef CONFIG_PAX_PER_CPU_PGD
18065 +extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
18066 +enum cpu_pgd_type {kernel = 0, user = 1};
18067 +static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
18068 +{
18069 + return cpu_pgd[cpu][type];
18070 +}
18071 +#endif
18072 +
18073 #include <linux/mm_types.h>
18074 #include <linux/mmdebug.h>
18075 #include <linux/log2.h>
18076 @@ -586,7 +663,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
18077 * Currently stuck as a macro due to indirect forward reference to
18078 * linux/mmzone.h's __section_mem_map_addr() definition:
18079 */
18080 -#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
18081 +#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
18082
18083 /* Find an entry in the second-level page table.. */
18084 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
18085 @@ -626,7 +703,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
18086 * Currently stuck as a macro due to indirect forward reference to
18087 * linux/mmzone.h's __section_mem_map_addr() definition:
18088 */
18089 -#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
18090 +#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
18091
18092 /* to find an entry in a page-table-directory. */
18093 static inline unsigned long pud_index(unsigned long address)
18094 @@ -641,7 +718,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
18095
18096 static inline int pgd_bad(pgd_t pgd)
18097 {
18098 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
18099 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
18100 }
18101
18102 static inline int pgd_none(pgd_t pgd)
18103 @@ -664,7 +741,12 @@ static inline int pgd_none(pgd_t pgd)
18104 * pgd_offset() returns a (pgd_t *)
18105 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
18106 */
18107 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
18108 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
18109 +
18110 +#ifdef CONFIG_PAX_PER_CPU_PGD
18111 +#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
18112 +#endif
18113 +
18114 /*
18115 * a shortcut which implies the use of the kernel's pgd, instead
18116 * of a process's
18117 @@ -675,6 +757,23 @@ static inline int pgd_none(pgd_t pgd)
18118 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
18119 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
18120
18121 +#ifdef CONFIG_X86_32
18122 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
18123 +#else
18124 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
18125 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
18126 +
18127 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18128 +#ifdef __ASSEMBLY__
18129 +#define pax_user_shadow_base pax_user_shadow_base(%rip)
18130 +#else
18131 +extern unsigned long pax_user_shadow_base;
18132 +extern pgdval_t clone_pgd_mask;
18133 +#endif
18134 +#endif
18135 +
18136 +#endif
18137 +
18138 #ifndef __ASSEMBLY__
18139
18140 extern int direct_gbpages;
18141 @@ -841,11 +940,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
18142 * dst and src can be on the same page, but the range must not overlap,
18143 * and must not cross a page boundary.
18144 */
18145 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
18146 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
18147 {
18148 - memcpy(dst, src, count * sizeof(pgd_t));
18149 + pax_open_kernel();
18150 + while (count--)
18151 + *dst++ = *src++;
18152 + pax_close_kernel();
18153 }
18154
18155 +#ifdef CONFIG_PAX_PER_CPU_PGD
18156 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
18157 +#endif
18158 +
18159 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18160 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
18161 +#else
18162 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
18163 +#endif
18164 +
18165 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
18166 static inline int page_level_shift(enum pg_level level)
18167 {
18168 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
18169 index b6c0b40..3535d47 100644
18170 --- a/arch/x86/include/asm/pgtable_32.h
18171 +++ b/arch/x86/include/asm/pgtable_32.h
18172 @@ -25,9 +25,6 @@
18173 struct mm_struct;
18174 struct vm_area_struct;
18175
18176 -extern pgd_t swapper_pg_dir[1024];
18177 -extern pgd_t initial_page_table[1024];
18178 -
18179 static inline void pgtable_cache_init(void) { }
18180 static inline void check_pgt_cache(void) { }
18181 void paging_init(void);
18182 @@ -45,6 +42,12 @@ void paging_init(void);
18183 # include <asm/pgtable-2level.h>
18184 #endif
18185
18186 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
18187 +extern pgd_t initial_page_table[PTRS_PER_PGD];
18188 +#ifdef CONFIG_X86_PAE
18189 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
18190 +#endif
18191 +
18192 #if defined(CONFIG_HIGHPTE)
18193 #define pte_offset_map(dir, address) \
18194 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
18195 @@ -59,12 +62,17 @@ void paging_init(void);
18196 /* Clear a kernel PTE and flush it from the TLB */
18197 #define kpte_clear_flush(ptep, vaddr) \
18198 do { \
18199 + pax_open_kernel(); \
18200 pte_clear(&init_mm, (vaddr), (ptep)); \
18201 + pax_close_kernel(); \
18202 __flush_tlb_one((vaddr)); \
18203 } while (0)
18204
18205 #endif /* !__ASSEMBLY__ */
18206
18207 +#define HAVE_ARCH_UNMAPPED_AREA
18208 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
18209 +
18210 /*
18211 * kern_addr_valid() is (1) for FLATMEM and (0) for
18212 * SPARSEMEM and DISCONTIGMEM
18213 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
18214 index ed5903b..c7fe163 100644
18215 --- a/arch/x86/include/asm/pgtable_32_types.h
18216 +++ b/arch/x86/include/asm/pgtable_32_types.h
18217 @@ -8,7 +8,7 @@
18218 */
18219 #ifdef CONFIG_X86_PAE
18220 # include <asm/pgtable-3level_types.h>
18221 -# define PMD_SIZE (1UL << PMD_SHIFT)
18222 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
18223 # define PMD_MASK (~(PMD_SIZE - 1))
18224 #else
18225 # include <asm/pgtable-2level_types.h>
18226 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
18227 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
18228 #endif
18229
18230 +#ifdef CONFIG_PAX_KERNEXEC
18231 +#ifndef __ASSEMBLY__
18232 +extern unsigned char MODULES_EXEC_VADDR[];
18233 +extern unsigned char MODULES_EXEC_END[];
18234 +#endif
18235 +#include <asm/boot.h>
18236 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
18237 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
18238 +#else
18239 +#define ktla_ktva(addr) (addr)
18240 +#define ktva_ktla(addr) (addr)
18241 +#endif
18242 +
18243 #define MODULES_VADDR VMALLOC_START
18244 #define MODULES_END VMALLOC_END
18245 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
18246 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
18247 index 4572b2f..4430113 100644
18248 --- a/arch/x86/include/asm/pgtable_64.h
18249 +++ b/arch/x86/include/asm/pgtable_64.h
18250 @@ -16,11 +16,16 @@
18251
18252 extern pud_t level3_kernel_pgt[512];
18253 extern pud_t level3_ident_pgt[512];
18254 +extern pud_t level3_vmalloc_start_pgt[512];
18255 +extern pud_t level3_vmalloc_end_pgt[512];
18256 +extern pud_t level3_vmemmap_pgt[512];
18257 +extern pud_t level2_vmemmap_pgt[512];
18258 extern pmd_t level2_kernel_pgt[512];
18259 extern pmd_t level2_fixmap_pgt[512];
18260 -extern pmd_t level2_ident_pgt[512];
18261 +extern pmd_t level2_ident_pgt[512*2];
18262 extern pte_t level1_fixmap_pgt[512];
18263 -extern pgd_t init_level4_pgt[];
18264 +extern pte_t level1_vsyscall_pgt[512];
18265 +extern pgd_t init_level4_pgt[512];
18266
18267 #define swapper_pg_dir init_level4_pgt
18268
18269 @@ -62,7 +67,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18270
18271 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18272 {
18273 + pax_open_kernel();
18274 *pmdp = pmd;
18275 + pax_close_kernel();
18276 }
18277
18278 static inline void native_pmd_clear(pmd_t *pmd)
18279 @@ -98,7 +105,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
18280
18281 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18282 {
18283 + pax_open_kernel();
18284 *pudp = pud;
18285 + pax_close_kernel();
18286 }
18287
18288 static inline void native_pud_clear(pud_t *pud)
18289 @@ -108,6 +117,13 @@ static inline void native_pud_clear(pud_t *pud)
18290
18291 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
18292 {
18293 + pax_open_kernel();
18294 + *pgdp = pgd;
18295 + pax_close_kernel();
18296 +}
18297 +
18298 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18299 +{
18300 *pgdp = pgd;
18301 }
18302
18303 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
18304 index 7166e25..baaa6fe 100644
18305 --- a/arch/x86/include/asm/pgtable_64_types.h
18306 +++ b/arch/x86/include/asm/pgtable_64_types.h
18307 @@ -61,9 +61,14 @@ typedef struct { pteval_t pte; } pte_t;
18308 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
18309 #define MODULES_END _AC(0xffffffffff000000, UL)
18310 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
18311 +#define MODULES_EXEC_VADDR MODULES_VADDR
18312 +#define MODULES_EXEC_END MODULES_END
18313 #define ESPFIX_PGD_ENTRY _AC(-2, UL)
18314 #define ESPFIX_BASE_ADDR (ESPFIX_PGD_ENTRY << PGDIR_SHIFT)
18315
18316 +#define ktla_ktva(addr) (addr)
18317 +#define ktva_ktla(addr) (addr)
18318 +
18319 #define EARLY_DYNAMIC_PAGE_TABLES 64
18320
18321 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
18322 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
18323 index 0778964..0e94758 100644
18324 --- a/arch/x86/include/asm/pgtable_types.h
18325 +++ b/arch/x86/include/asm/pgtable_types.h
18326 @@ -110,8 +110,10 @@
18327
18328 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
18329 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
18330 -#else
18331 +#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
18332 #define _PAGE_NX (_AT(pteval_t, 0))
18333 +#else
18334 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
18335 #endif
18336
18337 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
18338 @@ -150,6 +152,9 @@
18339 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
18340 _PAGE_ACCESSED)
18341
18342 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
18343 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
18344 +
18345 #define __PAGE_KERNEL_EXEC \
18346 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
18347 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
18348 @@ -160,7 +165,7 @@
18349 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
18350 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
18351 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
18352 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
18353 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
18354 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
18355 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
18356 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
18357 @@ -217,7 +222,7 @@
18358 #ifdef CONFIG_X86_64
18359 #define __PAGE_KERNEL_IDENT_LARGE_EXEC __PAGE_KERNEL_LARGE_EXEC
18360 #else
18361 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18362 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18363 #define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18364 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18365 #endif
18366 @@ -256,7 +261,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18367 {
18368 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18369 }
18370 +#endif
18371
18372 +#if PAGETABLE_LEVELS == 3
18373 +#include <asm-generic/pgtable-nopud.h>
18374 +#endif
18375 +
18376 +#if PAGETABLE_LEVELS == 2
18377 +#include <asm-generic/pgtable-nopmd.h>
18378 +#endif
18379 +
18380 +#ifndef __ASSEMBLY__
18381 #if PAGETABLE_LEVELS > 3
18382 typedef struct { pudval_t pud; } pud_t;
18383
18384 @@ -270,8 +285,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18385 return pud.pud;
18386 }
18387 #else
18388 -#include <asm-generic/pgtable-nopud.h>
18389 -
18390 static inline pudval_t native_pud_val(pud_t pud)
18391 {
18392 return native_pgd_val(pud.pgd);
18393 @@ -291,8 +304,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18394 return pmd.pmd;
18395 }
18396 #else
18397 -#include <asm-generic/pgtable-nopmd.h>
18398 -
18399 static inline pmdval_t native_pmd_val(pmd_t pmd)
18400 {
18401 return native_pgd_val(pmd.pud.pgd);
18402 @@ -346,7 +357,6 @@ typedef struct page *pgtable_t;
18403
18404 extern pteval_t __supported_pte_mask;
18405 extern void set_nx(void);
18406 -extern int nx_enabled;
18407
18408 #define pgprot_writecombine pgprot_writecombine
18409 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18410 diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18411 index 4008734..48f0d81 100644
18412 --- a/arch/x86/include/asm/preempt.h
18413 +++ b/arch/x86/include/asm/preempt.h
18414 @@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18415 */
18416 static __always_inline bool __preempt_count_dec_and_test(void)
18417 {
18418 - GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18419 + GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18420 }
18421
18422 /*
18423 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18424 index eb71ec7..f06532a 100644
18425 --- a/arch/x86/include/asm/processor.h
18426 +++ b/arch/x86/include/asm/processor.h
18427 @@ -127,7 +127,7 @@ struct cpuinfo_x86 {
18428 /* Index into per_cpu list: */
18429 u16 cpu_index;
18430 u32 microcode;
18431 -} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18432 +} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18433
18434 #define X86_VENDOR_INTEL 0
18435 #define X86_VENDOR_CYRIX 1
18436 @@ -198,9 +198,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18437 : "memory");
18438 }
18439
18440 +/* invpcid (%rdx),%rax */
18441 +#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18442 +
18443 +#define INVPCID_SINGLE_ADDRESS 0UL
18444 +#define INVPCID_SINGLE_CONTEXT 1UL
18445 +#define INVPCID_ALL_GLOBAL 2UL
18446 +#define INVPCID_ALL_NONGLOBAL 3UL
18447 +
18448 +#define PCID_KERNEL 0UL
18449 +#define PCID_USER 1UL
18450 +#define PCID_NOFLUSH (1UL << 63)
18451 +
18452 static inline void load_cr3(pgd_t *pgdir)
18453 {
18454 - write_cr3(__pa(pgdir));
18455 + write_cr3(__pa(pgdir) | PCID_KERNEL);
18456 }
18457
18458 #ifdef CONFIG_X86_32
18459 @@ -282,7 +294,7 @@ struct tss_struct {
18460
18461 } ____cacheline_aligned;
18462
18463 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18464 +extern struct tss_struct init_tss[NR_CPUS];
18465
18466 /*
18467 * Save the original ist values for checking stack pointers during debugging
18468 @@ -478,6 +490,7 @@ struct thread_struct {
18469 unsigned short ds;
18470 unsigned short fsindex;
18471 unsigned short gsindex;
18472 + unsigned short ss;
18473 #endif
18474 #ifdef CONFIG_X86_32
18475 unsigned long ip;
18476 @@ -587,29 +600,8 @@ static inline void load_sp0(struct tss_struct *tss,
18477 extern unsigned long mmu_cr4_features;
18478 extern u32 *trampoline_cr4_features;
18479
18480 -static inline void set_in_cr4(unsigned long mask)
18481 -{
18482 - unsigned long cr4;
18483 -
18484 - mmu_cr4_features |= mask;
18485 - if (trampoline_cr4_features)
18486 - *trampoline_cr4_features = mmu_cr4_features;
18487 - cr4 = read_cr4();
18488 - cr4 |= mask;
18489 - write_cr4(cr4);
18490 -}
18491 -
18492 -static inline void clear_in_cr4(unsigned long mask)
18493 -{
18494 - unsigned long cr4;
18495 -
18496 - mmu_cr4_features &= ~mask;
18497 - if (trampoline_cr4_features)
18498 - *trampoline_cr4_features = mmu_cr4_features;
18499 - cr4 = read_cr4();
18500 - cr4 &= ~mask;
18501 - write_cr4(cr4);
18502 -}
18503 +extern void set_in_cr4(unsigned long mask);
18504 +extern void clear_in_cr4(unsigned long mask);
18505
18506 typedef struct {
18507 unsigned long seg;
18508 @@ -837,11 +829,18 @@ static inline void spin_lock_prefetch(const void *x)
18509 */
18510 #define TASK_SIZE PAGE_OFFSET
18511 #define TASK_SIZE_MAX TASK_SIZE
18512 +
18513 +#ifdef CONFIG_PAX_SEGMEXEC
18514 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18515 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18516 +#else
18517 #define STACK_TOP TASK_SIZE
18518 -#define STACK_TOP_MAX STACK_TOP
18519 +#endif
18520 +
18521 +#define STACK_TOP_MAX TASK_SIZE
18522
18523 #define INIT_THREAD { \
18524 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18525 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18526 .vm86_info = NULL, \
18527 .sysenter_cs = __KERNEL_CS, \
18528 .io_bitmap_ptr = NULL, \
18529 @@ -855,7 +854,7 @@ static inline void spin_lock_prefetch(const void *x)
18530 */
18531 #define INIT_TSS { \
18532 .x86_tss = { \
18533 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18534 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18535 .ss0 = __KERNEL_DS, \
18536 .ss1 = __KERNEL_CS, \
18537 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18538 @@ -866,11 +865,7 @@ static inline void spin_lock_prefetch(const void *x)
18539 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18540
18541 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18542 -#define KSTK_TOP(info) \
18543 -({ \
18544 - unsigned long *__ptr = (unsigned long *)(info); \
18545 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18546 -})
18547 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18548
18549 /*
18550 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18551 @@ -885,7 +880,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18552 #define task_pt_regs(task) \
18553 ({ \
18554 struct pt_regs *__regs__; \
18555 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18556 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18557 __regs__ - 1; \
18558 })
18559
18560 @@ -895,13 +890,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18561 /*
18562 * User space process size. 47bits minus one guard page.
18563 */
18564 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18565 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18566
18567 /* This decides where the kernel will search for a free chunk of vm
18568 * space during mmap's.
18569 */
18570 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18571 - 0xc0000000 : 0xFFFFe000)
18572 + 0xc0000000 : 0xFFFFf000)
18573
18574 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18575 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18576 @@ -912,11 +907,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18577 #define STACK_TOP_MAX TASK_SIZE_MAX
18578
18579 #define INIT_THREAD { \
18580 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18581 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18582 }
18583
18584 #define INIT_TSS { \
18585 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18586 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18587 }
18588
18589 /*
18590 @@ -944,6 +939,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18591 */
18592 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18593
18594 +#ifdef CONFIG_PAX_SEGMEXEC
18595 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18596 +#endif
18597 +
18598 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18599
18600 /* Get/set a process' ability to use the timestamp counter instruction */
18601 @@ -970,7 +969,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18602 return 0;
18603 }
18604
18605 -extern unsigned long arch_align_stack(unsigned long sp);
18606 +#define arch_align_stack(x) ((x) & ~0xfUL)
18607 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18608
18609 void default_idle(void);
18610 @@ -980,6 +979,6 @@ bool xen_set_default_idle(void);
18611 #define xen_set_default_idle 0
18612 #endif
18613
18614 -void stop_this_cpu(void *dummy);
18615 +void stop_this_cpu(void *dummy) __noreturn;
18616 void df_debug(struct pt_regs *regs, long error_code);
18617 #endif /* _ASM_X86_PROCESSOR_H */
18618 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18619 index 86fc2bb..bd5049a 100644
18620 --- a/arch/x86/include/asm/ptrace.h
18621 +++ b/arch/x86/include/asm/ptrace.h
18622 @@ -89,28 +89,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18623 }
18624
18625 /*
18626 - * user_mode_vm(regs) determines whether a register set came from user mode.
18627 + * user_mode(regs) determines whether a register set came from user mode.
18628 * This is true if V8086 mode was enabled OR if the register set was from
18629 * protected mode with RPL-3 CS value. This tricky test checks that with
18630 * one comparison. Many places in the kernel can bypass this full check
18631 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18632 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18633 + * be used.
18634 */
18635 -static inline int user_mode(struct pt_regs *regs)
18636 +static inline int user_mode_novm(struct pt_regs *regs)
18637 {
18638 #ifdef CONFIG_X86_32
18639 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18640 #else
18641 - return !!(regs->cs & 3);
18642 + return !!(regs->cs & SEGMENT_RPL_MASK);
18643 #endif
18644 }
18645
18646 -static inline int user_mode_vm(struct pt_regs *regs)
18647 +static inline int user_mode(struct pt_regs *regs)
18648 {
18649 #ifdef CONFIG_X86_32
18650 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18651 USER_RPL;
18652 #else
18653 - return user_mode(regs);
18654 + return user_mode_novm(regs);
18655 #endif
18656 }
18657
18658 @@ -126,15 +127,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18659 #ifdef CONFIG_X86_64
18660 static inline bool user_64bit_mode(struct pt_regs *regs)
18661 {
18662 + unsigned long cs = regs->cs & 0xffff;
18663 #ifndef CONFIG_PARAVIRT
18664 /*
18665 * On non-paravirt systems, this is the only long mode CPL 3
18666 * selector. We do not allow long mode selectors in the LDT.
18667 */
18668 - return regs->cs == __USER_CS;
18669 + return cs == __USER_CS;
18670 #else
18671 /* Headers are too twisted for this to go in paravirt.h. */
18672 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18673 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18674 #endif
18675 }
18676
18677 @@ -185,9 +187,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18678 * Traps from the kernel do not save sp and ss.
18679 * Use the helper function to retrieve sp.
18680 */
18681 - if (offset == offsetof(struct pt_regs, sp) &&
18682 - regs->cs == __KERNEL_CS)
18683 - return kernel_stack_pointer(regs);
18684 + if (offset == offsetof(struct pt_regs, sp)) {
18685 + unsigned long cs = regs->cs & 0xffff;
18686 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18687 + return kernel_stack_pointer(regs);
18688 + }
18689 #endif
18690 return *(unsigned long *)((unsigned long)regs + offset);
18691 }
18692 diff --git a/arch/x86/include/asm/qrwlock.h b/arch/x86/include/asm/qrwlock.h
18693 index ae0e241..e80b10b 100644
18694 --- a/arch/x86/include/asm/qrwlock.h
18695 +++ b/arch/x86/include/asm/qrwlock.h
18696 @@ -7,8 +7,8 @@
18697 #define queue_write_unlock queue_write_unlock
18698 static inline void queue_write_unlock(struct qrwlock *lock)
18699 {
18700 - barrier();
18701 - ACCESS_ONCE(*(u8 *)&lock->cnts) = 0;
18702 + barrier();
18703 + ACCESS_ONCE_RW(*(u8 *)&lock->cnts) = 0;
18704 }
18705 #endif
18706
18707 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18708 index 9c6b890..5305f53 100644
18709 --- a/arch/x86/include/asm/realmode.h
18710 +++ b/arch/x86/include/asm/realmode.h
18711 @@ -22,16 +22,14 @@ struct real_mode_header {
18712 #endif
18713 /* APM/BIOS reboot */
18714 u32 machine_real_restart_asm;
18715 -#ifdef CONFIG_X86_64
18716 u32 machine_real_restart_seg;
18717 -#endif
18718 };
18719
18720 /* This must match data at trampoline_32/64.S */
18721 struct trampoline_header {
18722 #ifdef CONFIG_X86_32
18723 u32 start;
18724 - u16 gdt_pad;
18725 + u16 boot_cs;
18726 u16 gdt_limit;
18727 u32 gdt_base;
18728 #else
18729 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18730 index a82c4f1..ac45053 100644
18731 --- a/arch/x86/include/asm/reboot.h
18732 +++ b/arch/x86/include/asm/reboot.h
18733 @@ -6,13 +6,13 @@
18734 struct pt_regs;
18735
18736 struct machine_ops {
18737 - void (*restart)(char *cmd);
18738 - void (*halt)(void);
18739 - void (*power_off)(void);
18740 + void (* __noreturn restart)(char *cmd);
18741 + void (* __noreturn halt)(void);
18742 + void (* __noreturn power_off)(void);
18743 void (*shutdown)(void);
18744 void (*crash_shutdown)(struct pt_regs *);
18745 - void (*emergency_restart)(void);
18746 -};
18747 + void (* __noreturn emergency_restart)(void);
18748 +} __no_const;
18749
18750 extern struct machine_ops machine_ops;
18751
18752 diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18753 index 8f7866a..e442f20 100644
18754 --- a/arch/x86/include/asm/rmwcc.h
18755 +++ b/arch/x86/include/asm/rmwcc.h
18756 @@ -3,7 +3,34 @@
18757
18758 #ifdef CC_HAVE_ASM_GOTO
18759
18760 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18761 +#ifdef CONFIG_PAX_REFCOUNT
18762 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18763 +do { \
18764 + asm_volatile_goto (fullop \
18765 + ";jno 0f\n" \
18766 + fullantiop \
18767 + ";int $4\n0:\n" \
18768 + _ASM_EXTABLE(0b, 0b) \
18769 + ";j" cc " %l[cc_label]" \
18770 + : : "m" (var), ## __VA_ARGS__ \
18771 + : "memory" : cc_label); \
18772 + return 0; \
18773 +cc_label: \
18774 + return 1; \
18775 +} while (0)
18776 +#else
18777 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18778 +do { \
18779 + asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18780 + : : "m" (var), ## __VA_ARGS__ \
18781 + : "memory" : cc_label); \
18782 + return 0; \
18783 +cc_label: \
18784 + return 1; \
18785 +} while (0)
18786 +#endif
18787 +
18788 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18789 do { \
18790 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18791 : : "m" (var), ## __VA_ARGS__ \
18792 @@ -13,15 +40,46 @@ cc_label: \
18793 return 1; \
18794 } while (0)
18795
18796 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18797 - __GEN_RMWcc(op " " arg0, var, cc)
18798 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18799 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18800
18801 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18802 - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18803 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18804 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18805 +
18806 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18807 + __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18808 +
18809 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18810 + __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18811
18812 #else /* !CC_HAVE_ASM_GOTO */
18813
18814 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18815 +#ifdef CONFIG_PAX_REFCOUNT
18816 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18817 +do { \
18818 + char c; \
18819 + asm volatile (fullop \
18820 + ";jno 0f\n" \
18821 + fullantiop \
18822 + ";int $4\n0:\n" \
18823 + _ASM_EXTABLE(0b, 0b) \
18824 + "; set" cc " %1" \
18825 + : "+m" (var), "=qm" (c) \
18826 + : __VA_ARGS__ : "memory"); \
18827 + return c != 0; \
18828 +} while (0)
18829 +#else
18830 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18831 +do { \
18832 + char c; \
18833 + asm volatile (fullop "; set" cc " %1" \
18834 + : "+m" (var), "=qm" (c) \
18835 + : __VA_ARGS__ : "memory"); \
18836 + return c != 0; \
18837 +} while (0)
18838 +#endif
18839 +
18840 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18841 do { \
18842 char c; \
18843 asm volatile (fullop "; set" cc " %1" \
18844 @@ -30,11 +88,17 @@ do { \
18845 return c != 0; \
18846 } while (0)
18847
18848 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18849 - __GEN_RMWcc(op " " arg0, var, cc)
18850 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18851 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18852 +
18853 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18854 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18855 +
18856 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18857 + __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18858
18859 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18860 - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18861 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18862 + __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18863
18864 #endif /* CC_HAVE_ASM_GOTO */
18865
18866 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18867 index cad82c9..2e5c5c1 100644
18868 --- a/arch/x86/include/asm/rwsem.h
18869 +++ b/arch/x86/include/asm/rwsem.h
18870 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18871 {
18872 asm volatile("# beginning down_read\n\t"
18873 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18874 +
18875 +#ifdef CONFIG_PAX_REFCOUNT
18876 + "jno 0f\n"
18877 + LOCK_PREFIX _ASM_DEC "(%1)\n"
18878 + "int $4\n0:\n"
18879 + _ASM_EXTABLE(0b, 0b)
18880 +#endif
18881 +
18882 /* adds 0x00000001 */
18883 " jns 1f\n"
18884 " call call_rwsem_down_read_failed\n"
18885 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18886 "1:\n\t"
18887 " mov %1,%2\n\t"
18888 " add %3,%2\n\t"
18889 +
18890 +#ifdef CONFIG_PAX_REFCOUNT
18891 + "jno 0f\n"
18892 + "sub %3,%2\n"
18893 + "int $4\n0:\n"
18894 + _ASM_EXTABLE(0b, 0b)
18895 +#endif
18896 +
18897 " jle 2f\n\t"
18898 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18899 " jnz 1b\n\t"
18900 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18901 long tmp;
18902 asm volatile("# beginning down_write\n\t"
18903 LOCK_PREFIX " xadd %1,(%2)\n\t"
18904 +
18905 +#ifdef CONFIG_PAX_REFCOUNT
18906 + "jno 0f\n"
18907 + "mov %1,(%2)\n"
18908 + "int $4\n0:\n"
18909 + _ASM_EXTABLE(0b, 0b)
18910 +#endif
18911 +
18912 /* adds 0xffff0001, returns the old value */
18913 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18914 /* was the active mask 0 before? */
18915 @@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18916 long tmp;
18917 asm volatile("# beginning __up_read\n\t"
18918 LOCK_PREFIX " xadd %1,(%2)\n\t"
18919 +
18920 +#ifdef CONFIG_PAX_REFCOUNT
18921 + "jno 0f\n"
18922 + "mov %1,(%2)\n"
18923 + "int $4\n0:\n"
18924 + _ASM_EXTABLE(0b, 0b)
18925 +#endif
18926 +
18927 /* subtracts 1, returns the old value */
18928 " jns 1f\n\t"
18929 " call call_rwsem_wake\n" /* expects old value in %edx */
18930 @@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18931 long tmp;
18932 asm volatile("# beginning __up_write\n\t"
18933 LOCK_PREFIX " xadd %1,(%2)\n\t"
18934 +
18935 +#ifdef CONFIG_PAX_REFCOUNT
18936 + "jno 0f\n"
18937 + "mov %1,(%2)\n"
18938 + "int $4\n0:\n"
18939 + _ASM_EXTABLE(0b, 0b)
18940 +#endif
18941 +
18942 /* subtracts 0xffff0001, returns the old value */
18943 " jns 1f\n\t"
18944 " call call_rwsem_wake\n" /* expects old value in %edx */
18945 @@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18946 {
18947 asm volatile("# beginning __downgrade_write\n\t"
18948 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18949 +
18950 +#ifdef CONFIG_PAX_REFCOUNT
18951 + "jno 0f\n"
18952 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18953 + "int $4\n0:\n"
18954 + _ASM_EXTABLE(0b, 0b)
18955 +#endif
18956 +
18957 /*
18958 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18959 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18960 @@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18961 */
18962 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18963 {
18964 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18965 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18966 +
18967 +#ifdef CONFIG_PAX_REFCOUNT
18968 + "jno 0f\n"
18969 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
18970 + "int $4\n0:\n"
18971 + _ASM_EXTABLE(0b, 0b)
18972 +#endif
18973 +
18974 : "+m" (sem->count)
18975 : "er" (delta));
18976 }
18977 @@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18978 */
18979 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18980 {
18981 - return delta + xadd(&sem->count, delta);
18982 + return delta + xadd_check_overflow(&sem->count, delta);
18983 }
18984
18985 #endif /* __KERNEL__ */
18986 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18987 index 6f1c3a8..7744f19 100644
18988 --- a/arch/x86/include/asm/segment.h
18989 +++ b/arch/x86/include/asm/segment.h
18990 @@ -64,10 +64,15 @@
18991 * 26 - ESPFIX small SS
18992 * 27 - per-cpu [ offset to per-cpu data area ]
18993 * 28 - stack_canary-20 [ for stack protector ]
18994 - * 29 - unused
18995 - * 30 - unused
18996 + * 29 - PCI BIOS CS
18997 + * 30 - PCI BIOS DS
18998 * 31 - TSS for double fault handler
18999 */
19000 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
19001 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
19002 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
19003 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
19004 +
19005 #define GDT_ENTRY_TLS_MIN 6
19006 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
19007
19008 @@ -79,6 +84,8 @@
19009
19010 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
19011
19012 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
19013 +
19014 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
19015
19016 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
19017 @@ -104,6 +111,12 @@
19018 #define __KERNEL_STACK_CANARY 0
19019 #endif
19020
19021 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
19022 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
19023 +
19024 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
19025 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
19026 +
19027 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
19028
19029 /*
19030 @@ -141,7 +154,7 @@
19031 */
19032
19033 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
19034 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
19035 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
19036
19037
19038 #else
19039 @@ -165,6 +178,8 @@
19040 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
19041 #define __USER32_DS __USER_DS
19042
19043 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
19044 +
19045 #define GDT_ENTRY_TSS 8 /* needs two entries */
19046 #define GDT_ENTRY_LDT 10 /* needs two entries */
19047 #define GDT_ENTRY_TLS_MIN 12
19048 @@ -173,6 +188,8 @@
19049 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
19050 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
19051
19052 +#define GDT_ENTRY_UDEREF_KERNEL_DS 16
19053 +
19054 /* TLS indexes for 64bit - hardcoded in arch_prctl */
19055 #define FS_TLS 0
19056 #define GS_TLS 1
19057 @@ -180,12 +197,14 @@
19058 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
19059 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
19060
19061 -#define GDT_ENTRIES 16
19062 +#define GDT_ENTRIES 17
19063
19064 #endif
19065
19066 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
19067 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
19068 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
19069 +#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
19070 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
19071 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
19072 #ifndef CONFIG_PARAVIRT
19073 @@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
19074 {
19075 unsigned long __limit;
19076 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
19077 - return __limit + 1;
19078 + return __limit;
19079 }
19080
19081 #endif /* !__ASSEMBLY__ */
19082 diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
19083 index 8d3120f..352b440 100644
19084 --- a/arch/x86/include/asm/smap.h
19085 +++ b/arch/x86/include/asm/smap.h
19086 @@ -25,11 +25,40 @@
19087
19088 #include <asm/alternative-asm.h>
19089
19090 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19091 +#define ASM_PAX_OPEN_USERLAND \
19092 + 661: jmp 663f; \
19093 + .pushsection .altinstr_replacement, "a" ; \
19094 + 662: pushq %rax; nop; \
19095 + .popsection ; \
19096 + .pushsection .altinstructions, "a" ; \
19097 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19098 + .popsection ; \
19099 + call __pax_open_userland; \
19100 + popq %rax; \
19101 + 663:
19102 +
19103 +#define ASM_PAX_CLOSE_USERLAND \
19104 + 661: jmp 663f; \
19105 + .pushsection .altinstr_replacement, "a" ; \
19106 + 662: pushq %rax; nop; \
19107 + .popsection; \
19108 + .pushsection .altinstructions, "a" ; \
19109 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19110 + .popsection; \
19111 + call __pax_close_userland; \
19112 + popq %rax; \
19113 + 663:
19114 +#else
19115 +#define ASM_PAX_OPEN_USERLAND
19116 +#define ASM_PAX_CLOSE_USERLAND
19117 +#endif
19118 +
19119 #ifdef CONFIG_X86_SMAP
19120
19121 #define ASM_CLAC \
19122 661: ASM_NOP3 ; \
19123 - .pushsection .altinstr_replacement, "ax" ; \
19124 + .pushsection .altinstr_replacement, "a" ; \
19125 662: __ASM_CLAC ; \
19126 .popsection ; \
19127 .pushsection .altinstructions, "a" ; \
19128 @@ -38,7 +67,7 @@
19129
19130 #define ASM_STAC \
19131 661: ASM_NOP3 ; \
19132 - .pushsection .altinstr_replacement, "ax" ; \
19133 + .pushsection .altinstr_replacement, "a" ; \
19134 662: __ASM_STAC ; \
19135 .popsection ; \
19136 .pushsection .altinstructions, "a" ; \
19137 @@ -56,6 +85,37 @@
19138
19139 #include <asm/alternative.h>
19140
19141 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
19142 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
19143 +
19144 +extern void __pax_open_userland(void);
19145 +static __always_inline unsigned long pax_open_userland(void)
19146 +{
19147 +
19148 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19149 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
19150 + :
19151 + : [open] "i" (__pax_open_userland)
19152 + : "memory", "rax");
19153 +#endif
19154 +
19155 + return 0;
19156 +}
19157 +
19158 +extern void __pax_close_userland(void);
19159 +static __always_inline unsigned long pax_close_userland(void)
19160 +{
19161 +
19162 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19163 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
19164 + :
19165 + : [close] "i" (__pax_close_userland)
19166 + : "memory", "rax");
19167 +#endif
19168 +
19169 + return 0;
19170 +}
19171 +
19172 #ifdef CONFIG_X86_SMAP
19173
19174 static __always_inline void clac(void)
19175 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
19176 index 8cd1cc3..827e09e 100644
19177 --- a/arch/x86/include/asm/smp.h
19178 +++ b/arch/x86/include/asm/smp.h
19179 @@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
19180 /* cpus sharing the last level cache: */
19181 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
19182 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
19183 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
19184 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19185
19186 static inline struct cpumask *cpu_sibling_mask(int cpu)
19187 {
19188 @@ -78,7 +78,7 @@ struct smp_ops {
19189
19190 void (*send_call_func_ipi)(const struct cpumask *mask);
19191 void (*send_call_func_single_ipi)(int cpu);
19192 -};
19193 +} __no_const;
19194
19195 /* Globals due to paravirt */
19196 extern void set_cpu_sibling_map(int cpu);
19197 @@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
19198 extern int safe_smp_processor_id(void);
19199
19200 #elif defined(CONFIG_X86_64_SMP)
19201 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19202 -
19203 -#define stack_smp_processor_id() \
19204 -({ \
19205 - struct thread_info *ti; \
19206 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
19207 - ti->cpu; \
19208 -})
19209 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19210 +#define stack_smp_processor_id() raw_smp_processor_id()
19211 #define safe_smp_processor_id() smp_processor_id()
19212
19213 #endif
19214 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19215 index 6a99859..03cb807 100644
19216 --- a/arch/x86/include/asm/stackprotector.h
19217 +++ b/arch/x86/include/asm/stackprotector.h
19218 @@ -47,7 +47,7 @@
19219 * head_32 for boot CPU and setup_per_cpu_areas() for others.
19220 */
19221 #define GDT_STACK_CANARY_INIT \
19222 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
19223 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
19224
19225 /*
19226 * Initialize the stackprotector canary value.
19227 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
19228
19229 static inline void load_stack_canary_segment(void)
19230 {
19231 -#ifdef CONFIG_X86_32
19232 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19233 asm volatile ("mov %0, %%gs" : : "r" (0));
19234 #endif
19235 }
19236 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
19237 index 70bbe39..4ae2bd4 100644
19238 --- a/arch/x86/include/asm/stacktrace.h
19239 +++ b/arch/x86/include/asm/stacktrace.h
19240 @@ -11,28 +11,20 @@
19241
19242 extern int kstack_depth_to_print;
19243
19244 -struct thread_info;
19245 +struct task_struct;
19246 struct stacktrace_ops;
19247
19248 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
19249 - unsigned long *stack,
19250 - unsigned long bp,
19251 - const struct stacktrace_ops *ops,
19252 - void *data,
19253 - unsigned long *end,
19254 - int *graph);
19255 +typedef unsigned long walk_stack_t(struct task_struct *task,
19256 + void *stack_start,
19257 + unsigned long *stack,
19258 + unsigned long bp,
19259 + const struct stacktrace_ops *ops,
19260 + void *data,
19261 + unsigned long *end,
19262 + int *graph);
19263
19264 -extern unsigned long
19265 -print_context_stack(struct thread_info *tinfo,
19266 - unsigned long *stack, unsigned long bp,
19267 - const struct stacktrace_ops *ops, void *data,
19268 - unsigned long *end, int *graph);
19269 -
19270 -extern unsigned long
19271 -print_context_stack_bp(struct thread_info *tinfo,
19272 - unsigned long *stack, unsigned long bp,
19273 - const struct stacktrace_ops *ops, void *data,
19274 - unsigned long *end, int *graph);
19275 +extern walk_stack_t print_context_stack;
19276 +extern walk_stack_t print_context_stack_bp;
19277
19278 /* Generic stack tracer with callbacks */
19279
19280 @@ -40,7 +32,7 @@ struct stacktrace_ops {
19281 void (*address)(void *data, unsigned long address, int reliable);
19282 /* On negative return stop dumping */
19283 int (*stack)(void *data, char *name);
19284 - walk_stack_t walk_stack;
19285 + walk_stack_t *walk_stack;
19286 };
19287
19288 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
19289 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
19290 index d7f3b3b..3cc39f1 100644
19291 --- a/arch/x86/include/asm/switch_to.h
19292 +++ b/arch/x86/include/asm/switch_to.h
19293 @@ -108,7 +108,7 @@ do { \
19294 "call __switch_to\n\t" \
19295 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
19296 __switch_canary \
19297 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
19298 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
19299 "movq %%rax,%%rdi\n\t" \
19300 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19301 "jnz ret_from_fork\n\t" \
19302 @@ -119,7 +119,7 @@ do { \
19303 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19304 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19305 [_tif_fork] "i" (_TIF_FORK), \
19306 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
19307 + [thread_info] "m" (current_tinfo), \
19308 [current_task] "m" (current_task) \
19309 __switch_canary_iparam \
19310 : "memory", "cc" __EXTRA_CLOBBER)
19311 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19312 index 547e344..6be1175 100644
19313 --- a/arch/x86/include/asm/thread_info.h
19314 +++ b/arch/x86/include/asm/thread_info.h
19315 @@ -24,7 +24,6 @@ struct exec_domain;
19316 #include <linux/atomic.h>
19317
19318 struct thread_info {
19319 - struct task_struct *task; /* main task structure */
19320 struct exec_domain *exec_domain; /* execution domain */
19321 __u32 flags; /* low level flags */
19322 __u32 status; /* thread synchronous flags */
19323 @@ -33,13 +32,13 @@ struct thread_info {
19324 mm_segment_t addr_limit;
19325 struct restart_block restart_block;
19326 void __user *sysenter_return;
19327 + unsigned long lowest_stack;
19328 unsigned int sig_on_uaccess_error:1;
19329 unsigned int uaccess_err:1; /* uaccess failed */
19330 };
19331
19332 -#define INIT_THREAD_INFO(tsk) \
19333 +#define INIT_THREAD_INFO \
19334 { \
19335 - .task = &tsk, \
19336 .exec_domain = &default_exec_domain, \
19337 .flags = 0, \
19338 .cpu = 0, \
19339 @@ -50,7 +49,7 @@ struct thread_info {
19340 }, \
19341 }
19342
19343 -#define init_thread_info (init_thread_union.thread_info)
19344 +#define init_thread_info (init_thread_union.stack)
19345 #define init_stack (init_thread_union.stack)
19346
19347 #else /* !__ASSEMBLY__ */
19348 @@ -91,6 +90,7 @@ struct thread_info {
19349 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19350 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19351 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19352 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19353
19354 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19355 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19356 @@ -115,17 +115,18 @@ struct thread_info {
19357 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19358 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19359 #define _TIF_X32 (1 << TIF_X32)
19360 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19361
19362 /* work to do in syscall_trace_enter() */
19363 #define _TIF_WORK_SYSCALL_ENTRY \
19364 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19365 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19366 - _TIF_NOHZ)
19367 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19368
19369 /* work to do in syscall_trace_leave() */
19370 #define _TIF_WORK_SYSCALL_EXIT \
19371 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19372 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19373 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19374
19375 /* work to do on interrupt/exception return */
19376 #define _TIF_WORK_MASK \
19377 @@ -136,7 +137,7 @@ struct thread_info {
19378 /* work to do on any return to user space */
19379 #define _TIF_ALLWORK_MASK \
19380 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19381 - _TIF_NOHZ)
19382 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19383
19384 /* Only used for 64 bit */
19385 #define _TIF_DO_NOTIFY_MASK \
19386 @@ -151,7 +152,6 @@ struct thread_info {
19387 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19388
19389 #define STACK_WARN (THREAD_SIZE/8)
19390 -#define KERNEL_STACK_OFFSET (5*(BITS_PER_LONG/8))
19391
19392 /*
19393 * macros/functions for gaining access to the thread information structure
19394 @@ -162,26 +162,18 @@ struct thread_info {
19395
19396 DECLARE_PER_CPU(unsigned long, kernel_stack);
19397
19398 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19399 +
19400 static inline struct thread_info *current_thread_info(void)
19401 {
19402 - struct thread_info *ti;
19403 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
19404 - KERNEL_STACK_OFFSET - THREAD_SIZE);
19405 - return ti;
19406 + return this_cpu_read_stable(current_tinfo);
19407 }
19408
19409 #else /* !__ASSEMBLY__ */
19410
19411 /* how to get the thread information struct from ASM */
19412 #define GET_THREAD_INFO(reg) \
19413 - _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
19414 - _ASM_SUB $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg ;
19415 -
19416 -/*
19417 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19418 - * a certain register (to be used in assembler memory operands).
19419 - */
19420 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19421 + _ASM_MOV PER_CPU_VAR(current_tinfo),reg ;
19422
19423 #endif
19424
19425 @@ -237,5 +229,12 @@ static inline bool is_ia32_task(void)
19426 extern void arch_task_cache_init(void);
19427 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19428 extern void arch_release_task_struct(struct task_struct *tsk);
19429 +
19430 +#define __HAVE_THREAD_FUNCTIONS
19431 +#define task_thread_info(task) (&(task)->tinfo)
19432 +#define task_stack_page(task) ((task)->stack)
19433 +#define setup_thread_stack(p, org) do {} while (0)
19434 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19435 +
19436 #endif
19437 #endif /* _ASM_X86_THREAD_INFO_H */
19438 diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19439 index 04905bf..1178cdf 100644
19440 --- a/arch/x86/include/asm/tlbflush.h
19441 +++ b/arch/x86/include/asm/tlbflush.h
19442 @@ -17,18 +17,44 @@
19443
19444 static inline void __native_flush_tlb(void)
19445 {
19446 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19447 + u64 descriptor[2];
19448 +
19449 + descriptor[0] = PCID_KERNEL;
19450 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_NONGLOBAL) : "memory");
19451 + return;
19452 + }
19453 +
19454 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19455 + if (static_cpu_has(X86_FEATURE_PCID)) {
19456 + unsigned int cpu = raw_get_cpu();
19457 +
19458 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19459 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19460 + raw_put_cpu_no_resched();
19461 + return;
19462 + }
19463 +#endif
19464 +
19465 native_write_cr3(native_read_cr3());
19466 }
19467
19468 static inline void __native_flush_tlb_global_irq_disabled(void)
19469 {
19470 - unsigned long cr4;
19471 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19472 + u64 descriptor[2];
19473
19474 - cr4 = native_read_cr4();
19475 - /* clear PGE */
19476 - native_write_cr4(cr4 & ~X86_CR4_PGE);
19477 - /* write old PGE again and flush TLBs */
19478 - native_write_cr4(cr4);
19479 + descriptor[0] = PCID_KERNEL;
19480 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19481 + } else {
19482 + unsigned long cr4;
19483 +
19484 + cr4 = native_read_cr4();
19485 + /* clear PGE */
19486 + native_write_cr4(cr4 & ~X86_CR4_PGE);
19487 + /* write old PGE again and flush TLBs */
19488 + native_write_cr4(cr4);
19489 + }
19490 }
19491
19492 static inline void __native_flush_tlb_global(void)
19493 @@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19494
19495 static inline void __native_flush_tlb_single(unsigned long addr)
19496 {
19497 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19498 + u64 descriptor[2];
19499 +
19500 + descriptor[0] = PCID_KERNEL;
19501 + descriptor[1] = addr;
19502 +
19503 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19504 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19505 + if (addr < TASK_SIZE_MAX)
19506 + descriptor[1] += pax_user_shadow_base;
19507 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19508 + }
19509 +
19510 + descriptor[0] = PCID_USER;
19511 + descriptor[1] = addr;
19512 +#endif
19513 +
19514 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19515 + return;
19516 + }
19517 +
19518 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19519 + if (static_cpu_has(X86_FEATURE_PCID)) {
19520 + unsigned int cpu = raw_get_cpu();
19521 +
19522 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19523 + asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19524 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19525 + raw_put_cpu_no_resched();
19526 +
19527 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19528 + addr += pax_user_shadow_base;
19529 + }
19530 +#endif
19531 +
19532 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19533 }
19534
19535 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19536 index 0d592e0..526f797 100644
19537 --- a/arch/x86/include/asm/uaccess.h
19538 +++ b/arch/x86/include/asm/uaccess.h
19539 @@ -7,6 +7,7 @@
19540 #include <linux/compiler.h>
19541 #include <linux/thread_info.h>
19542 #include <linux/string.h>
19543 +#include <linux/spinlock.h>
19544 #include <asm/asm.h>
19545 #include <asm/page.h>
19546 #include <asm/smap.h>
19547 @@ -29,7 +30,12 @@
19548
19549 #define get_ds() (KERNEL_DS)
19550 #define get_fs() (current_thread_info()->addr_limit)
19551 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19552 +void __set_fs(mm_segment_t x);
19553 +void set_fs(mm_segment_t x);
19554 +#else
19555 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19556 +#endif
19557
19558 #define segment_eq(a, b) ((a).seg == (b).seg)
19559
19560 @@ -85,8 +91,36 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19561 * checks that the pointer is in the user space range - after calling
19562 * this function, memory access functions may still return -EFAULT.
19563 */
19564 -#define access_ok(type, addr, size) \
19565 - likely(!__range_not_ok(addr, size, user_addr_max()))
19566 +extern int _cond_resched(void);
19567 +#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19568 +#define access_ok(type, addr, size) \
19569 +({ \
19570 + unsigned long __size = size; \
19571 + unsigned long __addr = (unsigned long)addr; \
19572 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19573 + if (__ret_ao && __size) { \
19574 + unsigned long __addr_ao = __addr & PAGE_MASK; \
19575 + unsigned long __end_ao = __addr + __size - 1; \
19576 + if (unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19577 + while (__addr_ao <= __end_ao) { \
19578 + char __c_ao; \
19579 + __addr_ao += PAGE_SIZE; \
19580 + if (__size > PAGE_SIZE) \
19581 + _cond_resched(); \
19582 + if (__get_user(__c_ao, (char __user *)__addr)) \
19583 + break; \
19584 + if (type != VERIFY_WRITE) { \
19585 + __addr = __addr_ao; \
19586 + continue; \
19587 + } \
19588 + if (__put_user(__c_ao, (char __user *)__addr)) \
19589 + break; \
19590 + __addr = __addr_ao; \
19591 + } \
19592 + } \
19593 + } \
19594 + __ret_ao; \
19595 +})
19596
19597 /*
19598 * The exception table consists of pairs of addresses relative to the
19599 @@ -176,10 +210,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19600 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19601 __chk_user_ptr(ptr); \
19602 might_fault(); \
19603 + pax_open_userland(); \
19604 asm volatile("call __get_user_%P3" \
19605 : "=a" (__ret_gu), "=r" (__val_gu) \
19606 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19607 (x) = (__typeof__(*(ptr))) __val_gu; \
19608 + pax_close_userland(); \
19609 __ret_gu; \
19610 })
19611
19612 @@ -187,13 +223,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19613 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19614 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19615
19616 -
19617 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19618 +#define __copyuser_seg "gs;"
19619 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19620 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19621 +#else
19622 +#define __copyuser_seg
19623 +#define __COPYUSER_SET_ES
19624 +#define __COPYUSER_RESTORE_ES
19625 +#endif
19626
19627 #ifdef CONFIG_X86_32
19628 #define __put_user_asm_u64(x, addr, err, errret) \
19629 asm volatile(ASM_STAC "\n" \
19630 - "1: movl %%eax,0(%2)\n" \
19631 - "2: movl %%edx,4(%2)\n" \
19632 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19633 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19634 "3: " ASM_CLAC "\n" \
19635 ".section .fixup,\"ax\"\n" \
19636 "4: movl %3,%0\n" \
19637 @@ -206,8 +250,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19638
19639 #define __put_user_asm_ex_u64(x, addr) \
19640 asm volatile(ASM_STAC "\n" \
19641 - "1: movl %%eax,0(%1)\n" \
19642 - "2: movl %%edx,4(%1)\n" \
19643 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19644 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19645 "3: " ASM_CLAC "\n" \
19646 _ASM_EXTABLE_EX(1b, 2b) \
19647 _ASM_EXTABLE_EX(2b, 3b) \
19648 @@ -257,7 +301,8 @@ extern void __put_user_8(void);
19649 __typeof__(*(ptr)) __pu_val; \
19650 __chk_user_ptr(ptr); \
19651 might_fault(); \
19652 - __pu_val = x; \
19653 + __pu_val = (x); \
19654 + pax_open_userland(); \
19655 switch (sizeof(*(ptr))) { \
19656 case 1: \
19657 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19658 @@ -275,6 +320,7 @@ extern void __put_user_8(void);
19659 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19660 break; \
19661 } \
19662 + pax_close_userland(); \
19663 __ret_pu; \
19664 })
19665
19666 @@ -355,8 +401,10 @@ do { \
19667 } while (0)
19668
19669 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19670 +do { \
19671 + pax_open_userland(); \
19672 asm volatile(ASM_STAC "\n" \
19673 - "1: mov"itype" %2,%"rtype"1\n" \
19674 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19675 "2: " ASM_CLAC "\n" \
19676 ".section .fixup,\"ax\"\n" \
19677 "3: mov %3,%0\n" \
19678 @@ -364,8 +412,10 @@ do { \
19679 " jmp 2b\n" \
19680 ".previous\n" \
19681 _ASM_EXTABLE(1b, 3b) \
19682 - : "=r" (err), ltype(x) \
19683 - : "m" (__m(addr)), "i" (errret), "0" (err))
19684 + : "=r" (err), ltype (x) \
19685 + : "m" (__m(addr)), "i" (errret), "0" (err)); \
19686 + pax_close_userland(); \
19687 +} while (0)
19688
19689 #define __get_user_size_ex(x, ptr, size) \
19690 do { \
19691 @@ -389,7 +439,7 @@ do { \
19692 } while (0)
19693
19694 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19695 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19696 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19697 "2:\n" \
19698 _ASM_EXTABLE_EX(1b, 2b) \
19699 : ltype(x) : "m" (__m(addr)))
19700 @@ -406,13 +456,24 @@ do { \
19701 int __gu_err; \
19702 unsigned long __gu_val; \
19703 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19704 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
19705 + (x) = (__typeof__(*(ptr)))__gu_val; \
19706 __gu_err; \
19707 })
19708
19709 /* FIXME: this hack is definitely wrong -AK */
19710 struct __large_struct { unsigned long buf[100]; };
19711 -#define __m(x) (*(struct __large_struct __user *)(x))
19712 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19713 +#define ____m(x) \
19714 +({ \
19715 + unsigned long ____x = (unsigned long)(x); \
19716 + if (____x < pax_user_shadow_base) \
19717 + ____x += pax_user_shadow_base; \
19718 + (typeof(x))____x; \
19719 +})
19720 +#else
19721 +#define ____m(x) (x)
19722 +#endif
19723 +#define __m(x) (*(struct __large_struct __user *)____m(x))
19724
19725 /*
19726 * Tell gcc we read from memory instead of writing: this is because
19727 @@ -420,8 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
19728 * aliasing issues.
19729 */
19730 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19731 +do { \
19732 + pax_open_userland(); \
19733 asm volatile(ASM_STAC "\n" \
19734 - "1: mov"itype" %"rtype"1,%2\n" \
19735 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19736 "2: " ASM_CLAC "\n" \
19737 ".section .fixup,\"ax\"\n" \
19738 "3: mov %3,%0\n" \
19739 @@ -429,10 +492,12 @@ struct __large_struct { unsigned long buf[100]; };
19740 ".previous\n" \
19741 _ASM_EXTABLE(1b, 3b) \
19742 : "=r"(err) \
19743 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19744 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19745 + pax_close_userland(); \
19746 +} while (0)
19747
19748 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19749 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19750 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19751 "2:\n" \
19752 _ASM_EXTABLE_EX(1b, 2b) \
19753 : : ltype(x), "m" (__m(addr)))
19754 @@ -442,11 +507,13 @@ struct __large_struct { unsigned long buf[100]; };
19755 */
19756 #define uaccess_try do { \
19757 current_thread_info()->uaccess_err = 0; \
19758 + pax_open_userland(); \
19759 stac(); \
19760 barrier();
19761
19762 #define uaccess_catch(err) \
19763 clac(); \
19764 + pax_close_userland(); \
19765 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19766 } while (0)
19767
19768 @@ -471,8 +538,12 @@ struct __large_struct { unsigned long buf[100]; };
19769 * On error, the variable @x is set to zero.
19770 */
19771
19772 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19773 +#define __get_user(x, ptr) get_user((x), (ptr))
19774 +#else
19775 #define __get_user(x, ptr) \
19776 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19777 +#endif
19778
19779 /**
19780 * __put_user: - Write a simple value into user space, with less checking.
19781 @@ -494,8 +565,12 @@ struct __large_struct { unsigned long buf[100]; };
19782 * Returns zero on success, or -EFAULT on error.
19783 */
19784
19785 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19786 +#define __put_user(x, ptr) put_user((x), (ptr))
19787 +#else
19788 #define __put_user(x, ptr) \
19789 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19790 +#endif
19791
19792 #define __get_user_unaligned __get_user
19793 #define __put_user_unaligned __put_user
19794 @@ -513,7 +588,7 @@ struct __large_struct { unsigned long buf[100]; };
19795 #define get_user_ex(x, ptr) do { \
19796 unsigned long __gue_val; \
19797 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19798 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
19799 + (x) = (__typeof__(*(ptr)))__gue_val; \
19800 } while (0)
19801
19802 #define put_user_try uaccess_try
19803 @@ -542,18 +617,19 @@ extern void __cmpxchg_wrong_size(void)
19804 __typeof__(ptr) __uval = (uval); \
19805 __typeof__(*(ptr)) __old = (old); \
19806 __typeof__(*(ptr)) __new = (new); \
19807 + pax_open_userland(); \
19808 switch (size) { \
19809 case 1: \
19810 { \
19811 asm volatile("\t" ASM_STAC "\n" \
19812 - "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
19813 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
19814 "2:\t" ASM_CLAC "\n" \
19815 "\t.section .fixup, \"ax\"\n" \
19816 "3:\tmov %3, %0\n" \
19817 "\tjmp 2b\n" \
19818 "\t.previous\n" \
19819 _ASM_EXTABLE(1b, 3b) \
19820 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19821 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19822 : "i" (-EFAULT), "q" (__new), "1" (__old) \
19823 : "memory" \
19824 ); \
19825 @@ -562,14 +638,14 @@ extern void __cmpxchg_wrong_size(void)
19826 case 2: \
19827 { \
19828 asm volatile("\t" ASM_STAC "\n" \
19829 - "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
19830 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
19831 "2:\t" ASM_CLAC "\n" \
19832 "\t.section .fixup, \"ax\"\n" \
19833 "3:\tmov %3, %0\n" \
19834 "\tjmp 2b\n" \
19835 "\t.previous\n" \
19836 _ASM_EXTABLE(1b, 3b) \
19837 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19838 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19839 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19840 : "memory" \
19841 ); \
19842 @@ -578,14 +654,14 @@ extern void __cmpxchg_wrong_size(void)
19843 case 4: \
19844 { \
19845 asm volatile("\t" ASM_STAC "\n" \
19846 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
19847 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
19848 "2:\t" ASM_CLAC "\n" \
19849 "\t.section .fixup, \"ax\"\n" \
19850 "3:\tmov %3, %0\n" \
19851 "\tjmp 2b\n" \
19852 "\t.previous\n" \
19853 _ASM_EXTABLE(1b, 3b) \
19854 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19855 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19856 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19857 : "memory" \
19858 ); \
19859 @@ -597,14 +673,14 @@ extern void __cmpxchg_wrong_size(void)
19860 __cmpxchg_wrong_size(); \
19861 \
19862 asm volatile("\t" ASM_STAC "\n" \
19863 - "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
19864 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
19865 "2:\t" ASM_CLAC "\n" \
19866 "\t.section .fixup, \"ax\"\n" \
19867 "3:\tmov %3, %0\n" \
19868 "\tjmp 2b\n" \
19869 "\t.previous\n" \
19870 _ASM_EXTABLE(1b, 3b) \
19871 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19872 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19873 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19874 : "memory" \
19875 ); \
19876 @@ -613,6 +689,7 @@ extern void __cmpxchg_wrong_size(void)
19877 default: \
19878 __cmpxchg_wrong_size(); \
19879 } \
19880 + pax_close_userland(); \
19881 *__uval = __old; \
19882 __ret; \
19883 })
19884 @@ -636,17 +713,6 @@ extern struct movsl_mask {
19885
19886 #define ARCH_HAS_NOCACHE_UACCESS 1
19887
19888 -#ifdef CONFIG_X86_32
19889 -# include <asm/uaccess_32.h>
19890 -#else
19891 -# include <asm/uaccess_64.h>
19892 -#endif
19893 -
19894 -unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19895 - unsigned n);
19896 -unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19897 - unsigned n);
19898 -
19899 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19900 # define copy_user_diag __compiletime_error
19901 #else
19902 @@ -656,7 +722,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19903 extern void copy_user_diag("copy_from_user() buffer size is too small")
19904 copy_from_user_overflow(void);
19905 extern void copy_user_diag("copy_to_user() buffer size is too small")
19906 -copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19907 +copy_to_user_overflow(void);
19908
19909 #undef copy_user_diag
19910
19911 @@ -669,7 +735,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19912
19913 extern void
19914 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19915 -__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19916 +__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19917 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19918
19919 #else
19920 @@ -684,10 +750,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19921
19922 #endif
19923
19924 +#ifdef CONFIG_X86_32
19925 +# include <asm/uaccess_32.h>
19926 +#else
19927 +# include <asm/uaccess_64.h>
19928 +#endif
19929 +
19930 static inline unsigned long __must_check
19931 copy_from_user(void *to, const void __user *from, unsigned long n)
19932 {
19933 - int sz = __compiletime_object_size(to);
19934 + size_t sz = __compiletime_object_size(to);
19935
19936 might_fault();
19937
19938 @@ -709,12 +781,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19939 * case, and do only runtime checking for non-constant sizes.
19940 */
19941
19942 - if (likely(sz < 0 || sz >= n))
19943 - n = _copy_from_user(to, from, n);
19944 - else if(__builtin_constant_p(n))
19945 - copy_from_user_overflow();
19946 - else
19947 - __copy_from_user_overflow(sz, n);
19948 + if (likely(sz != (size_t)-1 && sz < n)) {
19949 + if(__builtin_constant_p(n))
19950 + copy_from_user_overflow();
19951 + else
19952 + __copy_from_user_overflow(sz, n);
19953 + } else if (access_ok(VERIFY_READ, from, n))
19954 + n = __copy_from_user(to, from, n);
19955 + else if ((long)n > 0)
19956 + memset(to, 0, n);
19957
19958 return n;
19959 }
19960 @@ -722,17 +797,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19961 static inline unsigned long __must_check
19962 copy_to_user(void __user *to, const void *from, unsigned long n)
19963 {
19964 - int sz = __compiletime_object_size(from);
19965 + size_t sz = __compiletime_object_size(from);
19966
19967 might_fault();
19968
19969 /* See the comment in copy_from_user() above. */
19970 - if (likely(sz < 0 || sz >= n))
19971 - n = _copy_to_user(to, from, n);
19972 - else if(__builtin_constant_p(n))
19973 - copy_to_user_overflow();
19974 - else
19975 - __copy_to_user_overflow(sz, n);
19976 + if (likely(sz != (size_t)-1 && sz < n)) {
19977 + if(__builtin_constant_p(n))
19978 + copy_to_user_overflow();
19979 + else
19980 + __copy_to_user_overflow(sz, n);
19981 + } else if (access_ok(VERIFY_WRITE, to, n))
19982 + n = __copy_to_user(to, from, n);
19983
19984 return n;
19985 }
19986 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
19987 index 3c03a5d..1071638 100644
19988 --- a/arch/x86/include/asm/uaccess_32.h
19989 +++ b/arch/x86/include/asm/uaccess_32.h
19990 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
19991 static __always_inline unsigned long __must_check
19992 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
19993 {
19994 + if ((long)n < 0)
19995 + return n;
19996 +
19997 + check_object_size(from, n, true);
19998 +
19999 if (__builtin_constant_p(n)) {
20000 unsigned long ret;
20001
20002 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
20003 __copy_to_user(void __user *to, const void *from, unsigned long n)
20004 {
20005 might_fault();
20006 +
20007 return __copy_to_user_inatomic(to, from, n);
20008 }
20009
20010 static __always_inline unsigned long
20011 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
20012 {
20013 + if ((long)n < 0)
20014 + return n;
20015 +
20016 /* Avoid zeroing the tail if the copy fails..
20017 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
20018 * but as the zeroing behaviour is only significant when n is not
20019 @@ -137,6 +146,12 @@ static __always_inline unsigned long
20020 __copy_from_user(void *to, const void __user *from, unsigned long n)
20021 {
20022 might_fault();
20023 +
20024 + if ((long)n < 0)
20025 + return n;
20026 +
20027 + check_object_size(to, n, false);
20028 +
20029 if (__builtin_constant_p(n)) {
20030 unsigned long ret;
20031
20032 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
20033 const void __user *from, unsigned long n)
20034 {
20035 might_fault();
20036 +
20037 + if ((long)n < 0)
20038 + return n;
20039 +
20040 if (__builtin_constant_p(n)) {
20041 unsigned long ret;
20042
20043 @@ -181,7 +200,10 @@ static __always_inline unsigned long
20044 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
20045 unsigned long n)
20046 {
20047 - return __copy_from_user_ll_nocache_nozero(to, from, n);
20048 + if ((long)n < 0)
20049 + return n;
20050 +
20051 + return __copy_from_user_ll_nocache_nozero(to, from, n);
20052 }
20053
20054 #endif /* _ASM_X86_UACCESS_32_H */
20055 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
20056 index 12a26b9..206c200 100644
20057 --- a/arch/x86/include/asm/uaccess_64.h
20058 +++ b/arch/x86/include/asm/uaccess_64.h
20059 @@ -10,6 +10,9 @@
20060 #include <asm/alternative.h>
20061 #include <asm/cpufeature.h>
20062 #include <asm/page.h>
20063 +#include <asm/pgtable.h>
20064 +
20065 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
20066
20067 /*
20068 * Copy To/From Userspace
20069 @@ -17,14 +20,14 @@
20070
20071 /* Handles exceptions in both to and from, but doesn't do access_ok */
20072 __must_check unsigned long
20073 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
20074 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
20075 __must_check unsigned long
20076 -copy_user_generic_string(void *to, const void *from, unsigned len);
20077 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
20078 __must_check unsigned long
20079 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
20080 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
20081
20082 static __always_inline __must_check unsigned long
20083 -copy_user_generic(void *to, const void *from, unsigned len)
20084 +copy_user_generic(void *to, const void *from, unsigned long len)
20085 {
20086 unsigned ret;
20087
20088 @@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
20089 }
20090
20091 __must_check unsigned long
20092 -copy_in_user(void __user *to, const void __user *from, unsigned len);
20093 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
20094
20095 static __always_inline __must_check
20096 -int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
20097 +unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
20098 {
20099 - int ret = 0;
20100 + size_t sz = __compiletime_object_size(dst);
20101 + unsigned ret = 0;
20102 +
20103 + if (size > INT_MAX)
20104 + return size;
20105 +
20106 + check_object_size(dst, size, false);
20107 +
20108 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20109 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20110 + return size;
20111 +#endif
20112 +
20113 + if (unlikely(sz != (size_t)-1 && sz < size)) {
20114 + if(__builtin_constant_p(size))
20115 + copy_from_user_overflow();
20116 + else
20117 + __copy_from_user_overflow(sz, size);
20118 + return size;
20119 + }
20120
20121 if (!__builtin_constant_p(size))
20122 - return copy_user_generic(dst, (__force void *)src, size);
20123 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20124 switch (size) {
20125 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
20126 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
20127 ret, "b", "b", "=q", 1);
20128 return ret;
20129 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
20130 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
20131 ret, "w", "w", "=r", 2);
20132 return ret;
20133 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
20134 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
20135 ret, "l", "k", "=r", 4);
20136 return ret;
20137 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
20138 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20139 ret, "q", "", "=r", 8);
20140 return ret;
20141 case 10:
20142 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20143 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20144 ret, "q", "", "=r", 10);
20145 if (unlikely(ret))
20146 return ret;
20147 __get_user_asm(*(u16 *)(8 + (char *)dst),
20148 - (u16 __user *)(8 + (char __user *)src),
20149 + (const u16 __user *)(8 + (const char __user *)src),
20150 ret, "w", "w", "=r", 2);
20151 return ret;
20152 case 16:
20153 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20154 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20155 ret, "q", "", "=r", 16);
20156 if (unlikely(ret))
20157 return ret;
20158 __get_user_asm(*(u64 *)(8 + (char *)dst),
20159 - (u64 __user *)(8 + (char __user *)src),
20160 + (const u64 __user *)(8 + (const char __user *)src),
20161 ret, "q", "", "=r", 8);
20162 return ret;
20163 default:
20164 - return copy_user_generic(dst, (__force void *)src, size);
20165 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20166 }
20167 }
20168
20169 static __always_inline __must_check
20170 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
20171 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
20172 {
20173 might_fault();
20174 return __copy_from_user_nocheck(dst, src, size);
20175 }
20176
20177 static __always_inline __must_check
20178 -int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
20179 +unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
20180 {
20181 - int ret = 0;
20182 + size_t sz = __compiletime_object_size(src);
20183 + unsigned ret = 0;
20184 +
20185 + if (size > INT_MAX)
20186 + return size;
20187 +
20188 + check_object_size(src, size, true);
20189 +
20190 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20191 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20192 + return size;
20193 +#endif
20194 +
20195 + if (unlikely(sz != (size_t)-1 && sz < size)) {
20196 + if(__builtin_constant_p(size))
20197 + copy_to_user_overflow();
20198 + else
20199 + __copy_to_user_overflow(sz, size);
20200 + return size;
20201 + }
20202
20203 if (!__builtin_constant_p(size))
20204 - return copy_user_generic((__force void *)dst, src, size);
20205 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20206 switch (size) {
20207 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20208 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20209 ret, "b", "b", "iq", 1);
20210 return ret;
20211 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20212 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20213 ret, "w", "w", "ir", 2);
20214 return ret;
20215 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20216 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20217 ret, "l", "k", "ir", 4);
20218 return ret;
20219 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
20220 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20221 ret, "q", "", "er", 8);
20222 return ret;
20223 case 10:
20224 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20225 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20226 ret, "q", "", "er", 10);
20227 if (unlikely(ret))
20228 return ret;
20229 asm("":::"memory");
20230 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
20231 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
20232 ret, "w", "w", "ir", 2);
20233 return ret;
20234 case 16:
20235 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20236 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20237 ret, "q", "", "er", 16);
20238 if (unlikely(ret))
20239 return ret;
20240 asm("":::"memory");
20241 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
20242 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
20243 ret, "q", "", "er", 8);
20244 return ret;
20245 default:
20246 - return copy_user_generic((__force void *)dst, src, size);
20247 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20248 }
20249 }
20250
20251 static __always_inline __must_check
20252 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
20253 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
20254 {
20255 might_fault();
20256 return __copy_to_user_nocheck(dst, src, size);
20257 }
20258
20259 static __always_inline __must_check
20260 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20261 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20262 {
20263 - int ret = 0;
20264 + unsigned ret = 0;
20265
20266 might_fault();
20267 +
20268 + if (size > INT_MAX)
20269 + return size;
20270 +
20271 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20272 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20273 + return size;
20274 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20275 + return size;
20276 +#endif
20277 +
20278 if (!__builtin_constant_p(size))
20279 - return copy_user_generic((__force void *)dst,
20280 - (__force void *)src, size);
20281 + return copy_user_generic((__force_kernel void *)____m(dst),
20282 + (__force_kernel const void *)____m(src), size);
20283 switch (size) {
20284 case 1: {
20285 u8 tmp;
20286 - __get_user_asm(tmp, (u8 __user *)src,
20287 + __get_user_asm(tmp, (const u8 __user *)src,
20288 ret, "b", "b", "=q", 1);
20289 if (likely(!ret))
20290 __put_user_asm(tmp, (u8 __user *)dst,
20291 @@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20292 }
20293 case 2: {
20294 u16 tmp;
20295 - __get_user_asm(tmp, (u16 __user *)src,
20296 + __get_user_asm(tmp, (const u16 __user *)src,
20297 ret, "w", "w", "=r", 2);
20298 if (likely(!ret))
20299 __put_user_asm(tmp, (u16 __user *)dst,
20300 @@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20301
20302 case 4: {
20303 u32 tmp;
20304 - __get_user_asm(tmp, (u32 __user *)src,
20305 + __get_user_asm(tmp, (const u32 __user *)src,
20306 ret, "l", "k", "=r", 4);
20307 if (likely(!ret))
20308 __put_user_asm(tmp, (u32 __user *)dst,
20309 @@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20310 }
20311 case 8: {
20312 u64 tmp;
20313 - __get_user_asm(tmp, (u64 __user *)src,
20314 + __get_user_asm(tmp, (const u64 __user *)src,
20315 ret, "q", "", "=r", 8);
20316 if (likely(!ret))
20317 __put_user_asm(tmp, (u64 __user *)dst,
20318 @@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20319 return ret;
20320 }
20321 default:
20322 - return copy_user_generic((__force void *)dst,
20323 - (__force void *)src, size);
20324 + return copy_user_generic((__force_kernel void *)____m(dst),
20325 + (__force_kernel const void *)____m(src), size);
20326 }
20327 }
20328
20329 -static __must_check __always_inline int
20330 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20331 +static __must_check __always_inline unsigned long
20332 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20333 {
20334 return __copy_from_user_nocheck(dst, src, size);
20335 }
20336
20337 -static __must_check __always_inline int
20338 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20339 +static __must_check __always_inline unsigned long
20340 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20341 {
20342 return __copy_to_user_nocheck(dst, src, size);
20343 }
20344
20345 -extern long __copy_user_nocache(void *dst, const void __user *src,
20346 - unsigned size, int zerorest);
20347 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20348 + unsigned long size, int zerorest);
20349
20350 -static inline int
20351 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20352 +static inline unsigned long
20353 +__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20354 {
20355 might_fault();
20356 +
20357 + if (size > INT_MAX)
20358 + return size;
20359 +
20360 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20361 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20362 + return size;
20363 +#endif
20364 +
20365 return __copy_user_nocache(dst, src, size, 1);
20366 }
20367
20368 -static inline int
20369 +static inline unsigned long
20370 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20371 - unsigned size)
20372 + unsigned long size)
20373 {
20374 + if (size > INT_MAX)
20375 + return size;
20376 +
20377 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20378 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20379 + return size;
20380 +#endif
20381 +
20382 return __copy_user_nocache(dst, src, size, 0);
20383 }
20384
20385 unsigned long
20386 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20387 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20388
20389 #endif /* _ASM_X86_UACCESS_64_H */
20390 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20391 index 5b238981..77fdd78 100644
20392 --- a/arch/x86/include/asm/word-at-a-time.h
20393 +++ b/arch/x86/include/asm/word-at-a-time.h
20394 @@ -11,7 +11,7 @@
20395 * and shift, for example.
20396 */
20397 struct word_at_a_time {
20398 - const unsigned long one_bits, high_bits;
20399 + unsigned long one_bits, high_bits;
20400 };
20401
20402 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20403 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20404 index e45e4da..44e8572 100644
20405 --- a/arch/x86/include/asm/x86_init.h
20406 +++ b/arch/x86/include/asm/x86_init.h
20407 @@ -129,7 +129,7 @@ struct x86_init_ops {
20408 struct x86_init_timers timers;
20409 struct x86_init_iommu iommu;
20410 struct x86_init_pci pci;
20411 -};
20412 +} __no_const;
20413
20414 /**
20415 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20416 @@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20417 void (*setup_percpu_clockev)(void);
20418 void (*early_percpu_clock_init)(void);
20419 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20420 -};
20421 +} __no_const;
20422
20423 struct timespec;
20424
20425 @@ -168,7 +168,7 @@ struct x86_platform_ops {
20426 void (*save_sched_clock_state)(void);
20427 void (*restore_sched_clock_state)(void);
20428 void (*apic_post_init)(void);
20429 -};
20430 +} __no_const;
20431
20432 struct pci_dev;
20433 struct msi_msg;
20434 @@ -185,7 +185,7 @@ struct x86_msi_ops {
20435 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20436 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20437 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20438 -};
20439 +} __no_const;
20440
20441 struct IO_APIC_route_entry;
20442 struct io_apic_irq_attr;
20443 @@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20444 unsigned int destination, int vector,
20445 struct io_apic_irq_attr *attr);
20446 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20447 -};
20448 +} __no_const;
20449
20450 extern struct x86_init_ops x86_init;
20451 extern struct x86_cpuinit_ops x86_cpuinit;
20452 diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20453 index c949923..c22bfa4 100644
20454 --- a/arch/x86/include/asm/xen/page.h
20455 +++ b/arch/x86/include/asm/xen/page.h
20456 @@ -63,7 +63,7 @@ extern int m2p_remove_override(struct page *page,
20457 extern struct page *m2p_find_override(unsigned long mfn);
20458 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20459
20460 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
20461 +static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20462 {
20463 unsigned long mfn;
20464
20465 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20466 index 7e7a79a..0824666 100644
20467 --- a/arch/x86/include/asm/xsave.h
20468 +++ b/arch/x86/include/asm/xsave.h
20469 @@ -228,12 +228,16 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20470 if (unlikely(err))
20471 return -EFAULT;
20472
20473 + pax_open_userland();
20474 __asm__ __volatile__(ASM_STAC "\n"
20475 - "1:"XSAVE"\n"
20476 + "1:"
20477 + __copyuser_seg
20478 + XSAVE"\n"
20479 "2: " ASM_CLAC "\n"
20480 xstate_fault
20481 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20482 : "memory");
20483 + pax_close_userland();
20484 return err;
20485 }
20486
20487 @@ -243,16 +247,20 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20488 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20489 {
20490 int err = 0;
20491 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20492 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20493 u32 lmask = mask;
20494 u32 hmask = mask >> 32;
20495
20496 + pax_open_userland();
20497 __asm__ __volatile__(ASM_STAC "\n"
20498 - "1:"XRSTOR"\n"
20499 + "1:"
20500 + __copyuser_seg
20501 + XRSTOR"\n"
20502 "2: " ASM_CLAC "\n"
20503 xstate_fault
20504 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20505 : "memory"); /* memory required? */
20506 + pax_close_userland();
20507 return err;
20508 }
20509
20510 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20511 index d993e33..8db1b18 100644
20512 --- a/arch/x86/include/uapi/asm/e820.h
20513 +++ b/arch/x86/include/uapi/asm/e820.h
20514 @@ -58,7 +58,7 @@ struct e820map {
20515 #define ISA_START_ADDRESS 0xa0000
20516 #define ISA_END_ADDRESS 0x100000
20517
20518 -#define BIOS_BEGIN 0x000a0000
20519 +#define BIOS_BEGIN 0x000c0000
20520 #define BIOS_END 0x00100000
20521
20522 #define BIOS_ROM_BASE 0xffe00000
20523 diff --git a/arch/x86/include/uapi/asm/ldt.h b/arch/x86/include/uapi/asm/ldt.h
20524 index 46727eb..6e1aaf7 100644
20525 --- a/arch/x86/include/uapi/asm/ldt.h
20526 +++ b/arch/x86/include/uapi/asm/ldt.h
20527 @@ -28,6 +28,13 @@ struct user_desc {
20528 unsigned int seg_not_present:1;
20529 unsigned int useable:1;
20530 #ifdef __x86_64__
20531 + /*
20532 + * Because this bit is not present in 32-bit user code, user
20533 + * programs can pass uninitialized values here. Therefore, in
20534 + * any context in which a user_desc comes from a 32-bit program,
20535 + * the kernel must act as though lm == 0, regardless of the
20536 + * actual value.
20537 + */
20538 unsigned int lm:1;
20539 #endif
20540 };
20541 diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20542 index 7b0a55a..ad115bf 100644
20543 --- a/arch/x86/include/uapi/asm/ptrace-abi.h
20544 +++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20545 @@ -49,7 +49,6 @@
20546 #define EFLAGS 144
20547 #define RSP 152
20548 #define SS 160
20549 -#define ARGOFFSET R11
20550 #endif /* __ASSEMBLY__ */
20551
20552 /* top of stack page */
20553 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20554 index 8f1e774..9b4c381 100644
20555 --- a/arch/x86/kernel/Makefile
20556 +++ b/arch/x86/kernel/Makefile
20557 @@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20558 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20559 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20560 obj-y += probe_roms.o
20561 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20562 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20563 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20564 obj-$(CONFIG_X86_64) += mcount_64.o
20565 obj-y += syscall_$(BITS).o vsyscall_gtod.o
20566 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20567 index a142e77..6222cdd 100644
20568 --- a/arch/x86/kernel/acpi/boot.c
20569 +++ b/arch/x86/kernel/acpi/boot.c
20570 @@ -1276,7 +1276,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20571 * If your system is blacklisted here, but you find that acpi=force
20572 * works for you, please contact linux-acpi@vger.kernel.org
20573 */
20574 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
20575 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20576 /*
20577 * Boxes that need ACPI disabled
20578 */
20579 @@ -1351,7 +1351,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20580 };
20581
20582 /* second table for DMI checks that should run after early-quirks */
20583 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20584 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20585 /*
20586 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20587 * which includes some code which overrides all temperature
20588 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20589 index 3136820..e2c6577 100644
20590 --- a/arch/x86/kernel/acpi/sleep.c
20591 +++ b/arch/x86/kernel/acpi/sleep.c
20592 @@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20593 #else /* CONFIG_64BIT */
20594 #ifdef CONFIG_SMP
20595 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20596 +
20597 + pax_open_kernel();
20598 early_gdt_descr.address =
20599 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20600 + pax_close_kernel();
20601 +
20602 initial_gs = per_cpu_offset(smp_processor_id());
20603 #endif
20604 initial_code = (unsigned long)wakeup_long64;
20605 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20606 index 665c6b7..eae4d56 100644
20607 --- a/arch/x86/kernel/acpi/wakeup_32.S
20608 +++ b/arch/x86/kernel/acpi/wakeup_32.S
20609 @@ -29,13 +29,11 @@ wakeup_pmode_return:
20610 # and restore the stack ... but you need gdt for this to work
20611 movl saved_context_esp, %esp
20612
20613 - movl %cs:saved_magic, %eax
20614 - cmpl $0x12345678, %eax
20615 + cmpl $0x12345678, saved_magic
20616 jne bogus_magic
20617
20618 # jump to place where we left off
20619 - movl saved_eip, %eax
20620 - jmp *%eax
20621 + jmp *(saved_eip)
20622
20623 bogus_magic:
20624 jmp bogus_magic
20625 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20626 index 703130f..27a155d 100644
20627 --- a/arch/x86/kernel/alternative.c
20628 +++ b/arch/x86/kernel/alternative.c
20629 @@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20630 */
20631 for (a = start; a < end; a++) {
20632 instr = (u8 *)&a->instr_offset + a->instr_offset;
20633 +
20634 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20635 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20636 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20637 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20638 +#endif
20639 +
20640 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20641 BUG_ON(a->replacementlen > a->instrlen);
20642 BUG_ON(a->instrlen > sizeof(insnbuf));
20643 @@ -284,6 +291,11 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20644 add_nops(insnbuf + a->replacementlen,
20645 a->instrlen - a->replacementlen);
20646
20647 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20648 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20649 + instr = ktva_ktla(instr);
20650 +#endif
20651 +
20652 text_poke_early(instr, insnbuf, a->instrlen);
20653 }
20654 }
20655 @@ -299,10 +311,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20656 for (poff = start; poff < end; poff++) {
20657 u8 *ptr = (u8 *)poff + *poff;
20658
20659 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20660 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20661 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20662 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20663 +#endif
20664 +
20665 if (!*poff || ptr < text || ptr >= text_end)
20666 continue;
20667 /* turn DS segment override prefix into lock prefix */
20668 - if (*ptr == 0x3e)
20669 + if (*ktla_ktva(ptr) == 0x3e)
20670 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20671 }
20672 mutex_unlock(&text_mutex);
20673 @@ -317,10 +335,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20674 for (poff = start; poff < end; poff++) {
20675 u8 *ptr = (u8 *)poff + *poff;
20676
20677 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20678 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20679 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20680 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20681 +#endif
20682 +
20683 if (!*poff || ptr < text || ptr >= text_end)
20684 continue;
20685 /* turn lock prefix into DS segment override prefix */
20686 - if (*ptr == 0xf0)
20687 + if (*ktla_ktva(ptr) == 0xf0)
20688 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20689 }
20690 mutex_unlock(&text_mutex);
20691 @@ -457,7 +481,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20692
20693 BUG_ON(p->len > MAX_PATCH_LEN);
20694 /* prep the buffer with the original instructions */
20695 - memcpy(insnbuf, p->instr, p->len);
20696 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20697 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20698 (unsigned long)p->instr, p->len);
20699
20700 @@ -504,7 +528,7 @@ void __init alternative_instructions(void)
20701 if (!uniproc_patched || num_possible_cpus() == 1)
20702 free_init_pages("SMP alternatives",
20703 (unsigned long)__smp_locks,
20704 - (unsigned long)__smp_locks_end);
20705 + PAGE_ALIGN((unsigned long)__smp_locks_end));
20706 #endif
20707
20708 apply_paravirt(__parainstructions, __parainstructions_end);
20709 @@ -524,13 +548,17 @@ void __init alternative_instructions(void)
20710 * instructions. And on the local CPU you need to be protected again NMI or MCE
20711 * handlers seeing an inconsistent instruction while you patch.
20712 */
20713 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
20714 +void *__kprobes text_poke_early(void *addr, const void *opcode,
20715 size_t len)
20716 {
20717 unsigned long flags;
20718 local_irq_save(flags);
20719 - memcpy(addr, opcode, len);
20720 +
20721 + pax_open_kernel();
20722 + memcpy(ktla_ktva(addr), opcode, len);
20723 sync_core();
20724 + pax_close_kernel();
20725 +
20726 local_irq_restore(flags);
20727 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20728 that causes hangs on some VIA CPUs. */
20729 @@ -552,36 +580,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20730 */
20731 void *text_poke(void *addr, const void *opcode, size_t len)
20732 {
20733 - unsigned long flags;
20734 - char *vaddr;
20735 + unsigned char *vaddr = ktla_ktva(addr);
20736 struct page *pages[2];
20737 - int i;
20738 + size_t i;
20739
20740 if (!core_kernel_text((unsigned long)addr)) {
20741 - pages[0] = vmalloc_to_page(addr);
20742 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20743 + pages[0] = vmalloc_to_page(vaddr);
20744 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20745 } else {
20746 - pages[0] = virt_to_page(addr);
20747 + pages[0] = virt_to_page(vaddr);
20748 WARN_ON(!PageReserved(pages[0]));
20749 - pages[1] = virt_to_page(addr + PAGE_SIZE);
20750 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20751 }
20752 BUG_ON(!pages[0]);
20753 - local_irq_save(flags);
20754 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20755 - if (pages[1])
20756 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20757 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20758 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20759 - clear_fixmap(FIX_TEXT_POKE0);
20760 - if (pages[1])
20761 - clear_fixmap(FIX_TEXT_POKE1);
20762 - local_flush_tlb();
20763 - sync_core();
20764 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
20765 - that causes hangs on some VIA CPUs. */
20766 + text_poke_early(addr, opcode, len);
20767 for (i = 0; i < len; i++)
20768 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20769 - local_irq_restore(flags);
20770 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20771 return addr;
20772 }
20773
20774 @@ -601,7 +615,7 @@ int poke_int3_handler(struct pt_regs *regs)
20775 if (likely(!bp_patching_in_progress))
20776 return 0;
20777
20778 - if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20779 + if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20780 return 0;
20781
20782 /* set up the specified breakpoint handler */
20783 @@ -635,7 +649,7 @@ int poke_int3_handler(struct pt_regs *regs)
20784 */
20785 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20786 {
20787 - unsigned char int3 = 0xcc;
20788 + const unsigned char int3 = 0xcc;
20789
20790 bp_int3_handler = handler;
20791 bp_int3_addr = (u8 *)addr + sizeof(int3);
20792 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20793 index ba6cc04..06fd971 100644
20794 --- a/arch/x86/kernel/apic/apic.c
20795 +++ b/arch/x86/kernel/apic/apic.c
20796 @@ -201,7 +201,7 @@ int first_system_vector = 0xfe;
20797 /*
20798 * Debug level, exported for io_apic.c
20799 */
20800 -unsigned int apic_verbosity;
20801 +int apic_verbosity;
20802
20803 int pic_mode;
20804
20805 @@ -1989,7 +1989,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20806 apic_write(APIC_ESR, 0);
20807 v = apic_read(APIC_ESR);
20808 ack_APIC_irq();
20809 - atomic_inc(&irq_err_count);
20810 + atomic_inc_unchecked(&irq_err_count);
20811
20812 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
20813 smp_processor_id(), v);
20814 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20815 index de918c4..32eed23 100644
20816 --- a/arch/x86/kernel/apic/apic_flat_64.c
20817 +++ b/arch/x86/kernel/apic/apic_flat_64.c
20818 @@ -154,7 +154,7 @@ static int flat_probe(void)
20819 return 1;
20820 }
20821
20822 -static struct apic apic_flat = {
20823 +static struct apic apic_flat __read_only = {
20824 .name = "flat",
20825 .probe = flat_probe,
20826 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20827 @@ -260,7 +260,7 @@ static int physflat_probe(void)
20828 return 0;
20829 }
20830
20831 -static struct apic apic_physflat = {
20832 +static struct apic apic_physflat __read_only = {
20833
20834 .name = "physical flat",
20835 .probe = physflat_probe,
20836 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20837 index b205cdb..d8503ff 100644
20838 --- a/arch/x86/kernel/apic/apic_noop.c
20839 +++ b/arch/x86/kernel/apic/apic_noop.c
20840 @@ -108,7 +108,7 @@ static void noop_apic_write(u32 reg, u32 v)
20841 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20842 }
20843
20844 -struct apic apic_noop = {
20845 +struct apic apic_noop __read_only = {
20846 .name = "noop",
20847 .probe = noop_probe,
20848 .acpi_madt_oem_check = NULL,
20849 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20850 index c4a8d63..fe893ac 100644
20851 --- a/arch/x86/kernel/apic/bigsmp_32.c
20852 +++ b/arch/x86/kernel/apic/bigsmp_32.c
20853 @@ -147,7 +147,7 @@ static int probe_bigsmp(void)
20854 return dmi_bigsmp;
20855 }
20856
20857 -static struct apic apic_bigsmp = {
20858 +static struct apic apic_bigsmp __read_only = {
20859
20860 .name = "bigsmp",
20861 .probe = probe_bigsmp,
20862 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20863 index 1183d54..6158e47 100644
20864 --- a/arch/x86/kernel/apic/io_apic.c
20865 +++ b/arch/x86/kernel/apic/io_apic.c
20866 @@ -1230,7 +1230,7 @@ out:
20867 }
20868 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20869
20870 -void lock_vector_lock(void)
20871 +void lock_vector_lock(void) __acquires(vector_lock)
20872 {
20873 /* Used to the online set of cpus does not change
20874 * during assign_irq_vector.
20875 @@ -1238,7 +1238,7 @@ void lock_vector_lock(void)
20876 raw_spin_lock(&vector_lock);
20877 }
20878
20879 -void unlock_vector_lock(void)
20880 +void unlock_vector_lock(void) __releases(vector_lock)
20881 {
20882 raw_spin_unlock(&vector_lock);
20883 }
20884 @@ -2465,7 +2465,7 @@ static void ack_apic_edge(struct irq_data *data)
20885 ack_APIC_irq();
20886 }
20887
20888 -atomic_t irq_mis_count;
20889 +atomic_unchecked_t irq_mis_count;
20890
20891 #ifdef CONFIG_GENERIC_PENDING_IRQ
20892 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20893 @@ -2606,7 +2606,7 @@ static void ack_apic_level(struct irq_data *data)
20894 * at the cpu.
20895 */
20896 if (!(v & (1 << (i & 0x1f)))) {
20897 - atomic_inc(&irq_mis_count);
20898 + atomic_inc_unchecked(&irq_mis_count);
20899
20900 eoi_ioapic_irq(irq, cfg);
20901 }
20902 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20903 index bda4886..f9c7195 100644
20904 --- a/arch/x86/kernel/apic/probe_32.c
20905 +++ b/arch/x86/kernel/apic/probe_32.c
20906 @@ -72,7 +72,7 @@ static int probe_default(void)
20907 return 1;
20908 }
20909
20910 -static struct apic apic_default = {
20911 +static struct apic apic_default __read_only = {
20912
20913 .name = "default",
20914 .probe = probe_default,
20915 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20916 index e658f21..b695a1a 100644
20917 --- a/arch/x86/kernel/apic/x2apic_cluster.c
20918 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
20919 @@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20920 return notifier_from_errno(err);
20921 }
20922
20923 -static struct notifier_block __refdata x2apic_cpu_notifier = {
20924 +static struct notifier_block x2apic_cpu_notifier = {
20925 .notifier_call = update_clusterinfo,
20926 };
20927
20928 @@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20929 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20930 }
20931
20932 -static struct apic apic_x2apic_cluster = {
20933 +static struct apic apic_x2apic_cluster __read_only = {
20934
20935 .name = "cluster x2apic",
20936 .probe = x2apic_cluster_probe,
20937 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20938 index 6fae733..5ca17af 100644
20939 --- a/arch/x86/kernel/apic/x2apic_phys.c
20940 +++ b/arch/x86/kernel/apic/x2apic_phys.c
20941 @@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
20942 return apic == &apic_x2apic_phys;
20943 }
20944
20945 -static struct apic apic_x2apic_phys = {
20946 +static struct apic apic_x2apic_phys __read_only = {
20947
20948 .name = "physical x2apic",
20949 .probe = x2apic_phys_probe,
20950 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20951 index 8e9dcfd..c61b3e4 100644
20952 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
20953 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20954 @@ -348,7 +348,7 @@ static int uv_probe(void)
20955 return apic == &apic_x2apic_uv_x;
20956 }
20957
20958 -static struct apic __refdata apic_x2apic_uv_x = {
20959 +static struct apic apic_x2apic_uv_x __read_only = {
20960
20961 .name = "UV large system",
20962 .probe = uv_probe,
20963 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20964 index 5848744..56cb598 100644
20965 --- a/arch/x86/kernel/apm_32.c
20966 +++ b/arch/x86/kernel/apm_32.c
20967 @@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20968 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20969 * even though they are called in protected mode.
20970 */
20971 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20972 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20973 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20974
20975 static const char driver_version[] = "1.16ac"; /* no spaces */
20976 @@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
20977 BUG_ON(cpu != 0);
20978 gdt = get_cpu_gdt_table(cpu);
20979 save_desc_40 = gdt[0x40 / 8];
20980 +
20981 + pax_open_kernel();
20982 gdt[0x40 / 8] = bad_bios_desc;
20983 + pax_close_kernel();
20984
20985 apm_irq_save(flags);
20986 APM_DO_SAVE_SEGS;
20987 @@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20988 &call->esi);
20989 APM_DO_RESTORE_SEGS;
20990 apm_irq_restore(flags);
20991 +
20992 + pax_open_kernel();
20993 gdt[0x40 / 8] = save_desc_40;
20994 + pax_close_kernel();
20995 +
20996 put_cpu();
20997
20998 return call->eax & 0xff;
20999 @@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
21000 BUG_ON(cpu != 0);
21001 gdt = get_cpu_gdt_table(cpu);
21002 save_desc_40 = gdt[0x40 / 8];
21003 +
21004 + pax_open_kernel();
21005 gdt[0x40 / 8] = bad_bios_desc;
21006 + pax_close_kernel();
21007
21008 apm_irq_save(flags);
21009 APM_DO_SAVE_SEGS;
21010 @@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
21011 &call->eax);
21012 APM_DO_RESTORE_SEGS;
21013 apm_irq_restore(flags);
21014 +
21015 + pax_open_kernel();
21016 gdt[0x40 / 8] = save_desc_40;
21017 + pax_close_kernel();
21018 +
21019 put_cpu();
21020 return error;
21021 }
21022 @@ -2350,12 +2364,15 @@ static int __init apm_init(void)
21023 * code to that CPU.
21024 */
21025 gdt = get_cpu_gdt_table(0);
21026 +
21027 + pax_open_kernel();
21028 set_desc_base(&gdt[APM_CS >> 3],
21029 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
21030 set_desc_base(&gdt[APM_CS_16 >> 3],
21031 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
21032 set_desc_base(&gdt[APM_DS >> 3],
21033 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
21034 + pax_close_kernel();
21035
21036 proc_create("apm", 0, NULL, &apm_file_ops);
21037
21038 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
21039 index 9f6b934..cf5ffb3 100644
21040 --- a/arch/x86/kernel/asm-offsets.c
21041 +++ b/arch/x86/kernel/asm-offsets.c
21042 @@ -32,6 +32,8 @@ void common(void) {
21043 OFFSET(TI_flags, thread_info, flags);
21044 OFFSET(TI_status, thread_info, status);
21045 OFFSET(TI_addr_limit, thread_info, addr_limit);
21046 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
21047 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
21048
21049 BLANK();
21050 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
21051 @@ -52,8 +54,26 @@ void common(void) {
21052 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
21053 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
21054 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
21055 +
21056 +#ifdef CONFIG_PAX_KERNEXEC
21057 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
21058 #endif
21059
21060 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21061 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
21062 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
21063 +#ifdef CONFIG_X86_64
21064 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
21065 +#endif
21066 +#endif
21067 +
21068 +#endif
21069 +
21070 + BLANK();
21071 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
21072 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
21073 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
21074 +
21075 #ifdef CONFIG_XEN
21076 BLANK();
21077 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
21078 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
21079 index e7c798b..2b2019b 100644
21080 --- a/arch/x86/kernel/asm-offsets_64.c
21081 +++ b/arch/x86/kernel/asm-offsets_64.c
21082 @@ -77,6 +77,7 @@ int main(void)
21083 BLANK();
21084 #undef ENTRY
21085
21086 + DEFINE(TSS_size, sizeof(struct tss_struct));
21087 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
21088 BLANK();
21089
21090 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
21091 index e27b49d..85b106c 100644
21092 --- a/arch/x86/kernel/cpu/Makefile
21093 +++ b/arch/x86/kernel/cpu/Makefile
21094 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
21095 CFLAGS_REMOVE_perf_event.o = -pg
21096 endif
21097
21098 -# Make sure load_percpu_segment has no stackprotector
21099 -nostackp := $(call cc-option, -fno-stack-protector)
21100 -CFLAGS_common.o := $(nostackp)
21101 -
21102 obj-y := intel_cacheinfo.o scattered.o topology.o
21103 obj-y += common.o
21104 obj-y += rdrand.o
21105 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
21106 index 813d29d..6e542d4 100644
21107 --- a/arch/x86/kernel/cpu/amd.c
21108 +++ b/arch/x86/kernel/cpu/amd.c
21109 @@ -718,7 +718,7 @@ static void init_amd(struct cpuinfo_x86 *c)
21110 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
21111 {
21112 /* AMD errata T13 (order #21922) */
21113 - if ((c->x86 == 6)) {
21114 + if (c->x86 == 6) {
21115 /* Duron Rev A0 */
21116 if (c->x86_model == 3 && c->x86_mask == 0)
21117 size = 64;
21118 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
21119 index cfa9b5b..19b5084 100644
21120 --- a/arch/x86/kernel/cpu/common.c
21121 +++ b/arch/x86/kernel/cpu/common.c
21122 @@ -90,60 +90,6 @@ static const struct cpu_dev default_cpu = {
21123
21124 static const struct cpu_dev *this_cpu = &default_cpu;
21125
21126 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
21127 -#ifdef CONFIG_X86_64
21128 - /*
21129 - * We need valid kernel segments for data and code in long mode too
21130 - * IRET will check the segment types kkeil 2000/10/28
21131 - * Also sysret mandates a special GDT layout
21132 - *
21133 - * TLS descriptors are currently at a different place compared to i386.
21134 - * Hopefully nobody expects them at a fixed place (Wine?)
21135 - */
21136 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
21137 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
21138 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
21139 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
21140 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
21141 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
21142 -#else
21143 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
21144 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21145 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
21146 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
21147 - /*
21148 - * Segments used for calling PnP BIOS have byte granularity.
21149 - * They code segments and data segments have fixed 64k limits,
21150 - * the transfer segment sizes are set at run time.
21151 - */
21152 - /* 32-bit code */
21153 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21154 - /* 16-bit code */
21155 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21156 - /* 16-bit data */
21157 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
21158 - /* 16-bit data */
21159 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
21160 - /* 16-bit data */
21161 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
21162 - /*
21163 - * The APM segments have byte granularity and their bases
21164 - * are set at run time. All have 64k limits.
21165 - */
21166 - /* 32-bit code */
21167 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21168 - /* 16-bit code */
21169 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21170 - /* data */
21171 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
21172 -
21173 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21174 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21175 - GDT_STACK_CANARY_INIT
21176 -#endif
21177 -} };
21178 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
21179 -
21180 static int __init x86_xsave_setup(char *s)
21181 {
21182 if (strlen(s))
21183 @@ -305,6 +251,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
21184 }
21185 }
21186
21187 +#ifdef CONFIG_X86_64
21188 +static __init int setup_disable_pcid(char *arg)
21189 +{
21190 + setup_clear_cpu_cap(X86_FEATURE_PCID);
21191 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
21192 +
21193 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21194 + if (clone_pgd_mask != ~(pgdval_t)0UL)
21195 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21196 +#endif
21197 +
21198 + return 1;
21199 +}
21200 +__setup("nopcid", setup_disable_pcid);
21201 +
21202 +static void setup_pcid(struct cpuinfo_x86 *c)
21203 +{
21204 + if (!cpu_has(c, X86_FEATURE_PCID)) {
21205 + clear_cpu_cap(c, X86_FEATURE_INVPCID);
21206 +
21207 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21208 + if (clone_pgd_mask != ~(pgdval_t)0UL) {
21209 + pax_open_kernel();
21210 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21211 + pax_close_kernel();
21212 + printk("PAX: slow and weak UDEREF enabled\n");
21213 + } else
21214 + printk("PAX: UDEREF disabled\n");
21215 +#endif
21216 +
21217 + return;
21218 + }
21219 +
21220 + printk("PAX: PCID detected\n");
21221 + set_in_cr4(X86_CR4_PCIDE);
21222 +
21223 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21224 + pax_open_kernel();
21225 + clone_pgd_mask = ~(pgdval_t)0UL;
21226 + pax_close_kernel();
21227 + if (pax_user_shadow_base)
21228 + printk("PAX: weak UDEREF enabled\n");
21229 + else {
21230 + set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21231 + printk("PAX: strong UDEREF enabled\n");
21232 + }
21233 +#endif
21234 +
21235 + if (cpu_has(c, X86_FEATURE_INVPCID))
21236 + printk("PAX: INVPCID detected\n");
21237 +}
21238 +#endif
21239 +
21240 /*
21241 * Some CPU features depend on higher CPUID levels, which may not always
21242 * be available due to CPUID level capping or broken virtualization
21243 @@ -405,7 +404,7 @@ void switch_to_new_gdt(int cpu)
21244 {
21245 struct desc_ptr gdt_descr;
21246
21247 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
21248 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21249 gdt_descr.size = GDT_SIZE - 1;
21250 load_gdt(&gdt_descr);
21251 /* Reload the per-cpu base */
21252 @@ -895,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21253 setup_smep(c);
21254 setup_smap(c);
21255
21256 +#ifdef CONFIG_X86_64
21257 + setup_pcid(c);
21258 +#endif
21259 +
21260 /*
21261 * The vendor-specific functions might have changed features.
21262 * Now we do "generic changes."
21263 @@ -903,6 +906,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21264 /* Filter out anything that depends on CPUID levels we don't have */
21265 filter_cpuid_features(c, true);
21266
21267 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21268 + setup_clear_cpu_cap(X86_FEATURE_SEP);
21269 +#endif
21270 +
21271 /* If the model name is still unset, do table lookup. */
21272 if (!c->x86_model_id[0]) {
21273 const char *p;
21274 @@ -985,7 +992,7 @@ static void syscall32_cpu_init(void)
21275 void enable_sep_cpu(void)
21276 {
21277 int cpu = get_cpu();
21278 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
21279 + struct tss_struct *tss = init_tss + cpu;
21280
21281 if (!boot_cpu_has(X86_FEATURE_SEP)) {
21282 put_cpu();
21283 @@ -1125,14 +1132,16 @@ static __init int setup_disablecpuid(char *arg)
21284 }
21285 __setup("clearcpuid=", setup_disablecpuid);
21286
21287 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
21288 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
21289 +
21290 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21291 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21292 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21293 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21294
21295 #ifdef CONFIG_X86_64
21296 -struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21297 -struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21298 - (unsigned long) debug_idt_table };
21299 +struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21300 +const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21301
21302 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21303 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21304 @@ -1309,7 +1318,7 @@ void cpu_init(void)
21305 */
21306 load_ucode_ap();
21307
21308 - t = &per_cpu(init_tss, cpu);
21309 + t = init_tss + cpu;
21310 oist = &per_cpu(orig_ist, cpu);
21311
21312 #ifdef CONFIG_NUMA
21313 @@ -1341,7 +1350,6 @@ void cpu_init(void)
21314 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21315 barrier();
21316
21317 - x86_configure_nx();
21318 enable_x2apic();
21319
21320 /*
21321 @@ -1393,7 +1401,7 @@ void cpu_init(void)
21322 {
21323 int cpu = smp_processor_id();
21324 struct task_struct *curr = current;
21325 - struct tss_struct *t = &per_cpu(init_tss, cpu);
21326 + struct tss_struct *t = init_tss + cpu;
21327 struct thread_struct *thread = &curr->thread;
21328
21329 wait_for_master_cpu(cpu);
21330 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21331 index c703507..28535e3 100644
21332 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21333 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21334 @@ -1026,6 +1026,22 @@ static struct attribute *default_attrs[] = {
21335 };
21336
21337 #ifdef CONFIG_AMD_NB
21338 +static struct attribute *default_attrs_amd_nb[] = {
21339 + &type.attr,
21340 + &level.attr,
21341 + &coherency_line_size.attr,
21342 + &physical_line_partition.attr,
21343 + &ways_of_associativity.attr,
21344 + &number_of_sets.attr,
21345 + &size.attr,
21346 + &shared_cpu_map.attr,
21347 + &shared_cpu_list.attr,
21348 + NULL,
21349 + NULL,
21350 + NULL,
21351 + NULL
21352 +};
21353 +
21354 static struct attribute **amd_l3_attrs(void)
21355 {
21356 static struct attribute **attrs;
21357 @@ -1036,18 +1052,7 @@ static struct attribute **amd_l3_attrs(void)
21358
21359 n = ARRAY_SIZE(default_attrs);
21360
21361 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21362 - n += 2;
21363 -
21364 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21365 - n += 1;
21366 -
21367 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21368 - if (attrs == NULL)
21369 - return attrs = default_attrs;
21370 -
21371 - for (n = 0; default_attrs[n]; n++)
21372 - attrs[n] = default_attrs[n];
21373 + attrs = default_attrs_amd_nb;
21374
21375 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21376 attrs[n++] = &cache_disable_0.attr;
21377 @@ -1098,6 +1103,13 @@ static struct kobj_type ktype_cache = {
21378 .default_attrs = default_attrs,
21379 };
21380
21381 +#ifdef CONFIG_AMD_NB
21382 +static struct kobj_type ktype_cache_amd_nb = {
21383 + .sysfs_ops = &sysfs_ops,
21384 + .default_attrs = default_attrs_amd_nb,
21385 +};
21386 +#endif
21387 +
21388 static struct kobj_type ktype_percpu_entry = {
21389 .sysfs_ops = &sysfs_ops,
21390 };
21391 @@ -1163,20 +1175,26 @@ static int cache_add_dev(struct device *dev)
21392 return retval;
21393 }
21394
21395 +#ifdef CONFIG_AMD_NB
21396 + amd_l3_attrs();
21397 +#endif
21398 +
21399 for (i = 0; i < num_cache_leaves; i++) {
21400 + struct kobj_type *ktype;
21401 +
21402 this_object = INDEX_KOBJECT_PTR(cpu, i);
21403 this_object->cpu = cpu;
21404 this_object->index = i;
21405
21406 this_leaf = CPUID4_INFO_IDX(cpu, i);
21407
21408 - ktype_cache.default_attrs = default_attrs;
21409 + ktype = &ktype_cache;
21410 #ifdef CONFIG_AMD_NB
21411 if (this_leaf->base.nb)
21412 - ktype_cache.default_attrs = amd_l3_attrs();
21413 + ktype = &ktype_cache_amd_nb;
21414 #endif
21415 retval = kobject_init_and_add(&(this_object->kobj),
21416 - &ktype_cache,
21417 + ktype,
21418 per_cpu(ici_cache_kobject, cpu),
21419 "index%1lu", i);
21420 if (unlikely(retval)) {
21421 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21422 index 61a9668ce..b446a37 100644
21423 --- a/arch/x86/kernel/cpu/mcheck/mce.c
21424 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
21425 @@ -45,6 +45,7 @@
21426 #include <asm/processor.h>
21427 #include <asm/mce.h>
21428 #include <asm/msr.h>
21429 +#include <asm/local.h>
21430
21431 #include "mce-internal.h"
21432
21433 @@ -259,7 +260,7 @@ static void print_mce(struct mce *m)
21434 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21435 m->cs, m->ip);
21436
21437 - if (m->cs == __KERNEL_CS)
21438 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21439 print_symbol("{%s}", m->ip);
21440 pr_cont("\n");
21441 }
21442 @@ -292,10 +293,10 @@ static void print_mce(struct mce *m)
21443
21444 #define PANIC_TIMEOUT 5 /* 5 seconds */
21445
21446 -static atomic_t mce_paniced;
21447 +static atomic_unchecked_t mce_paniced;
21448
21449 static int fake_panic;
21450 -static atomic_t mce_fake_paniced;
21451 +static atomic_unchecked_t mce_fake_paniced;
21452
21453 /* Panic in progress. Enable interrupts and wait for final IPI */
21454 static void wait_for_panic(void)
21455 @@ -319,7 +320,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21456 /*
21457 * Make sure only one CPU runs in machine check panic
21458 */
21459 - if (atomic_inc_return(&mce_paniced) > 1)
21460 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21461 wait_for_panic();
21462 barrier();
21463
21464 @@ -327,7 +328,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21465 console_verbose();
21466 } else {
21467 /* Don't log too much for fake panic */
21468 - if (atomic_inc_return(&mce_fake_paniced) > 1)
21469 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21470 return;
21471 }
21472 /* First print corrected ones that are still unlogged */
21473 @@ -366,7 +367,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21474 if (!fake_panic) {
21475 if (panic_timeout == 0)
21476 panic_timeout = mca_cfg.panic_timeout;
21477 - panic(msg);
21478 + panic("%s", msg);
21479 } else
21480 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21481 }
21482 @@ -697,7 +698,7 @@ static int mce_timed_out(u64 *t)
21483 * might have been modified by someone else.
21484 */
21485 rmb();
21486 - if (atomic_read(&mce_paniced))
21487 + if (atomic_read_unchecked(&mce_paniced))
21488 wait_for_panic();
21489 if (!mca_cfg.monarch_timeout)
21490 goto out;
21491 @@ -1674,7 +1675,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21492 }
21493
21494 /* Call the installed machine check handler for this CPU setup. */
21495 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
21496 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21497 unexpected_machine_check;
21498
21499 /*
21500 @@ -1697,7 +1698,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21501 return;
21502 }
21503
21504 + pax_open_kernel();
21505 machine_check_vector = do_machine_check;
21506 + pax_close_kernel();
21507
21508 __mcheck_cpu_init_generic();
21509 __mcheck_cpu_init_vendor(c);
21510 @@ -1711,7 +1714,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21511 */
21512
21513 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21514 -static int mce_chrdev_open_count; /* #times opened */
21515 +static local_t mce_chrdev_open_count; /* #times opened */
21516 static int mce_chrdev_open_exclu; /* already open exclusive? */
21517
21518 static int mce_chrdev_open(struct inode *inode, struct file *file)
21519 @@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21520 spin_lock(&mce_chrdev_state_lock);
21521
21522 if (mce_chrdev_open_exclu ||
21523 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21524 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21525 spin_unlock(&mce_chrdev_state_lock);
21526
21527 return -EBUSY;
21528 @@ -1727,7 +1730,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21529
21530 if (file->f_flags & O_EXCL)
21531 mce_chrdev_open_exclu = 1;
21532 - mce_chrdev_open_count++;
21533 + local_inc(&mce_chrdev_open_count);
21534
21535 spin_unlock(&mce_chrdev_state_lock);
21536
21537 @@ -1738,7 +1741,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21538 {
21539 spin_lock(&mce_chrdev_state_lock);
21540
21541 - mce_chrdev_open_count--;
21542 + local_dec(&mce_chrdev_open_count);
21543 mce_chrdev_open_exclu = 0;
21544
21545 spin_unlock(&mce_chrdev_state_lock);
21546 @@ -2413,7 +2416,7 @@ static __init void mce_init_banks(void)
21547
21548 for (i = 0; i < mca_cfg.banks; i++) {
21549 struct mce_bank *b = &mce_banks[i];
21550 - struct device_attribute *a = &b->attr;
21551 + device_attribute_no_const *a = &b->attr;
21552
21553 sysfs_attr_init(&a->attr);
21554 a->attr.name = b->attrname;
21555 @@ -2520,7 +2523,7 @@ struct dentry *mce_get_debugfs_dir(void)
21556 static void mce_reset(void)
21557 {
21558 cpu_missing = 0;
21559 - atomic_set(&mce_fake_paniced, 0);
21560 + atomic_set_unchecked(&mce_fake_paniced, 0);
21561 atomic_set(&mce_executing, 0);
21562 atomic_set(&mce_callin, 0);
21563 atomic_set(&global_nwo, 0);
21564 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21565 index a304298..49b6d06 100644
21566 --- a/arch/x86/kernel/cpu/mcheck/p5.c
21567 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
21568 @@ -10,6 +10,7 @@
21569 #include <asm/processor.h>
21570 #include <asm/mce.h>
21571 #include <asm/msr.h>
21572 +#include <asm/pgtable.h>
21573
21574 /* By default disabled */
21575 int mce_p5_enabled __read_mostly;
21576 @@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21577 if (!cpu_has(c, X86_FEATURE_MCE))
21578 return;
21579
21580 + pax_open_kernel();
21581 machine_check_vector = pentium_machine_check;
21582 + pax_close_kernel();
21583 /* Make sure the vector pointer is visible before we enable MCEs: */
21584 wmb();
21585
21586 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21587 index 7dc5564..1273569 100644
21588 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
21589 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21590 @@ -9,6 +9,7 @@
21591 #include <asm/processor.h>
21592 #include <asm/mce.h>
21593 #include <asm/msr.h>
21594 +#include <asm/pgtable.h>
21595
21596 /* Machine check handler for WinChip C6: */
21597 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21598 @@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21599 {
21600 u32 lo, hi;
21601
21602 + pax_open_kernel();
21603 machine_check_vector = winchip_machine_check;
21604 + pax_close_kernel();
21605 /* Make sure the vector pointer is visible before we enable MCEs: */
21606 wmb();
21607
21608 diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21609 index 08fe6e8..35885b0 100644
21610 --- a/arch/x86/kernel/cpu/microcode/core.c
21611 +++ b/arch/x86/kernel/cpu/microcode/core.c
21612 @@ -526,7 +526,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21613 return NOTIFY_OK;
21614 }
21615
21616 -static struct notifier_block __refdata mc_cpu_notifier = {
21617 +static struct notifier_block mc_cpu_notifier = {
21618 .notifier_call = mc_cpu_callback,
21619 };
21620
21621 diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21622 index c6826d1..ad18e14a 100644
21623 --- a/arch/x86/kernel/cpu/microcode/intel.c
21624 +++ b/arch/x86/kernel/cpu/microcode/intel.c
21625 @@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21626
21627 static int get_ucode_user(void *to, const void *from, size_t n)
21628 {
21629 - return copy_from_user(to, from, n);
21630 + return copy_from_user(to, (const void __force_user *)from, n);
21631 }
21632
21633 static enum ucode_state
21634 request_microcode_user(int cpu, const void __user *buf, size_t size)
21635 {
21636 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21637 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21638 }
21639
21640 static void microcode_fini_cpu(int cpu)
21641 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21642 index ea5f363..cb0e905 100644
21643 --- a/arch/x86/kernel/cpu/mtrr/main.c
21644 +++ b/arch/x86/kernel/cpu/mtrr/main.c
21645 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21646 u64 size_or_mask, size_and_mask;
21647 static bool mtrr_aps_delayed_init;
21648
21649 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21650 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21651
21652 const struct mtrr_ops *mtrr_if;
21653
21654 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21655 index df5e41f..816c719 100644
21656 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21657 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21658 @@ -25,7 +25,7 @@ struct mtrr_ops {
21659 int (*validate_add_page)(unsigned long base, unsigned long size,
21660 unsigned int type);
21661 int (*have_wrcomb)(void);
21662 -};
21663 +} __do_const;
21664
21665 extern int generic_get_free_region(unsigned long base, unsigned long size,
21666 int replace_reg);
21667 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21668 index 143e5f5..5825081 100644
21669 --- a/arch/x86/kernel/cpu/perf_event.c
21670 +++ b/arch/x86/kernel/cpu/perf_event.c
21671 @@ -1374,7 +1374,7 @@ static void __init pmu_check_apic(void)
21672
21673 }
21674
21675 -static struct attribute_group x86_pmu_format_group = {
21676 +static attribute_group_no_const x86_pmu_format_group = {
21677 .name = "format",
21678 .attrs = NULL,
21679 };
21680 @@ -1473,7 +1473,7 @@ static struct attribute *events_attr[] = {
21681 NULL,
21682 };
21683
21684 -static struct attribute_group x86_pmu_events_group = {
21685 +static attribute_group_no_const x86_pmu_events_group = {
21686 .name = "events",
21687 .attrs = events_attr,
21688 };
21689 @@ -1997,7 +1997,7 @@ static unsigned long get_segment_base(unsigned int segment)
21690 if (idx > GDT_ENTRIES)
21691 return 0;
21692
21693 - desc = raw_cpu_ptr(gdt_page.gdt);
21694 + desc = get_cpu_gdt_table(smp_processor_id());
21695 }
21696
21697 return get_desc_base(desc + idx);
21698 @@ -2087,7 +2087,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21699 break;
21700
21701 perf_callchain_store(entry, frame.return_address);
21702 - fp = frame.next_frame;
21703 + fp = (const void __force_user *)frame.next_frame;
21704 }
21705 }
21706
21707 diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21708 index 639d128..e92d7e5 100644
21709 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21710 +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21711 @@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21712 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21713 {
21714 struct attribute **attrs;
21715 - struct attribute_group *attr_group;
21716 + attribute_group_no_const *attr_group;
21717 int i = 0, j;
21718
21719 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21720 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21721 index 944bf01..4a4392f 100644
21722 --- a/arch/x86/kernel/cpu/perf_event_intel.c
21723 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
21724 @@ -2353,10 +2353,10 @@ __init int intel_pmu_init(void)
21725 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21726
21727 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21728 - u64 capabilities;
21729 + u64 capabilities = x86_pmu.intel_cap.capabilities;
21730
21731 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21732 - x86_pmu.intel_cap.capabilities = capabilities;
21733 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21734 + x86_pmu.intel_cap.capabilities = capabilities;
21735 }
21736
21737 intel_ds_init();
21738 diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21739 index d64f275..26522ff 100644
21740 --- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21741 +++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21742 @@ -449,7 +449,7 @@ static struct attribute *rapl_events_hsw_attr[] = {
21743 NULL,
21744 };
21745
21746 -static struct attribute_group rapl_pmu_events_group = {
21747 +static attribute_group_no_const rapl_pmu_events_group __read_only = {
21748 .name = "events",
21749 .attrs = NULL, /* patched at runtime */
21750 };
21751 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21752 index 9762dbd..53d5d21 100644
21753 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21754 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21755 @@ -721,7 +721,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21756 static int __init uncore_type_init(struct intel_uncore_type *type)
21757 {
21758 struct intel_uncore_pmu *pmus;
21759 - struct attribute_group *attr_group;
21760 + attribute_group_no_const *attr_group;
21761 struct attribute **attrs;
21762 int i, j;
21763
21764 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21765 index 18eb78b..18747cc 100644
21766 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21767 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21768 @@ -114,7 +114,7 @@ struct intel_uncore_box {
21769 struct uncore_event_desc {
21770 struct kobj_attribute attr;
21771 const char *config;
21772 -};
21773 +} __do_const;
21774
21775 ssize_t uncore_event_show(struct kobject *kobj,
21776 struct kobj_attribute *attr, char *buf);
21777 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21778 index 3225ae6c..ee3c6db 100644
21779 --- a/arch/x86/kernel/cpuid.c
21780 +++ b/arch/x86/kernel/cpuid.c
21781 @@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21782 return notifier_from_errno(err);
21783 }
21784
21785 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
21786 +static struct notifier_block cpuid_class_cpu_notifier =
21787 {
21788 .notifier_call = cpuid_class_cpu_callback,
21789 };
21790 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21791 index f5ab56d..d3b201a 100644
21792 --- a/arch/x86/kernel/crash.c
21793 +++ b/arch/x86/kernel/crash.c
21794 @@ -104,7 +104,7 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21795 #ifdef CONFIG_X86_32
21796 struct pt_regs fixed_regs;
21797
21798 - if (!user_mode_vm(regs)) {
21799 + if (!user_mode(regs)) {
21800 crash_fixup_ss_esp(&fixed_regs, regs);
21801 regs = &fixed_regs;
21802 }
21803 diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21804 index afa64ad..dce67dd 100644
21805 --- a/arch/x86/kernel/crash_dump_64.c
21806 +++ b/arch/x86/kernel/crash_dump_64.c
21807 @@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21808 return -ENOMEM;
21809
21810 if (userbuf) {
21811 - if (copy_to_user(buf, vaddr + offset, csize)) {
21812 + if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21813 iounmap(vaddr);
21814 return -EFAULT;
21815 }
21816 diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21817 index f6dfd93..892ade4 100644
21818 --- a/arch/x86/kernel/doublefault.c
21819 +++ b/arch/x86/kernel/doublefault.c
21820 @@ -12,7 +12,7 @@
21821
21822 #define DOUBLEFAULT_STACKSIZE (1024)
21823 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21824 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21825 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21826
21827 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21828
21829 @@ -22,7 +22,7 @@ static void doublefault_fn(void)
21830 unsigned long gdt, tss;
21831
21832 native_store_gdt(&gdt_desc);
21833 - gdt = gdt_desc.address;
21834 + gdt = (unsigned long)gdt_desc.address;
21835
21836 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21837
21838 @@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21839 /* 0x2 bit is always set */
21840 .flags = X86_EFLAGS_SF | 0x2,
21841 .sp = STACK_START,
21842 - .es = __USER_DS,
21843 + .es = __KERNEL_DS,
21844 .cs = __KERNEL_CS,
21845 .ss = __KERNEL_DS,
21846 - .ds = __USER_DS,
21847 + .ds = __KERNEL_DS,
21848 .fs = __KERNEL_PERCPU,
21849
21850 .__cr3 = __pa_nodebug(swapper_pg_dir),
21851 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21852 index b74ebc7..2c95874 100644
21853 --- a/arch/x86/kernel/dumpstack.c
21854 +++ b/arch/x86/kernel/dumpstack.c
21855 @@ -2,6 +2,9 @@
21856 * Copyright (C) 1991, 1992 Linus Torvalds
21857 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21858 */
21859 +#ifdef CONFIG_GRKERNSEC_HIDESYM
21860 +#define __INCLUDED_BY_HIDESYM 1
21861 +#endif
21862 #include <linux/kallsyms.h>
21863 #include <linux/kprobes.h>
21864 #include <linux/uaccess.h>
21865 @@ -33,23 +36,21 @@ static void printk_stack_address(unsigned long address, int reliable)
21866
21867 void printk_address(unsigned long address)
21868 {
21869 - pr_cont(" [<%p>] %pS\n", (void *)address, (void *)address);
21870 + pr_cont(" [<%p>] %pA\n", (void *)address, (void *)address);
21871 }
21872
21873 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
21874 static void
21875 print_ftrace_graph_addr(unsigned long addr, void *data,
21876 const struct stacktrace_ops *ops,
21877 - struct thread_info *tinfo, int *graph)
21878 + struct task_struct *task, int *graph)
21879 {
21880 - struct task_struct *task;
21881 unsigned long ret_addr;
21882 int index;
21883
21884 if (addr != (unsigned long)return_to_handler)
21885 return;
21886
21887 - task = tinfo->task;
21888 index = task->curr_ret_stack;
21889
21890 if (!task->ret_stack || index < *graph)
21891 @@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21892 static inline void
21893 print_ftrace_graph_addr(unsigned long addr, void *data,
21894 const struct stacktrace_ops *ops,
21895 - struct thread_info *tinfo, int *graph)
21896 + struct task_struct *task, int *graph)
21897 { }
21898 #endif
21899
21900 @@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21901 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21902 */
21903
21904 -static inline int valid_stack_ptr(struct thread_info *tinfo,
21905 - void *p, unsigned int size, void *end)
21906 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21907 {
21908 - void *t = tinfo;
21909 if (end) {
21910 if (p < end && p >= (end-THREAD_SIZE))
21911 return 1;
21912 @@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21913 }
21914
21915 unsigned long
21916 -print_context_stack(struct thread_info *tinfo,
21917 +print_context_stack(struct task_struct *task, void *stack_start,
21918 unsigned long *stack, unsigned long bp,
21919 const struct stacktrace_ops *ops, void *data,
21920 unsigned long *end, int *graph)
21921 {
21922 struct stack_frame *frame = (struct stack_frame *)bp;
21923
21924 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21925 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21926 unsigned long addr;
21927
21928 addr = *stack;
21929 @@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21930 } else {
21931 ops->address(data, addr, 0);
21932 }
21933 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21934 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21935 }
21936 stack++;
21937 }
21938 @@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21939 EXPORT_SYMBOL_GPL(print_context_stack);
21940
21941 unsigned long
21942 -print_context_stack_bp(struct thread_info *tinfo,
21943 +print_context_stack_bp(struct task_struct *task, void *stack_start,
21944 unsigned long *stack, unsigned long bp,
21945 const struct stacktrace_ops *ops, void *data,
21946 unsigned long *end, int *graph)
21947 @@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21948 struct stack_frame *frame = (struct stack_frame *)bp;
21949 unsigned long *ret_addr = &frame->return_address;
21950
21951 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21952 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21953 unsigned long addr = *ret_addr;
21954
21955 if (!__kernel_text_address(addr))
21956 @@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21957 ops->address(data, addr, 1);
21958 frame = frame->next_frame;
21959 ret_addr = &frame->return_address;
21960 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21961 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21962 }
21963
21964 return (unsigned long)frame;
21965 @@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
21966 static void print_trace_address(void *data, unsigned long addr, int reliable)
21967 {
21968 touch_nmi_watchdog();
21969 - printk(data);
21970 + printk("%s", (char *)data);
21971 printk_stack_address(addr, reliable);
21972 }
21973
21974 @@ -225,6 +224,8 @@ unsigned long oops_begin(void)
21975 EXPORT_SYMBOL_GPL(oops_begin);
21976 NOKPROBE_SYMBOL(oops_begin);
21977
21978 +extern void gr_handle_kernel_exploit(void);
21979 +
21980 void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21981 {
21982 if (regs && kexec_should_crash(current))
21983 @@ -246,7 +247,10 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21984 panic("Fatal exception in interrupt");
21985 if (panic_on_oops)
21986 panic("Fatal exception");
21987 - do_exit(signr);
21988 +
21989 + gr_handle_kernel_exploit();
21990 +
21991 + do_group_exit(signr);
21992 }
21993 NOKPROBE_SYMBOL(oops_end);
21994
21995 @@ -275,7 +279,7 @@ int __die(const char *str, struct pt_regs *regs, long err)
21996 print_modules();
21997 show_regs(regs);
21998 #ifdef CONFIG_X86_32
21999 - if (user_mode_vm(regs)) {
22000 + if (user_mode(regs)) {
22001 sp = regs->sp;
22002 ss = regs->ss & 0xffff;
22003 } else {
22004 @@ -304,7 +308,7 @@ void die(const char *str, struct pt_regs *regs, long err)
22005 unsigned long flags = oops_begin();
22006 int sig = SIGSEGV;
22007
22008 - if (!user_mode_vm(regs))
22009 + if (!user_mode(regs))
22010 report_bug(regs->ip, regs);
22011
22012 if (__die(str, regs, err))
22013 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
22014 index 5abd4cd..c65733b 100644
22015 --- a/arch/x86/kernel/dumpstack_32.c
22016 +++ b/arch/x86/kernel/dumpstack_32.c
22017 @@ -61,15 +61,14 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22018 bp = stack_frame(task, regs);
22019
22020 for (;;) {
22021 - struct thread_info *context;
22022 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22023 void *end_stack;
22024
22025 end_stack = is_hardirq_stack(stack, cpu);
22026 if (!end_stack)
22027 end_stack = is_softirq_stack(stack, cpu);
22028
22029 - context = task_thread_info(task);
22030 - bp = ops->walk_stack(context, stack, bp, ops, data,
22031 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data,
22032 end_stack, &graph);
22033
22034 /* Stop if not on irq stack */
22035 @@ -123,27 +122,28 @@ void show_regs(struct pt_regs *regs)
22036 int i;
22037
22038 show_regs_print_info(KERN_EMERG);
22039 - __show_regs(regs, !user_mode_vm(regs));
22040 + __show_regs(regs, !user_mode(regs));
22041
22042 /*
22043 * When in-kernel, we also print out the stack and code at the
22044 * time of the fault..
22045 */
22046 - if (!user_mode_vm(regs)) {
22047 + if (!user_mode(regs)) {
22048 unsigned int code_prologue = code_bytes * 43 / 64;
22049 unsigned int code_len = code_bytes;
22050 unsigned char c;
22051 u8 *ip;
22052 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
22053
22054 pr_emerg("Stack:\n");
22055 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
22056
22057 pr_emerg("Code:");
22058
22059 - ip = (u8 *)regs->ip - code_prologue;
22060 + ip = (u8 *)regs->ip - code_prologue + cs_base;
22061 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
22062 /* try starting at IP */
22063 - ip = (u8 *)regs->ip;
22064 + ip = (u8 *)regs->ip + cs_base;
22065 code_len = code_len - code_prologue + 1;
22066 }
22067 for (i = 0; i < code_len; i++, ip++) {
22068 @@ -152,7 +152,7 @@ void show_regs(struct pt_regs *regs)
22069 pr_cont(" Bad EIP value.");
22070 break;
22071 }
22072 - if (ip == (u8 *)regs->ip)
22073 + if (ip == (u8 *)regs->ip + cs_base)
22074 pr_cont(" <%02x>", c);
22075 else
22076 pr_cont(" %02x", c);
22077 @@ -165,6 +165,7 @@ int is_valid_bugaddr(unsigned long ip)
22078 {
22079 unsigned short ud2;
22080
22081 + ip = ktla_ktva(ip);
22082 if (ip < PAGE_OFFSET)
22083 return 0;
22084 if (probe_kernel_address((unsigned short *)ip, ud2))
22085 @@ -172,3 +173,15 @@ int is_valid_bugaddr(unsigned long ip)
22086
22087 return ud2 == 0x0b0f;
22088 }
22089 +
22090 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22091 +void pax_check_alloca(unsigned long size)
22092 +{
22093 + unsigned long sp = (unsigned long)&sp, stack_left;
22094 +
22095 + /* all kernel stacks are of the same size */
22096 + stack_left = sp & (THREAD_SIZE - 1);
22097 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22098 +}
22099 +EXPORT_SYMBOL(pax_check_alloca);
22100 +#endif
22101 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
22102 index ff86f19..a20c62c 100644
22103 --- a/arch/x86/kernel/dumpstack_64.c
22104 +++ b/arch/x86/kernel/dumpstack_64.c
22105 @@ -153,12 +153,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22106 const struct stacktrace_ops *ops, void *data)
22107 {
22108 const unsigned cpu = get_cpu();
22109 - struct thread_info *tinfo;
22110 unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
22111 unsigned long dummy;
22112 unsigned used = 0;
22113 int graph = 0;
22114 int done = 0;
22115 + void *stack_start;
22116
22117 if (!task)
22118 task = current;
22119 @@ -179,7 +179,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22120 * current stack address. If the stacks consist of nested
22121 * exceptions
22122 */
22123 - tinfo = task_thread_info(task);
22124 while (!done) {
22125 unsigned long *stack_end;
22126 enum stack_type stype;
22127 @@ -202,7 +201,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22128 if (ops->stack(data, id) < 0)
22129 break;
22130
22131 - bp = ops->walk_stack(tinfo, stack, bp, ops,
22132 + bp = ops->walk_stack(task, stack_end - EXCEPTION_STKSZ, stack, bp, ops,
22133 data, stack_end, &graph);
22134 ops->stack(data, "<EOE>");
22135 /*
22136 @@ -210,6 +209,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22137 * second-to-last pointer (index -2 to end) in the
22138 * exception stack:
22139 */
22140 + if ((u16)stack_end[-1] != __KERNEL_DS)
22141 + goto out;
22142 stack = (unsigned long *) stack_end[-2];
22143 done = 0;
22144 break;
22145 @@ -218,7 +219,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22146
22147 if (ops->stack(data, "IRQ") < 0)
22148 break;
22149 - bp = ops->walk_stack(tinfo, stack, bp,
22150 + bp = ops->walk_stack(task, irq_stack, stack, bp,
22151 ops, data, stack_end, &graph);
22152 /*
22153 * We link to the next stack (which would be
22154 @@ -240,7 +241,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22155 /*
22156 * This handles the process stack:
22157 */
22158 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
22159 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22160 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
22161 +out:
22162 put_cpu();
22163 }
22164 EXPORT_SYMBOL(dump_trace);
22165 @@ -349,3 +352,50 @@ int is_valid_bugaddr(unsigned long ip)
22166
22167 return ud2 == 0x0b0f;
22168 }
22169 +
22170 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22171 +void pax_check_alloca(unsigned long size)
22172 +{
22173 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
22174 + unsigned cpu, used;
22175 + char *id;
22176 +
22177 + /* check the process stack first */
22178 + stack_start = (unsigned long)task_stack_page(current);
22179 + stack_end = stack_start + THREAD_SIZE;
22180 + if (likely(stack_start <= sp && sp < stack_end)) {
22181 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
22182 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22183 + return;
22184 + }
22185 +
22186 + cpu = get_cpu();
22187 +
22188 + /* check the irq stacks */
22189 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
22190 + stack_start = stack_end - IRQ_STACK_SIZE;
22191 + if (stack_start <= sp && sp < stack_end) {
22192 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
22193 + put_cpu();
22194 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22195 + return;
22196 + }
22197 +
22198 + /* check the exception stacks */
22199 + used = 0;
22200 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
22201 + stack_start = stack_end - EXCEPTION_STKSZ;
22202 + if (stack_end && stack_start <= sp && sp < stack_end) {
22203 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
22204 + put_cpu();
22205 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22206 + return;
22207 + }
22208 +
22209 + put_cpu();
22210 +
22211 + /* unknown stack */
22212 + BUG();
22213 +}
22214 +EXPORT_SYMBOL(pax_check_alloca);
22215 +#endif
22216 diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
22217 index 49f8864..1cc6d07 100644
22218 --- a/arch/x86/kernel/e820.c
22219 +++ b/arch/x86/kernel/e820.c
22220 @@ -802,8 +802,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
22221
22222 static void early_panic(char *msg)
22223 {
22224 - early_printk(msg);
22225 - panic(msg);
22226 + early_printk("%s", msg);
22227 + panic("%s", msg);
22228 }
22229
22230 static int userdef __initdata;
22231 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22232 index 01d1c18..8073693 100644
22233 --- a/arch/x86/kernel/early_printk.c
22234 +++ b/arch/x86/kernel/early_printk.c
22235 @@ -7,6 +7,7 @@
22236 #include <linux/pci_regs.h>
22237 #include <linux/pci_ids.h>
22238 #include <linux/errno.h>
22239 +#include <linux/sched.h>
22240 #include <asm/io.h>
22241 #include <asm/processor.h>
22242 #include <asm/fcntl.h>
22243 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
22244 index 344b63f..ccdac7a 100644
22245 --- a/arch/x86/kernel/entry_32.S
22246 +++ b/arch/x86/kernel/entry_32.S
22247 @@ -177,13 +177,153 @@
22248 /*CFI_REL_OFFSET gs, PT_GS*/
22249 .endm
22250 .macro SET_KERNEL_GS reg
22251 +
22252 +#ifdef CONFIG_CC_STACKPROTECTOR
22253 movl $(__KERNEL_STACK_CANARY), \reg
22254 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22255 + movl $(__USER_DS), \reg
22256 +#else
22257 + xorl \reg, \reg
22258 +#endif
22259 +
22260 movl \reg, %gs
22261 .endm
22262
22263 #endif /* CONFIG_X86_32_LAZY_GS */
22264
22265 -.macro SAVE_ALL
22266 +.macro pax_enter_kernel
22267 +#ifdef CONFIG_PAX_KERNEXEC
22268 + call pax_enter_kernel
22269 +#endif
22270 +.endm
22271 +
22272 +.macro pax_exit_kernel
22273 +#ifdef CONFIG_PAX_KERNEXEC
22274 + call pax_exit_kernel
22275 +#endif
22276 +.endm
22277 +
22278 +#ifdef CONFIG_PAX_KERNEXEC
22279 +ENTRY(pax_enter_kernel)
22280 +#ifdef CONFIG_PARAVIRT
22281 + pushl %eax
22282 + pushl %ecx
22283 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
22284 + mov %eax, %esi
22285 +#else
22286 + mov %cr0, %esi
22287 +#endif
22288 + bts $16, %esi
22289 + jnc 1f
22290 + mov %cs, %esi
22291 + cmp $__KERNEL_CS, %esi
22292 + jz 3f
22293 + ljmp $__KERNEL_CS, $3f
22294 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
22295 +2:
22296 +#ifdef CONFIG_PARAVIRT
22297 + mov %esi, %eax
22298 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
22299 +#else
22300 + mov %esi, %cr0
22301 +#endif
22302 +3:
22303 +#ifdef CONFIG_PARAVIRT
22304 + popl %ecx
22305 + popl %eax
22306 +#endif
22307 + ret
22308 +ENDPROC(pax_enter_kernel)
22309 +
22310 +ENTRY(pax_exit_kernel)
22311 +#ifdef CONFIG_PARAVIRT
22312 + pushl %eax
22313 + pushl %ecx
22314 +#endif
22315 + mov %cs, %esi
22316 + cmp $__KERNEXEC_KERNEL_CS, %esi
22317 + jnz 2f
22318 +#ifdef CONFIG_PARAVIRT
22319 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
22320 + mov %eax, %esi
22321 +#else
22322 + mov %cr0, %esi
22323 +#endif
22324 + btr $16, %esi
22325 + ljmp $__KERNEL_CS, $1f
22326 +1:
22327 +#ifdef CONFIG_PARAVIRT
22328 + mov %esi, %eax
22329 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
22330 +#else
22331 + mov %esi, %cr0
22332 +#endif
22333 +2:
22334 +#ifdef CONFIG_PARAVIRT
22335 + popl %ecx
22336 + popl %eax
22337 +#endif
22338 + ret
22339 +ENDPROC(pax_exit_kernel)
22340 +#endif
22341 +
22342 + .macro pax_erase_kstack
22343 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22344 + call pax_erase_kstack
22345 +#endif
22346 + .endm
22347 +
22348 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22349 +/*
22350 + * ebp: thread_info
22351 + */
22352 +ENTRY(pax_erase_kstack)
22353 + pushl %edi
22354 + pushl %ecx
22355 + pushl %eax
22356 +
22357 + mov TI_lowest_stack(%ebp), %edi
22358 + mov $-0xBEEF, %eax
22359 + std
22360 +
22361 +1: mov %edi, %ecx
22362 + and $THREAD_SIZE_asm - 1, %ecx
22363 + shr $2, %ecx
22364 + repne scasl
22365 + jecxz 2f
22366 +
22367 + cmp $2*16, %ecx
22368 + jc 2f
22369 +
22370 + mov $2*16, %ecx
22371 + repe scasl
22372 + jecxz 2f
22373 + jne 1b
22374 +
22375 +2: cld
22376 + mov %esp, %ecx
22377 + sub %edi, %ecx
22378 +
22379 + cmp $THREAD_SIZE_asm, %ecx
22380 + jb 3f
22381 + ud2
22382 +3:
22383 +
22384 + shr $2, %ecx
22385 + rep stosl
22386 +
22387 + mov TI_task_thread_sp0(%ebp), %edi
22388 + sub $128, %edi
22389 + mov %edi, TI_lowest_stack(%ebp)
22390 +
22391 + popl %eax
22392 + popl %ecx
22393 + popl %edi
22394 + ret
22395 +ENDPROC(pax_erase_kstack)
22396 +#endif
22397 +
22398 +.macro __SAVE_ALL _DS
22399 cld
22400 PUSH_GS
22401 pushl_cfi %fs
22402 @@ -206,7 +346,7 @@
22403 CFI_REL_OFFSET ecx, 0
22404 pushl_cfi %ebx
22405 CFI_REL_OFFSET ebx, 0
22406 - movl $(__USER_DS), %edx
22407 + movl $\_DS, %edx
22408 movl %edx, %ds
22409 movl %edx, %es
22410 movl $(__KERNEL_PERCPU), %edx
22411 @@ -214,6 +354,15 @@
22412 SET_KERNEL_GS %edx
22413 .endm
22414
22415 +.macro SAVE_ALL
22416 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22417 + __SAVE_ALL __KERNEL_DS
22418 + pax_enter_kernel
22419 +#else
22420 + __SAVE_ALL __USER_DS
22421 +#endif
22422 +.endm
22423 +
22424 .macro RESTORE_INT_REGS
22425 popl_cfi %ebx
22426 CFI_RESTORE ebx
22427 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22428 popfl_cfi
22429 jmp syscall_exit
22430 CFI_ENDPROC
22431 -END(ret_from_fork)
22432 +ENDPROC(ret_from_fork)
22433
22434 ENTRY(ret_from_kernel_thread)
22435 CFI_STARTPROC
22436 @@ -340,7 +489,15 @@ ret_from_intr:
22437 andl $SEGMENT_RPL_MASK, %eax
22438 #endif
22439 cmpl $USER_RPL, %eax
22440 +
22441 +#ifdef CONFIG_PAX_KERNEXEC
22442 + jae resume_userspace
22443 +
22444 + pax_exit_kernel
22445 + jmp resume_kernel
22446 +#else
22447 jb resume_kernel # not returning to v8086 or userspace
22448 +#endif
22449
22450 ENTRY(resume_userspace)
22451 LOCKDEP_SYS_EXIT
22452 @@ -352,8 +509,8 @@ ENTRY(resume_userspace)
22453 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22454 # int/exception return?
22455 jne work_pending
22456 - jmp restore_all
22457 -END(ret_from_exception)
22458 + jmp restore_all_pax
22459 +ENDPROC(ret_from_exception)
22460
22461 #ifdef CONFIG_PREEMPT
22462 ENTRY(resume_kernel)
22463 @@ -365,7 +522,7 @@ need_resched:
22464 jz restore_all
22465 call preempt_schedule_irq
22466 jmp need_resched
22467 -END(resume_kernel)
22468 +ENDPROC(resume_kernel)
22469 #endif
22470 CFI_ENDPROC
22471
22472 @@ -395,30 +552,45 @@ sysenter_past_esp:
22473 /*CFI_REL_OFFSET cs, 0*/
22474 /*
22475 * Push current_thread_info()->sysenter_return to the stack.
22476 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22477 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
22478 */
22479 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22480 + pushl_cfi $0
22481 CFI_REL_OFFSET eip, 0
22482
22483 pushl_cfi %eax
22484 SAVE_ALL
22485 + GET_THREAD_INFO(%ebp)
22486 + movl TI_sysenter_return(%ebp),%ebp
22487 + movl %ebp,PT_EIP(%esp)
22488 ENABLE_INTERRUPTS(CLBR_NONE)
22489
22490 /*
22491 * Load the potential sixth argument from user stack.
22492 * Careful about security.
22493 */
22494 + movl PT_OLDESP(%esp),%ebp
22495 +
22496 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22497 + mov PT_OLDSS(%esp),%ds
22498 +1: movl %ds:(%ebp),%ebp
22499 + push %ss
22500 + pop %ds
22501 +#else
22502 cmpl $__PAGE_OFFSET-3,%ebp
22503 jae syscall_fault
22504 ASM_STAC
22505 1: movl (%ebp),%ebp
22506 ASM_CLAC
22507 +#endif
22508 +
22509 movl %ebp,PT_EBP(%esp)
22510 _ASM_EXTABLE(1b,syscall_fault)
22511
22512 GET_THREAD_INFO(%ebp)
22513
22514 +#ifdef CONFIG_PAX_RANDKSTACK
22515 + pax_erase_kstack
22516 +#endif
22517 +
22518 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22519 jnz sysenter_audit
22520 sysenter_do_call:
22521 @@ -434,12 +606,24 @@ sysenter_after_call:
22522 testl $_TIF_ALLWORK_MASK, %ecx
22523 jne sysexit_audit
22524 sysenter_exit:
22525 +
22526 +#ifdef CONFIG_PAX_RANDKSTACK
22527 + pushl_cfi %eax
22528 + movl %esp, %eax
22529 + call pax_randomize_kstack
22530 + popl_cfi %eax
22531 +#endif
22532 +
22533 + pax_erase_kstack
22534 +
22535 /* if something modifies registers it must also disable sysexit */
22536 movl PT_EIP(%esp), %edx
22537 movl PT_OLDESP(%esp), %ecx
22538 xorl %ebp,%ebp
22539 TRACE_IRQS_ON
22540 1: mov PT_FS(%esp), %fs
22541 +2: mov PT_DS(%esp), %ds
22542 +3: mov PT_ES(%esp), %es
22543 PTGS_TO_GS
22544 ENABLE_INTERRUPTS_SYSEXIT
22545
22546 @@ -453,6 +637,9 @@ sysenter_audit:
22547 pushl_cfi PT_ESI(%esp) /* a3: 5th arg */
22548 pushl_cfi PT_EDX+4(%esp) /* a2: 4th arg */
22549 call __audit_syscall_entry
22550 +
22551 + pax_erase_kstack
22552 +
22553 popl_cfi %ecx /* get that remapped edx off the stack */
22554 popl_cfi %ecx /* get that remapped esi off the stack */
22555 movl PT_EAX(%esp),%eax /* reload syscall number */
22556 @@ -479,10 +666,16 @@ sysexit_audit:
22557
22558 CFI_ENDPROC
22559 .pushsection .fixup,"ax"
22560 -2: movl $0,PT_FS(%esp)
22561 +4: movl $0,PT_FS(%esp)
22562 + jmp 1b
22563 +5: movl $0,PT_DS(%esp)
22564 + jmp 1b
22565 +6: movl $0,PT_ES(%esp)
22566 jmp 1b
22567 .popsection
22568 - _ASM_EXTABLE(1b,2b)
22569 + _ASM_EXTABLE(1b,4b)
22570 + _ASM_EXTABLE(2b,5b)
22571 + _ASM_EXTABLE(3b,6b)
22572 PTGS_TO_GS_EX
22573 ENDPROC(ia32_sysenter_target)
22574
22575 @@ -493,6 +686,11 @@ ENTRY(system_call)
22576 pushl_cfi %eax # save orig_eax
22577 SAVE_ALL
22578 GET_THREAD_INFO(%ebp)
22579 +
22580 +#ifdef CONFIG_PAX_RANDKSTACK
22581 + pax_erase_kstack
22582 +#endif
22583 +
22584 # system call tracing in operation / emulation
22585 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22586 jnz syscall_trace_entry
22587 @@ -512,6 +710,15 @@ syscall_exit:
22588 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22589 jne syscall_exit_work
22590
22591 +restore_all_pax:
22592 +
22593 +#ifdef CONFIG_PAX_RANDKSTACK
22594 + movl %esp, %eax
22595 + call pax_randomize_kstack
22596 +#endif
22597 +
22598 + pax_erase_kstack
22599 +
22600 restore_all:
22601 TRACE_IRQS_IRET
22602 restore_all_notrace:
22603 @@ -566,14 +773,34 @@ ldt_ss:
22604 * compensating for the offset by changing to the ESPFIX segment with
22605 * a base address that matches for the difference.
22606 */
22607 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22608 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22609 mov %esp, %edx /* load kernel esp */
22610 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22611 mov %dx, %ax /* eax: new kernel esp */
22612 sub %eax, %edx /* offset (low word is 0) */
22613 +#ifdef CONFIG_SMP
22614 + movl PER_CPU_VAR(cpu_number), %ebx
22615 + shll $PAGE_SHIFT_asm, %ebx
22616 + addl $cpu_gdt_table, %ebx
22617 +#else
22618 + movl $cpu_gdt_table, %ebx
22619 +#endif
22620 shr $16, %edx
22621 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22622 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22623 +
22624 +#ifdef CONFIG_PAX_KERNEXEC
22625 + mov %cr0, %esi
22626 + btr $16, %esi
22627 + mov %esi, %cr0
22628 +#endif
22629 +
22630 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22631 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22632 +
22633 +#ifdef CONFIG_PAX_KERNEXEC
22634 + bts $16, %esi
22635 + mov %esi, %cr0
22636 +#endif
22637 +
22638 pushl_cfi $__ESPFIX_SS
22639 pushl_cfi %eax /* new kernel esp */
22640 /* Disable interrupts, but do not irqtrace this section: we
22641 @@ -603,20 +830,18 @@ work_resched:
22642 movl TI_flags(%ebp), %ecx
22643 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22644 # than syscall tracing?
22645 - jz restore_all
22646 + jz restore_all_pax
22647 testb $_TIF_NEED_RESCHED, %cl
22648 jnz work_resched
22649
22650 work_notifysig: # deal with pending signals and
22651 # notify-resume requests
22652 + movl %esp, %eax
22653 #ifdef CONFIG_VM86
22654 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22655 - movl %esp, %eax
22656 jne work_notifysig_v86 # returning to kernel-space or
22657 # vm86-space
22658 1:
22659 -#else
22660 - movl %esp, %eax
22661 #endif
22662 TRACE_IRQS_ON
22663 ENABLE_INTERRUPTS(CLBR_NONE)
22664 @@ -637,7 +862,7 @@ work_notifysig_v86:
22665 movl %eax, %esp
22666 jmp 1b
22667 #endif
22668 -END(work_pending)
22669 +ENDPROC(work_pending)
22670
22671 # perform syscall exit tracing
22672 ALIGN
22673 @@ -645,11 +870,14 @@ syscall_trace_entry:
22674 movl $-ENOSYS,PT_EAX(%esp)
22675 movl %esp, %eax
22676 call syscall_trace_enter
22677 +
22678 + pax_erase_kstack
22679 +
22680 /* What it returned is what we'll actually use. */
22681 cmpl $(NR_syscalls), %eax
22682 jnae syscall_call
22683 jmp syscall_exit
22684 -END(syscall_trace_entry)
22685 +ENDPROC(syscall_trace_entry)
22686
22687 # perform syscall exit tracing
22688 ALIGN
22689 @@ -662,26 +890,30 @@ syscall_exit_work:
22690 movl %esp, %eax
22691 call syscall_trace_leave
22692 jmp resume_userspace
22693 -END(syscall_exit_work)
22694 +ENDPROC(syscall_exit_work)
22695 CFI_ENDPROC
22696
22697 RING0_INT_FRAME # can't unwind into user space anyway
22698 syscall_fault:
22699 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22700 + push %ss
22701 + pop %ds
22702 +#endif
22703 ASM_CLAC
22704 GET_THREAD_INFO(%ebp)
22705 movl $-EFAULT,PT_EAX(%esp)
22706 jmp resume_userspace
22707 -END(syscall_fault)
22708 +ENDPROC(syscall_fault)
22709
22710 syscall_badsys:
22711 movl $-ENOSYS,%eax
22712 jmp syscall_after_call
22713 -END(syscall_badsys)
22714 +ENDPROC(syscall_badsys)
22715
22716 sysenter_badsys:
22717 movl $-ENOSYS,%eax
22718 jmp sysenter_after_call
22719 -END(sysenter_badsys)
22720 +ENDPROC(sysenter_badsys)
22721 CFI_ENDPROC
22722
22723 .macro FIXUP_ESPFIX_STACK
22724 @@ -694,8 +926,15 @@ END(sysenter_badsys)
22725 */
22726 #ifdef CONFIG_X86_ESPFIX32
22727 /* fixup the stack */
22728 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22729 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22730 +#ifdef CONFIG_SMP
22731 + movl PER_CPU_VAR(cpu_number), %ebx
22732 + shll $PAGE_SHIFT_asm, %ebx
22733 + addl $cpu_gdt_table, %ebx
22734 +#else
22735 + movl $cpu_gdt_table, %ebx
22736 +#endif
22737 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22738 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22739 shl $16, %eax
22740 addl %esp, %eax /* the adjusted stack pointer */
22741 pushl_cfi $__KERNEL_DS
22742 @@ -751,7 +990,7 @@ vector=vector+1
22743 .endr
22744 2: jmp common_interrupt
22745 .endr
22746 -END(irq_entries_start)
22747 +ENDPROC(irq_entries_start)
22748
22749 .previous
22750 END(interrupt)
22751 @@ -808,7 +1047,7 @@ ENTRY(coprocessor_error)
22752 pushl_cfi $do_coprocessor_error
22753 jmp error_code
22754 CFI_ENDPROC
22755 -END(coprocessor_error)
22756 +ENDPROC(coprocessor_error)
22757
22758 ENTRY(simd_coprocessor_error)
22759 RING0_INT_FRAME
22760 @@ -821,7 +1060,7 @@ ENTRY(simd_coprocessor_error)
22761 .section .altinstructions,"a"
22762 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22763 .previous
22764 -.section .altinstr_replacement,"ax"
22765 +.section .altinstr_replacement,"a"
22766 663: pushl $do_simd_coprocessor_error
22767 664:
22768 .previous
22769 @@ -830,7 +1069,7 @@ ENTRY(simd_coprocessor_error)
22770 #endif
22771 jmp error_code
22772 CFI_ENDPROC
22773 -END(simd_coprocessor_error)
22774 +ENDPROC(simd_coprocessor_error)
22775
22776 ENTRY(device_not_available)
22777 RING0_INT_FRAME
22778 @@ -839,18 +1078,18 @@ ENTRY(device_not_available)
22779 pushl_cfi $do_device_not_available
22780 jmp error_code
22781 CFI_ENDPROC
22782 -END(device_not_available)
22783 +ENDPROC(device_not_available)
22784
22785 #ifdef CONFIG_PARAVIRT
22786 ENTRY(native_iret)
22787 iret
22788 _ASM_EXTABLE(native_iret, iret_exc)
22789 -END(native_iret)
22790 +ENDPROC(native_iret)
22791
22792 ENTRY(native_irq_enable_sysexit)
22793 sti
22794 sysexit
22795 -END(native_irq_enable_sysexit)
22796 +ENDPROC(native_irq_enable_sysexit)
22797 #endif
22798
22799 ENTRY(overflow)
22800 @@ -860,7 +1099,7 @@ ENTRY(overflow)
22801 pushl_cfi $do_overflow
22802 jmp error_code
22803 CFI_ENDPROC
22804 -END(overflow)
22805 +ENDPROC(overflow)
22806
22807 ENTRY(bounds)
22808 RING0_INT_FRAME
22809 @@ -869,7 +1108,7 @@ ENTRY(bounds)
22810 pushl_cfi $do_bounds
22811 jmp error_code
22812 CFI_ENDPROC
22813 -END(bounds)
22814 +ENDPROC(bounds)
22815
22816 ENTRY(invalid_op)
22817 RING0_INT_FRAME
22818 @@ -878,7 +1117,7 @@ ENTRY(invalid_op)
22819 pushl_cfi $do_invalid_op
22820 jmp error_code
22821 CFI_ENDPROC
22822 -END(invalid_op)
22823 +ENDPROC(invalid_op)
22824
22825 ENTRY(coprocessor_segment_overrun)
22826 RING0_INT_FRAME
22827 @@ -887,7 +1126,7 @@ ENTRY(coprocessor_segment_overrun)
22828 pushl_cfi $do_coprocessor_segment_overrun
22829 jmp error_code
22830 CFI_ENDPROC
22831 -END(coprocessor_segment_overrun)
22832 +ENDPROC(coprocessor_segment_overrun)
22833
22834 ENTRY(invalid_TSS)
22835 RING0_EC_FRAME
22836 @@ -895,7 +1134,7 @@ ENTRY(invalid_TSS)
22837 pushl_cfi $do_invalid_TSS
22838 jmp error_code
22839 CFI_ENDPROC
22840 -END(invalid_TSS)
22841 +ENDPROC(invalid_TSS)
22842
22843 ENTRY(segment_not_present)
22844 RING0_EC_FRAME
22845 @@ -903,7 +1142,7 @@ ENTRY(segment_not_present)
22846 pushl_cfi $do_segment_not_present
22847 jmp error_code
22848 CFI_ENDPROC
22849 -END(segment_not_present)
22850 +ENDPROC(segment_not_present)
22851
22852 ENTRY(stack_segment)
22853 RING0_EC_FRAME
22854 @@ -911,7 +1150,7 @@ ENTRY(stack_segment)
22855 pushl_cfi $do_stack_segment
22856 jmp error_code
22857 CFI_ENDPROC
22858 -END(stack_segment)
22859 +ENDPROC(stack_segment)
22860
22861 ENTRY(alignment_check)
22862 RING0_EC_FRAME
22863 @@ -919,7 +1158,7 @@ ENTRY(alignment_check)
22864 pushl_cfi $do_alignment_check
22865 jmp error_code
22866 CFI_ENDPROC
22867 -END(alignment_check)
22868 +ENDPROC(alignment_check)
22869
22870 ENTRY(divide_error)
22871 RING0_INT_FRAME
22872 @@ -928,7 +1167,7 @@ ENTRY(divide_error)
22873 pushl_cfi $do_divide_error
22874 jmp error_code
22875 CFI_ENDPROC
22876 -END(divide_error)
22877 +ENDPROC(divide_error)
22878
22879 #ifdef CONFIG_X86_MCE
22880 ENTRY(machine_check)
22881 @@ -938,7 +1177,7 @@ ENTRY(machine_check)
22882 pushl_cfi machine_check_vector
22883 jmp error_code
22884 CFI_ENDPROC
22885 -END(machine_check)
22886 +ENDPROC(machine_check)
22887 #endif
22888
22889 ENTRY(spurious_interrupt_bug)
22890 @@ -948,7 +1187,7 @@ ENTRY(spurious_interrupt_bug)
22891 pushl_cfi $do_spurious_interrupt_bug
22892 jmp error_code
22893 CFI_ENDPROC
22894 -END(spurious_interrupt_bug)
22895 +ENDPROC(spurious_interrupt_bug)
22896
22897 #ifdef CONFIG_XEN
22898 /* Xen doesn't set %esp to be precisely what the normal sysenter
22899 @@ -1054,7 +1293,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22900
22901 ENTRY(mcount)
22902 ret
22903 -END(mcount)
22904 +ENDPROC(mcount)
22905
22906 ENTRY(ftrace_caller)
22907 pushl %eax
22908 @@ -1084,7 +1323,7 @@ ftrace_graph_call:
22909 .globl ftrace_stub
22910 ftrace_stub:
22911 ret
22912 -END(ftrace_caller)
22913 +ENDPROC(ftrace_caller)
22914
22915 ENTRY(ftrace_regs_caller)
22916 pushf /* push flags before compare (in cs location) */
22917 @@ -1182,7 +1421,7 @@ trace:
22918 popl %ecx
22919 popl %eax
22920 jmp ftrace_stub
22921 -END(mcount)
22922 +ENDPROC(mcount)
22923 #endif /* CONFIG_DYNAMIC_FTRACE */
22924 #endif /* CONFIG_FUNCTION_TRACER */
22925
22926 @@ -1200,7 +1439,7 @@ ENTRY(ftrace_graph_caller)
22927 popl %ecx
22928 popl %eax
22929 ret
22930 -END(ftrace_graph_caller)
22931 +ENDPROC(ftrace_graph_caller)
22932
22933 .globl return_to_handler
22934 return_to_handler:
22935 @@ -1261,15 +1500,18 @@ error_code:
22936 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22937 REG_TO_PTGS %ecx
22938 SET_KERNEL_GS %ecx
22939 - movl $(__USER_DS), %ecx
22940 + movl $(__KERNEL_DS), %ecx
22941 movl %ecx, %ds
22942 movl %ecx, %es
22943 +
22944 + pax_enter_kernel
22945 +
22946 TRACE_IRQS_OFF
22947 movl %esp,%eax # pt_regs pointer
22948 call *%edi
22949 jmp ret_from_exception
22950 CFI_ENDPROC
22951 -END(page_fault)
22952 +ENDPROC(page_fault)
22953
22954 /*
22955 * Debug traps and NMI can happen at the one SYSENTER instruction
22956 @@ -1312,7 +1554,7 @@ debug_stack_correct:
22957 call do_debug
22958 jmp ret_from_exception
22959 CFI_ENDPROC
22960 -END(debug)
22961 +ENDPROC(debug)
22962
22963 /*
22964 * NMI is doubly nasty. It can happen _while_ we're handling
22965 @@ -1352,6 +1594,9 @@ nmi_stack_correct:
22966 xorl %edx,%edx # zero error code
22967 movl %esp,%eax # pt_regs pointer
22968 call do_nmi
22969 +
22970 + pax_exit_kernel
22971 +
22972 jmp restore_all_notrace
22973 CFI_ENDPROC
22974
22975 @@ -1389,13 +1634,16 @@ nmi_espfix_stack:
22976 FIXUP_ESPFIX_STACK # %eax == %esp
22977 xorl %edx,%edx # zero error code
22978 call do_nmi
22979 +
22980 + pax_exit_kernel
22981 +
22982 RESTORE_REGS
22983 lss 12+4(%esp), %esp # back to espfix stack
22984 CFI_ADJUST_CFA_OFFSET -24
22985 jmp irq_return
22986 #endif
22987 CFI_ENDPROC
22988 -END(nmi)
22989 +ENDPROC(nmi)
22990
22991 ENTRY(int3)
22992 RING0_INT_FRAME
22993 @@ -1408,14 +1656,14 @@ ENTRY(int3)
22994 call do_int3
22995 jmp ret_from_exception
22996 CFI_ENDPROC
22997 -END(int3)
22998 +ENDPROC(int3)
22999
23000 ENTRY(general_protection)
23001 RING0_EC_FRAME
23002 pushl_cfi $do_general_protection
23003 jmp error_code
23004 CFI_ENDPROC
23005 -END(general_protection)
23006 +ENDPROC(general_protection)
23007
23008 #ifdef CONFIG_KVM_GUEST
23009 ENTRY(async_page_fault)
23010 @@ -1424,6 +1672,6 @@ ENTRY(async_page_fault)
23011 pushl_cfi $do_async_page_fault
23012 jmp error_code
23013 CFI_ENDPROC
23014 -END(async_page_fault)
23015 +ENDPROC(async_page_fault)
23016 #endif
23017
23018 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
23019 index c0226ab..b1d8cdd 100644
23020 --- a/arch/x86/kernel/entry_64.S
23021 +++ b/arch/x86/kernel/entry_64.S
23022 @@ -59,6 +59,8 @@
23023 #include <asm/smap.h>
23024 #include <asm/pgtable_types.h>
23025 #include <linux/err.h>
23026 +#include <asm/pgtable.h>
23027 +#include <asm/alternative-asm.h>
23028
23029 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
23030 #include <linux/elf-em.h>
23031 @@ -81,6 +83,430 @@ ENTRY(native_usergs_sysret64)
23032 ENDPROC(native_usergs_sysret64)
23033 #endif /* CONFIG_PARAVIRT */
23034
23035 + .macro ljmpq sel, off
23036 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
23037 + .byte 0x48; ljmp *1234f(%rip)
23038 + .pushsection .rodata
23039 + .align 16
23040 + 1234: .quad \off; .word \sel
23041 + .popsection
23042 +#else
23043 + pushq $\sel
23044 + pushq $\off
23045 + lretq
23046 +#endif
23047 + .endm
23048 +
23049 + .macro pax_enter_kernel
23050 + pax_set_fptr_mask
23051 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23052 + call pax_enter_kernel
23053 +#endif
23054 + .endm
23055 +
23056 + .macro pax_exit_kernel
23057 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23058 + call pax_exit_kernel
23059 +#endif
23060 +
23061 + .endm
23062 +
23063 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23064 +ENTRY(pax_enter_kernel)
23065 + pushq %rdi
23066 +
23067 +#ifdef CONFIG_PARAVIRT
23068 + PV_SAVE_REGS(CLBR_RDI)
23069 +#endif
23070 +
23071 +#ifdef CONFIG_PAX_KERNEXEC
23072 + GET_CR0_INTO_RDI
23073 + bts $16,%rdi
23074 + jnc 3f
23075 + mov %cs,%edi
23076 + cmp $__KERNEL_CS,%edi
23077 + jnz 2f
23078 +1:
23079 +#endif
23080 +
23081 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23082 + 661: jmp 111f
23083 + .pushsection .altinstr_replacement, "a"
23084 + 662: ASM_NOP2
23085 + .popsection
23086 + .pushsection .altinstructions, "a"
23087 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23088 + .popsection
23089 + GET_CR3_INTO_RDI
23090 + cmp $0,%dil
23091 + jnz 112f
23092 + mov $__KERNEL_DS,%edi
23093 + mov %edi,%ss
23094 + jmp 111f
23095 +112: cmp $1,%dil
23096 + jz 113f
23097 + ud2
23098 +113: sub $4097,%rdi
23099 + bts $63,%rdi
23100 + SET_RDI_INTO_CR3
23101 + mov $__UDEREF_KERNEL_DS,%edi
23102 + mov %edi,%ss
23103 +111:
23104 +#endif
23105 +
23106 +#ifdef CONFIG_PARAVIRT
23107 + PV_RESTORE_REGS(CLBR_RDI)
23108 +#endif
23109 +
23110 + popq %rdi
23111 + pax_force_retaddr
23112 + retq
23113 +
23114 +#ifdef CONFIG_PAX_KERNEXEC
23115 +2: ljmpq __KERNEL_CS,1b
23116 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
23117 +4: SET_RDI_INTO_CR0
23118 + jmp 1b
23119 +#endif
23120 +ENDPROC(pax_enter_kernel)
23121 +
23122 +ENTRY(pax_exit_kernel)
23123 + pushq %rdi
23124 +
23125 +#ifdef CONFIG_PARAVIRT
23126 + PV_SAVE_REGS(CLBR_RDI)
23127 +#endif
23128 +
23129 +#ifdef CONFIG_PAX_KERNEXEC
23130 + mov %cs,%rdi
23131 + cmp $__KERNEXEC_KERNEL_CS,%edi
23132 + jz 2f
23133 + GET_CR0_INTO_RDI
23134 + bts $16,%rdi
23135 + jnc 4f
23136 +1:
23137 +#endif
23138 +
23139 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23140 + 661: jmp 111f
23141 + .pushsection .altinstr_replacement, "a"
23142 + 662: ASM_NOP2
23143 + .popsection
23144 + .pushsection .altinstructions, "a"
23145 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23146 + .popsection
23147 + mov %ss,%edi
23148 + cmp $__UDEREF_KERNEL_DS,%edi
23149 + jnz 111f
23150 + GET_CR3_INTO_RDI
23151 + cmp $0,%dil
23152 + jz 112f
23153 + ud2
23154 +112: add $4097,%rdi
23155 + bts $63,%rdi
23156 + SET_RDI_INTO_CR3
23157 + mov $__KERNEL_DS,%edi
23158 + mov %edi,%ss
23159 +111:
23160 +#endif
23161 +
23162 +#ifdef CONFIG_PARAVIRT
23163 + PV_RESTORE_REGS(CLBR_RDI);
23164 +#endif
23165 +
23166 + popq %rdi
23167 + pax_force_retaddr
23168 + retq
23169 +
23170 +#ifdef CONFIG_PAX_KERNEXEC
23171 +2: GET_CR0_INTO_RDI
23172 + btr $16,%rdi
23173 + jnc 4f
23174 + ljmpq __KERNEL_CS,3f
23175 +3: SET_RDI_INTO_CR0
23176 + jmp 1b
23177 +4: ud2
23178 + jmp 4b
23179 +#endif
23180 +ENDPROC(pax_exit_kernel)
23181 +#endif
23182 +
23183 + .macro pax_enter_kernel_user
23184 + pax_set_fptr_mask
23185 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23186 + call pax_enter_kernel_user
23187 +#endif
23188 + .endm
23189 +
23190 + .macro pax_exit_kernel_user
23191 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23192 + call pax_exit_kernel_user
23193 +#endif
23194 +#ifdef CONFIG_PAX_RANDKSTACK
23195 + pushq %rax
23196 + pushq %r11
23197 + call pax_randomize_kstack
23198 + popq %r11
23199 + popq %rax
23200 +#endif
23201 + .endm
23202 +
23203 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23204 +ENTRY(pax_enter_kernel_user)
23205 + pushq %rdi
23206 + pushq %rbx
23207 +
23208 +#ifdef CONFIG_PARAVIRT
23209 + PV_SAVE_REGS(CLBR_RDI)
23210 +#endif
23211 +
23212 + 661: jmp 111f
23213 + .pushsection .altinstr_replacement, "a"
23214 + 662: ASM_NOP2
23215 + .popsection
23216 + .pushsection .altinstructions, "a"
23217 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23218 + .popsection
23219 + GET_CR3_INTO_RDI
23220 + cmp $1,%dil
23221 + jnz 4f
23222 + sub $4097,%rdi
23223 + bts $63,%rdi
23224 + SET_RDI_INTO_CR3
23225 + jmp 3f
23226 +111:
23227 +
23228 + GET_CR3_INTO_RDI
23229 + mov %rdi,%rbx
23230 + add $__START_KERNEL_map,%rbx
23231 + sub phys_base(%rip),%rbx
23232 +
23233 +#ifdef CONFIG_PARAVIRT
23234 + cmpl $0, pv_info+PARAVIRT_enabled
23235 + jz 1f
23236 + pushq %rdi
23237 + i = 0
23238 + .rept USER_PGD_PTRS
23239 + mov i*8(%rbx),%rsi
23240 + mov $0,%sil
23241 + lea i*8(%rbx),%rdi
23242 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23243 + i = i + 1
23244 + .endr
23245 + popq %rdi
23246 + jmp 2f
23247 +1:
23248 +#endif
23249 +
23250 + i = 0
23251 + .rept USER_PGD_PTRS
23252 + movb $0,i*8(%rbx)
23253 + i = i + 1
23254 + .endr
23255 +
23256 +2: SET_RDI_INTO_CR3
23257 +
23258 +#ifdef CONFIG_PAX_KERNEXEC
23259 + GET_CR0_INTO_RDI
23260 + bts $16,%rdi
23261 + SET_RDI_INTO_CR0
23262 +#endif
23263 +
23264 +3:
23265 +
23266 +#ifdef CONFIG_PARAVIRT
23267 + PV_RESTORE_REGS(CLBR_RDI)
23268 +#endif
23269 +
23270 + popq %rbx
23271 + popq %rdi
23272 + pax_force_retaddr
23273 + retq
23274 +4: ud2
23275 +ENDPROC(pax_enter_kernel_user)
23276 +
23277 +ENTRY(pax_exit_kernel_user)
23278 + pushq %rdi
23279 + pushq %rbx
23280 +
23281 +#ifdef CONFIG_PARAVIRT
23282 + PV_SAVE_REGS(CLBR_RDI)
23283 +#endif
23284 +
23285 + GET_CR3_INTO_RDI
23286 + 661: jmp 1f
23287 + .pushsection .altinstr_replacement, "a"
23288 + 662: ASM_NOP2
23289 + .popsection
23290 + .pushsection .altinstructions, "a"
23291 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23292 + .popsection
23293 + cmp $0,%dil
23294 + jnz 3f
23295 + add $4097,%rdi
23296 + bts $63,%rdi
23297 + SET_RDI_INTO_CR3
23298 + jmp 2f
23299 +1:
23300 +
23301 + mov %rdi,%rbx
23302 +
23303 +#ifdef CONFIG_PAX_KERNEXEC
23304 + GET_CR0_INTO_RDI
23305 + btr $16,%rdi
23306 + jnc 3f
23307 + SET_RDI_INTO_CR0
23308 +#endif
23309 +
23310 + add $__START_KERNEL_map,%rbx
23311 + sub phys_base(%rip),%rbx
23312 +
23313 +#ifdef CONFIG_PARAVIRT
23314 + cmpl $0, pv_info+PARAVIRT_enabled
23315 + jz 1f
23316 + i = 0
23317 + .rept USER_PGD_PTRS
23318 + mov i*8(%rbx),%rsi
23319 + mov $0x67,%sil
23320 + lea i*8(%rbx),%rdi
23321 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23322 + i = i + 1
23323 + .endr
23324 + jmp 2f
23325 +1:
23326 +#endif
23327 +
23328 + i = 0
23329 + .rept USER_PGD_PTRS
23330 + movb $0x67,i*8(%rbx)
23331 + i = i + 1
23332 + .endr
23333 +2:
23334 +
23335 +#ifdef CONFIG_PARAVIRT
23336 + PV_RESTORE_REGS(CLBR_RDI)
23337 +#endif
23338 +
23339 + popq %rbx
23340 + popq %rdi
23341 + pax_force_retaddr
23342 + retq
23343 +3: ud2
23344 +ENDPROC(pax_exit_kernel_user)
23345 +#endif
23346 +
23347 + .macro pax_enter_kernel_nmi
23348 + pax_set_fptr_mask
23349 +
23350 +#ifdef CONFIG_PAX_KERNEXEC
23351 + GET_CR0_INTO_RDI
23352 + bts $16,%rdi
23353 + jc 110f
23354 + SET_RDI_INTO_CR0
23355 + or $2,%ebx
23356 +110:
23357 +#endif
23358 +
23359 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23360 + 661: jmp 111f
23361 + .pushsection .altinstr_replacement, "a"
23362 + 662: ASM_NOP2
23363 + .popsection
23364 + .pushsection .altinstructions, "a"
23365 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23366 + .popsection
23367 + GET_CR3_INTO_RDI
23368 + cmp $0,%dil
23369 + jz 111f
23370 + sub $4097,%rdi
23371 + or $4,%ebx
23372 + bts $63,%rdi
23373 + SET_RDI_INTO_CR3
23374 + mov $__UDEREF_KERNEL_DS,%edi
23375 + mov %edi,%ss
23376 +111:
23377 +#endif
23378 + .endm
23379 +
23380 + .macro pax_exit_kernel_nmi
23381 +#ifdef CONFIG_PAX_KERNEXEC
23382 + btr $1,%ebx
23383 + jnc 110f
23384 + GET_CR0_INTO_RDI
23385 + btr $16,%rdi
23386 + SET_RDI_INTO_CR0
23387 +110:
23388 +#endif
23389 +
23390 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23391 + btr $2,%ebx
23392 + jnc 111f
23393 + GET_CR3_INTO_RDI
23394 + add $4097,%rdi
23395 + bts $63,%rdi
23396 + SET_RDI_INTO_CR3
23397 + mov $__KERNEL_DS,%edi
23398 + mov %edi,%ss
23399 +111:
23400 +#endif
23401 + .endm
23402 +
23403 + .macro pax_erase_kstack
23404 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23405 + call pax_erase_kstack
23406 +#endif
23407 + .endm
23408 +
23409 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23410 +ENTRY(pax_erase_kstack)
23411 + pushq %rdi
23412 + pushq %rcx
23413 + pushq %rax
23414 + pushq %r11
23415 +
23416 + GET_THREAD_INFO(%r11)
23417 + mov TI_lowest_stack(%r11), %rdi
23418 + mov $-0xBEEF, %rax
23419 + std
23420 +
23421 +1: mov %edi, %ecx
23422 + and $THREAD_SIZE_asm - 1, %ecx
23423 + shr $3, %ecx
23424 + repne scasq
23425 + jecxz 2f
23426 +
23427 + cmp $2*8, %ecx
23428 + jc 2f
23429 +
23430 + mov $2*8, %ecx
23431 + repe scasq
23432 + jecxz 2f
23433 + jne 1b
23434 +
23435 +2: cld
23436 + mov %esp, %ecx
23437 + sub %edi, %ecx
23438 +
23439 + cmp $THREAD_SIZE_asm, %rcx
23440 + jb 3f
23441 + ud2
23442 +3:
23443 +
23444 + shr $3, %ecx
23445 + rep stosq
23446 +
23447 + mov TI_task_thread_sp0(%r11), %rdi
23448 + sub $256, %rdi
23449 + mov %rdi, TI_lowest_stack(%r11)
23450 +
23451 + popq %r11
23452 + popq %rax
23453 + popq %rcx
23454 + popq %rdi
23455 + pax_force_retaddr
23456 + ret
23457 +ENDPROC(pax_erase_kstack)
23458 +#endif
23459
23460 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23461 #ifdef CONFIG_TRACE_IRQFLAGS
23462 @@ -117,7 +543,7 @@ ENDPROC(native_usergs_sysret64)
23463 .endm
23464
23465 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23466 - bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23467 + bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23468 jnc 1f
23469 TRACE_IRQS_ON_DEBUG
23470 1:
23471 @@ -155,27 +581,6 @@ ENDPROC(native_usergs_sysret64)
23472 movq \tmp,R11+\offset(%rsp)
23473 .endm
23474
23475 - .macro FAKE_STACK_FRAME child_rip
23476 - /* push in order ss, rsp, eflags, cs, rip */
23477 - xorl %eax, %eax
23478 - pushq_cfi $__KERNEL_DS /* ss */
23479 - /*CFI_REL_OFFSET ss,0*/
23480 - pushq_cfi %rax /* rsp */
23481 - CFI_REL_OFFSET rsp,0
23482 - pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23483 - /*CFI_REL_OFFSET rflags,0*/
23484 - pushq_cfi $__KERNEL_CS /* cs */
23485 - /*CFI_REL_OFFSET cs,0*/
23486 - pushq_cfi \child_rip /* rip */
23487 - CFI_REL_OFFSET rip,0
23488 - pushq_cfi %rax /* orig rax */
23489 - .endm
23490 -
23491 - .macro UNFAKE_STACK_FRAME
23492 - addq $8*6, %rsp
23493 - CFI_ADJUST_CFA_OFFSET -(6*8)
23494 - .endm
23495 -
23496 /*
23497 * initial frame state for interrupts (and exceptions without error code)
23498 */
23499 @@ -241,25 +646,26 @@ ENDPROC(native_usergs_sysret64)
23500 /* save partial stack frame */
23501 .macro SAVE_ARGS_IRQ
23502 cld
23503 - /* start from rbp in pt_regs and jump over */
23504 - movq_cfi rdi, (RDI-RBP)
23505 - movq_cfi rsi, (RSI-RBP)
23506 - movq_cfi rdx, (RDX-RBP)
23507 - movq_cfi rcx, (RCX-RBP)
23508 - movq_cfi rax, (RAX-RBP)
23509 - movq_cfi r8, (R8-RBP)
23510 - movq_cfi r9, (R9-RBP)
23511 - movq_cfi r10, (R10-RBP)
23512 - movq_cfi r11, (R11-RBP)
23513 + /* start from r15 in pt_regs and jump over */
23514 + movq_cfi rdi, RDI
23515 + movq_cfi rsi, RSI
23516 + movq_cfi rdx, RDX
23517 + movq_cfi rcx, RCX
23518 + movq_cfi rax, RAX
23519 + movq_cfi r8, R8
23520 + movq_cfi r9, R9
23521 + movq_cfi r10, R10
23522 + movq_cfi r11, R11
23523 + movq_cfi r12, R12
23524
23525 /* Save rbp so that we can unwind from get_irq_regs() */
23526 - movq_cfi rbp, 0
23527 + movq_cfi rbp, RBP
23528
23529 /* Save previous stack value */
23530 movq %rsp, %rsi
23531
23532 - leaq -RBP(%rsp),%rdi /* arg1 for handler */
23533 - testl $3, CS-RBP(%rsi)
23534 + movq %rsp,%rdi /* arg1 for handler */
23535 + testb $3, CS(%rsi)
23536 je 1f
23537 SWAPGS
23538 /*
23539 @@ -279,6 +685,18 @@ ENDPROC(native_usergs_sysret64)
23540 0x06 /* DW_OP_deref */, \
23541 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23542 0x22 /* DW_OP_plus */
23543 +
23544 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23545 + testb $3, CS(%rdi)
23546 + jnz 1f
23547 + pax_enter_kernel
23548 + jmp 2f
23549 +1: pax_enter_kernel_user
23550 +2:
23551 +#else
23552 + pax_enter_kernel
23553 +#endif
23554 +
23555 /* We entered an interrupt context - irqs are off: */
23556 TRACE_IRQS_OFF
23557 .endm
23558 @@ -308,9 +726,52 @@ ENTRY(save_paranoid)
23559 js 1f /* negative -> in kernel */
23560 SWAPGS
23561 xorl %ebx,%ebx
23562 -1: ret
23563 +1:
23564 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23565 + testb $3, CS+8(%rsp)
23566 + jnz 1f
23567 + pax_enter_kernel
23568 + jmp 2f
23569 +1: pax_enter_kernel_user
23570 +2:
23571 +#else
23572 + pax_enter_kernel
23573 +#endif
23574 + pax_force_retaddr
23575 + ret
23576 CFI_ENDPROC
23577 -END(save_paranoid)
23578 +ENDPROC(save_paranoid)
23579 +
23580 +ENTRY(save_paranoid_nmi)
23581 + XCPT_FRAME 1 RDI+8
23582 + cld
23583 + movq_cfi rdi, RDI+8
23584 + movq_cfi rsi, RSI+8
23585 + movq_cfi rdx, RDX+8
23586 + movq_cfi rcx, RCX+8
23587 + movq_cfi rax, RAX+8
23588 + movq_cfi r8, R8+8
23589 + movq_cfi r9, R9+8
23590 + movq_cfi r10, R10+8
23591 + movq_cfi r11, R11+8
23592 + movq_cfi rbx, RBX+8
23593 + movq_cfi rbp, RBP+8
23594 + movq_cfi r12, R12+8
23595 + movq_cfi r13, R13+8
23596 + movq_cfi r14, R14+8
23597 + movq_cfi r15, R15+8
23598 + movl $1,%ebx
23599 + movl $MSR_GS_BASE,%ecx
23600 + rdmsr
23601 + testl %edx,%edx
23602 + js 1f /* negative -> in kernel */
23603 + SWAPGS
23604 + xorl %ebx,%ebx
23605 +1: pax_enter_kernel_nmi
23606 + pax_force_retaddr
23607 + ret
23608 + CFI_ENDPROC
23609 +ENDPROC(save_paranoid_nmi)
23610
23611 /*
23612 * A newly forked process directly context switches into this address.
23613 @@ -331,7 +792,7 @@ ENTRY(ret_from_fork)
23614
23615 RESTORE_REST
23616
23617 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23618 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23619 jz 1f
23620
23621 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23622 @@ -341,15 +802,13 @@ ENTRY(ret_from_fork)
23623 jmp ret_from_sys_call # go to the SYSRET fastpath
23624
23625 1:
23626 - subq $REST_SKIP, %rsp # leave space for volatiles
23627 - CFI_ADJUST_CFA_OFFSET REST_SKIP
23628 movq %rbp, %rdi
23629 call *%rbx
23630 movl $0, RAX(%rsp)
23631 RESTORE_REST
23632 jmp int_ret_from_sys_call
23633 CFI_ENDPROC
23634 -END(ret_from_fork)
23635 +ENDPROC(ret_from_fork)
23636
23637 /*
23638 * System call entry. Up to 6 arguments in registers are supported.
23639 @@ -386,7 +845,7 @@ END(ret_from_fork)
23640 ENTRY(system_call)
23641 CFI_STARTPROC simple
23642 CFI_SIGNAL_FRAME
23643 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23644 + CFI_DEF_CFA rsp,0
23645 CFI_REGISTER rip,rcx
23646 /*CFI_REGISTER rflags,r11*/
23647 SWAPGS_UNSAFE_STACK
23648 @@ -399,16 +858,23 @@ GLOBAL(system_call_after_swapgs)
23649
23650 movq %rsp,PER_CPU_VAR(old_rsp)
23651 movq PER_CPU_VAR(kernel_stack),%rsp
23652 + SAVE_ARGS 8*6, 0, rax_enosys=1
23653 + pax_enter_kernel_user
23654 +
23655 +#ifdef CONFIG_PAX_RANDKSTACK
23656 + pax_erase_kstack
23657 +#endif
23658 +
23659 /*
23660 * No need to follow this irqs off/on section - it's straight
23661 * and short:
23662 */
23663 ENABLE_INTERRUPTS(CLBR_NONE)
23664 - SAVE_ARGS 8, 0, rax_enosys=1
23665 movq_cfi rax,(ORIG_RAX-ARGOFFSET)
23666 movq %rcx,RIP-ARGOFFSET(%rsp)
23667 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23668 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23669 + GET_THREAD_INFO(%rcx)
23670 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23671 jnz tracesys
23672 system_call_fastpath:
23673 #if __SYSCALL_MASK == ~0
23674 @@ -432,10 +898,13 @@ sysret_check:
23675 LOCKDEP_SYS_EXIT
23676 DISABLE_INTERRUPTS(CLBR_NONE)
23677 TRACE_IRQS_OFF
23678 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23679 + GET_THREAD_INFO(%rcx)
23680 + movl TI_flags(%rcx),%edx
23681 andl %edi,%edx
23682 jnz sysret_careful
23683 CFI_REMEMBER_STATE
23684 + pax_exit_kernel_user
23685 + pax_erase_kstack
23686 /*
23687 * sysretq will re-enable interrupts:
23688 */
23689 @@ -494,11 +963,14 @@ sysret_audit:
23690
23691 /* Do syscall tracing */
23692 tracesys:
23693 - leaq -REST_SKIP(%rsp), %rdi
23694 + movq %rsp, %rdi
23695 movq $AUDIT_ARCH_X86_64, %rsi
23696 call syscall_trace_enter_phase1
23697 test %rax, %rax
23698 jnz tracesys_phase2 /* if needed, run the slow path */
23699 +
23700 + pax_erase_kstack
23701 +
23702 LOAD_ARGS 0 /* else restore clobbered regs */
23703 jmp system_call_fastpath /* and return to the fast path */
23704
23705 @@ -510,12 +982,14 @@ tracesys_phase2:
23706 movq %rax,%rdx
23707 call syscall_trace_enter_phase2
23708
23709 + pax_erase_kstack
23710 +
23711 /*
23712 * Reload arg registers from stack in case ptrace changed them.
23713 * We don't reload %rax because syscall_trace_entry_phase2() returned
23714 * the value it wants us to use in the table lookup.
23715 */
23716 - LOAD_ARGS ARGOFFSET, 1
23717 + LOAD_ARGS 1
23718 RESTORE_REST
23719 #if __SYSCALL_MASK == ~0
23720 cmpq $__NR_syscall_max,%rax
23721 @@ -545,7 +1019,9 @@ GLOBAL(int_with_check)
23722 andl %edi,%edx
23723 jnz int_careful
23724 andl $~TS_COMPAT,TI_status(%rcx)
23725 - jmp retint_swapgs
23726 + pax_exit_kernel_user
23727 + pax_erase_kstack
23728 + jmp retint_swapgs_pax
23729
23730 /* Either reschedule or signal or syscall exit tracking needed. */
23731 /* First do a reschedule test. */
23732 @@ -591,7 +1067,7 @@ int_restore_rest:
23733 TRACE_IRQS_OFF
23734 jmp int_with_check
23735 CFI_ENDPROC
23736 -END(system_call)
23737 +ENDPROC(system_call)
23738
23739 .macro FORK_LIKE func
23740 ENTRY(stub_\func)
23741 @@ -604,9 +1080,10 @@ ENTRY(stub_\func)
23742 DEFAULT_FRAME 0 8 /* offset 8: return address */
23743 call sys_\func
23744 RESTORE_TOP_OF_STACK %r11, 8
23745 - ret $REST_SKIP /* pop extended registers */
23746 + pax_force_retaddr
23747 + ret
23748 CFI_ENDPROC
23749 -END(stub_\func)
23750 +ENDPROC(stub_\func)
23751 .endm
23752
23753 .macro FIXED_FRAME label,func
23754 @@ -616,9 +1093,10 @@ ENTRY(\label)
23755 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23756 call \func
23757 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23758 + pax_force_retaddr
23759 ret
23760 CFI_ENDPROC
23761 -END(\label)
23762 +ENDPROC(\label)
23763 .endm
23764
23765 FORK_LIKE clone
23766 @@ -626,19 +1104,6 @@ END(\label)
23767 FORK_LIKE vfork
23768 FIXED_FRAME stub_iopl, sys_iopl
23769
23770 -ENTRY(ptregscall_common)
23771 - DEFAULT_FRAME 1 8 /* offset 8: return address */
23772 - RESTORE_TOP_OF_STACK %r11, 8
23773 - movq_cfi_restore R15+8, r15
23774 - movq_cfi_restore R14+8, r14
23775 - movq_cfi_restore R13+8, r13
23776 - movq_cfi_restore R12+8, r12
23777 - movq_cfi_restore RBP+8, rbp
23778 - movq_cfi_restore RBX+8, rbx
23779 - ret $REST_SKIP /* pop extended registers */
23780 - CFI_ENDPROC
23781 -END(ptregscall_common)
23782 -
23783 ENTRY(stub_execve)
23784 CFI_STARTPROC
23785 addq $8, %rsp
23786 @@ -650,7 +1115,7 @@ ENTRY(stub_execve)
23787 RESTORE_REST
23788 jmp int_ret_from_sys_call
23789 CFI_ENDPROC
23790 -END(stub_execve)
23791 +ENDPROC(stub_execve)
23792
23793 /*
23794 * sigreturn is special because it needs to restore all registers on return.
23795 @@ -667,7 +1132,7 @@ ENTRY(stub_rt_sigreturn)
23796 RESTORE_REST
23797 jmp int_ret_from_sys_call
23798 CFI_ENDPROC
23799 -END(stub_rt_sigreturn)
23800 +ENDPROC(stub_rt_sigreturn)
23801
23802 #ifdef CONFIG_X86_X32_ABI
23803 ENTRY(stub_x32_rt_sigreturn)
23804 @@ -681,7 +1146,7 @@ ENTRY(stub_x32_rt_sigreturn)
23805 RESTORE_REST
23806 jmp int_ret_from_sys_call
23807 CFI_ENDPROC
23808 -END(stub_x32_rt_sigreturn)
23809 +ENDPROC(stub_x32_rt_sigreturn)
23810
23811 ENTRY(stub_x32_execve)
23812 CFI_STARTPROC
23813 @@ -695,7 +1160,7 @@ ENTRY(stub_x32_execve)
23814 RESTORE_REST
23815 jmp int_ret_from_sys_call
23816 CFI_ENDPROC
23817 -END(stub_x32_execve)
23818 +ENDPROC(stub_x32_execve)
23819
23820 #endif
23821
23822 @@ -732,7 +1197,7 @@ vector=vector+1
23823 2: jmp common_interrupt
23824 .endr
23825 CFI_ENDPROC
23826 -END(irq_entries_start)
23827 +ENDPROC(irq_entries_start)
23828
23829 .previous
23830 END(interrupt)
23831 @@ -749,8 +1214,8 @@ END(interrupt)
23832 /* 0(%rsp): ~(interrupt number) */
23833 .macro interrupt func
23834 /* reserve pt_regs for scratch regs and rbp */
23835 - subq $ORIG_RAX-RBP, %rsp
23836 - CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23837 + subq $ORIG_RAX, %rsp
23838 + CFI_ADJUST_CFA_OFFSET ORIG_RAX
23839 SAVE_ARGS_IRQ
23840 call \func
23841 .endm
23842 @@ -773,14 +1238,14 @@ ret_from_intr:
23843
23844 /* Restore saved previous stack */
23845 popq %rsi
23846 - CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23847 - leaq ARGOFFSET-RBP(%rsi), %rsp
23848 + CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23849 + movq %rsi, %rsp
23850 CFI_DEF_CFA_REGISTER rsp
23851 - CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23852 + CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23853
23854 exit_intr:
23855 GET_THREAD_INFO(%rcx)
23856 - testl $3,CS-ARGOFFSET(%rsp)
23857 + testb $3,CS-ARGOFFSET(%rsp)
23858 je retint_kernel
23859
23860 /* Interrupt came from user space */
23861 @@ -802,12 +1267,35 @@ retint_swapgs: /* return to user-space */
23862 * The iretq could re-enable interrupts:
23863 */
23864 DISABLE_INTERRUPTS(CLBR_ANY)
23865 + pax_exit_kernel_user
23866 +retint_swapgs_pax:
23867 TRACE_IRQS_IRETQ
23868 SWAPGS
23869 jmp restore_args
23870
23871 retint_restore_args: /* return to kernel space */
23872 DISABLE_INTERRUPTS(CLBR_ANY)
23873 + pax_exit_kernel
23874 +
23875 +#if defined(CONFIG_EFI) && defined(CONFIG_PAX_KERNEXEC)
23876 + /* This is a quirk to allow IRQs/NMIs/MCEs during early EFI setup,
23877 + * namely calling EFI runtime services with a phys mapping. We're
23878 + * starting off with NOPs and patch in the real instrumentation
23879 + * (BTS/OR) before starting any userland process; even before starting
23880 + * up the APs.
23881 + */
23882 + .pushsection .altinstr_replacement, "a"
23883 + 601: pax_force_retaddr (RIP-ARGOFFSET)
23884 + 602:
23885 + .popsection
23886 + 603: .fill 602b-601b, 1, 0x90
23887 + .pushsection .altinstructions, "a"
23888 + altinstruction_entry 603b, 601b, X86_FEATURE_ALWAYS, 602b-601b, 602b-601b
23889 + .popsection
23890 +#else
23891 + pax_force_retaddr (RIP-ARGOFFSET)
23892 +#endif
23893 +
23894 /*
23895 * The iretq could re-enable interrupts:
23896 */
23897 @@ -907,7 +1395,7 @@ ENTRY(retint_kernel)
23898 jmp exit_intr
23899 #endif
23900 CFI_ENDPROC
23901 -END(common_interrupt)
23902 +ENDPROC(common_interrupt)
23903
23904 /*
23905 * APIC interrupts.
23906 @@ -921,7 +1409,7 @@ ENTRY(\sym)
23907 interrupt \do_sym
23908 jmp ret_from_intr
23909 CFI_ENDPROC
23910 -END(\sym)
23911 +ENDPROC(\sym)
23912 .endm
23913
23914 #ifdef CONFIG_TRACING
23915 @@ -994,7 +1482,7 @@ apicinterrupt IRQ_WORK_VECTOR \
23916 /*
23917 * Exception entry points.
23918 */
23919 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23920 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23921
23922 .macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1
23923 ENTRY(\sym)
23924 @@ -1045,6 +1533,12 @@ ENTRY(\sym)
23925 .endif
23926
23927 .if \shift_ist != -1
23928 +#ifdef CONFIG_SMP
23929 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23930 + lea init_tss(%r13), %r13
23931 +#else
23932 + lea init_tss(%rip), %r13
23933 +#endif
23934 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\shift_ist)
23935 .endif
23936
23937 @@ -1061,7 +1555,7 @@ ENTRY(\sym)
23938 .endif
23939
23940 CFI_ENDPROC
23941 -END(\sym)
23942 +ENDPROC(\sym)
23943 .endm
23944
23945 #ifdef CONFIG_TRACING
23946 @@ -1102,9 +1596,10 @@ gs_change:
23947 2: mfence /* workaround */
23948 SWAPGS
23949 popfq_cfi
23950 + pax_force_retaddr
23951 ret
23952 CFI_ENDPROC
23953 -END(native_load_gs_index)
23954 +ENDPROC(native_load_gs_index)
23955
23956 _ASM_EXTABLE(gs_change,bad_gs)
23957 .section .fixup,"ax"
23958 @@ -1132,9 +1627,10 @@ ENTRY(do_softirq_own_stack)
23959 CFI_DEF_CFA_REGISTER rsp
23960 CFI_ADJUST_CFA_OFFSET -8
23961 decl PER_CPU_VAR(irq_count)
23962 + pax_force_retaddr
23963 ret
23964 CFI_ENDPROC
23965 -END(do_softirq_own_stack)
23966 +ENDPROC(do_softirq_own_stack)
23967
23968 #ifdef CONFIG_XEN
23969 idtentry xen_hypervisor_callback xen_do_hypervisor_callback has_error_code=0
23970 @@ -1172,7 +1668,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
23971 decl PER_CPU_VAR(irq_count)
23972 jmp error_exit
23973 CFI_ENDPROC
23974 -END(xen_do_hypervisor_callback)
23975 +ENDPROC(xen_do_hypervisor_callback)
23976
23977 /*
23978 * Hypervisor uses this for application faults while it executes.
23979 @@ -1231,7 +1727,7 @@ ENTRY(xen_failsafe_callback)
23980 SAVE_ALL
23981 jmp error_exit
23982 CFI_ENDPROC
23983 -END(xen_failsafe_callback)
23984 +ENDPROC(xen_failsafe_callback)
23985
23986 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
23987 xen_hvm_callback_vector xen_evtchn_do_upcall
23988 @@ -1278,18 +1774,33 @@ ENTRY(paranoid_exit)
23989 DEFAULT_FRAME
23990 DISABLE_INTERRUPTS(CLBR_NONE)
23991 TRACE_IRQS_OFF_DEBUG
23992 - testl %ebx,%ebx /* swapgs needed? */
23993 + testl $1,%ebx /* swapgs needed? */
23994 jnz paranoid_restore
23995 - testl $3,CS(%rsp)
23996 + testb $3,CS(%rsp)
23997 jnz paranoid_userspace
23998 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23999 + pax_exit_kernel
24000 + TRACE_IRQS_IRETQ 0
24001 + SWAPGS_UNSAFE_STACK
24002 + RESTORE_ALL 8
24003 + pax_force_retaddr_bts
24004 + jmp irq_return
24005 +#endif
24006 paranoid_swapgs:
24007 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24008 + pax_exit_kernel_user
24009 +#else
24010 + pax_exit_kernel
24011 +#endif
24012 TRACE_IRQS_IRETQ 0
24013 SWAPGS_UNSAFE_STACK
24014 RESTORE_ALL 8
24015 jmp irq_return
24016 paranoid_restore:
24017 + pax_exit_kernel
24018 TRACE_IRQS_IRETQ_DEBUG 0
24019 RESTORE_ALL 8
24020 + pax_force_retaddr_bts
24021 jmp irq_return
24022 paranoid_userspace:
24023 GET_THREAD_INFO(%rcx)
24024 @@ -1318,7 +1829,7 @@ paranoid_schedule:
24025 TRACE_IRQS_OFF
24026 jmp paranoid_userspace
24027 CFI_ENDPROC
24028 -END(paranoid_exit)
24029 +ENDPROC(paranoid_exit)
24030
24031 /*
24032 * Exception entry point. This expects an error code/orig_rax on the stack.
24033 @@ -1345,12 +1856,23 @@ ENTRY(error_entry)
24034 movq %r14, R14+8(%rsp)
24035 movq %r15, R15+8(%rsp)
24036 xorl %ebx,%ebx
24037 - testl $3,CS+8(%rsp)
24038 + testb $3,CS+8(%rsp)
24039 je error_kernelspace
24040 error_swapgs:
24041 SWAPGS
24042 error_sti:
24043 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24044 + testb $3, CS+8(%rsp)
24045 + jnz 1f
24046 + pax_enter_kernel
24047 + jmp 2f
24048 +1: pax_enter_kernel_user
24049 +2:
24050 +#else
24051 + pax_enter_kernel
24052 +#endif
24053 TRACE_IRQS_OFF
24054 + pax_force_retaddr
24055 ret
24056
24057 /*
24058 @@ -1385,7 +1907,7 @@ error_bad_iret:
24059 decl %ebx /* Return to usergs */
24060 jmp error_sti
24061 CFI_ENDPROC
24062 -END(error_entry)
24063 +ENDPROC(error_entry)
24064
24065
24066 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
24067 @@ -1396,7 +1918,7 @@ ENTRY(error_exit)
24068 DISABLE_INTERRUPTS(CLBR_NONE)
24069 TRACE_IRQS_OFF
24070 GET_THREAD_INFO(%rcx)
24071 - testl %eax,%eax
24072 + testl $1,%eax
24073 jne retint_kernel
24074 LOCKDEP_SYS_EXIT_IRQ
24075 movl TI_flags(%rcx),%edx
24076 @@ -1405,7 +1927,7 @@ ENTRY(error_exit)
24077 jnz retint_careful
24078 jmp retint_swapgs
24079 CFI_ENDPROC
24080 -END(error_exit)
24081 +ENDPROC(error_exit)
24082
24083 /*
24084 * Test if a given stack is an NMI stack or not.
24085 @@ -1463,9 +1985,11 @@ ENTRY(nmi)
24086 * If %cs was not the kernel segment, then the NMI triggered in user
24087 * space, which means it is definitely not nested.
24088 */
24089 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
24090 + je 1f
24091 cmpl $__KERNEL_CS, 16(%rsp)
24092 jne first_nmi
24093 -
24094 +1:
24095 /*
24096 * Check the special variable on the stack to see if NMIs are
24097 * executing.
24098 @@ -1499,8 +2023,7 @@ nested_nmi:
24099
24100 1:
24101 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
24102 - leaq -1*8(%rsp), %rdx
24103 - movq %rdx, %rsp
24104 + subq $8, %rsp
24105 CFI_ADJUST_CFA_OFFSET 1*8
24106 leaq -10*8(%rsp), %rdx
24107 pushq_cfi $__KERNEL_DS
24108 @@ -1518,6 +2041,7 @@ nested_nmi_out:
24109 CFI_RESTORE rdx
24110
24111 /* No need to check faults here */
24112 +# pax_force_retaddr_bts
24113 INTERRUPT_RETURN
24114
24115 CFI_RESTORE_STATE
24116 @@ -1614,13 +2138,13 @@ end_repeat_nmi:
24117 subq $ORIG_RAX-R15, %rsp
24118 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
24119 /*
24120 - * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
24121 + * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
24122 * as we should not be calling schedule in NMI context.
24123 * Even with normal interrupts enabled. An NMI should not be
24124 * setting NEED_RESCHED or anything that normal interrupts and
24125 * exceptions might do.
24126 */
24127 - call save_paranoid
24128 + call save_paranoid_nmi
24129 DEFAULT_FRAME 0
24130
24131 /*
24132 @@ -1630,9 +2154,9 @@ end_repeat_nmi:
24133 * NMI itself takes a page fault, the page fault that was preempted
24134 * will read the information from the NMI page fault and not the
24135 * origin fault. Save it off and restore it if it changes.
24136 - * Use the r12 callee-saved register.
24137 + * Use the r13 callee-saved register.
24138 */
24139 - movq %cr2, %r12
24140 + movq %cr2, %r13
24141
24142 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24143 movq %rsp,%rdi
24144 @@ -1641,29 +2165,34 @@ end_repeat_nmi:
24145
24146 /* Did the NMI take a page fault? Restore cr2 if it did */
24147 movq %cr2, %rcx
24148 - cmpq %rcx, %r12
24149 + cmpq %rcx, %r13
24150 je 1f
24151 - movq %r12, %cr2
24152 + movq %r13, %cr2
24153 1:
24154
24155 - testl %ebx,%ebx /* swapgs needed? */
24156 + testl $1,%ebx /* swapgs needed? */
24157 jnz nmi_restore
24158 nmi_swapgs:
24159 SWAPGS_UNSAFE_STACK
24160 nmi_restore:
24161 + pax_exit_kernel_nmi
24162 /* Pop the extra iret frame at once */
24163 RESTORE_ALL 6*8
24164 + testb $3, 8(%rsp)
24165 + jnz 1f
24166 + pax_force_retaddr_bts
24167 +1:
24168
24169 /* Clear the NMI executing stack variable */
24170 movq $0, 5*8(%rsp)
24171 jmp irq_return
24172 CFI_ENDPROC
24173 -END(nmi)
24174 +ENDPROC(nmi)
24175
24176 ENTRY(ignore_sysret)
24177 CFI_STARTPROC
24178 mov $-ENOSYS,%eax
24179 sysret
24180 CFI_ENDPROC
24181 -END(ignore_sysret)
24182 +ENDPROC(ignore_sysret)
24183
24184 diff --git a/arch/x86/kernel/espfix_64.c b/arch/x86/kernel/espfix_64.c
24185 index 94d857f..5bce89c 100644
24186 --- a/arch/x86/kernel/espfix_64.c
24187 +++ b/arch/x86/kernel/espfix_64.c
24188 @@ -70,8 +70,7 @@ static DEFINE_MUTEX(espfix_init_mutex);
24189 #define ESPFIX_MAX_PAGES DIV_ROUND_UP(CONFIG_NR_CPUS, ESPFIX_STACKS_PER_PAGE)
24190 static void *espfix_pages[ESPFIX_MAX_PAGES];
24191
24192 -static __page_aligned_bss pud_t espfix_pud_page[PTRS_PER_PUD]
24193 - __aligned(PAGE_SIZE);
24194 +static pud_t espfix_pud_page[PTRS_PER_PUD] __page_aligned_rodata;
24195
24196 static unsigned int page_random, slot_random;
24197
24198 @@ -122,14 +121,17 @@ static void init_espfix_random(void)
24199 void __init init_espfix_bsp(void)
24200 {
24201 pgd_t *pgd_p;
24202 - pteval_t ptemask;
24203 -
24204 - ptemask = __supported_pte_mask;
24205 + unsigned long index = pgd_index(ESPFIX_BASE_ADDR);
24206
24207 /* Install the espfix pud into the kernel page directory */
24208 - pgd_p = &init_level4_pgt[pgd_index(ESPFIX_BASE_ADDR)];
24209 + pgd_p = &init_level4_pgt[index];
24210 pgd_populate(&init_mm, pgd_p, (pud_t *)espfix_pud_page);
24211
24212 +#ifdef CONFIG_PAX_PER_CPU_PGD
24213 + clone_pgd_range(get_cpu_pgd(0, kernel) + index, swapper_pg_dir + index, 1);
24214 + clone_pgd_range(get_cpu_pgd(0, user) + index, swapper_pg_dir + index, 1);
24215 +#endif
24216 +
24217 /* Randomize the locations */
24218 init_espfix_random();
24219
24220 @@ -197,7 +199,7 @@ void init_espfix_ap(void)
24221 set_pte(&pte_p[n*PTE_STRIDE], pte);
24222
24223 /* Job is done for this CPU and any CPU which shares this page */
24224 - ACCESS_ONCE(espfix_pages[page]) = stack_page;
24225 + ACCESS_ONCE_RW(espfix_pages[page]) = stack_page;
24226
24227 unlock_done:
24228 mutex_unlock(&espfix_init_mutex);
24229 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24230 index 3386dc9..28bdf81 100644
24231 --- a/arch/x86/kernel/ftrace.c
24232 +++ b/arch/x86/kernel/ftrace.c
24233 @@ -88,7 +88,7 @@ static unsigned long text_ip_addr(unsigned long ip)
24234 * kernel identity mapping to modify code.
24235 */
24236 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24237 - ip = (unsigned long)__va(__pa_symbol(ip));
24238 + ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24239
24240 return ip;
24241 }
24242 @@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24243 {
24244 unsigned char replaced[MCOUNT_INSN_SIZE];
24245
24246 + ip = ktla_ktva(ip);
24247 +
24248 /*
24249 * Note: Due to modules and __init, code can
24250 * disappear and change, we need to protect against faulting
24251 @@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
24252 unsigned char old[MCOUNT_INSN_SIZE];
24253 int ret;
24254
24255 - memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
24256 + memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
24257
24258 ftrace_update_func = ip;
24259 /* Make sure the breakpoints see the ftrace_update_func update */
24260 @@ -310,7 +312,7 @@ static int add_break(unsigned long ip, const char *old)
24261 unsigned char replaced[MCOUNT_INSN_SIZE];
24262 unsigned char brk = BREAKPOINT_INSTRUCTION;
24263
24264 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
24265 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
24266 return -EFAULT;
24267
24268 /* Make sure it is what we expect it to be */
24269 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
24270 index eda1a86..8f6df48 100644
24271 --- a/arch/x86/kernel/head64.c
24272 +++ b/arch/x86/kernel/head64.c
24273 @@ -67,12 +67,12 @@ again:
24274 pgd = *pgd_p;
24275
24276 /*
24277 - * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
24278 - * critical -- __PAGE_OFFSET would point us back into the dynamic
24279 + * The use of __early_va rather than __va here is critical:
24280 + * __va would point us back into the dynamic
24281 * range and we might end up looping forever...
24282 */
24283 if (pgd)
24284 - pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24285 + pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24286 else {
24287 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24288 reset_early_page_tables();
24289 @@ -82,13 +82,13 @@ again:
24290 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24291 for (i = 0; i < PTRS_PER_PUD; i++)
24292 pud_p[i] = 0;
24293 - *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24294 + *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24295 }
24296 pud_p += pud_index(address);
24297 pud = *pud_p;
24298
24299 if (pud)
24300 - pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24301 + pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24302 else {
24303 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24304 reset_early_page_tables();
24305 @@ -98,7 +98,7 @@ again:
24306 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24307 for (i = 0; i < PTRS_PER_PMD; i++)
24308 pmd_p[i] = 0;
24309 - *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24310 + *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24311 }
24312 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24313 pmd_p[pmd_index(address)] = pmd;
24314 @@ -175,7 +175,6 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
24315 if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG)
24316 early_printk("Kernel alive\n");
24317
24318 - clear_page(init_level4_pgt);
24319 /* set init_level4_pgt kernel high mapping*/
24320 init_level4_pgt[511] = early_level4_pgt[511];
24321
24322 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24323 index f36bd42..0ab4474 100644
24324 --- a/arch/x86/kernel/head_32.S
24325 +++ b/arch/x86/kernel/head_32.S
24326 @@ -26,6 +26,12 @@
24327 /* Physical address */
24328 #define pa(X) ((X) - __PAGE_OFFSET)
24329
24330 +#ifdef CONFIG_PAX_KERNEXEC
24331 +#define ta(X) (X)
24332 +#else
24333 +#define ta(X) ((X) - __PAGE_OFFSET)
24334 +#endif
24335 +
24336 /*
24337 * References to members of the new_cpu_data structure.
24338 */
24339 @@ -55,11 +61,7 @@
24340 * and small than max_low_pfn, otherwise will waste some page table entries
24341 */
24342
24343 -#if PTRS_PER_PMD > 1
24344 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24345 -#else
24346 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24347 -#endif
24348 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24349
24350 /* Number of possible pages in the lowmem region */
24351 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24352 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24353 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24354
24355 /*
24356 + * Real beginning of normal "text" segment
24357 + */
24358 +ENTRY(stext)
24359 +ENTRY(_stext)
24360 +
24361 +/*
24362 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24363 * %esi points to the real-mode code as a 32-bit pointer.
24364 * CS and DS must be 4 GB flat segments, but we don't depend on
24365 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24366 * can.
24367 */
24368 __HEAD
24369 +
24370 +#ifdef CONFIG_PAX_KERNEXEC
24371 + jmp startup_32
24372 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24373 +.fill PAGE_SIZE-5,1,0xcc
24374 +#endif
24375 +
24376 ENTRY(startup_32)
24377 movl pa(stack_start),%ecx
24378
24379 @@ -106,6 +121,59 @@ ENTRY(startup_32)
24380 2:
24381 leal -__PAGE_OFFSET(%ecx),%esp
24382
24383 +#ifdef CONFIG_SMP
24384 + movl $pa(cpu_gdt_table),%edi
24385 + movl $__per_cpu_load,%eax
24386 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24387 + rorl $16,%eax
24388 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24389 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24390 + movl $__per_cpu_end - 1,%eax
24391 + subl $__per_cpu_start,%eax
24392 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24393 +#endif
24394 +
24395 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24396 + movl $NR_CPUS,%ecx
24397 + movl $pa(cpu_gdt_table),%edi
24398 +1:
24399 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24400 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24401 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24402 + addl $PAGE_SIZE_asm,%edi
24403 + loop 1b
24404 +#endif
24405 +
24406 +#ifdef CONFIG_PAX_KERNEXEC
24407 + movl $pa(boot_gdt),%edi
24408 + movl $__LOAD_PHYSICAL_ADDR,%eax
24409 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24410 + rorl $16,%eax
24411 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24412 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24413 + rorl $16,%eax
24414 +
24415 + ljmp $(__BOOT_CS),$1f
24416 +1:
24417 +
24418 + movl $NR_CPUS,%ecx
24419 + movl $pa(cpu_gdt_table),%edi
24420 + addl $__PAGE_OFFSET,%eax
24421 +1:
24422 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24423 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24424 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24425 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24426 + rorl $16,%eax
24427 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24428 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24429 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24430 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24431 + rorl $16,%eax
24432 + addl $PAGE_SIZE_asm,%edi
24433 + loop 1b
24434 +#endif
24435 +
24436 /*
24437 * Clear BSS first so that there are no surprises...
24438 */
24439 @@ -201,8 +269,11 @@ ENTRY(startup_32)
24440 movl %eax, pa(max_pfn_mapped)
24441
24442 /* Do early initialization of the fixmap area */
24443 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24444 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24445 +#ifdef CONFIG_COMPAT_VDSO
24446 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24447 +#else
24448 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24449 +#endif
24450 #else /* Not PAE */
24451
24452 page_pde_offset = (__PAGE_OFFSET >> 20);
24453 @@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24454 movl %eax, pa(max_pfn_mapped)
24455
24456 /* Do early initialization of the fixmap area */
24457 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24458 - movl %eax,pa(initial_page_table+0xffc)
24459 +#ifdef CONFIG_COMPAT_VDSO
24460 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24461 +#else
24462 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24463 +#endif
24464 #endif
24465
24466 #ifdef CONFIG_PARAVIRT
24467 @@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24468 cmpl $num_subarch_entries, %eax
24469 jae bad_subarch
24470
24471 - movl pa(subarch_entries)(,%eax,4), %eax
24472 - subl $__PAGE_OFFSET, %eax
24473 - jmp *%eax
24474 + jmp *pa(subarch_entries)(,%eax,4)
24475
24476 bad_subarch:
24477 WEAK(lguest_entry)
24478 @@ -261,10 +333,10 @@ WEAK(xen_entry)
24479 __INITDATA
24480
24481 subarch_entries:
24482 - .long default_entry /* normal x86/PC */
24483 - .long lguest_entry /* lguest hypervisor */
24484 - .long xen_entry /* Xen hypervisor */
24485 - .long default_entry /* Moorestown MID */
24486 + .long ta(default_entry) /* normal x86/PC */
24487 + .long ta(lguest_entry) /* lguest hypervisor */
24488 + .long ta(xen_entry) /* Xen hypervisor */
24489 + .long ta(default_entry) /* Moorestown MID */
24490 num_subarch_entries = (. - subarch_entries) / 4
24491 .previous
24492 #else
24493 @@ -354,6 +426,7 @@ default_entry:
24494 movl pa(mmu_cr4_features),%eax
24495 movl %eax,%cr4
24496
24497 +#ifdef CONFIG_X86_PAE
24498 testb $X86_CR4_PAE, %al # check if PAE is enabled
24499 jz enable_paging
24500
24501 @@ -382,6 +455,9 @@ default_entry:
24502 /* Make changes effective */
24503 wrmsr
24504
24505 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24506 +#endif
24507 +
24508 enable_paging:
24509
24510 /*
24511 @@ -449,14 +525,20 @@ is486:
24512 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24513 movl %eax,%ss # after changing gdt.
24514
24515 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
24516 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24517 movl %eax,%ds
24518 movl %eax,%es
24519
24520 movl $(__KERNEL_PERCPU), %eax
24521 movl %eax,%fs # set this cpu's percpu
24522
24523 +#ifdef CONFIG_CC_STACKPROTECTOR
24524 movl $(__KERNEL_STACK_CANARY),%eax
24525 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24526 + movl $(__USER_DS),%eax
24527 +#else
24528 + xorl %eax,%eax
24529 +#endif
24530 movl %eax,%gs
24531
24532 xorl %eax,%eax # Clear LDT
24533 @@ -512,8 +594,11 @@ setup_once:
24534 * relocation. Manually set base address in stack canary
24535 * segment descriptor.
24536 */
24537 - movl $gdt_page,%eax
24538 + movl $cpu_gdt_table,%eax
24539 movl $stack_canary,%ecx
24540 +#ifdef CONFIG_SMP
24541 + addl $__per_cpu_load,%ecx
24542 +#endif
24543 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24544 shrl $16, %ecx
24545 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24546 @@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24547 cmpl $2,(%esp) # X86_TRAP_NMI
24548 je is_nmi # Ignore NMI
24549
24550 - cmpl $2,%ss:early_recursion_flag
24551 + cmpl $1,%ss:early_recursion_flag
24552 je hlt_loop
24553 incl %ss:early_recursion_flag
24554
24555 @@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24556 pushl (20+6*4)(%esp) /* trapno */
24557 pushl $fault_msg
24558 call printk
24559 -#endif
24560 call dump_stack
24561 +#endif
24562 hlt_loop:
24563 hlt
24564 jmp hlt_loop
24565 @@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24566 /* This is the default interrupt "handler" :-) */
24567 ALIGN
24568 ignore_int:
24569 - cld
24570 #ifdef CONFIG_PRINTK
24571 + cmpl $2,%ss:early_recursion_flag
24572 + je hlt_loop
24573 + incl %ss:early_recursion_flag
24574 + cld
24575 pushl %eax
24576 pushl %ecx
24577 pushl %edx
24578 @@ -617,9 +705,6 @@ ignore_int:
24579 movl $(__KERNEL_DS),%eax
24580 movl %eax,%ds
24581 movl %eax,%es
24582 - cmpl $2,early_recursion_flag
24583 - je hlt_loop
24584 - incl early_recursion_flag
24585 pushl 16(%esp)
24586 pushl 24(%esp)
24587 pushl 32(%esp)
24588 @@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24589 /*
24590 * BSS section
24591 */
24592 -__PAGE_ALIGNED_BSS
24593 - .align PAGE_SIZE
24594 #ifdef CONFIG_X86_PAE
24595 +.section .initial_pg_pmd,"a",@progbits
24596 initial_pg_pmd:
24597 .fill 1024*KPMDS,4,0
24598 #else
24599 +.section .initial_page_table,"a",@progbits
24600 ENTRY(initial_page_table)
24601 .fill 1024,4,0
24602 #endif
24603 +.section .initial_pg_fixmap,"a",@progbits
24604 initial_pg_fixmap:
24605 .fill 1024,4,0
24606 +.section .empty_zero_page,"a",@progbits
24607 ENTRY(empty_zero_page)
24608 .fill 4096,1,0
24609 +.section .swapper_pg_dir,"a",@progbits
24610 ENTRY(swapper_pg_dir)
24611 +#ifdef CONFIG_X86_PAE
24612 + .fill 4,8,0
24613 +#else
24614 .fill 1024,4,0
24615 +#endif
24616
24617 /*
24618 * This starts the data section.
24619 */
24620 #ifdef CONFIG_X86_PAE
24621 -__PAGE_ALIGNED_DATA
24622 - /* Page-aligned for the benefit of paravirt? */
24623 - .align PAGE_SIZE
24624 +.section .initial_page_table,"a",@progbits
24625 ENTRY(initial_page_table)
24626 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24627 # if KPMDS == 3
24628 @@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24629 # error "Kernel PMDs should be 1, 2 or 3"
24630 # endif
24631 .align PAGE_SIZE /* needs to be page-sized too */
24632 +
24633 +#ifdef CONFIG_PAX_PER_CPU_PGD
24634 +ENTRY(cpu_pgd)
24635 + .rept 2*NR_CPUS
24636 + .fill 4,8,0
24637 + .endr
24638 +#endif
24639 +
24640 #endif
24641
24642 .data
24643 .balign 4
24644 ENTRY(stack_start)
24645 - .long init_thread_union+THREAD_SIZE
24646 + .long init_thread_union+THREAD_SIZE-8
24647
24648 __INITRODATA
24649 int_msg:
24650 @@ -727,7 +825,7 @@ fault_msg:
24651 * segment size, and 32-bit linear address value:
24652 */
24653
24654 - .data
24655 +.section .rodata,"a",@progbits
24656 .globl boot_gdt_descr
24657 .globl idt_descr
24658
24659 @@ -736,7 +834,7 @@ fault_msg:
24660 .word 0 # 32 bit align gdt_desc.address
24661 boot_gdt_descr:
24662 .word __BOOT_DS+7
24663 - .long boot_gdt - __PAGE_OFFSET
24664 + .long pa(boot_gdt)
24665
24666 .word 0 # 32-bit align idt_desc.address
24667 idt_descr:
24668 @@ -747,7 +845,7 @@ idt_descr:
24669 .word 0 # 32 bit align gdt_desc.address
24670 ENTRY(early_gdt_descr)
24671 .word GDT_ENTRIES*8-1
24672 - .long gdt_page /* Overwritten for secondary CPUs */
24673 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
24674
24675 /*
24676 * The boot_gdt must mirror the equivalent in setup.S and is
24677 @@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24678 .align L1_CACHE_BYTES
24679 ENTRY(boot_gdt)
24680 .fill GDT_ENTRY_BOOT_CS,8,0
24681 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24682 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24683 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24684 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24685 +
24686 + .align PAGE_SIZE_asm
24687 +ENTRY(cpu_gdt_table)
24688 + .rept NR_CPUS
24689 + .quad 0x0000000000000000 /* NULL descriptor */
24690 + .quad 0x0000000000000000 /* 0x0b reserved */
24691 + .quad 0x0000000000000000 /* 0x13 reserved */
24692 + .quad 0x0000000000000000 /* 0x1b reserved */
24693 +
24694 +#ifdef CONFIG_PAX_KERNEXEC
24695 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24696 +#else
24697 + .quad 0x0000000000000000 /* 0x20 unused */
24698 +#endif
24699 +
24700 + .quad 0x0000000000000000 /* 0x28 unused */
24701 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24702 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24703 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24704 + .quad 0x0000000000000000 /* 0x4b reserved */
24705 + .quad 0x0000000000000000 /* 0x53 reserved */
24706 + .quad 0x0000000000000000 /* 0x5b reserved */
24707 +
24708 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24709 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24710 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24711 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24712 +
24713 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24714 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24715 +
24716 + /*
24717 + * Segments used for calling PnP BIOS have byte granularity.
24718 + * The code segments and data segments have fixed 64k limits,
24719 + * the transfer segment sizes are set at run time.
24720 + */
24721 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
24722 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
24723 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
24724 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
24725 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
24726 +
24727 + /*
24728 + * The APM segments have byte granularity and their bases
24729 + * are set at run time. All have 64k limits.
24730 + */
24731 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24732 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24733 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
24734 +
24735 + .quad 0x00c093000000ffff /* 0xd0 - ESPFIX SS */
24736 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24737 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24738 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24739 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24740 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24741 +
24742 + /* Be sure this is zeroed to avoid false validations in Xen */
24743 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24744 + .endr
24745 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24746 index a468c0a..8b5a879 100644
24747 --- a/arch/x86/kernel/head_64.S
24748 +++ b/arch/x86/kernel/head_64.S
24749 @@ -20,6 +20,8 @@
24750 #include <asm/processor-flags.h>
24751 #include <asm/percpu.h>
24752 #include <asm/nops.h>
24753 +#include <asm/cpufeature.h>
24754 +#include <asm/alternative-asm.h>
24755
24756 #ifdef CONFIG_PARAVIRT
24757 #include <asm/asm-offsets.h>
24758 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24759 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24760 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24761 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24762 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
24763 +L3_VMALLOC_START = pud_index(VMALLOC_START)
24764 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
24765 +L3_VMALLOC_END = pud_index(VMALLOC_END)
24766 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24767 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24768
24769 .text
24770 __HEAD
24771 @@ -89,11 +97,24 @@ startup_64:
24772 * Fixup the physical addresses in the page table
24773 */
24774 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24775 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24776 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24777 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24778 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24779 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24780
24781 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24782 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24783 + addq %rbp, level3_ident_pgt + (0*8)(%rip)
24784 +#ifndef CONFIG_XEN
24785 + addq %rbp, level3_ident_pgt + (1*8)(%rip)
24786 +#endif
24787 +
24788 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24789 +
24790 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24791 + addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24792
24793 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24794 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24795
24796 /*
24797 * Set up the identity mapping for the switchover. These
24798 @@ -174,11 +195,12 @@ ENTRY(secondary_startup_64)
24799 * after the boot processor executes this code.
24800 */
24801
24802 + orq $-1, %rbp
24803 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24804 1:
24805
24806 - /* Enable PAE mode and PGE */
24807 - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24808 + /* Enable PAE mode and PSE/PGE */
24809 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24810 movq %rcx, %cr4
24811
24812 /* Setup early boot stage 4 level pagetables. */
24813 @@ -199,10 +221,19 @@ ENTRY(secondary_startup_64)
24814 movl $MSR_EFER, %ecx
24815 rdmsr
24816 btsl $_EFER_SCE, %eax /* Enable System Call */
24817 - btl $20,%edi /* No Execute supported? */
24818 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24819 jnc 1f
24820 btsl $_EFER_NX, %eax
24821 + cmpq $-1, %rbp
24822 + je 1f
24823 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24824 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24825 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24826 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24827 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24828 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24829 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24830 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24831 1: wrmsr /* Make changes effective */
24832
24833 /* Setup cr0 */
24834 @@ -282,6 +313,7 @@ ENTRY(secondary_startup_64)
24835 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24836 * address given in m16:64.
24837 */
24838 + pax_set_fptr_mask
24839 movq initial_code(%rip),%rax
24840 pushq $0 # fake return address to stop unwinder
24841 pushq $__KERNEL_CS # set correct cs
24842 @@ -313,7 +345,7 @@ ENDPROC(start_cpu0)
24843 .quad INIT_PER_CPU_VAR(irq_stack_union)
24844
24845 GLOBAL(stack_start)
24846 - .quad init_thread_union+THREAD_SIZE-8
24847 + .quad init_thread_union+THREAD_SIZE-16
24848 .word 0
24849 __FINITDATA
24850
24851 @@ -391,7 +423,7 @@ ENTRY(early_idt_handler)
24852 call dump_stack
24853 #ifdef CONFIG_KALLSYMS
24854 leaq early_idt_ripmsg(%rip),%rdi
24855 - movq 40(%rsp),%rsi # %rip again
24856 + movq 88(%rsp),%rsi # %rip again
24857 call __print_symbol
24858 #endif
24859 #endif /* EARLY_PRINTK */
24860 @@ -420,6 +452,7 @@ ENDPROC(early_idt_handler)
24861 early_recursion_flag:
24862 .long 0
24863
24864 + .section .rodata,"a",@progbits
24865 #ifdef CONFIG_EARLY_PRINTK
24866 early_idt_msg:
24867 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24868 @@ -447,29 +480,52 @@ NEXT_PAGE(early_level4_pgt)
24869 NEXT_PAGE(early_dynamic_pgts)
24870 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24871
24872 - .data
24873 + .section .rodata,"a",@progbits
24874
24875 -#ifndef CONFIG_XEN
24876 NEXT_PAGE(init_level4_pgt)
24877 - .fill 512,8,0
24878 -#else
24879 -NEXT_PAGE(init_level4_pgt)
24880 - .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24881 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24882 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24883 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
24884 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24885 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
24886 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24887 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24888 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24889 .org init_level4_pgt + L4_START_KERNEL*8, 0
24890 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24891 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24892
24893 +#ifdef CONFIG_PAX_PER_CPU_PGD
24894 +NEXT_PAGE(cpu_pgd)
24895 + .rept 2*NR_CPUS
24896 + .fill 512,8,0
24897 + .endr
24898 +#endif
24899 +
24900 NEXT_PAGE(level3_ident_pgt)
24901 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24902 +#ifdef CONFIG_XEN
24903 .fill 511, 8, 0
24904 +#else
24905 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24906 + .fill 510,8,0
24907 +#endif
24908 +
24909 +NEXT_PAGE(level3_vmalloc_start_pgt)
24910 + .fill 512,8,0
24911 +
24912 +NEXT_PAGE(level3_vmalloc_end_pgt)
24913 + .fill 512,8,0
24914 +
24915 +NEXT_PAGE(level3_vmemmap_pgt)
24916 + .fill L3_VMEMMAP_START,8,0
24917 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24918 +
24919 NEXT_PAGE(level2_ident_pgt)
24920 - /* Since I easily can, map the first 1G.
24921 + /* Since I easily can, map the first 2G.
24922 * Don't set NX because code runs from these pages.
24923 */
24924 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24925 -#endif
24926 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24927
24928 NEXT_PAGE(level3_kernel_pgt)
24929 .fill L3_START_KERNEL,8,0
24930 @@ -477,6 +533,9 @@ NEXT_PAGE(level3_kernel_pgt)
24931 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24932 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24933
24934 +NEXT_PAGE(level2_vmemmap_pgt)
24935 + .fill 512,8,0
24936 +
24937 NEXT_PAGE(level2_kernel_pgt)
24938 /*
24939 * 512 MB kernel mapping. We spend a full page on this pagetable
24940 @@ -494,28 +553,64 @@ NEXT_PAGE(level2_kernel_pgt)
24941 NEXT_PAGE(level2_fixmap_pgt)
24942 .fill 506,8,0
24943 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24944 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
24945 - .fill 5,8,0
24946 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
24947 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
24948 + .fill 4,8,0
24949
24950 NEXT_PAGE(level1_fixmap_pgt)
24951 .fill 512,8,0
24952
24953 +NEXT_PAGE(level1_vsyscall_pgt)
24954 + .fill 512,8,0
24955 +
24956 #undef PMDS
24957
24958 - .data
24959 + .align PAGE_SIZE
24960 +ENTRY(cpu_gdt_table)
24961 + .rept NR_CPUS
24962 + .quad 0x0000000000000000 /* NULL descriptor */
24963 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24964 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
24965 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
24966 + .quad 0x00cffb000000ffff /* __USER32_CS */
24967 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
24968 + .quad 0x00affb000000ffff /* __USER_CS */
24969 +
24970 +#ifdef CONFIG_PAX_KERNEXEC
24971 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
24972 +#else
24973 + .quad 0x0 /* unused */
24974 +#endif
24975 +
24976 + .quad 0,0 /* TSS */
24977 + .quad 0,0 /* LDT */
24978 + .quad 0,0,0 /* three TLS descriptors */
24979 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
24980 + /* asm/segment.h:GDT_ENTRIES must match this */
24981 +
24982 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24983 + .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
24984 +#else
24985 + .quad 0x0 /* unused */
24986 +#endif
24987 +
24988 + /* zero the remaining page */
24989 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
24990 + .endr
24991 +
24992 .align 16
24993 .globl early_gdt_descr
24994 early_gdt_descr:
24995 .word GDT_ENTRIES*8-1
24996 early_gdt_descr_base:
24997 - .quad INIT_PER_CPU_VAR(gdt_page)
24998 + .quad cpu_gdt_table
24999
25000 ENTRY(phys_base)
25001 /* This must match the first entry in level2_kernel_pgt */
25002 .quad 0x0000000000000000
25003
25004 #include "../../x86/xen/xen-head.S"
25005 -
25006 - __PAGE_ALIGNED_BSS
25007 +
25008 + .section .rodata,"a",@progbits
25009 NEXT_PAGE(empty_zero_page)
25010 .skip PAGE_SIZE
25011 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
25012 index 05fd74f..c3548b1 100644
25013 --- a/arch/x86/kernel/i386_ksyms_32.c
25014 +++ b/arch/x86/kernel/i386_ksyms_32.c
25015 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
25016 EXPORT_SYMBOL(cmpxchg8b_emu);
25017 #endif
25018
25019 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
25020 +
25021 /* Networking helper routines. */
25022 EXPORT_SYMBOL(csum_partial_copy_generic);
25023 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
25024 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
25025
25026 EXPORT_SYMBOL(__get_user_1);
25027 EXPORT_SYMBOL(__get_user_2);
25028 @@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
25029 EXPORT_SYMBOL(___preempt_schedule_context);
25030 #endif
25031 #endif
25032 +
25033 +#ifdef CONFIG_PAX_KERNEXEC
25034 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
25035 +#endif
25036 +
25037 +#ifdef CONFIG_PAX_PER_CPU_PGD
25038 +EXPORT_SYMBOL(cpu_pgd);
25039 +#endif
25040 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
25041 index a9a4229..6f4d476 100644
25042 --- a/arch/x86/kernel/i387.c
25043 +++ b/arch/x86/kernel/i387.c
25044 @@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
25045 static inline bool interrupted_user_mode(void)
25046 {
25047 struct pt_regs *regs = get_irq_regs();
25048 - return regs && user_mode_vm(regs);
25049 + return regs && user_mode(regs);
25050 }
25051
25052 /*
25053 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
25054 index e7cc537..67d7372 100644
25055 --- a/arch/x86/kernel/i8259.c
25056 +++ b/arch/x86/kernel/i8259.c
25057 @@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
25058 static void make_8259A_irq(unsigned int irq)
25059 {
25060 disable_irq_nosync(irq);
25061 - io_apic_irqs &= ~(1<<irq);
25062 + io_apic_irqs &= ~(1UL<<irq);
25063 irq_set_chip_and_handler(irq, &i8259A_chip, handle_level_irq);
25064 enable_irq(irq);
25065 }
25066 @@ -208,7 +208,7 @@ spurious_8259A_irq:
25067 "spurious 8259A interrupt: IRQ%d.\n", irq);
25068 spurious_irq_mask |= irqmask;
25069 }
25070 - atomic_inc(&irq_err_count);
25071 + atomic_inc_unchecked(&irq_err_count);
25072 /*
25073 * Theoretically we do not have to handle this IRQ,
25074 * but in Linux this does not cause problems and is
25075 @@ -349,14 +349,16 @@ static void init_8259A(int auto_eoi)
25076 /* (slave's support for AEOI in flat mode is to be investigated) */
25077 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
25078
25079 + pax_open_kernel();
25080 if (auto_eoi)
25081 /*
25082 * In AEOI mode we just have to mask the interrupt
25083 * when acking.
25084 */
25085 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
25086 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
25087 else
25088 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25089 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25090 + pax_close_kernel();
25091
25092 udelay(100); /* wait for 8259A to initialize */
25093
25094 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
25095 index a979b5b..1d6db75 100644
25096 --- a/arch/x86/kernel/io_delay.c
25097 +++ b/arch/x86/kernel/io_delay.c
25098 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
25099 * Quirk table for systems that misbehave (lock up, etc.) if port
25100 * 0x80 is used:
25101 */
25102 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
25103 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
25104 {
25105 .callback = dmi_io_delay_0xed_port,
25106 .ident = "Compaq Presario V6000",
25107 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
25108 index 4ddaf66..49d5c18 100644
25109 --- a/arch/x86/kernel/ioport.c
25110 +++ b/arch/x86/kernel/ioport.c
25111 @@ -6,6 +6,7 @@
25112 #include <linux/sched.h>
25113 #include <linux/kernel.h>
25114 #include <linux/capability.h>
25115 +#include <linux/security.h>
25116 #include <linux/errno.h>
25117 #include <linux/types.h>
25118 #include <linux/ioport.h>
25119 @@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25120 return -EINVAL;
25121 if (turn_on && !capable(CAP_SYS_RAWIO))
25122 return -EPERM;
25123 +#ifdef CONFIG_GRKERNSEC_IO
25124 + if (turn_on && grsec_disable_privio) {
25125 + gr_handle_ioperm();
25126 + return -ENODEV;
25127 + }
25128 +#endif
25129
25130 /*
25131 * If it's the first ioperm() call in this thread's lifetime, set the
25132 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25133 * because the ->io_bitmap_max value must match the bitmap
25134 * contents:
25135 */
25136 - tss = &per_cpu(init_tss, get_cpu());
25137 + tss = init_tss + get_cpu();
25138
25139 if (turn_on)
25140 bitmap_clear(t->io_bitmap_ptr, from, num);
25141 @@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
25142 if (level > old) {
25143 if (!capable(CAP_SYS_RAWIO))
25144 return -EPERM;
25145 +#ifdef CONFIG_GRKERNSEC_IO
25146 + if (grsec_disable_privio) {
25147 + gr_handle_iopl();
25148 + return -ENODEV;
25149 + }
25150 +#endif
25151 }
25152 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
25153 t->iopl = level << 12;
25154 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
25155 index 922d285..6d20692 100644
25156 --- a/arch/x86/kernel/irq.c
25157 +++ b/arch/x86/kernel/irq.c
25158 @@ -22,7 +22,7 @@
25159 #define CREATE_TRACE_POINTS
25160 #include <asm/trace/irq_vectors.h>
25161
25162 -atomic_t irq_err_count;
25163 +atomic_unchecked_t irq_err_count;
25164
25165 /* Function pointer for generic interrupt vector handling */
25166 void (*x86_platform_ipi_callback)(void) = NULL;
25167 @@ -132,9 +132,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
25168 seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);
25169 seq_printf(p, " Hypervisor callback interrupts\n");
25170 #endif
25171 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
25172 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
25173 #if defined(CONFIG_X86_IO_APIC)
25174 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
25175 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
25176 #endif
25177 return 0;
25178 }
25179 @@ -174,7 +174,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
25180
25181 u64 arch_irq_stat(void)
25182 {
25183 - u64 sum = atomic_read(&irq_err_count);
25184 + u64 sum = atomic_read_unchecked(&irq_err_count);
25185 return sum;
25186 }
25187
25188 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25189 index 63ce838..2ea3e06 100644
25190 --- a/arch/x86/kernel/irq_32.c
25191 +++ b/arch/x86/kernel/irq_32.c
25192 @@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25193
25194 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25195
25196 +extern void gr_handle_kernel_exploit(void);
25197 +
25198 int sysctl_panic_on_stackoverflow __read_mostly;
25199
25200 /* Debugging check for stack overflow: is there less than 1KB free? */
25201 @@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25202 __asm__ __volatile__("andl %%esp,%0" :
25203 "=r" (sp) : "0" (THREAD_SIZE - 1));
25204
25205 - return sp < (sizeof(struct thread_info) + STACK_WARN);
25206 + return sp < STACK_WARN;
25207 }
25208
25209 static void print_stack_overflow(void)
25210 {
25211 printk(KERN_WARNING "low stack detected by irq handler\n");
25212 dump_stack();
25213 + gr_handle_kernel_exploit();
25214 if (sysctl_panic_on_stackoverflow)
25215 panic("low stack detected by irq handler - check messages\n");
25216 }
25217 @@ -84,10 +87,9 @@ static inline void *current_stack(void)
25218 static inline int
25219 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25220 {
25221 - struct irq_stack *curstk, *irqstk;
25222 + struct irq_stack *irqstk;
25223 u32 *isp, *prev_esp, arg1, arg2;
25224
25225 - curstk = (struct irq_stack *) current_stack();
25226 irqstk = __this_cpu_read(hardirq_stack);
25227
25228 /*
25229 @@ -96,15 +98,19 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25230 * handler) we can't do that and just have to keep using the
25231 * current stack (which is the irq stack already after all)
25232 */
25233 - if (unlikely(curstk == irqstk))
25234 + if (unlikely((void *)current_stack_pointer - (void *)irqstk < THREAD_SIZE))
25235 return 0;
25236
25237 - isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
25238 + isp = (u32 *) ((char *)irqstk + sizeof(*irqstk) - 8);
25239
25240 /* Save the next esp at the bottom of the stack */
25241 prev_esp = (u32 *)irqstk;
25242 *prev_esp = current_stack_pointer;
25243
25244 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25245 + __set_fs(MAKE_MM_SEG(0));
25246 +#endif
25247 +
25248 if (unlikely(overflow))
25249 call_on_stack(print_stack_overflow, isp);
25250
25251 @@ -115,6 +121,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25252 : "0" (irq), "1" (desc), "2" (isp),
25253 "D" (desc->handle_irq)
25254 : "memory", "cc", "ecx");
25255 +
25256 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25257 + __set_fs(current_thread_info()->addr_limit);
25258 +#endif
25259 +
25260 return 1;
25261 }
25262
25263 @@ -123,32 +134,18 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25264 */
25265 void irq_ctx_init(int cpu)
25266 {
25267 - struct irq_stack *irqstk;
25268 -
25269 if (per_cpu(hardirq_stack, cpu))
25270 return;
25271
25272 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25273 - THREADINFO_GFP,
25274 - THREAD_SIZE_ORDER));
25275 - per_cpu(hardirq_stack, cpu) = irqstk;
25276 -
25277 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25278 - THREADINFO_GFP,
25279 - THREAD_SIZE_ORDER));
25280 - per_cpu(softirq_stack, cpu) = irqstk;
25281 -
25282 - printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
25283 - cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
25284 + per_cpu(hardirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25285 + per_cpu(softirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25286 }
25287
25288 void do_softirq_own_stack(void)
25289 {
25290 - struct thread_info *curstk;
25291 struct irq_stack *irqstk;
25292 u32 *isp, *prev_esp;
25293
25294 - curstk = current_stack();
25295 irqstk = __this_cpu_read(softirq_stack);
25296
25297 /* build the stack frame on the softirq stack */
25298 @@ -158,7 +155,16 @@ void do_softirq_own_stack(void)
25299 prev_esp = (u32 *)irqstk;
25300 *prev_esp = current_stack_pointer;
25301
25302 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25303 + __set_fs(MAKE_MM_SEG(0));
25304 +#endif
25305 +
25306 call_on_stack(__do_softirq, isp);
25307 +
25308 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25309 + __set_fs(current_thread_info()->addr_limit);
25310 +#endif
25311 +
25312 }
25313
25314 bool handle_irq(unsigned irq, struct pt_regs *regs)
25315 @@ -172,7 +178,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25316 if (unlikely(!desc))
25317 return false;
25318
25319 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25320 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25321 if (unlikely(overflow))
25322 print_stack_overflow();
25323 desc->handle_irq(irq, desc);
25324 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25325 index e4b503d..824fce8 100644
25326 --- a/arch/x86/kernel/irq_64.c
25327 +++ b/arch/x86/kernel/irq_64.c
25328 @@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
25329 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
25330 EXPORT_PER_CPU_SYMBOL(irq_regs);
25331
25332 +extern void gr_handle_kernel_exploit(void);
25333 +
25334 int sysctl_panic_on_stackoverflow;
25335
25336 /*
25337 @@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25338 u64 estack_top, estack_bottom;
25339 u64 curbase = (u64)task_stack_page(current);
25340
25341 - if (user_mode_vm(regs))
25342 + if (user_mode(regs))
25343 return;
25344
25345 if (regs->sp >= curbase + sizeof(struct thread_info) +
25346 @@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25347 irq_stack_top, irq_stack_bottom,
25348 estack_top, estack_bottom);
25349
25350 + gr_handle_kernel_exploit();
25351 +
25352 if (sysctl_panic_on_stackoverflow)
25353 panic("low stack detected by irq handler - check messages\n");
25354 #endif
25355 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25356 index 26d5a55..a01160a 100644
25357 --- a/arch/x86/kernel/jump_label.c
25358 +++ b/arch/x86/kernel/jump_label.c
25359 @@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25360 * Jump label is enabled for the first time.
25361 * So we expect a default_nop...
25362 */
25363 - if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25364 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25365 != 0))
25366 bug_at((void *)entry->code, __LINE__);
25367 } else {
25368 @@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25369 * ...otherwise expect an ideal_nop. Otherwise
25370 * something went horribly wrong.
25371 */
25372 - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25373 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25374 != 0))
25375 bug_at((void *)entry->code, __LINE__);
25376 }
25377 @@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25378 * are converting the default nop to the ideal nop.
25379 */
25380 if (init) {
25381 - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25382 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25383 bug_at((void *)entry->code, __LINE__);
25384 } else {
25385 code.jump = 0xe9;
25386 code.offset = entry->target -
25387 (entry->code + JUMP_LABEL_NOP_SIZE);
25388 - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25389 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25390 bug_at((void *)entry->code, __LINE__);
25391 }
25392 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25393 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25394 index 7ec1d5f..5a7d130 100644
25395 --- a/arch/x86/kernel/kgdb.c
25396 +++ b/arch/x86/kernel/kgdb.c
25397 @@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25398 #ifdef CONFIG_X86_32
25399 switch (regno) {
25400 case GDB_SS:
25401 - if (!user_mode_vm(regs))
25402 + if (!user_mode(regs))
25403 *(unsigned long *)mem = __KERNEL_DS;
25404 break;
25405 case GDB_SP:
25406 - if (!user_mode_vm(regs))
25407 + if (!user_mode(regs))
25408 *(unsigned long *)mem = kernel_stack_pointer(regs);
25409 break;
25410 case GDB_GS:
25411 @@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25412 bp->attr.bp_addr = breakinfo[breakno].addr;
25413 bp->attr.bp_len = breakinfo[breakno].len;
25414 bp->attr.bp_type = breakinfo[breakno].type;
25415 - info->address = breakinfo[breakno].addr;
25416 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25417 + info->address = ktla_ktva(breakinfo[breakno].addr);
25418 + else
25419 + info->address = breakinfo[breakno].addr;
25420 info->len = breakinfo[breakno].len;
25421 info->type = breakinfo[breakno].type;
25422 val = arch_install_hw_breakpoint(bp);
25423 @@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25424 case 'k':
25425 /* clear the trace bit */
25426 linux_regs->flags &= ~X86_EFLAGS_TF;
25427 - atomic_set(&kgdb_cpu_doing_single_step, -1);
25428 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25429
25430 /* set the trace bit if we're stepping */
25431 if (remcomInBuffer[0] == 's') {
25432 linux_regs->flags |= X86_EFLAGS_TF;
25433 - atomic_set(&kgdb_cpu_doing_single_step,
25434 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25435 raw_smp_processor_id());
25436 }
25437
25438 @@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25439
25440 switch (cmd) {
25441 case DIE_DEBUG:
25442 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25443 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25444 if (user_mode(regs))
25445 return single_step_cont(regs, args);
25446 break;
25447 @@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25448 #endif /* CONFIG_DEBUG_RODATA */
25449
25450 bpt->type = BP_BREAKPOINT;
25451 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25452 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25453 BREAK_INSTR_SIZE);
25454 if (err)
25455 return err;
25456 - err = probe_kernel_write((char *)bpt->bpt_addr,
25457 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25458 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25459 #ifdef CONFIG_DEBUG_RODATA
25460 if (!err)
25461 @@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25462 return -EBUSY;
25463 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25464 BREAK_INSTR_SIZE);
25465 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25466 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25467 if (err)
25468 return err;
25469 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25470 @@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25471 if (mutex_is_locked(&text_mutex))
25472 goto knl_write;
25473 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25474 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25475 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25476 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25477 goto knl_write;
25478 return err;
25479 knl_write:
25480 #endif /* CONFIG_DEBUG_RODATA */
25481 - return probe_kernel_write((char *)bpt->bpt_addr,
25482 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25483 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25484 }
25485
25486 diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25487 index 67e6d19..731ed28 100644
25488 --- a/arch/x86/kernel/kprobes/core.c
25489 +++ b/arch/x86/kernel/kprobes/core.c
25490 @@ -120,9 +120,12 @@ __synthesize_relative_insn(void *from, void *to, u8 op)
25491 s32 raddr;
25492 } __packed *insn;
25493
25494 - insn = (struct __arch_relative_insn *)from;
25495 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
25496 +
25497 + pax_open_kernel();
25498 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25499 insn->op = op;
25500 + pax_close_kernel();
25501 }
25502
25503 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25504 @@ -168,7 +171,7 @@ int can_boost(kprobe_opcode_t *opcodes)
25505 kprobe_opcode_t opcode;
25506 kprobe_opcode_t *orig_opcodes = opcodes;
25507
25508 - if (search_exception_tables((unsigned long)opcodes))
25509 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25510 return 0; /* Page fault may occur on this address. */
25511
25512 retry:
25513 @@ -242,9 +245,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25514 * for the first byte, we can recover the original instruction
25515 * from it and kp->opcode.
25516 */
25517 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25518 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25519 buf[0] = kp->opcode;
25520 - return (unsigned long)buf;
25521 + return ktva_ktla((unsigned long)buf);
25522 }
25523
25524 /*
25525 @@ -336,7 +339,9 @@ int __copy_instruction(u8 *dest, u8 *src)
25526 /* Another subsystem puts a breakpoint, failed to recover */
25527 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25528 return 0;
25529 + pax_open_kernel();
25530 memcpy(dest, insn.kaddr, insn.length);
25531 + pax_close_kernel();
25532
25533 #ifdef CONFIG_X86_64
25534 if (insn_rip_relative(&insn)) {
25535 @@ -363,7 +368,9 @@ int __copy_instruction(u8 *dest, u8 *src)
25536 return 0;
25537 }
25538 disp = (u8 *) dest + insn_offset_displacement(&insn);
25539 + pax_open_kernel();
25540 *(s32 *) disp = (s32) newdisp;
25541 + pax_close_kernel();
25542 }
25543 #endif
25544 return insn.length;
25545 @@ -505,7 +512,7 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
25546 * nor set current_kprobe, because it doesn't use single
25547 * stepping.
25548 */
25549 - regs->ip = (unsigned long)p->ainsn.insn;
25550 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25551 preempt_enable_no_resched();
25552 return;
25553 }
25554 @@ -522,9 +529,9 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
25555 regs->flags &= ~X86_EFLAGS_IF;
25556 /* single step inline if the instruction is an int3 */
25557 if (p->opcode == BREAKPOINT_INSTRUCTION)
25558 - regs->ip = (unsigned long)p->addr;
25559 + regs->ip = ktla_ktva((unsigned long)p->addr);
25560 else
25561 - regs->ip = (unsigned long)p->ainsn.insn;
25562 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25563 }
25564 NOKPROBE_SYMBOL(setup_singlestep);
25565
25566 @@ -574,7 +581,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
25567 struct kprobe *p;
25568 struct kprobe_ctlblk *kcb;
25569
25570 - if (user_mode_vm(regs))
25571 + if (user_mode(regs))
25572 return 0;
25573
25574 addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
25575 @@ -609,7 +616,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
25576 setup_singlestep(p, regs, kcb, 0);
25577 return 1;
25578 }
25579 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
25580 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25581 /*
25582 * The breakpoint instruction was removed right
25583 * after we hit it. Another cpu has removed
25584 @@ -656,6 +663,9 @@ static void __used kretprobe_trampoline_holder(void)
25585 " movq %rax, 152(%rsp)\n"
25586 RESTORE_REGS_STRING
25587 " popfq\n"
25588 +#ifdef KERNEXEC_PLUGIN
25589 + " btsq $63,(%rsp)\n"
25590 +#endif
25591 #else
25592 " pushf\n"
25593 SAVE_REGS_STRING
25594 @@ -796,7 +806,7 @@ static void resume_execution(struct kprobe *p, struct pt_regs *regs,
25595 struct kprobe_ctlblk *kcb)
25596 {
25597 unsigned long *tos = stack_addr(regs);
25598 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25599 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25600 unsigned long orig_ip = (unsigned long)p->addr;
25601 kprobe_opcode_t *insn = p->ainsn.insn;
25602
25603 @@ -979,7 +989,7 @@ int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val,
25604 struct die_args *args = data;
25605 int ret = NOTIFY_DONE;
25606
25607 - if (args->regs && user_mode_vm(args->regs))
25608 + if (args->regs && user_mode(args->regs))
25609 return ret;
25610
25611 if (val == DIE_GPF) {
25612 diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25613 index f1314d0..15f3154 100644
25614 --- a/arch/x86/kernel/kprobes/opt.c
25615 +++ b/arch/x86/kernel/kprobes/opt.c
25616 @@ -79,6 +79,7 @@ found:
25617 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25618 static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25619 {
25620 + pax_open_kernel();
25621 #ifdef CONFIG_X86_64
25622 *addr++ = 0x48;
25623 *addr++ = 0xbf;
25624 @@ -86,6 +87,7 @@ static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25625 *addr++ = 0xb8;
25626 #endif
25627 *(unsigned long *)addr = val;
25628 + pax_close_kernel();
25629 }
25630
25631 asm (
25632 @@ -337,7 +339,7 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25633 * Verify if the address gap is in 2GB range, because this uses
25634 * a relative jump.
25635 */
25636 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25637 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25638 if (abs(rel) > 0x7fffffff) {
25639 __arch_remove_optimized_kprobe(op, 0);
25640 return -ERANGE;
25641 @@ -354,16 +356,18 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25642 op->optinsn.size = ret;
25643
25644 /* Copy arch-dep-instance from template */
25645 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25646 + pax_open_kernel();
25647 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25648 + pax_close_kernel();
25649
25650 /* Set probe information */
25651 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25652
25653 /* Set probe function call */
25654 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25655 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25656
25657 /* Set returning jmp instruction at the tail of out-of-line buffer */
25658 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25659 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25660 (u8 *)op->kp.addr + op->optinsn.size);
25661
25662 flush_icache_range((unsigned long) buf,
25663 @@ -388,7 +392,7 @@ void arch_optimize_kprobes(struct list_head *oplist)
25664 WARN_ON(kprobe_disabled(&op->kp));
25665
25666 /* Backup instructions which will be replaced by jump address */
25667 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25668 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25669 RELATIVE_ADDR_SIZE);
25670
25671 insn_buf[0] = RELATIVEJUMP_OPCODE;
25672 @@ -436,7 +440,7 @@ int setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25673 /* This kprobe is really able to run optimized path. */
25674 op = container_of(p, struct optimized_kprobe, kp);
25675 /* Detour through copied instructions */
25676 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25677 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25678 if (!reenter)
25679 reset_current_kprobe();
25680 preempt_enable_no_resched();
25681 diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25682 index c2bedae..25e7ab60 100644
25683 --- a/arch/x86/kernel/ksysfs.c
25684 +++ b/arch/x86/kernel/ksysfs.c
25685 @@ -184,7 +184,7 @@ out:
25686
25687 static struct kobj_attribute type_attr = __ATTR_RO(type);
25688
25689 -static struct bin_attribute data_attr = {
25690 +static bin_attribute_no_const data_attr __read_only = {
25691 .attr = {
25692 .name = "data",
25693 .mode = S_IRUGO,
25694 diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
25695 index f6945bef..94f6434 100644
25696 --- a/arch/x86/kernel/kvm.c
25697 +++ b/arch/x86/kernel/kvm.c
25698 @@ -283,7 +283,14 @@ NOKPROBE_SYMBOL(do_async_page_fault);
25699 static void __init paravirt_ops_setup(void)
25700 {
25701 pv_info.name = "KVM";
25702 - pv_info.paravirt_enabled = 1;
25703 +
25704 + /*
25705 + * KVM isn't paravirt in the sense of paravirt_enabled. A KVM
25706 + * guest kernel works like a bare metal kernel with additional
25707 + * features, and paravirt_enabled is about features that are
25708 + * missing.
25709 + */
25710 + pv_info.paravirt_enabled = 0;
25711
25712 if (kvm_para_has_feature(KVM_FEATURE_NOP_IO_DELAY))
25713 pv_cpu_ops.io_delay = kvm_io_delay;
25714 diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c
25715 index d9156ce..a2de9bc 100644
25716 --- a/arch/x86/kernel/kvmclock.c
25717 +++ b/arch/x86/kernel/kvmclock.c
25718 @@ -263,7 +263,6 @@ void __init kvmclock_init(void)
25719 #endif
25720 kvm_get_preset_lpj();
25721 clocksource_register_hz(&kvm_clock, NSEC_PER_SEC);
25722 - pv_info.paravirt_enabled = 1;
25723 pv_info.name = "KVM";
25724
25725 if (kvm_para_has_feature(KVM_FEATURE_CLOCKSOURCE_STABLE_BIT))
25726 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25727 index c37886d..d851d32 100644
25728 --- a/arch/x86/kernel/ldt.c
25729 +++ b/arch/x86/kernel/ldt.c
25730 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25731 if (reload) {
25732 #ifdef CONFIG_SMP
25733 preempt_disable();
25734 - load_LDT(pc);
25735 + load_LDT_nolock(pc);
25736 if (!cpumask_equal(mm_cpumask(current->mm),
25737 cpumask_of(smp_processor_id())))
25738 smp_call_function(flush_ldt, current->mm, 1);
25739 preempt_enable();
25740 #else
25741 - load_LDT(pc);
25742 + load_LDT_nolock(pc);
25743 #endif
25744 }
25745 if (oldsize) {
25746 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25747 return err;
25748
25749 for (i = 0; i < old->size; i++)
25750 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25751 + write_ldt_entry(new->ldt, i, old->ldt + i);
25752 return 0;
25753 }
25754
25755 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25756 retval = copy_ldt(&mm->context, &old_mm->context);
25757 mutex_unlock(&old_mm->context.lock);
25758 }
25759 +
25760 + if (tsk == current) {
25761 + mm->context.vdso = 0;
25762 +
25763 +#ifdef CONFIG_X86_32
25764 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25765 + mm->context.user_cs_base = 0UL;
25766 + mm->context.user_cs_limit = ~0UL;
25767 +
25768 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25769 + cpus_clear(mm->context.cpu_user_cs_mask);
25770 +#endif
25771 +
25772 +#endif
25773 +#endif
25774 +
25775 + }
25776 +
25777 return retval;
25778 }
25779
25780 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25781 }
25782 }
25783
25784 +#ifdef CONFIG_PAX_SEGMEXEC
25785 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25786 + error = -EINVAL;
25787 + goto out_unlock;
25788 + }
25789 +#endif
25790 +
25791 if (!IS_ENABLED(CONFIG_X86_16BIT) && !ldt_info.seg_32bit) {
25792 error = -EINVAL;
25793 goto out_unlock;
25794 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25795 index 72e8e31..f2f1605 100644
25796 --- a/arch/x86/kernel/machine_kexec_32.c
25797 +++ b/arch/x86/kernel/machine_kexec_32.c
25798 @@ -25,7 +25,7 @@
25799 #include <asm/cacheflush.h>
25800 #include <asm/debugreg.h>
25801
25802 -static void set_idt(void *newidt, __u16 limit)
25803 +static void set_idt(struct desc_struct *newidt, __u16 limit)
25804 {
25805 struct desc_ptr curidt;
25806
25807 @@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
25808 }
25809
25810
25811 -static void set_gdt(void *newgdt, __u16 limit)
25812 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25813 {
25814 struct desc_ptr curgdt;
25815
25816 @@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
25817 }
25818
25819 control_page = page_address(image->control_code_page);
25820 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25821 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25822
25823 relocate_kernel_ptr = control_page;
25824 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25825 diff --git a/arch/x86/kernel/mcount_64.S b/arch/x86/kernel/mcount_64.S
25826 index c73aecf..4c63630 100644
25827 --- a/arch/x86/kernel/mcount_64.S
25828 +++ b/arch/x86/kernel/mcount_64.S
25829 @@ -7,7 +7,7 @@
25830 #include <linux/linkage.h>
25831 #include <asm/ptrace.h>
25832 #include <asm/ftrace.h>
25833 -
25834 +#include <asm/alternative-asm.h>
25835
25836 .code64
25837 .section .entry.text, "ax"
25838 @@ -24,8 +24,9 @@
25839 #ifdef CONFIG_DYNAMIC_FTRACE
25840
25841 ENTRY(function_hook)
25842 + pax_force_retaddr
25843 retq
25844 -END(function_hook)
25845 +ENDPROC(function_hook)
25846
25847 /* skip is set if stack has been adjusted */
25848 .macro ftrace_caller_setup skip=0
25849 @@ -62,8 +63,9 @@ GLOBAL(ftrace_graph_call)
25850 #endif
25851
25852 GLOBAL(ftrace_stub)
25853 + pax_force_retaddr
25854 retq
25855 -END(ftrace_caller)
25856 +ENDPROC(ftrace_caller)
25857
25858 ENTRY(ftrace_regs_caller)
25859 /* Save the current flags before compare (in SS location)*/
25860 @@ -127,7 +129,7 @@ GLOBAL(ftrace_regs_call)
25861 popfq
25862 jmp ftrace_stub
25863
25864 -END(ftrace_regs_caller)
25865 +ENDPROC(ftrace_regs_caller)
25866
25867
25868 #else /* ! CONFIG_DYNAMIC_FTRACE */
25869 @@ -145,6 +147,7 @@ ENTRY(function_hook)
25870 #endif
25871
25872 GLOBAL(ftrace_stub)
25873 + pax_force_retaddr
25874 retq
25875
25876 trace:
25877 @@ -158,12 +161,13 @@ trace:
25878 #endif
25879 subq $MCOUNT_INSN_SIZE, %rdi
25880
25881 + pax_force_fptr ftrace_trace_function
25882 call *ftrace_trace_function
25883
25884 MCOUNT_RESTORE_FRAME
25885
25886 jmp ftrace_stub
25887 -END(function_hook)
25888 +ENDPROC(function_hook)
25889 #endif /* CONFIG_DYNAMIC_FTRACE */
25890 #endif /* CONFIG_FUNCTION_TRACER */
25891
25892 @@ -185,8 +189,9 @@ ENTRY(ftrace_graph_caller)
25893
25894 MCOUNT_RESTORE_FRAME
25895
25896 + pax_force_retaddr
25897 retq
25898 -END(ftrace_graph_caller)
25899 +ENDPROC(ftrace_graph_caller)
25900
25901 GLOBAL(return_to_handler)
25902 subq $24, %rsp
25903 @@ -202,5 +207,7 @@ GLOBAL(return_to_handler)
25904 movq 8(%rsp), %rdx
25905 movq (%rsp), %rax
25906 addq $24, %rsp
25907 + pax_force_fptr %rdi
25908 jmp *%rdi
25909 +ENDPROC(return_to_handler)
25910 #endif
25911 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25912 index e69f988..da078ea 100644
25913 --- a/arch/x86/kernel/module.c
25914 +++ b/arch/x86/kernel/module.c
25915 @@ -81,17 +81,62 @@ static unsigned long int get_module_load_offset(void)
25916 }
25917 #endif
25918
25919 -void *module_alloc(unsigned long size)
25920 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25921 {
25922 - if (PAGE_ALIGN(size) > MODULES_LEN)
25923 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25924 return NULL;
25925 return __vmalloc_node_range(size, 1,
25926 MODULES_VADDR + get_module_load_offset(),
25927 - MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
25928 - PAGE_KERNEL_EXEC, NUMA_NO_NODE,
25929 + MODULES_END, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
25930 + prot, NUMA_NO_NODE,
25931 __builtin_return_address(0));
25932 }
25933
25934 +void *module_alloc(unsigned long size)
25935 +{
25936 +
25937 +#ifdef CONFIG_PAX_KERNEXEC
25938 + return __module_alloc(size, PAGE_KERNEL);
25939 +#else
25940 + return __module_alloc(size, PAGE_KERNEL_EXEC);
25941 +#endif
25942 +
25943 +}
25944 +
25945 +#ifdef CONFIG_PAX_KERNEXEC
25946 +#ifdef CONFIG_X86_32
25947 +void *module_alloc_exec(unsigned long size)
25948 +{
25949 + struct vm_struct *area;
25950 +
25951 + if (size == 0)
25952 + return NULL;
25953 +
25954 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25955 +return area ? area->addr : NULL;
25956 +}
25957 +EXPORT_SYMBOL(module_alloc_exec);
25958 +
25959 +void module_free_exec(struct module *mod, void *module_region)
25960 +{
25961 + vunmap(module_region);
25962 +}
25963 +EXPORT_SYMBOL(module_free_exec);
25964 +#else
25965 +void module_free_exec(struct module *mod, void *module_region)
25966 +{
25967 + module_free(mod, module_region);
25968 +}
25969 +EXPORT_SYMBOL(module_free_exec);
25970 +
25971 +void *module_alloc_exec(unsigned long size)
25972 +{
25973 + return __module_alloc(size, PAGE_KERNEL_RX);
25974 +}
25975 +EXPORT_SYMBOL(module_alloc_exec);
25976 +#endif
25977 +#endif
25978 +
25979 #ifdef CONFIG_X86_32
25980 int apply_relocate(Elf32_Shdr *sechdrs,
25981 const char *strtab,
25982 @@ -102,14 +147,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25983 unsigned int i;
25984 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25985 Elf32_Sym *sym;
25986 - uint32_t *location;
25987 + uint32_t *plocation, location;
25988
25989 DEBUGP("Applying relocate section %u to %u\n",
25990 relsec, sechdrs[relsec].sh_info);
25991 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
25992 /* This is where to make the change */
25993 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
25994 - + rel[i].r_offset;
25995 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
25996 + location = (uint32_t)plocation;
25997 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
25998 + plocation = ktla_ktva((void *)plocation);
25999 /* This is the symbol it is referring to. Note that all
26000 undefined symbols have been resolved. */
26001 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
26002 @@ -118,11 +165,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26003 switch (ELF32_R_TYPE(rel[i].r_info)) {
26004 case R_386_32:
26005 /* We add the value into the location given */
26006 - *location += sym->st_value;
26007 + pax_open_kernel();
26008 + *plocation += sym->st_value;
26009 + pax_close_kernel();
26010 break;
26011 case R_386_PC32:
26012 /* Add the value, subtract its position */
26013 - *location += sym->st_value - (uint32_t)location;
26014 + pax_open_kernel();
26015 + *plocation += sym->st_value - location;
26016 + pax_close_kernel();
26017 break;
26018 default:
26019 pr_err("%s: Unknown relocation: %u\n",
26020 @@ -167,21 +218,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
26021 case R_X86_64_NONE:
26022 break;
26023 case R_X86_64_64:
26024 + pax_open_kernel();
26025 *(u64 *)loc = val;
26026 + pax_close_kernel();
26027 break;
26028 case R_X86_64_32:
26029 + pax_open_kernel();
26030 *(u32 *)loc = val;
26031 + pax_close_kernel();
26032 if (val != *(u32 *)loc)
26033 goto overflow;
26034 break;
26035 case R_X86_64_32S:
26036 + pax_open_kernel();
26037 *(s32 *)loc = val;
26038 + pax_close_kernel();
26039 if ((s64)val != *(s32 *)loc)
26040 goto overflow;
26041 break;
26042 case R_X86_64_PC32:
26043 val -= (u64)loc;
26044 + pax_open_kernel();
26045 *(u32 *)loc = val;
26046 + pax_close_kernel();
26047 +
26048 #if 0
26049 if ((s64)val != *(s32 *)loc)
26050 goto overflow;
26051 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
26052 index c9603ac..9f88728 100644
26053 --- a/arch/x86/kernel/msr.c
26054 +++ b/arch/x86/kernel/msr.c
26055 @@ -37,6 +37,7 @@
26056 #include <linux/notifier.h>
26057 #include <linux/uaccess.h>
26058 #include <linux/gfp.h>
26059 +#include <linux/grsecurity.h>
26060
26061 #include <asm/processor.h>
26062 #include <asm/msr.h>
26063 @@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
26064 int err = 0;
26065 ssize_t bytes = 0;
26066
26067 +#ifdef CONFIG_GRKERNSEC_KMEM
26068 + gr_handle_msr_write();
26069 + return -EPERM;
26070 +#endif
26071 +
26072 if (count % 8)
26073 return -EINVAL; /* Invalid chunk size */
26074
26075 @@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
26076 err = -EBADF;
26077 break;
26078 }
26079 +#ifdef CONFIG_GRKERNSEC_KMEM
26080 + gr_handle_msr_write();
26081 + return -EPERM;
26082 +#endif
26083 if (copy_from_user(&regs, uregs, sizeof regs)) {
26084 err = -EFAULT;
26085 break;
26086 @@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
26087 return notifier_from_errno(err);
26088 }
26089
26090 -static struct notifier_block __refdata msr_class_cpu_notifier = {
26091 +static struct notifier_block msr_class_cpu_notifier = {
26092 .notifier_call = msr_class_cpu_callback,
26093 };
26094
26095 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
26096 index c3e985d..110a36a 100644
26097 --- a/arch/x86/kernel/nmi.c
26098 +++ b/arch/x86/kernel/nmi.c
26099 @@ -98,16 +98,16 @@ fs_initcall(nmi_warning_debugfs);
26100
26101 static void nmi_max_handler(struct irq_work *w)
26102 {
26103 - struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
26104 + struct nmiwork *n = container_of(w, struct nmiwork, irq_work);
26105 int remainder_ns, decimal_msecs;
26106 - u64 whole_msecs = ACCESS_ONCE(a->max_duration);
26107 + u64 whole_msecs = ACCESS_ONCE(n->max_duration);
26108
26109 remainder_ns = do_div(whole_msecs, (1000 * 1000));
26110 decimal_msecs = remainder_ns / 1000;
26111
26112 printk_ratelimited(KERN_INFO
26113 "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
26114 - a->handler, whole_msecs, decimal_msecs);
26115 + n->action->handler, whole_msecs, decimal_msecs);
26116 }
26117
26118 static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26119 @@ -134,11 +134,11 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26120 delta = sched_clock() - delta;
26121 trace_nmi_handler(a->handler, (int)delta, thishandled);
26122
26123 - if (delta < nmi_longest_ns || delta < a->max_duration)
26124 + if (delta < nmi_longest_ns || delta < a->work->max_duration)
26125 continue;
26126
26127 - a->max_duration = delta;
26128 - irq_work_queue(&a->irq_work);
26129 + a->work->max_duration = delta;
26130 + irq_work_queue(&a->work->irq_work);
26131 }
26132
26133 rcu_read_unlock();
26134 @@ -148,7 +148,7 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26135 }
26136 NOKPROBE_SYMBOL(nmi_handle);
26137
26138 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26139 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
26140 {
26141 struct nmi_desc *desc = nmi_to_desc(type);
26142 unsigned long flags;
26143 @@ -156,7 +156,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26144 if (!action->handler)
26145 return -EINVAL;
26146
26147 - init_irq_work(&action->irq_work, nmi_max_handler);
26148 + action->work->action = action;
26149 + init_irq_work(&action->work->irq_work, nmi_max_handler);
26150
26151 spin_lock_irqsave(&desc->lock, flags);
26152
26153 @@ -174,9 +175,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26154 * event confuses some handlers (kdump uses this flag)
26155 */
26156 if (action->flags & NMI_FLAG_FIRST)
26157 - list_add_rcu(&action->list, &desc->head);
26158 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
26159 else
26160 - list_add_tail_rcu(&action->list, &desc->head);
26161 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
26162
26163 spin_unlock_irqrestore(&desc->lock, flags);
26164 return 0;
26165 @@ -199,7 +200,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
26166 if (!strcmp(n->name, name)) {
26167 WARN(in_nmi(),
26168 "Trying to free NMI (%s) from NMI context!\n", n->name);
26169 - list_del_rcu(&n->list);
26170 + pax_list_del_rcu((struct list_head *)&n->list);
26171 break;
26172 }
26173 }
26174 @@ -528,6 +529,17 @@ static inline void nmi_nesting_postprocess(void)
26175 dotraplinkage notrace void
26176 do_nmi(struct pt_regs *regs, long error_code)
26177 {
26178 +
26179 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26180 + if (!user_mode(regs)) {
26181 + unsigned long cs = regs->cs & 0xFFFF;
26182 + unsigned long ip = ktva_ktla(regs->ip);
26183 +
26184 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
26185 + regs->ip = ip;
26186 + }
26187 +#endif
26188 +
26189 nmi_nesting_preprocess(regs);
26190
26191 nmi_enter();
26192 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
26193 index 6d9582e..f746287 100644
26194 --- a/arch/x86/kernel/nmi_selftest.c
26195 +++ b/arch/x86/kernel/nmi_selftest.c
26196 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
26197 {
26198 /* trap all the unknown NMIs we may generate */
26199 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
26200 - __initdata);
26201 + __initconst);
26202 }
26203
26204 static void __init cleanup_nmi_testsuite(void)
26205 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
26206 unsigned long timeout;
26207
26208 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
26209 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
26210 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
26211 nmi_fail = FAILURE;
26212 return;
26213 }
26214 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
26215 index bbb6c73..24a58ef 100644
26216 --- a/arch/x86/kernel/paravirt-spinlocks.c
26217 +++ b/arch/x86/kernel/paravirt-spinlocks.c
26218 @@ -8,7 +8,7 @@
26219
26220 #include <asm/paravirt.h>
26221
26222 -struct pv_lock_ops pv_lock_ops = {
26223 +struct pv_lock_ops pv_lock_ops __read_only = {
26224 #ifdef CONFIG_SMP
26225 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
26226 .unlock_kick = paravirt_nop,
26227 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
26228 index 548d25f..f8fb99c 100644
26229 --- a/arch/x86/kernel/paravirt.c
26230 +++ b/arch/x86/kernel/paravirt.c
26231 @@ -56,6 +56,9 @@ u64 _paravirt_ident_64(u64 x)
26232 {
26233 return x;
26234 }
26235 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26236 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
26237 +#endif
26238
26239 void __init default_banner(void)
26240 {
26241 @@ -142,16 +145,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
26242
26243 if (opfunc == NULL)
26244 /* If there's no function, patch it with a ud2a (BUG) */
26245 - ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
26246 - else if (opfunc == _paravirt_nop)
26247 + ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
26248 + else if (opfunc == (void *)_paravirt_nop)
26249 /* If the operation is a nop, then nop the callsite */
26250 ret = paravirt_patch_nop();
26251
26252 /* identity functions just return their single argument */
26253 - else if (opfunc == _paravirt_ident_32)
26254 + else if (opfunc == (void *)_paravirt_ident_32)
26255 ret = paravirt_patch_ident_32(insnbuf, len);
26256 - else if (opfunc == _paravirt_ident_64)
26257 + else if (opfunc == (void *)_paravirt_ident_64)
26258 ret = paravirt_patch_ident_64(insnbuf, len);
26259 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26260 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
26261 + ret = paravirt_patch_ident_64(insnbuf, len);
26262 +#endif
26263
26264 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
26265 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
26266 @@ -176,7 +183,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
26267 if (insn_len > len || start == NULL)
26268 insn_len = len;
26269 else
26270 - memcpy(insnbuf, start, insn_len);
26271 + memcpy(insnbuf, ktla_ktva(start), insn_len);
26272
26273 return insn_len;
26274 }
26275 @@ -300,7 +307,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
26276 return this_cpu_read(paravirt_lazy_mode);
26277 }
26278
26279 -struct pv_info pv_info = {
26280 +struct pv_info pv_info __read_only = {
26281 .name = "bare hardware",
26282 .paravirt_enabled = 0,
26283 .kernel_rpl = 0,
26284 @@ -311,16 +318,16 @@ struct pv_info pv_info = {
26285 #endif
26286 };
26287
26288 -struct pv_init_ops pv_init_ops = {
26289 +struct pv_init_ops pv_init_ops __read_only = {
26290 .patch = native_patch,
26291 };
26292
26293 -struct pv_time_ops pv_time_ops = {
26294 +struct pv_time_ops pv_time_ops __read_only = {
26295 .sched_clock = native_sched_clock,
26296 .steal_clock = native_steal_clock,
26297 };
26298
26299 -__visible struct pv_irq_ops pv_irq_ops = {
26300 +__visible struct pv_irq_ops pv_irq_ops __read_only = {
26301 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
26302 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
26303 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
26304 @@ -332,7 +339,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
26305 #endif
26306 };
26307
26308 -__visible struct pv_cpu_ops pv_cpu_ops = {
26309 +__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
26310 .cpuid = native_cpuid,
26311 .get_debugreg = native_get_debugreg,
26312 .set_debugreg = native_set_debugreg,
26313 @@ -395,21 +402,26 @@ NOKPROBE_SYMBOL(native_get_debugreg);
26314 NOKPROBE_SYMBOL(native_set_debugreg);
26315 NOKPROBE_SYMBOL(native_load_idt);
26316
26317 -struct pv_apic_ops pv_apic_ops = {
26318 +struct pv_apic_ops pv_apic_ops __read_only= {
26319 #ifdef CONFIG_X86_LOCAL_APIC
26320 .startup_ipi_hook = paravirt_nop,
26321 #endif
26322 };
26323
26324 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
26325 +#ifdef CONFIG_X86_32
26326 +#ifdef CONFIG_X86_PAE
26327 +/* 64-bit pagetable entries */
26328 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
26329 +#else
26330 /* 32-bit pagetable entries */
26331 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
26332 +#endif
26333 #else
26334 /* 64-bit pagetable entries */
26335 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
26336 #endif
26337
26338 -struct pv_mmu_ops pv_mmu_ops = {
26339 +struct pv_mmu_ops pv_mmu_ops __read_only = {
26340
26341 .read_cr2 = native_read_cr2,
26342 .write_cr2 = native_write_cr2,
26343 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
26344 .make_pud = PTE_IDENT,
26345
26346 .set_pgd = native_set_pgd,
26347 + .set_pgd_batched = native_set_pgd_batched,
26348 #endif
26349 #endif /* PAGETABLE_LEVELS >= 3 */
26350
26351 @@ -479,6 +492,12 @@ struct pv_mmu_ops pv_mmu_ops = {
26352 },
26353
26354 .set_fixmap = native_set_fixmap,
26355 +
26356 +#ifdef CONFIG_PAX_KERNEXEC
26357 + .pax_open_kernel = native_pax_open_kernel,
26358 + .pax_close_kernel = native_pax_close_kernel,
26359 +#endif
26360 +
26361 };
26362
26363 EXPORT_SYMBOL_GPL(pv_time_ops);
26364 diff --git a/arch/x86/kernel/paravirt_patch_64.c b/arch/x86/kernel/paravirt_patch_64.c
26365 index a1da673..2c72d5b 100644
26366 --- a/arch/x86/kernel/paravirt_patch_64.c
26367 +++ b/arch/x86/kernel/paravirt_patch_64.c
26368 @@ -9,7 +9,9 @@ DEF_NATIVE(pv_irq_ops, save_fl, "pushfq; popq %rax");
26369 DEF_NATIVE(pv_mmu_ops, read_cr2, "movq %cr2, %rax");
26370 DEF_NATIVE(pv_mmu_ops, read_cr3, "movq %cr3, %rax");
26371 DEF_NATIVE(pv_mmu_ops, write_cr3, "movq %rdi, %cr3");
26372 +#ifndef CONFIG_PAX_MEMORY_UDEREF
26373 DEF_NATIVE(pv_mmu_ops, flush_tlb_single, "invlpg (%rdi)");
26374 +#endif
26375 DEF_NATIVE(pv_cpu_ops, clts, "clts");
26376 DEF_NATIVE(pv_cpu_ops, wbinvd, "wbinvd");
26377
26378 @@ -57,7 +59,9 @@ unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
26379 PATCH_SITE(pv_mmu_ops, read_cr3);
26380 PATCH_SITE(pv_mmu_ops, write_cr3);
26381 PATCH_SITE(pv_cpu_ops, clts);
26382 +#ifndef CONFIG_PAX_MEMORY_UDEREF
26383 PATCH_SITE(pv_mmu_ops, flush_tlb_single);
26384 +#endif
26385 PATCH_SITE(pv_cpu_ops, wbinvd);
26386
26387 patch_site:
26388 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
26389 index 0497f71..7186c0d 100644
26390 --- a/arch/x86/kernel/pci-calgary_64.c
26391 +++ b/arch/x86/kernel/pci-calgary_64.c
26392 @@ -1347,7 +1347,7 @@ static void __init get_tce_space_from_tar(void)
26393 tce_space = be64_to_cpu(readq(target));
26394 tce_space = tce_space & TAR_SW_BITS;
26395
26396 - tce_space = tce_space & (~specified_table_size);
26397 + tce_space = tce_space & (~(unsigned long)specified_table_size);
26398 info->tce_space = (u64 *)__va(tce_space);
26399 }
26400 }
26401 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
26402 index 35ccf75..7a15747 100644
26403 --- a/arch/x86/kernel/pci-iommu_table.c
26404 +++ b/arch/x86/kernel/pci-iommu_table.c
26405 @@ -2,7 +2,7 @@
26406 #include <asm/iommu_table.h>
26407 #include <linux/string.h>
26408 #include <linux/kallsyms.h>
26409 -
26410 +#include <linux/sched.h>
26411
26412 #define DEBUG 1
26413
26414 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
26415 index 77dd0ad..9ec4723 100644
26416 --- a/arch/x86/kernel/pci-swiotlb.c
26417 +++ b/arch/x86/kernel/pci-swiotlb.c
26418 @@ -33,7 +33,7 @@ void x86_swiotlb_free_coherent(struct device *dev, size_t size,
26419 struct dma_attrs *attrs)
26420 {
26421 if (is_swiotlb_buffer(dma_to_phys(dev, dma_addr)))
26422 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
26423 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
26424 else
26425 dma_generic_free_coherent(dev, size, vaddr, dma_addr, attrs);
26426 }
26427 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
26428 index e127dda..94e384d 100644
26429 --- a/arch/x86/kernel/process.c
26430 +++ b/arch/x86/kernel/process.c
26431 @@ -36,7 +36,8 @@
26432 * section. Since TSS's are completely CPU-local, we want them
26433 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
26434 */
26435 -__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
26436 +struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
26437 +EXPORT_SYMBOL(init_tss);
26438
26439 #ifdef CONFIG_X86_64
26440 static DEFINE_PER_CPU(unsigned char, is_idle);
26441 @@ -94,7 +95,7 @@ void arch_task_cache_init(void)
26442 task_xstate_cachep =
26443 kmem_cache_create("task_xstate", xstate_size,
26444 __alignof__(union thread_xstate),
26445 - SLAB_PANIC | SLAB_NOTRACK, NULL);
26446 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26447 setup_xstate_comp();
26448 }
26449
26450 @@ -108,7 +109,7 @@ void exit_thread(void)
26451 unsigned long *bp = t->io_bitmap_ptr;
26452
26453 if (bp) {
26454 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26455 + struct tss_struct *tss = init_tss + get_cpu();
26456
26457 t->io_bitmap_ptr = NULL;
26458 clear_thread_flag(TIF_IO_BITMAP);
26459 @@ -128,6 +129,9 @@ void flush_thread(void)
26460 {
26461 struct task_struct *tsk = current;
26462
26463 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26464 + loadsegment(gs, 0);
26465 +#endif
26466 flush_ptrace_hw_breakpoint(tsk);
26467 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26468 drop_init_fpu(tsk);
26469 @@ -274,7 +278,7 @@ static void __exit_idle(void)
26470 void exit_idle(void)
26471 {
26472 /* idle loop has pid 0 */
26473 - if (current->pid)
26474 + if (task_pid_nr(current))
26475 return;
26476 __exit_idle();
26477 }
26478 @@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
26479 return ret;
26480 }
26481 #endif
26482 -void stop_this_cpu(void *dummy)
26483 +__noreturn void stop_this_cpu(void *dummy)
26484 {
26485 local_irq_disable();
26486 /*
26487 @@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
26488 }
26489 early_param("idle", idle_setup);
26490
26491 -unsigned long arch_align_stack(unsigned long sp)
26492 +#ifdef CONFIG_PAX_RANDKSTACK
26493 +void pax_randomize_kstack(struct pt_regs *regs)
26494 {
26495 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26496 - sp -= get_random_int() % 8192;
26497 - return sp & ~0xf;
26498 -}
26499 + struct thread_struct *thread = &current->thread;
26500 + unsigned long time;
26501
26502 -unsigned long arch_randomize_brk(struct mm_struct *mm)
26503 -{
26504 - unsigned long range_end = mm->brk + 0x02000000;
26505 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26506 -}
26507 + if (!randomize_va_space)
26508 + return;
26509 +
26510 + if (v8086_mode(regs))
26511 + return;
26512
26513 + rdtscl(time);
26514 +
26515 + /* P4 seems to return a 0 LSB, ignore it */
26516 +#ifdef CONFIG_MPENTIUM4
26517 + time &= 0x3EUL;
26518 + time <<= 2;
26519 +#elif defined(CONFIG_X86_64)
26520 + time &= 0xFUL;
26521 + time <<= 4;
26522 +#else
26523 + time &= 0x1FUL;
26524 + time <<= 3;
26525 +#endif
26526 +
26527 + thread->sp0 ^= time;
26528 + load_sp0(init_tss + smp_processor_id(), thread);
26529 +
26530 +#ifdef CONFIG_X86_64
26531 + this_cpu_write(kernel_stack, thread->sp0);
26532 +#endif
26533 +}
26534 +#endif
26535 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26536 index 8f3ebfe..e6ced5a 100644
26537 --- a/arch/x86/kernel/process_32.c
26538 +++ b/arch/x86/kernel/process_32.c
26539 @@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26540 unsigned long thread_saved_pc(struct task_struct *tsk)
26541 {
26542 return ((unsigned long *)tsk->thread.sp)[3];
26543 +//XXX return tsk->thread.eip;
26544 }
26545
26546 void __show_regs(struct pt_regs *regs, int all)
26547 @@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26548 unsigned long sp;
26549 unsigned short ss, gs;
26550
26551 - if (user_mode_vm(regs)) {
26552 + if (user_mode(regs)) {
26553 sp = regs->sp;
26554 ss = regs->ss & 0xffff;
26555 - gs = get_user_gs(regs);
26556 } else {
26557 sp = kernel_stack_pointer(regs);
26558 savesegment(ss, ss);
26559 - savesegment(gs, gs);
26560 }
26561 + gs = get_user_gs(regs);
26562
26563 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26564 (u16)regs->cs, regs->ip, regs->flags,
26565 - smp_processor_id());
26566 + raw_smp_processor_id());
26567 print_symbol("EIP is at %s\n", regs->ip);
26568
26569 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26570 @@ -132,21 +132,22 @@ void release_thread(struct task_struct *dead_task)
26571 int copy_thread(unsigned long clone_flags, unsigned long sp,
26572 unsigned long arg, struct task_struct *p)
26573 {
26574 - struct pt_regs *childregs = task_pt_regs(p);
26575 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26576 struct task_struct *tsk;
26577 int err;
26578
26579 p->thread.sp = (unsigned long) childregs;
26580 p->thread.sp0 = (unsigned long) (childregs+1);
26581 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26582 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26583
26584 if (unlikely(p->flags & PF_KTHREAD)) {
26585 /* kernel thread */
26586 memset(childregs, 0, sizeof(struct pt_regs));
26587 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26588 - task_user_gs(p) = __KERNEL_STACK_CANARY;
26589 - childregs->ds = __USER_DS;
26590 - childregs->es = __USER_DS;
26591 + savesegment(gs, childregs->gs);
26592 + childregs->ds = __KERNEL_DS;
26593 + childregs->es = __KERNEL_DS;
26594 childregs->fs = __KERNEL_PERCPU;
26595 childregs->bx = sp; /* function */
26596 childregs->bp = arg;
26597 @@ -248,7 +249,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26598 struct thread_struct *prev = &prev_p->thread,
26599 *next = &next_p->thread;
26600 int cpu = smp_processor_id();
26601 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26602 + struct tss_struct *tss = init_tss + cpu;
26603 fpu_switch_t fpu;
26604
26605 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26606 @@ -272,6 +273,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26607 */
26608 lazy_save_gs(prev->gs);
26609
26610 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26611 + __set_fs(task_thread_info(next_p)->addr_limit);
26612 +#endif
26613 +
26614 /*
26615 * Load the per-thread Thread-Local Storage descriptor.
26616 */
26617 @@ -310,9 +315,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26618 */
26619 arch_end_context_switch(next_p);
26620
26621 - this_cpu_write(kernel_stack,
26622 - (unsigned long)task_stack_page(next_p) +
26623 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26624 + this_cpu_write(current_task, next_p);
26625 + this_cpu_write(current_tinfo, &next_p->tinfo);
26626 + this_cpu_write(kernel_stack, next->sp0);
26627
26628 /*
26629 * Restore %gs if needed (which is common)
26630 @@ -322,8 +327,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26631
26632 switch_fpu_finish(next_p, fpu);
26633
26634 - this_cpu_write(current_task, next_p);
26635 -
26636 return prev_p;
26637 }
26638
26639 @@ -353,4 +356,3 @@ unsigned long get_wchan(struct task_struct *p)
26640 } while (count++ < 16);
26641 return 0;
26642 }
26643 -
26644 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26645 index 3ed4a68..ee8f337 100644
26646 --- a/arch/x86/kernel/process_64.c
26647 +++ b/arch/x86/kernel/process_64.c
26648 @@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26649 struct pt_regs *childregs;
26650 struct task_struct *me = current;
26651
26652 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26653 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26654 childregs = task_pt_regs(p);
26655 p->thread.sp = (unsigned long) childregs;
26656 p->thread.usersp = me->thread.usersp;
26657 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26658 set_tsk_thread_flag(p, TIF_FORK);
26659 p->thread.io_bitmap_ptr = NULL;
26660
26661 @@ -171,6 +172,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26662 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26663 savesegment(es, p->thread.es);
26664 savesegment(ds, p->thread.ds);
26665 + savesegment(ss, p->thread.ss);
26666 + BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26667 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26668
26669 if (unlikely(p->flags & PF_KTHREAD)) {
26670 @@ -277,7 +280,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26671 struct thread_struct *prev = &prev_p->thread;
26672 struct thread_struct *next = &next_p->thread;
26673 int cpu = smp_processor_id();
26674 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26675 + struct tss_struct *tss = init_tss + cpu;
26676 unsigned fsindex, gsindex;
26677 fpu_switch_t fpu;
26678
26679 @@ -300,6 +303,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26680 if (unlikely(next->ds | prev->ds))
26681 loadsegment(ds, next->ds);
26682
26683 + savesegment(ss, prev->ss);
26684 + if (unlikely(next->ss != prev->ss))
26685 + loadsegment(ss, next->ss);
26686
26687 /* We must save %fs and %gs before load_TLS() because
26688 * %fs and %gs may be cleared by load_TLS().
26689 @@ -359,6 +365,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26690 prev->usersp = this_cpu_read(old_rsp);
26691 this_cpu_write(old_rsp, next->usersp);
26692 this_cpu_write(current_task, next_p);
26693 + this_cpu_write(current_tinfo, &next_p->tinfo);
26694
26695 /*
26696 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26697 @@ -368,9 +375,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26698 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26699 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26700
26701 - this_cpu_write(kernel_stack,
26702 - (unsigned long)task_stack_page(next_p) +
26703 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26704 + this_cpu_write(kernel_stack, next->sp0);
26705
26706 /*
26707 * Now maybe reload the debug registers and handle I/O bitmaps
26708 @@ -440,12 +445,11 @@ unsigned long get_wchan(struct task_struct *p)
26709 if (!p || p == current || p->state == TASK_RUNNING)
26710 return 0;
26711 stack = (unsigned long)task_stack_page(p);
26712 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26713 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26714 return 0;
26715 fp = *(u64 *)(p->thread.sp);
26716 do {
26717 - if (fp < (unsigned long)stack ||
26718 - fp >= (unsigned long)stack+THREAD_SIZE)
26719 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26720 return 0;
26721 ip = *(u64 *)(fp+8);
26722 if (!in_sched_functions(ip))
26723 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26724 index e510618..5165ac0 100644
26725 --- a/arch/x86/kernel/ptrace.c
26726 +++ b/arch/x86/kernel/ptrace.c
26727 @@ -186,10 +186,10 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26728 unsigned long sp = (unsigned long)&regs->sp;
26729 u32 *prev_esp;
26730
26731 - if (context == (sp & ~(THREAD_SIZE - 1)))
26732 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26733 return sp;
26734
26735 - prev_esp = (u32 *)(context);
26736 + prev_esp = *(u32 **)(context);
26737 if (prev_esp)
26738 return (unsigned long)prev_esp;
26739
26740 @@ -452,6 +452,20 @@ static int putreg(struct task_struct *child,
26741 if (child->thread.gs != value)
26742 return do_arch_prctl(child, ARCH_SET_GS, value);
26743 return 0;
26744 +
26745 + case offsetof(struct user_regs_struct,ip):
26746 + /*
26747 + * Protect against any attempt to set ip to an
26748 + * impossible address. There are dragons lurking if the
26749 + * address is noncanonical. (This explicitly allows
26750 + * setting ip to TASK_SIZE_MAX, because user code can do
26751 + * that all by itself by running off the end of its
26752 + * address space.
26753 + */
26754 + if (value > TASK_SIZE_MAX)
26755 + return -EIO;
26756 + break;
26757 +
26758 #endif
26759 }
26760
26761 @@ -588,7 +602,7 @@ static void ptrace_triggered(struct perf_event *bp,
26762 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26763 {
26764 int i;
26765 - int dr7 = 0;
26766 + unsigned long dr7 = 0;
26767 struct arch_hw_breakpoint *info;
26768
26769 for (i = 0; i < HBP_NUM; i++) {
26770 @@ -822,7 +836,7 @@ long arch_ptrace(struct task_struct *child, long request,
26771 unsigned long addr, unsigned long data)
26772 {
26773 int ret;
26774 - unsigned long __user *datap = (unsigned long __user *)data;
26775 + unsigned long __user *datap = (__force unsigned long __user *)data;
26776
26777 switch (request) {
26778 /* read the word at location addr in the USER area. */
26779 @@ -907,14 +921,14 @@ long arch_ptrace(struct task_struct *child, long request,
26780 if ((int) addr < 0)
26781 return -EIO;
26782 ret = do_get_thread_area(child, addr,
26783 - (struct user_desc __user *)data);
26784 + (__force struct user_desc __user *) data);
26785 break;
26786
26787 case PTRACE_SET_THREAD_AREA:
26788 if ((int) addr < 0)
26789 return -EIO;
26790 ret = do_set_thread_area(child, addr,
26791 - (struct user_desc __user *)data, 0);
26792 + (__force struct user_desc __user *) data, 0);
26793 break;
26794 #endif
26795
26796 @@ -1292,7 +1306,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26797
26798 #ifdef CONFIG_X86_64
26799
26800 -static struct user_regset x86_64_regsets[] __read_mostly = {
26801 +static user_regset_no_const x86_64_regsets[] __read_only = {
26802 [REGSET_GENERAL] = {
26803 .core_note_type = NT_PRSTATUS,
26804 .n = sizeof(struct user_regs_struct) / sizeof(long),
26805 @@ -1333,7 +1347,7 @@ static const struct user_regset_view user_x86_64_view = {
26806 #endif /* CONFIG_X86_64 */
26807
26808 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26809 -static struct user_regset x86_32_regsets[] __read_mostly = {
26810 +static user_regset_no_const x86_32_regsets[] __read_only = {
26811 [REGSET_GENERAL] = {
26812 .core_note_type = NT_PRSTATUS,
26813 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26814 @@ -1386,7 +1400,7 @@ static const struct user_regset_view user_x86_32_view = {
26815 */
26816 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26817
26818 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26819 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26820 {
26821 #ifdef CONFIG_X86_64
26822 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26823 @@ -1421,7 +1435,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26824 memset(info, 0, sizeof(*info));
26825 info->si_signo = SIGTRAP;
26826 info->si_code = si_code;
26827 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26828 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26829 }
26830
26831 void user_single_step_siginfo(struct task_struct *tsk,
26832 @@ -1455,6 +1469,10 @@ static void do_audit_syscall_entry(struct pt_regs *regs, u32 arch)
26833 }
26834 }
26835
26836 +#ifdef CONFIG_GRKERNSEC_SETXID
26837 +extern void gr_delayed_cred_worker(void);
26838 +#endif
26839 +
26840 /*
26841 * We can return 0 to resume the syscall or anything else to go to phase
26842 * 2. If we resume the syscall, we need to put something appropriate in
26843 @@ -1562,6 +1580,11 @@ long syscall_trace_enter_phase2(struct pt_regs *regs, u32 arch,
26844
26845 BUG_ON(regs != task_pt_regs(current));
26846
26847 +#ifdef CONFIG_GRKERNSEC_SETXID
26848 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26849 + gr_delayed_cred_worker();
26850 +#endif
26851 +
26852 /*
26853 * If we stepped into a sysenter/syscall insn, it trapped in
26854 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26855 @@ -1620,6 +1643,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26856 */
26857 user_exit();
26858
26859 +#ifdef CONFIG_GRKERNSEC_SETXID
26860 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26861 + gr_delayed_cred_worker();
26862 +#endif
26863 +
26864 audit_syscall_exit(regs);
26865
26866 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26867 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26868 index 2f355d2..e75ed0a 100644
26869 --- a/arch/x86/kernel/pvclock.c
26870 +++ b/arch/x86/kernel/pvclock.c
26871 @@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26872 reset_hung_task_detector();
26873 }
26874
26875 -static atomic64_t last_value = ATOMIC64_INIT(0);
26876 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26877
26878 void pvclock_resume(void)
26879 {
26880 - atomic64_set(&last_value, 0);
26881 + atomic64_set_unchecked(&last_value, 0);
26882 }
26883
26884 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26885 @@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26886 * updating at the same time, and one of them could be slightly behind,
26887 * making the assumption that last_value always go forward fail to hold.
26888 */
26889 - last = atomic64_read(&last_value);
26890 + last = atomic64_read_unchecked(&last_value);
26891 do {
26892 if (ret < last)
26893 return last;
26894 - last = atomic64_cmpxchg(&last_value, last, ret);
26895 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26896 } while (unlikely(last != ret));
26897
26898 return ret;
26899 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26900 index 17962e6..47f55db 100644
26901 --- a/arch/x86/kernel/reboot.c
26902 +++ b/arch/x86/kernel/reboot.c
26903 @@ -69,6 +69,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26904
26905 void __noreturn machine_real_restart(unsigned int type)
26906 {
26907 +
26908 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26909 + struct desc_struct *gdt;
26910 +#endif
26911 +
26912 local_irq_disable();
26913
26914 /*
26915 @@ -96,7 +101,29 @@ void __noreturn machine_real_restart(unsigned int type)
26916
26917 /* Jump to the identity-mapped low memory code */
26918 #ifdef CONFIG_X86_32
26919 - asm volatile("jmpl *%0" : :
26920 +
26921 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26922 + gdt = get_cpu_gdt_table(smp_processor_id());
26923 + pax_open_kernel();
26924 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26925 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26926 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26927 + loadsegment(ds, __KERNEL_DS);
26928 + loadsegment(es, __KERNEL_DS);
26929 + loadsegment(ss, __KERNEL_DS);
26930 +#endif
26931 +#ifdef CONFIG_PAX_KERNEXEC
26932 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26933 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26934 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26935 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26936 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26937 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26938 +#endif
26939 + pax_close_kernel();
26940 +#endif
26941 +
26942 + asm volatile("ljmpl *%0" : :
26943 "rm" (real_mode_header->machine_real_restart_asm),
26944 "a" (type));
26945 #else
26946 @@ -500,7 +527,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
26947 * This means that this function can never return, it can misbehave
26948 * by not rebooting properly and hanging.
26949 */
26950 -static void native_machine_emergency_restart(void)
26951 +static void __noreturn native_machine_emergency_restart(void)
26952 {
26953 int i;
26954 int attempt = 0;
26955 @@ -620,13 +647,13 @@ void native_machine_shutdown(void)
26956 #endif
26957 }
26958
26959 -static void __machine_emergency_restart(int emergency)
26960 +static void __noreturn __machine_emergency_restart(int emergency)
26961 {
26962 reboot_emergency = emergency;
26963 machine_ops.emergency_restart();
26964 }
26965
26966 -static void native_machine_restart(char *__unused)
26967 +static void __noreturn native_machine_restart(char *__unused)
26968 {
26969 pr_notice("machine restart\n");
26970
26971 @@ -635,7 +662,7 @@ static void native_machine_restart(char *__unused)
26972 __machine_emergency_restart(0);
26973 }
26974
26975 -static void native_machine_halt(void)
26976 +static void __noreturn native_machine_halt(void)
26977 {
26978 /* Stop other cpus and apics */
26979 machine_shutdown();
26980 @@ -645,7 +672,7 @@ static void native_machine_halt(void)
26981 stop_this_cpu(NULL);
26982 }
26983
26984 -static void native_machine_power_off(void)
26985 +static void __noreturn native_machine_power_off(void)
26986 {
26987 if (pm_power_off) {
26988 if (!reboot_force)
26989 @@ -654,9 +681,10 @@ static void native_machine_power_off(void)
26990 }
26991 /* A fallback in case there is no PM info available */
26992 tboot_shutdown(TB_SHUTDOWN_HALT);
26993 + unreachable();
26994 }
26995
26996 -struct machine_ops machine_ops = {
26997 +struct machine_ops machine_ops __read_only = {
26998 .power_off = native_machine_power_off,
26999 .shutdown = native_machine_shutdown,
27000 .emergency_restart = native_machine_emergency_restart,
27001 diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
27002 index c8e41e9..64049ef 100644
27003 --- a/arch/x86/kernel/reboot_fixups_32.c
27004 +++ b/arch/x86/kernel/reboot_fixups_32.c
27005 @@ -57,7 +57,7 @@ struct device_fixup {
27006 unsigned int vendor;
27007 unsigned int device;
27008 void (*reboot_fixup)(struct pci_dev *);
27009 -};
27010 +} __do_const;
27011
27012 /*
27013 * PCI ids solely used for fixups_table go here
27014 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
27015 index 3fd2c69..a444264 100644
27016 --- a/arch/x86/kernel/relocate_kernel_64.S
27017 +++ b/arch/x86/kernel/relocate_kernel_64.S
27018 @@ -96,8 +96,7 @@ relocate_kernel:
27019
27020 /* jump to identity mapped page */
27021 addq $(identity_mapped - relocate_kernel), %r8
27022 - pushq %r8
27023 - ret
27024 + jmp *%r8
27025
27026 identity_mapped:
27027 /* set return address to 0 if not preserving context */
27028 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
27029 index ab08aa2..6d74a3a 100644
27030 --- a/arch/x86/kernel/setup.c
27031 +++ b/arch/x86/kernel/setup.c
27032 @@ -110,6 +110,7 @@
27033 #include <asm/mce.h>
27034 #include <asm/alternative.h>
27035 #include <asm/prom.h>
27036 +#include <asm/boot.h>
27037
27038 /*
27039 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
27040 @@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
27041 #endif
27042
27043
27044 -#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
27045 -__visible unsigned long mmu_cr4_features;
27046 +#ifdef CONFIG_X86_64
27047 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
27048 +#elif defined(CONFIG_X86_PAE)
27049 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
27050 #else
27051 -__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
27052 +__visible unsigned long mmu_cr4_features __read_only;
27053 #endif
27054
27055 +void set_in_cr4(unsigned long mask)
27056 +{
27057 + unsigned long cr4 = read_cr4();
27058 +
27059 + if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
27060 + return;
27061 +
27062 + pax_open_kernel();
27063 + mmu_cr4_features |= mask;
27064 + pax_close_kernel();
27065 +
27066 + if (trampoline_cr4_features)
27067 + *trampoline_cr4_features = mmu_cr4_features;
27068 + cr4 |= mask;
27069 + write_cr4(cr4);
27070 +}
27071 +EXPORT_SYMBOL(set_in_cr4);
27072 +
27073 +void clear_in_cr4(unsigned long mask)
27074 +{
27075 + unsigned long cr4 = read_cr4();
27076 +
27077 + if (!(cr4 & mask) && cr4 == mmu_cr4_features)
27078 + return;
27079 +
27080 + pax_open_kernel();
27081 + mmu_cr4_features &= ~mask;
27082 + pax_close_kernel();
27083 +
27084 + if (trampoline_cr4_features)
27085 + *trampoline_cr4_features = mmu_cr4_features;
27086 + cr4 &= ~mask;
27087 + write_cr4(cr4);
27088 +}
27089 +EXPORT_SYMBOL(clear_in_cr4);
27090 +
27091 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
27092 int bootloader_type, bootloader_version;
27093
27094 @@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
27095 * area (640->1Mb) as ram even though it is not.
27096 * take them out.
27097 */
27098 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
27099 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
27100
27101 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
27102 }
27103 @@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
27104 /* called before trim_bios_range() to spare extra sanitize */
27105 static void __init e820_add_kernel_range(void)
27106 {
27107 - u64 start = __pa_symbol(_text);
27108 + u64 start = __pa_symbol(ktla_ktva(_text));
27109 u64 size = __pa_symbol(_end) - start;
27110
27111 /*
27112 @@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
27113
27114 void __init setup_arch(char **cmdline_p)
27115 {
27116 +#ifdef CONFIG_X86_32
27117 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
27118 +#else
27119 memblock_reserve(__pa_symbol(_text),
27120 (unsigned long)__bss_stop - (unsigned long)_text);
27121 +#endif
27122
27123 early_reserve_initrd();
27124
27125 @@ -955,14 +998,14 @@ void __init setup_arch(char **cmdline_p)
27126
27127 if (!boot_params.hdr.root_flags)
27128 root_mountflags &= ~MS_RDONLY;
27129 - init_mm.start_code = (unsigned long) _text;
27130 - init_mm.end_code = (unsigned long) _etext;
27131 + init_mm.start_code = ktla_ktva((unsigned long) _text);
27132 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
27133 init_mm.end_data = (unsigned long) _edata;
27134 init_mm.brk = _brk_end;
27135
27136 - code_resource.start = __pa_symbol(_text);
27137 - code_resource.end = __pa_symbol(_etext)-1;
27138 - data_resource.start = __pa_symbol(_etext);
27139 + code_resource.start = __pa_symbol(ktla_ktva(_text));
27140 + code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
27141 + data_resource.start = __pa_symbol(_sdata);
27142 data_resource.end = __pa_symbol(_edata)-1;
27143 bss_resource.start = __pa_symbol(__bss_start);
27144 bss_resource.end = __pa_symbol(__bss_stop)-1;
27145 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
27146 index 5cdff03..80fa283 100644
27147 --- a/arch/x86/kernel/setup_percpu.c
27148 +++ b/arch/x86/kernel/setup_percpu.c
27149 @@ -21,19 +21,17 @@
27150 #include <asm/cpu.h>
27151 #include <asm/stackprotector.h>
27152
27153 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
27154 +#ifdef CONFIG_SMP
27155 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
27156 EXPORT_PER_CPU_SYMBOL(cpu_number);
27157 +#endif
27158
27159 -#ifdef CONFIG_X86_64
27160 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
27161 -#else
27162 -#define BOOT_PERCPU_OFFSET 0
27163 -#endif
27164
27165 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
27166 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
27167
27168 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
27169 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
27170 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
27171 };
27172 EXPORT_SYMBOL(__per_cpu_offset);
27173 @@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
27174 {
27175 #ifdef CONFIG_NEED_MULTIPLE_NODES
27176 pg_data_t *last = NULL;
27177 - unsigned int cpu;
27178 + int cpu;
27179
27180 for_each_possible_cpu(cpu) {
27181 int node = early_cpu_to_node(cpu);
27182 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
27183 {
27184 #ifdef CONFIG_X86_32
27185 struct desc_struct gdt;
27186 + unsigned long base = per_cpu_offset(cpu);
27187
27188 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
27189 - 0x2 | DESCTYPE_S, 0x8);
27190 - gdt.s = 1;
27191 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
27192 + 0x83 | DESCTYPE_S, 0xC);
27193 write_gdt_entry(get_cpu_gdt_table(cpu),
27194 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
27195 #endif
27196 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
27197 /* alrighty, percpu areas up and running */
27198 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
27199 for_each_possible_cpu(cpu) {
27200 +#ifdef CONFIG_CC_STACKPROTECTOR
27201 +#ifdef CONFIG_X86_32
27202 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
27203 +#endif
27204 +#endif
27205 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
27206 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
27207 per_cpu(cpu_number, cpu) = cpu;
27208 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
27209 */
27210 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
27211 #endif
27212 +#ifdef CONFIG_CC_STACKPROTECTOR
27213 +#ifdef CONFIG_X86_32
27214 + if (!cpu)
27215 + per_cpu(stack_canary.canary, cpu) = canary;
27216 +#endif
27217 +#endif
27218 /*
27219 * Up to this point, the boot CPU has been using .init.data
27220 * area. Reload any changed state for the boot CPU.
27221 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
27222 index ed37a76..39f936e 100644
27223 --- a/arch/x86/kernel/signal.c
27224 +++ b/arch/x86/kernel/signal.c
27225 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
27226 * Align the stack pointer according to the i386 ABI,
27227 * i.e. so that on function entry ((sp + 4) & 15) == 0.
27228 */
27229 - sp = ((sp + 4) & -16ul) - 4;
27230 + sp = ((sp - 12) & -16ul) - 4;
27231 #else /* !CONFIG_X86_32 */
27232 sp = round_down(sp, 16) - 8;
27233 #endif
27234 @@ -298,10 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27235 }
27236
27237 if (current->mm->context.vdso)
27238 - restorer = current->mm->context.vdso +
27239 - selected_vdso32->sym___kernel_sigreturn;
27240 + restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_sigreturn);
27241 else
27242 - restorer = &frame->retcode;
27243 + restorer = (void __user *)&frame->retcode;
27244 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27245 restorer = ksig->ka.sa.sa_restorer;
27246
27247 @@ -315,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27248 * reasons and because gdb uses it as a signature to notice
27249 * signal handler stack frames.
27250 */
27251 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
27252 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
27253
27254 if (err)
27255 return -EFAULT;
27256 @@ -362,8 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27257 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
27258
27259 /* Set up to return from userspace. */
27260 - restorer = current->mm->context.vdso +
27261 - selected_vdso32->sym___kernel_rt_sigreturn;
27262 + if (current->mm->context.vdso)
27263 + restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_rt_sigreturn);
27264 + else
27265 + restorer = (void __user *)&frame->retcode;
27266 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27267 restorer = ksig->ka.sa.sa_restorer;
27268 put_user_ex(restorer, &frame->pretcode);
27269 @@ -375,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27270 * reasons and because gdb uses it as a signature to notice
27271 * signal handler stack frames.
27272 */
27273 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
27274 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
27275 } put_user_catch(err);
27276
27277 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
27278 @@ -611,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27279 {
27280 int usig = signr_convert(ksig->sig);
27281 sigset_t *set = sigmask_to_save();
27282 - compat_sigset_t *cset = (compat_sigset_t *) set;
27283 + sigset_t sigcopy;
27284 + compat_sigset_t *cset;
27285 +
27286 + sigcopy = *set;
27287 +
27288 + cset = (compat_sigset_t *) &sigcopy;
27289
27290 /* Set up the stack frame */
27291 if (is_ia32_frame()) {
27292 @@ -622,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27293 } else if (is_x32_frame()) {
27294 return x32_setup_rt_frame(ksig, cset, regs);
27295 } else {
27296 - return __setup_rt_frame(ksig->sig, ksig, set, regs);
27297 + return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
27298 }
27299 }
27300
27301 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
27302 index be8e1bd..a3d93fa 100644
27303 --- a/arch/x86/kernel/smp.c
27304 +++ b/arch/x86/kernel/smp.c
27305 @@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
27306
27307 __setup("nonmi_ipi", nonmi_ipi_setup);
27308
27309 -struct smp_ops smp_ops = {
27310 +struct smp_ops smp_ops __read_only = {
27311 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
27312 .smp_prepare_cpus = native_smp_prepare_cpus,
27313 .smp_cpus_done = native_smp_cpus_done,
27314 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
27315 index 668d8f2..84a9d54 100644
27316 --- a/arch/x86/kernel/smpboot.c
27317 +++ b/arch/x86/kernel/smpboot.c
27318 @@ -194,14 +194,17 @@ static void notrace start_secondary(void *unused)
27319
27320 enable_start_cpu0 = 0;
27321
27322 -#ifdef CONFIG_X86_32
27323 + /* otherwise gcc will move up smp_processor_id before the cpu_init */
27324 + barrier();
27325 +
27326 /* switch away from the initial page table */
27327 +#ifdef CONFIG_PAX_PER_CPU_PGD
27328 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
27329 +#else
27330 load_cr3(swapper_pg_dir);
27331 +#endif
27332 __flush_tlb_all();
27333 -#endif
27334
27335 - /* otherwise gcc will move up smp_processor_id before the cpu_init */
27336 - barrier();
27337 /*
27338 * Check TSC synchronization with the BP:
27339 */
27340 @@ -765,8 +768,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27341 alternatives_enable_smp();
27342
27343 idle->thread.sp = (unsigned long) (((struct pt_regs *)
27344 - (THREAD_SIZE + task_stack_page(idle))) - 1);
27345 + (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
27346 per_cpu(current_task, cpu) = idle;
27347 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27348
27349 #ifdef CONFIG_X86_32
27350 /* Stack for startup_32 can be just as for start_secondary onwards */
27351 @@ -775,10 +779,10 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27352 clear_tsk_thread_flag(idle, TIF_FORK);
27353 initial_gs = per_cpu_offset(cpu);
27354 #endif
27355 - per_cpu(kernel_stack, cpu) =
27356 - (unsigned long)task_stack_page(idle) -
27357 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27358 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27359 + pax_open_kernel();
27360 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
27361 + pax_close_kernel();
27362 initial_code = (unsigned long)start_secondary;
27363 stack_start = idle->thread.sp;
27364
27365 @@ -918,6 +922,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
27366 /* the FPU context is blank, nobody can own it */
27367 __cpu_disable_lazy_restore(cpu);
27368
27369 +#ifdef CONFIG_PAX_PER_CPU_PGD
27370 + clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
27371 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27372 + KERNEL_PGD_PTRS);
27373 + clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
27374 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27375 + KERNEL_PGD_PTRS);
27376 +#endif
27377 +
27378 err = do_boot_cpu(apicid, cpu, tidle);
27379 if (err) {
27380 pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu);
27381 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
27382 index 9b4d51d..5d28b58 100644
27383 --- a/arch/x86/kernel/step.c
27384 +++ b/arch/x86/kernel/step.c
27385 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27386 struct desc_struct *desc;
27387 unsigned long base;
27388
27389 - seg &= ~7UL;
27390 + seg >>= 3;
27391
27392 mutex_lock(&child->mm->context.lock);
27393 - if (unlikely((seg >> 3) >= child->mm->context.size))
27394 + if (unlikely(seg >= child->mm->context.size))
27395 addr = -1L; /* bogus selector, access would fault */
27396 else {
27397 desc = child->mm->context.ldt + seg;
27398 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27399 addr += base;
27400 }
27401 mutex_unlock(&child->mm->context.lock);
27402 - }
27403 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
27404 + addr = ktla_ktva(addr);
27405
27406 return addr;
27407 }
27408 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
27409 unsigned char opcode[15];
27410 unsigned long addr = convert_ip_to_linear(child, regs);
27411
27412 + if (addr == -EINVAL)
27413 + return 0;
27414 +
27415 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
27416 for (i = 0; i < copied; i++) {
27417 switch (opcode[i]) {
27418 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
27419 new file mode 100644
27420 index 0000000..5877189
27421 --- /dev/null
27422 +++ b/arch/x86/kernel/sys_i386_32.c
27423 @@ -0,0 +1,189 @@
27424 +/*
27425 + * This file contains various random system calls that
27426 + * have a non-standard calling sequence on the Linux/i386
27427 + * platform.
27428 + */
27429 +
27430 +#include <linux/errno.h>
27431 +#include <linux/sched.h>
27432 +#include <linux/mm.h>
27433 +#include <linux/fs.h>
27434 +#include <linux/smp.h>
27435 +#include <linux/sem.h>
27436 +#include <linux/msg.h>
27437 +#include <linux/shm.h>
27438 +#include <linux/stat.h>
27439 +#include <linux/syscalls.h>
27440 +#include <linux/mman.h>
27441 +#include <linux/file.h>
27442 +#include <linux/utsname.h>
27443 +#include <linux/ipc.h>
27444 +#include <linux/elf.h>
27445 +
27446 +#include <linux/uaccess.h>
27447 +#include <linux/unistd.h>
27448 +
27449 +#include <asm/syscalls.h>
27450 +
27451 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
27452 +{
27453 + unsigned long pax_task_size = TASK_SIZE;
27454 +
27455 +#ifdef CONFIG_PAX_SEGMEXEC
27456 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
27457 + pax_task_size = SEGMEXEC_TASK_SIZE;
27458 +#endif
27459 +
27460 + if (flags & MAP_FIXED)
27461 + if (len > pax_task_size || addr > pax_task_size - len)
27462 + return -EINVAL;
27463 +
27464 + return 0;
27465 +}
27466 +
27467 +/*
27468 + * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27469 + */
27470 +static unsigned long get_align_mask(void)
27471 +{
27472 + if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27473 + return 0;
27474 +
27475 + if (!(current->flags & PF_RANDOMIZE))
27476 + return 0;
27477 +
27478 + return va_align.mask;
27479 +}
27480 +
27481 +unsigned long
27482 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
27483 + unsigned long len, unsigned long pgoff, unsigned long flags)
27484 +{
27485 + struct mm_struct *mm = current->mm;
27486 + struct vm_area_struct *vma;
27487 + unsigned long pax_task_size = TASK_SIZE;
27488 + struct vm_unmapped_area_info info;
27489 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27490 +
27491 +#ifdef CONFIG_PAX_SEGMEXEC
27492 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27493 + pax_task_size = SEGMEXEC_TASK_SIZE;
27494 +#endif
27495 +
27496 + pax_task_size -= PAGE_SIZE;
27497 +
27498 + if (len > pax_task_size)
27499 + return -ENOMEM;
27500 +
27501 + if (flags & MAP_FIXED)
27502 + return addr;
27503 +
27504 +#ifdef CONFIG_PAX_RANDMMAP
27505 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27506 +#endif
27507 +
27508 + if (addr) {
27509 + addr = PAGE_ALIGN(addr);
27510 + if (pax_task_size - len >= addr) {
27511 + vma = find_vma(mm, addr);
27512 + if (check_heap_stack_gap(vma, addr, len, offset))
27513 + return addr;
27514 + }
27515 + }
27516 +
27517 + info.flags = 0;
27518 + info.length = len;
27519 + info.align_mask = filp ? get_align_mask() : 0;
27520 + info.align_offset = pgoff << PAGE_SHIFT;
27521 + info.threadstack_offset = offset;
27522 +
27523 +#ifdef CONFIG_PAX_PAGEEXEC
27524 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27525 + info.low_limit = 0x00110000UL;
27526 + info.high_limit = mm->start_code;
27527 +
27528 +#ifdef CONFIG_PAX_RANDMMAP
27529 + if (mm->pax_flags & MF_PAX_RANDMMAP)
27530 + info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27531 +#endif
27532 +
27533 + if (info.low_limit < info.high_limit) {
27534 + addr = vm_unmapped_area(&info);
27535 + if (!IS_ERR_VALUE(addr))
27536 + return addr;
27537 + }
27538 + } else
27539 +#endif
27540 +
27541 + info.low_limit = mm->mmap_base;
27542 + info.high_limit = pax_task_size;
27543 +
27544 + return vm_unmapped_area(&info);
27545 +}
27546 +
27547 +unsigned long
27548 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27549 + const unsigned long len, const unsigned long pgoff,
27550 + const unsigned long flags)
27551 +{
27552 + struct vm_area_struct *vma;
27553 + struct mm_struct *mm = current->mm;
27554 + unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27555 + struct vm_unmapped_area_info info;
27556 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27557 +
27558 +#ifdef CONFIG_PAX_SEGMEXEC
27559 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27560 + pax_task_size = SEGMEXEC_TASK_SIZE;
27561 +#endif
27562 +
27563 + pax_task_size -= PAGE_SIZE;
27564 +
27565 + /* requested length too big for entire address space */
27566 + if (len > pax_task_size)
27567 + return -ENOMEM;
27568 +
27569 + if (flags & MAP_FIXED)
27570 + return addr;
27571 +
27572 +#ifdef CONFIG_PAX_PAGEEXEC
27573 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27574 + goto bottomup;
27575 +#endif
27576 +
27577 +#ifdef CONFIG_PAX_RANDMMAP
27578 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27579 +#endif
27580 +
27581 + /* requesting a specific address */
27582 + if (addr) {
27583 + addr = PAGE_ALIGN(addr);
27584 + if (pax_task_size - len >= addr) {
27585 + vma = find_vma(mm, addr);
27586 + if (check_heap_stack_gap(vma, addr, len, offset))
27587 + return addr;
27588 + }
27589 + }
27590 +
27591 + info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27592 + info.length = len;
27593 + info.low_limit = PAGE_SIZE;
27594 + info.high_limit = mm->mmap_base;
27595 + info.align_mask = filp ? get_align_mask() : 0;
27596 + info.align_offset = pgoff << PAGE_SHIFT;
27597 + info.threadstack_offset = offset;
27598 +
27599 + addr = vm_unmapped_area(&info);
27600 + if (!(addr & ~PAGE_MASK))
27601 + return addr;
27602 + VM_BUG_ON(addr != -ENOMEM);
27603 +
27604 +bottomup:
27605 + /*
27606 + * A failed mmap() very likely causes application failure,
27607 + * so fall back to the bottom-up function here. This scenario
27608 + * can happen with large stack limits and large mmap()
27609 + * allocations.
27610 + */
27611 + return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27612 +}
27613 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27614 index 30277e2..5664a29 100644
27615 --- a/arch/x86/kernel/sys_x86_64.c
27616 +++ b/arch/x86/kernel/sys_x86_64.c
27617 @@ -81,8 +81,8 @@ out:
27618 return error;
27619 }
27620
27621 -static void find_start_end(unsigned long flags, unsigned long *begin,
27622 - unsigned long *end)
27623 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
27624 + unsigned long *begin, unsigned long *end)
27625 {
27626 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27627 unsigned long new_begin;
27628 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27629 *begin = new_begin;
27630 }
27631 } else {
27632 - *begin = current->mm->mmap_legacy_base;
27633 + *begin = mm->mmap_legacy_base;
27634 *end = TASK_SIZE;
27635 }
27636 }
27637 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27638 struct vm_area_struct *vma;
27639 struct vm_unmapped_area_info info;
27640 unsigned long begin, end;
27641 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27642
27643 if (flags & MAP_FIXED)
27644 return addr;
27645
27646 - find_start_end(flags, &begin, &end);
27647 + find_start_end(mm, flags, &begin, &end);
27648
27649 if (len > end)
27650 return -ENOMEM;
27651
27652 +#ifdef CONFIG_PAX_RANDMMAP
27653 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27654 +#endif
27655 +
27656 if (addr) {
27657 addr = PAGE_ALIGN(addr);
27658 vma = find_vma(mm, addr);
27659 - if (end - len >= addr &&
27660 - (!vma || addr + len <= vma->vm_start))
27661 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27662 return addr;
27663 }
27664
27665 @@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27666 info.high_limit = end;
27667 info.align_mask = filp ? get_align_mask() : 0;
27668 info.align_offset = pgoff << PAGE_SHIFT;
27669 + info.threadstack_offset = offset;
27670 return vm_unmapped_area(&info);
27671 }
27672
27673 @@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27674 struct mm_struct *mm = current->mm;
27675 unsigned long addr = addr0;
27676 struct vm_unmapped_area_info info;
27677 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27678
27679 /* requested length too big for entire address space */
27680 if (len > TASK_SIZE)
27681 @@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27682 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27683 goto bottomup;
27684
27685 +#ifdef CONFIG_PAX_RANDMMAP
27686 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27687 +#endif
27688 +
27689 /* requesting a specific address */
27690 if (addr) {
27691 addr = PAGE_ALIGN(addr);
27692 vma = find_vma(mm, addr);
27693 - if (TASK_SIZE - len >= addr &&
27694 - (!vma || addr + len <= vma->vm_start))
27695 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27696 return addr;
27697 }
27698
27699 @@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27700 info.high_limit = mm->mmap_base;
27701 info.align_mask = filp ? get_align_mask() : 0;
27702 info.align_offset = pgoff << PAGE_SHIFT;
27703 + info.threadstack_offset = offset;
27704 addr = vm_unmapped_area(&info);
27705 if (!(addr & ~PAGE_MASK))
27706 return addr;
27707 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27708 index 91a4496..bb87552 100644
27709 --- a/arch/x86/kernel/tboot.c
27710 +++ b/arch/x86/kernel/tboot.c
27711 @@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27712
27713 void tboot_shutdown(u32 shutdown_type)
27714 {
27715 - void (*shutdown)(void);
27716 + void (* __noreturn shutdown)(void);
27717
27718 if (!tboot_enabled())
27719 return;
27720 @@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27721
27722 switch_to_tboot_pt();
27723
27724 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27725 + shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27726 shutdown();
27727
27728 /* should not reach here */
27729 @@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27730 return -ENODEV;
27731 }
27732
27733 -static atomic_t ap_wfs_count;
27734 +static atomic_unchecked_t ap_wfs_count;
27735
27736 static int tboot_wait_for_aps(int num_aps)
27737 {
27738 @@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27739 {
27740 switch (action) {
27741 case CPU_DYING:
27742 - atomic_inc(&ap_wfs_count);
27743 + atomic_inc_unchecked(&ap_wfs_count);
27744 if (num_online_cpus() == 1)
27745 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27746 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27747 return NOTIFY_BAD;
27748 break;
27749 }
27750 @@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27751
27752 tboot_create_trampoline();
27753
27754 - atomic_set(&ap_wfs_count, 0);
27755 + atomic_set_unchecked(&ap_wfs_count, 0);
27756 register_hotcpu_notifier(&tboot_cpu_notifier);
27757
27758 #ifdef CONFIG_DEBUG_FS
27759 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27760 index 0fa2960..91eabbe 100644
27761 --- a/arch/x86/kernel/time.c
27762 +++ b/arch/x86/kernel/time.c
27763 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27764 {
27765 unsigned long pc = instruction_pointer(regs);
27766
27767 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27768 + if (!user_mode(regs) && in_lock_functions(pc)) {
27769 #ifdef CONFIG_FRAME_POINTER
27770 - return *(unsigned long *)(regs->bp + sizeof(long));
27771 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27772 #else
27773 unsigned long *sp =
27774 (unsigned long *)kernel_stack_pointer(regs);
27775 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27776 * or above a saved flags. Eflags has bits 22-31 zero,
27777 * kernel addresses don't.
27778 */
27779 +
27780 +#ifdef CONFIG_PAX_KERNEXEC
27781 + return ktla_ktva(sp[0]);
27782 +#else
27783 if (sp[0] >> 22)
27784 return sp[0];
27785 if (sp[1] >> 22)
27786 return sp[1];
27787 #endif
27788 +
27789 +#endif
27790 }
27791 return pc;
27792 }
27793 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27794 index f7fec09..d0f623f 100644
27795 --- a/arch/x86/kernel/tls.c
27796 +++ b/arch/x86/kernel/tls.c
27797 @@ -27,6 +27,37 @@ static int get_free_idx(void)
27798 return -ESRCH;
27799 }
27800
27801 +static bool tls_desc_okay(const struct user_desc *info)
27802 +{
27803 + if (LDT_empty(info))
27804 + return true;
27805 +
27806 + /*
27807 + * espfix is required for 16-bit data segments, but espfix
27808 + * only works for LDT segments.
27809 + */
27810 + if (!info->seg_32bit)
27811 + return false;
27812 +
27813 + /* Only allow data segments in the TLS array. */
27814 + if (info->contents > 1)
27815 + return false;
27816 +
27817 + /*
27818 + * Non-present segments with DPL 3 present an interesting attack
27819 + * surface. The kernel should handle such segments correctly,
27820 + * but TLS is very difficult to protect in a sandbox, so prevent
27821 + * such segments from being created.
27822 + *
27823 + * If userspace needs to remove a TLS entry, it can still delete
27824 + * it outright.
27825 + */
27826 + if (info->seg_not_present)
27827 + return false;
27828 +
27829 + return true;
27830 +}
27831 +
27832 static void set_tls_desc(struct task_struct *p, int idx,
27833 const struct user_desc *info, int n)
27834 {
27835 @@ -66,6 +97,9 @@ int do_set_thread_area(struct task_struct *p, int idx,
27836 if (copy_from_user(&info, u_info, sizeof(info)))
27837 return -EFAULT;
27838
27839 + if (!tls_desc_okay(&info))
27840 + return -EINVAL;
27841 +
27842 if (idx == -1)
27843 idx = info.entry_number;
27844
27845 @@ -84,6 +118,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27846 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27847 return -EINVAL;
27848
27849 +#ifdef CONFIG_PAX_SEGMEXEC
27850 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27851 + return -EINVAL;
27852 +#endif
27853 +
27854 set_tls_desc(p, idx, &info, 1);
27855
27856 return 0;
27857 @@ -192,6 +231,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27858 {
27859 struct user_desc infobuf[GDT_ENTRY_TLS_ENTRIES];
27860 const struct user_desc *info;
27861 + int i;
27862
27863 if (pos >= GDT_ENTRY_TLS_ENTRIES * sizeof(struct user_desc) ||
27864 (pos % sizeof(struct user_desc)) != 0 ||
27865 @@ -200,11 +240,15 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27866
27867 if (kbuf)
27868 info = kbuf;
27869 - else if (__copy_from_user(infobuf, ubuf, count))
27870 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27871 return -EFAULT;
27872 else
27873 info = infobuf;
27874
27875 + for (i = 0; i < count / sizeof(struct user_desc); i++)
27876 + if (!tls_desc_okay(info + i))
27877 + return -EINVAL;
27878 +
27879 set_tls_desc(target,
27880 GDT_ENTRY_TLS_MIN + (pos / sizeof(struct user_desc)),
27881 info, count / sizeof(struct user_desc));
27882 diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27883 index 1c113db..287b42e 100644
27884 --- a/arch/x86/kernel/tracepoint.c
27885 +++ b/arch/x86/kernel/tracepoint.c
27886 @@ -9,11 +9,11 @@
27887 #include <linux/atomic.h>
27888
27889 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27890 -struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27891 +const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27892 (unsigned long) trace_idt_table };
27893
27894 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27895 -gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27896 +gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27897
27898 static int trace_irq_vector_refcount;
27899 static DEFINE_MUTEX(irq_vector_mutex);
27900 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27901 index de801f2..f189dcf 100644
27902 --- a/arch/x86/kernel/traps.c
27903 +++ b/arch/x86/kernel/traps.c
27904 @@ -67,7 +67,7 @@
27905 #include <asm/proto.h>
27906
27907 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27908 -gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27909 +gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27910 #else
27911 #include <asm/processor-flags.h>
27912 #include <asm/setup.h>
27913 @@ -76,7 +76,7 @@ asmlinkage int system_call(void);
27914 #endif
27915
27916 /* Must be page-aligned because the real IDT is used in a fixmap. */
27917 -gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27918 +gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27919
27920 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27921 EXPORT_SYMBOL_GPL(used_vectors);
27922 @@ -108,11 +108,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27923 }
27924
27925 static nokprobe_inline int
27926 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27927 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27928 struct pt_regs *regs, long error_code)
27929 {
27930 #ifdef CONFIG_X86_32
27931 - if (regs->flags & X86_VM_MASK) {
27932 + if (v8086_mode(regs)) {
27933 /*
27934 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27935 * On nmi (interrupt 2), do_trap should not be called.
27936 @@ -125,12 +125,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27937 return -1;
27938 }
27939 #endif
27940 - if (!user_mode(regs)) {
27941 + if (!user_mode_novm(regs)) {
27942 if (!fixup_exception(regs)) {
27943 tsk->thread.error_code = error_code;
27944 tsk->thread.trap_nr = trapnr;
27945 +
27946 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27947 + if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27948 + str = "PAX: suspicious stack segment fault";
27949 +#endif
27950 +
27951 die(str, regs, error_code);
27952 }
27953 +
27954 +#ifdef CONFIG_PAX_REFCOUNT
27955 + if (trapnr == X86_TRAP_OF)
27956 + pax_report_refcount_overflow(regs);
27957 +#endif
27958 +
27959 return 0;
27960 }
27961
27962 @@ -169,7 +181,7 @@ static siginfo_t *fill_trap_info(struct pt_regs *regs, int signr, int trapnr,
27963 }
27964
27965 static void
27966 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27967 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27968 long error_code, siginfo_t *info)
27969 {
27970 struct task_struct *tsk = current;
27971 @@ -193,7 +205,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27972 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27973 printk_ratelimit()) {
27974 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27975 - tsk->comm, tsk->pid, str,
27976 + tsk->comm, task_pid_nr(tsk), str,
27977 regs->ip, regs->sp, error_code);
27978 print_vma_addr(" in ", regs->ip);
27979 pr_cont("\n");
27980 @@ -274,6 +286,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
27981 tsk->thread.error_code = error_code;
27982 tsk->thread.trap_nr = X86_TRAP_DF;
27983
27984 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
27985 + if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
27986 + die("grsec: kernel stack overflow detected", regs, error_code);
27987 +#endif
27988 +
27989 #ifdef CONFIG_DOUBLEFAULT
27990 df_debug(regs, error_code);
27991 #endif
27992 @@ -296,7 +313,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27993 conditional_sti(regs);
27994
27995 #ifdef CONFIG_X86_32
27996 - if (regs->flags & X86_VM_MASK) {
27997 + if (v8086_mode(regs)) {
27998 local_irq_enable();
27999 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
28000 goto exit;
28001 @@ -304,18 +321,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
28002 #endif
28003
28004 tsk = current;
28005 - if (!user_mode(regs)) {
28006 + if (!user_mode_novm(regs)) {
28007 if (fixup_exception(regs))
28008 goto exit;
28009
28010 tsk->thread.error_code = error_code;
28011 tsk->thread.trap_nr = X86_TRAP_GP;
28012 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
28013 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
28014 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
28015 +
28016 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28017 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
28018 + die("PAX: suspicious general protection fault", regs, error_code);
28019 + else
28020 +#endif
28021 +
28022 die("general protection fault", regs, error_code);
28023 + }
28024 goto exit;
28025 }
28026
28027 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
28028 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
28029 + struct mm_struct *mm = tsk->mm;
28030 + unsigned long limit;
28031 +
28032 + down_write(&mm->mmap_sem);
28033 + limit = mm->context.user_cs_limit;
28034 + if (limit < TASK_SIZE) {
28035 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
28036 + up_write(&mm->mmap_sem);
28037 + return;
28038 + }
28039 + up_write(&mm->mmap_sem);
28040 + }
28041 +#endif
28042 +
28043 tsk->thread.error_code = error_code;
28044 tsk->thread.trap_nr = X86_TRAP_GP;
28045
28046 @@ -433,7 +474,7 @@ struct bad_iret_stack *fixup_bad_iret(struct bad_iret_stack *s)
28047 /* Copy the remainder of the stack from the current stack. */
28048 memmove(new_stack, s, offsetof(struct bad_iret_stack, regs.ip));
28049
28050 - BUG_ON(!user_mode_vm(&new_stack->regs));
28051 + BUG_ON(!user_mode(&new_stack->regs));
28052 return new_stack;
28053 }
28054 #endif
28055 @@ -518,7 +559,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28056 /* It's safe to allow irq's after DR6 has been saved */
28057 preempt_conditional_sti(regs);
28058
28059 - if (regs->flags & X86_VM_MASK) {
28060 + if (v8086_mode(regs)) {
28061 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
28062 X86_TRAP_DB);
28063 preempt_conditional_cli(regs);
28064 @@ -533,7 +574,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28065 * We already checked v86 mode above, so we can check for kernel mode
28066 * by just checking the CPL of CS.
28067 */
28068 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
28069 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
28070 tsk->thread.debugreg6 &= ~DR_STEP;
28071 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
28072 regs->flags &= ~X86_EFLAGS_TF;
28073 @@ -566,7 +607,7 @@ static void math_error(struct pt_regs *regs, int error_code, int trapnr)
28074 return;
28075 conditional_sti(regs);
28076
28077 - if (!user_mode_vm(regs))
28078 + if (!user_mode(regs))
28079 {
28080 if (!fixup_exception(regs)) {
28081 task->thread.error_code = error_code;
28082 diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
28083 index b7e50bb..f4a93ae 100644
28084 --- a/arch/x86/kernel/tsc.c
28085 +++ b/arch/x86/kernel/tsc.c
28086 @@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
28087 */
28088 smp_wmb();
28089
28090 - ACCESS_ONCE(c2n->head) = data;
28091 + ACCESS_ONCE_RW(c2n->head) = data;
28092 }
28093
28094 /*
28095 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
28096 index 5d1cbfe..2a21feb 100644
28097 --- a/arch/x86/kernel/uprobes.c
28098 +++ b/arch/x86/kernel/uprobes.c
28099 @@ -845,7 +845,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
28100 int ret = NOTIFY_DONE;
28101
28102 /* We are only interested in userspace traps */
28103 - if (regs && !user_mode_vm(regs))
28104 + if (regs && !user_mode(regs))
28105 return NOTIFY_DONE;
28106
28107 switch (val) {
28108 @@ -919,7 +919,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
28109
28110 if (nleft != rasize) {
28111 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
28112 - "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
28113 + "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
28114
28115 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
28116 }
28117 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
28118 index b9242ba..50c5edd 100644
28119 --- a/arch/x86/kernel/verify_cpu.S
28120 +++ b/arch/x86/kernel/verify_cpu.S
28121 @@ -20,6 +20,7 @@
28122 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
28123 * arch/x86/kernel/trampoline_64.S: secondary processor verification
28124 * arch/x86/kernel/head_32.S: processor startup
28125 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
28126 *
28127 * verify_cpu, returns the status of longmode and SSE in register %eax.
28128 * 0: Success 1: Failure
28129 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
28130 index e8edcf5..27f9344 100644
28131 --- a/arch/x86/kernel/vm86_32.c
28132 +++ b/arch/x86/kernel/vm86_32.c
28133 @@ -44,6 +44,7 @@
28134 #include <linux/ptrace.h>
28135 #include <linux/audit.h>
28136 #include <linux/stddef.h>
28137 +#include <linux/grsecurity.h>
28138
28139 #include <asm/uaccess.h>
28140 #include <asm/io.h>
28141 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
28142 do_exit(SIGSEGV);
28143 }
28144
28145 - tss = &per_cpu(init_tss, get_cpu());
28146 + tss = init_tss + get_cpu();
28147 current->thread.sp0 = current->thread.saved_sp0;
28148 current->thread.sysenter_cs = __KERNEL_CS;
28149 load_sp0(tss, &current->thread);
28150 @@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
28151
28152 if (tsk->thread.saved_sp0)
28153 return -EPERM;
28154 +
28155 +#ifdef CONFIG_GRKERNSEC_VM86
28156 + if (!capable(CAP_SYS_RAWIO)) {
28157 + gr_handle_vm86();
28158 + return -EPERM;
28159 + }
28160 +#endif
28161 +
28162 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
28163 offsetof(struct kernel_vm86_struct, vm86plus) -
28164 sizeof(info.regs));
28165 @@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
28166 int tmp;
28167 struct vm86plus_struct __user *v86;
28168
28169 +#ifdef CONFIG_GRKERNSEC_VM86
28170 + if (!capable(CAP_SYS_RAWIO)) {
28171 + gr_handle_vm86();
28172 + return -EPERM;
28173 + }
28174 +#endif
28175 +
28176 tsk = current;
28177 switch (cmd) {
28178 case VM86_REQUEST_IRQ:
28179 @@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
28180 tsk->thread.saved_fs = info->regs32->fs;
28181 tsk->thread.saved_gs = get_user_gs(info->regs32);
28182
28183 - tss = &per_cpu(init_tss, get_cpu());
28184 + tss = init_tss + get_cpu();
28185 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
28186 if (cpu_has_sep)
28187 tsk->thread.sysenter_cs = 0;
28188 @@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
28189 goto cannot_handle;
28190 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
28191 goto cannot_handle;
28192 - intr_ptr = (unsigned long __user *) (i << 2);
28193 + intr_ptr = (__force unsigned long __user *) (i << 2);
28194 if (get_user(segoffs, intr_ptr))
28195 goto cannot_handle;
28196 if ((segoffs >> 16) == BIOSSEG)
28197 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
28198 index 49edf2d..c0d1362 100644
28199 --- a/arch/x86/kernel/vmlinux.lds.S
28200 +++ b/arch/x86/kernel/vmlinux.lds.S
28201 @@ -26,6 +26,13 @@
28202 #include <asm/page_types.h>
28203 #include <asm/cache.h>
28204 #include <asm/boot.h>
28205 +#include <asm/segment.h>
28206 +
28207 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28208 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
28209 +#else
28210 +#define __KERNEL_TEXT_OFFSET 0
28211 +#endif
28212
28213 #undef i386 /* in case the preprocessor is a 32bit one */
28214
28215 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
28216
28217 PHDRS {
28218 text PT_LOAD FLAGS(5); /* R_E */
28219 +#ifdef CONFIG_X86_32
28220 + module PT_LOAD FLAGS(5); /* R_E */
28221 +#endif
28222 +#ifdef CONFIG_XEN
28223 + rodata PT_LOAD FLAGS(5); /* R_E */
28224 +#else
28225 + rodata PT_LOAD FLAGS(4); /* R__ */
28226 +#endif
28227 data PT_LOAD FLAGS(6); /* RW_ */
28228 -#ifdef CONFIG_X86_64
28229 + init.begin PT_LOAD FLAGS(6); /* RW_ */
28230 #ifdef CONFIG_SMP
28231 percpu PT_LOAD FLAGS(6); /* RW_ */
28232 #endif
28233 + text.init PT_LOAD FLAGS(5); /* R_E */
28234 + text.exit PT_LOAD FLAGS(5); /* R_E */
28235 init PT_LOAD FLAGS(7); /* RWE */
28236 -#endif
28237 note PT_NOTE FLAGS(0); /* ___ */
28238 }
28239
28240 SECTIONS
28241 {
28242 #ifdef CONFIG_X86_32
28243 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
28244 - phys_startup_32 = startup_32 - LOAD_OFFSET;
28245 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
28246 #else
28247 - . = __START_KERNEL;
28248 - phys_startup_64 = startup_64 - LOAD_OFFSET;
28249 + . = __START_KERNEL;
28250 #endif
28251
28252 /* Text and read-only data */
28253 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
28254 - _text = .;
28255 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28256 /* bootstrapping code */
28257 +#ifdef CONFIG_X86_32
28258 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28259 +#else
28260 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28261 +#endif
28262 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28263 + _text = .;
28264 HEAD_TEXT
28265 . = ALIGN(8);
28266 _stext = .;
28267 @@ -104,13 +124,47 @@ SECTIONS
28268 IRQENTRY_TEXT
28269 *(.fixup)
28270 *(.gnu.warning)
28271 - /* End of text section */
28272 - _etext = .;
28273 } :text = 0x9090
28274
28275 - NOTES :text :note
28276 + . += __KERNEL_TEXT_OFFSET;
28277
28278 - EXCEPTION_TABLE(16) :text = 0x9090
28279 +#ifdef CONFIG_X86_32
28280 + . = ALIGN(PAGE_SIZE);
28281 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
28282 +
28283 +#ifdef CONFIG_PAX_KERNEXEC
28284 + MODULES_EXEC_VADDR = .;
28285 + BYTE(0)
28286 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
28287 + . = ALIGN(HPAGE_SIZE) - 1;
28288 + MODULES_EXEC_END = .;
28289 +#endif
28290 +
28291 + } :module
28292 +#endif
28293 +
28294 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
28295 + /* End of text section */
28296 + BYTE(0)
28297 + _etext = . - __KERNEL_TEXT_OFFSET;
28298 + }
28299 +
28300 +#ifdef CONFIG_X86_32
28301 + . = ALIGN(PAGE_SIZE);
28302 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
28303 + . = ALIGN(PAGE_SIZE);
28304 + *(.empty_zero_page)
28305 + *(.initial_pg_fixmap)
28306 + *(.initial_pg_pmd)
28307 + *(.initial_page_table)
28308 + *(.swapper_pg_dir)
28309 + } :rodata
28310 +#endif
28311 +
28312 + . = ALIGN(PAGE_SIZE);
28313 + NOTES :rodata :note
28314 +
28315 + EXCEPTION_TABLE(16) :rodata
28316
28317 #if defined(CONFIG_DEBUG_RODATA)
28318 /* .text should occupy whole number of pages */
28319 @@ -122,16 +176,20 @@ SECTIONS
28320
28321 /* Data */
28322 .data : AT(ADDR(.data) - LOAD_OFFSET) {
28323 +
28324 +#ifdef CONFIG_PAX_KERNEXEC
28325 + . = ALIGN(HPAGE_SIZE);
28326 +#else
28327 + . = ALIGN(PAGE_SIZE);
28328 +#endif
28329 +
28330 /* Start of data section */
28331 _sdata = .;
28332
28333 /* init_task */
28334 INIT_TASK_DATA(THREAD_SIZE)
28335
28336 -#ifdef CONFIG_X86_32
28337 - /* 32 bit has nosave before _edata */
28338 NOSAVE_DATA
28339 -#endif
28340
28341 PAGE_ALIGNED_DATA(PAGE_SIZE)
28342
28343 @@ -174,12 +232,19 @@ SECTIONS
28344 . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
28345
28346 /* Init code and data - will be freed after init */
28347 - . = ALIGN(PAGE_SIZE);
28348 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
28349 + BYTE(0)
28350 +
28351 +#ifdef CONFIG_PAX_KERNEXEC
28352 + . = ALIGN(HPAGE_SIZE);
28353 +#else
28354 + . = ALIGN(PAGE_SIZE);
28355 +#endif
28356 +
28357 __init_begin = .; /* paired with __init_end */
28358 - }
28359 + } :init.begin
28360
28361 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
28362 +#ifdef CONFIG_SMP
28363 /*
28364 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
28365 * output PHDR, so the next output section - .init.text - should
28366 @@ -188,12 +253,27 @@ SECTIONS
28367 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
28368 #endif
28369
28370 - INIT_TEXT_SECTION(PAGE_SIZE)
28371 -#ifdef CONFIG_X86_64
28372 - :init
28373 -#endif
28374 + . = ALIGN(PAGE_SIZE);
28375 + init_begin = .;
28376 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
28377 + VMLINUX_SYMBOL(_sinittext) = .;
28378 + INIT_TEXT
28379 + VMLINUX_SYMBOL(_einittext) = .;
28380 + . = ALIGN(PAGE_SIZE);
28381 + } :text.init
28382
28383 - INIT_DATA_SECTION(16)
28384 + /*
28385 + * .exit.text is discard at runtime, not link time, to deal with
28386 + * references from .altinstructions and .eh_frame
28387 + */
28388 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28389 + EXIT_TEXT
28390 + . = ALIGN(16);
28391 + } :text.exit
28392 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
28393 +
28394 + . = ALIGN(PAGE_SIZE);
28395 + INIT_DATA_SECTION(16) :init
28396
28397 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
28398 __x86_cpu_dev_start = .;
28399 @@ -264,19 +344,12 @@ SECTIONS
28400 }
28401
28402 . = ALIGN(8);
28403 - /*
28404 - * .exit.text is discard at runtime, not link time, to deal with
28405 - * references from .altinstructions and .eh_frame
28406 - */
28407 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
28408 - EXIT_TEXT
28409 - }
28410
28411 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
28412 EXIT_DATA
28413 }
28414
28415 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
28416 +#ifndef CONFIG_SMP
28417 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
28418 #endif
28419
28420 @@ -295,16 +368,10 @@ SECTIONS
28421 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
28422 __smp_locks = .;
28423 *(.smp_locks)
28424 - . = ALIGN(PAGE_SIZE);
28425 __smp_locks_end = .;
28426 + . = ALIGN(PAGE_SIZE);
28427 }
28428
28429 -#ifdef CONFIG_X86_64
28430 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
28431 - NOSAVE_DATA
28432 - }
28433 -#endif
28434 -
28435 /* BSS */
28436 . = ALIGN(PAGE_SIZE);
28437 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
28438 @@ -320,6 +387,7 @@ SECTIONS
28439 __brk_base = .;
28440 . += 64 * 1024; /* 64k alignment slop space */
28441 *(.brk_reservation) /* areas brk users have reserved */
28442 + . = ALIGN(HPAGE_SIZE);
28443 __brk_limit = .;
28444 }
28445
28446 @@ -346,13 +414,12 @@ SECTIONS
28447 * for the boot processor.
28448 */
28449 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
28450 -INIT_PER_CPU(gdt_page);
28451 INIT_PER_CPU(irq_stack_union);
28452
28453 /*
28454 * Build-time check on the image size:
28455 */
28456 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
28457 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
28458 "kernel image bigger than KERNEL_IMAGE_SIZE");
28459
28460 #ifdef CONFIG_SMP
28461 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
28462 index 957779f..74e405c 100644
28463 --- a/arch/x86/kernel/vsyscall_64.c
28464 +++ b/arch/x86/kernel/vsyscall_64.c
28465 @@ -54,15 +54,13 @@
28466
28467 DEFINE_VVAR(int, vgetcpu_mode);
28468
28469 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
28470 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
28471
28472 static int __init vsyscall_setup(char *str)
28473 {
28474 if (str) {
28475 if (!strcmp("emulate", str))
28476 vsyscall_mode = EMULATE;
28477 - else if (!strcmp("native", str))
28478 - vsyscall_mode = NATIVE;
28479 else if (!strcmp("none", str))
28480 vsyscall_mode = NONE;
28481 else
28482 @@ -279,8 +277,7 @@ do_ret:
28483 return true;
28484
28485 sigsegv:
28486 - force_sig(SIGSEGV, current);
28487 - return true;
28488 + do_group_exit(SIGKILL);
28489 }
28490
28491 /*
28492 @@ -331,10 +328,7 @@ void __init map_vsyscall(void)
28493 extern char __vsyscall_page;
28494 unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
28495
28496 - __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall,
28497 - vsyscall_mode == NATIVE
28498 - ? PAGE_KERNEL_VSYSCALL
28499 - : PAGE_KERNEL_VVAR);
28500 + __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
28501 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_PAGE) !=
28502 (unsigned long)VSYSCALL_ADDR);
28503 }
28504 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
28505 index 04068192..4d75aa6 100644
28506 --- a/arch/x86/kernel/x8664_ksyms_64.c
28507 +++ b/arch/x86/kernel/x8664_ksyms_64.c
28508 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
28509 EXPORT_SYMBOL(copy_user_generic_unrolled);
28510 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
28511 EXPORT_SYMBOL(__copy_user_nocache);
28512 -EXPORT_SYMBOL(_copy_from_user);
28513 -EXPORT_SYMBOL(_copy_to_user);
28514
28515 EXPORT_SYMBOL(copy_page);
28516 EXPORT_SYMBOL(clear_page);
28517 @@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
28518 EXPORT_SYMBOL(___preempt_schedule_context);
28519 #endif
28520 #endif
28521 +
28522 +#ifdef CONFIG_PAX_PER_CPU_PGD
28523 +EXPORT_SYMBOL(cpu_pgd);
28524 +#endif
28525 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
28526 index e48b674..a451dd9 100644
28527 --- a/arch/x86/kernel/x86_init.c
28528 +++ b/arch/x86/kernel/x86_init.c
28529 @@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
28530 static void default_nmi_init(void) { };
28531 static int default_i8042_detect(void) { return 1; };
28532
28533 -struct x86_platform_ops x86_platform = {
28534 +struct x86_platform_ops x86_platform __read_only = {
28535 .calibrate_tsc = native_calibrate_tsc,
28536 .get_wallclock = mach_get_cmos_time,
28537 .set_wallclock = mach_set_rtc_mmss,
28538 @@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
28539 EXPORT_SYMBOL_GPL(x86_platform);
28540
28541 #if defined(CONFIG_PCI_MSI)
28542 -struct x86_msi_ops x86_msi = {
28543 +struct x86_msi_ops x86_msi __read_only = {
28544 .setup_msi_irqs = native_setup_msi_irqs,
28545 .compose_msi_msg = native_compose_msi_msg,
28546 .teardown_msi_irq = native_teardown_msi_irq,
28547 @@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
28548 }
28549 #endif
28550
28551 -struct x86_io_apic_ops x86_io_apic_ops = {
28552 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
28553 .init = native_io_apic_init_mappings,
28554 .read = native_io_apic_read,
28555 .write = native_io_apic_write,
28556 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
28557 index 4c540c4..0b985b0 100644
28558 --- a/arch/x86/kernel/xsave.c
28559 +++ b/arch/x86/kernel/xsave.c
28560 @@ -167,18 +167,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28561
28562 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28563 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28564 - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28565 + err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28566
28567 if (!use_xsave())
28568 return err;
28569
28570 - err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28571 + err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28572
28573 /*
28574 * Read the xstate_bv which we copied (directly from the cpu or
28575 * from the state in task struct) to the user buffers.
28576 */
28577 - err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28578 + err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28579
28580 /*
28581 * For legacy compatible, we always set FP/SSE bits in the bit
28582 @@ -193,7 +193,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28583 */
28584 xstate_bv |= XSTATE_FPSSE;
28585
28586 - err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28587 + err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28588
28589 return err;
28590 }
28591 @@ -202,6 +202,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28592 {
28593 int err;
28594
28595 + buf = (struct xsave_struct __user *)____m(buf);
28596 if (use_xsave())
28597 err = xsave_user(buf);
28598 else if (use_fxsr())
28599 @@ -312,6 +313,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28600 */
28601 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28602 {
28603 + buf = (void __user *)____m(buf);
28604 if (use_xsave()) {
28605 if ((unsigned long)buf % 64 || fx_only) {
28606 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28607 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28608 index 976e3a5..8bb998c 100644
28609 --- a/arch/x86/kvm/cpuid.c
28610 +++ b/arch/x86/kvm/cpuid.c
28611 @@ -175,15 +175,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28612 struct kvm_cpuid2 *cpuid,
28613 struct kvm_cpuid_entry2 __user *entries)
28614 {
28615 - int r;
28616 + int r, i;
28617
28618 r = -E2BIG;
28619 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28620 goto out;
28621 r = -EFAULT;
28622 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28623 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28624 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28625 goto out;
28626 + for (i = 0; i < cpuid->nent; ++i) {
28627 + struct kvm_cpuid_entry2 cpuid_entry;
28628 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28629 + goto out;
28630 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
28631 + }
28632 vcpu->arch.cpuid_nent = cpuid->nent;
28633 kvm_apic_set_version(vcpu);
28634 kvm_x86_ops->cpuid_update(vcpu);
28635 @@ -196,15 +201,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28636 struct kvm_cpuid2 *cpuid,
28637 struct kvm_cpuid_entry2 __user *entries)
28638 {
28639 - int r;
28640 + int r, i;
28641
28642 r = -E2BIG;
28643 if (cpuid->nent < vcpu->arch.cpuid_nent)
28644 goto out;
28645 r = -EFAULT;
28646 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28647 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28648 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28649 goto out;
28650 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28651 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28652 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28653 + goto out;
28654 + }
28655 return 0;
28656
28657 out:
28658 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
28659 index 9f8a2fa..565eb4f 100644
28660 --- a/arch/x86/kvm/emulate.c
28661 +++ b/arch/x86/kvm/emulate.c
28662 @@ -3554,7 +3554,7 @@ static int check_cr_write(struct x86_emulate_ctxt *ctxt)
28663
28664 ctxt->ops->get_msr(ctxt, MSR_EFER, &efer);
28665 if (efer & EFER_LMA)
28666 - rsvd = CR3_L_MODE_RESERVED_BITS;
28667 + rsvd = CR3_L_MODE_RESERVED_BITS & ~CR3_PCID_INVD;
28668
28669 if (new_val & rsvd)
28670 return emulate_gp(ctxt, 0);
28671 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28672 index b8345dd..f225d71 100644
28673 --- a/arch/x86/kvm/lapic.c
28674 +++ b/arch/x86/kvm/lapic.c
28675 @@ -55,7 +55,7 @@
28676 #define APIC_BUS_CYCLE_NS 1
28677
28678 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28679 -#define apic_debug(fmt, arg...)
28680 +#define apic_debug(fmt, arg...) do {} while (0)
28681
28682 #define APIC_LVT_NUM 6
28683 /* 14 is the version for Xeon and Pentium 8.4.8*/
28684 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28685 index fd49c86..77e1aa0 100644
28686 --- a/arch/x86/kvm/paging_tmpl.h
28687 +++ b/arch/x86/kvm/paging_tmpl.h
28688 @@ -343,7 +343,7 @@ retry_walk:
28689 if (unlikely(kvm_is_error_hva(host_addr)))
28690 goto error;
28691
28692 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28693 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28694 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28695 goto error;
28696 walker->ptep_user[walker->level - 1] = ptep_user;
28697 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28698 index 7527cef..c63a838e 100644
28699 --- a/arch/x86/kvm/svm.c
28700 +++ b/arch/x86/kvm/svm.c
28701 @@ -3564,7 +3564,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28702 int cpu = raw_smp_processor_id();
28703
28704 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28705 +
28706 + pax_open_kernel();
28707 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28708 + pax_close_kernel();
28709 +
28710 load_TR_desc();
28711 }
28712
28713 @@ -3965,6 +3969,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28714 #endif
28715 #endif
28716
28717 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28718 + __set_fs(current_thread_info()->addr_limit);
28719 +#endif
28720 +
28721 reload_tss(vcpu);
28722
28723 local_irq_disable();
28724 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28725 index 3e556c6..08bbf7f 100644
28726 --- a/arch/x86/kvm/vmx.c
28727 +++ b/arch/x86/kvm/vmx.c
28728 @@ -1366,12 +1366,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28729 #endif
28730 }
28731
28732 -static void vmcs_clear_bits(unsigned long field, u32 mask)
28733 +static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28734 {
28735 vmcs_writel(field, vmcs_readl(field) & ~mask);
28736 }
28737
28738 -static void vmcs_set_bits(unsigned long field, u32 mask)
28739 +static void vmcs_set_bits(unsigned long field, unsigned long mask)
28740 {
28741 vmcs_writel(field, vmcs_readl(field) | mask);
28742 }
28743 @@ -1631,7 +1631,11 @@ static void reload_tss(void)
28744 struct desc_struct *descs;
28745
28746 descs = (void *)gdt->address;
28747 +
28748 + pax_open_kernel();
28749 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28750 + pax_close_kernel();
28751 +
28752 load_TR_desc();
28753 }
28754
28755 @@ -1859,6 +1863,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28756 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28757 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28758
28759 +#ifdef CONFIG_PAX_PER_CPU_PGD
28760 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28761 +#endif
28762 +
28763 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28764 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28765 vmx->loaded_vmcs->cpu = cpu;
28766 @@ -2148,7 +2156,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28767 * reads and returns guest's timestamp counter "register"
28768 * guest_tsc = host_tsc + tsc_offset -- 21.3
28769 */
28770 -static u64 guest_read_tsc(void)
28771 +static u64 __intentional_overflow(-1) guest_read_tsc(void)
28772 {
28773 u64 host_tsc, tsc_offset;
28774
28775 @@ -3146,11 +3154,16 @@ static __init int hardware_setup(void)
28776 * page upon invalidation. No need to do anything if the
28777 * processor does not have the APIC_ACCESS_ADDR VMCS field.
28778 */
28779 - kvm_x86_ops->set_apic_access_page_addr = NULL;
28780 + pax_open_kernel();
28781 + *(void **)&kvm_x86_ops->set_apic_access_page_addr = NULL;
28782 + pax_close_kernel();
28783 }
28784
28785 - if (!cpu_has_vmx_tpr_shadow())
28786 - kvm_x86_ops->update_cr8_intercept = NULL;
28787 + if (!cpu_has_vmx_tpr_shadow()) {
28788 + pax_open_kernel();
28789 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28790 + pax_close_kernel();
28791 + }
28792
28793 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28794 kvm_disable_largepages();
28795 @@ -3161,13 +3174,15 @@ static __init int hardware_setup(void)
28796 if (!cpu_has_vmx_apicv())
28797 enable_apicv = 0;
28798
28799 + pax_open_kernel();
28800 if (enable_apicv)
28801 - kvm_x86_ops->update_cr8_intercept = NULL;
28802 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28803 else {
28804 - kvm_x86_ops->hwapic_irr_update = NULL;
28805 - kvm_x86_ops->deliver_posted_interrupt = NULL;
28806 - kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28807 + *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28808 + *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28809 + *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28810 }
28811 + pax_close_kernel();
28812
28813 if (nested)
28814 nested_vmx_setup_ctls_msrs();
28815 @@ -4274,7 +4289,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28816 unsigned long cr4;
28817
28818 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28819 +
28820 +#ifndef CONFIG_PAX_PER_CPU_PGD
28821 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28822 +#endif
28823
28824 /* Save the most likely value for this task's CR4 in the VMCS. */
28825 cr4 = read_cr4();
28826 @@ -4301,7 +4319,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28827 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28828 vmx->host_idt_base = dt.address;
28829
28830 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28831 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28832
28833 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28834 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28835 @@ -7622,6 +7640,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28836 "jmp 2f \n\t"
28837 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28838 "2: "
28839 +
28840 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28841 + "ljmp %[cs],$3f\n\t"
28842 + "3: "
28843 +#endif
28844 +
28845 /* Save guest registers, load host registers, keep flags */
28846 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28847 "pop %0 \n\t"
28848 @@ -7674,6 +7698,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28849 #endif
28850 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28851 [wordsize]"i"(sizeof(ulong))
28852 +
28853 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28854 + ,[cs]"i"(__KERNEL_CS)
28855 +#endif
28856 +
28857 : "cc", "memory"
28858 #ifdef CONFIG_X86_64
28859 , "rax", "rbx", "rdi", "rsi"
28860 @@ -7687,7 +7716,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28861 if (debugctlmsr)
28862 update_debugctlmsr(debugctlmsr);
28863
28864 -#ifndef CONFIG_X86_64
28865 +#ifdef CONFIG_X86_32
28866 /*
28867 * The sysexit path does not restore ds/es, so we must set them to
28868 * a reasonable value ourselves.
28869 @@ -7696,8 +7725,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28870 * may be executed in interrupt context, which saves and restore segments
28871 * around it, nullifying its effect.
28872 */
28873 - loadsegment(ds, __USER_DS);
28874 - loadsegment(es, __USER_DS);
28875 + loadsegment(ds, __KERNEL_DS);
28876 + loadsegment(es, __KERNEL_DS);
28877 + loadsegment(ss, __KERNEL_DS);
28878 +
28879 +#ifdef CONFIG_PAX_KERNEXEC
28880 + loadsegment(fs, __KERNEL_PERCPU);
28881 +#endif
28882 +
28883 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28884 + __set_fs(current_thread_info()->addr_limit);
28885 +#endif
28886 +
28887 #endif
28888
28889 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28890 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28891 index 0033df3..db6236d 100644
28892 --- a/arch/x86/kvm/x86.c
28893 +++ b/arch/x86/kvm/x86.c
28894 @@ -732,6 +732,8 @@ EXPORT_SYMBOL_GPL(kvm_set_cr4);
28895
28896 int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
28897 {
28898 + cr3 &= ~CR3_PCID_INVD;
28899 +
28900 if (cr3 == kvm_read_cr3(vcpu) && !pdptrs_changed(vcpu)) {
28901 kvm_mmu_sync_roots(vcpu);
28902 kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu);
28903 @@ -1878,8 +1880,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28904 {
28905 struct kvm *kvm = vcpu->kvm;
28906 int lm = is_long_mode(vcpu);
28907 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28908 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28909 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28910 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28911 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28912 : kvm->arch.xen_hvm_config.blob_size_32;
28913 u32 page_num = data & ~PAGE_MASK;
28914 @@ -2806,6 +2808,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28915 if (n < msr_list.nmsrs)
28916 goto out;
28917 r = -EFAULT;
28918 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28919 + goto out;
28920 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28921 num_msrs_to_save * sizeof(u32)))
28922 goto out;
28923 @@ -5670,7 +5674,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28924 };
28925 #endif
28926
28927 -int kvm_arch_init(void *opaque)
28928 +int kvm_arch_init(const void *opaque)
28929 {
28930 int r;
28931 struct kvm_x86_ops *ops = opaque;
28932 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28933 index aae9413..d11e829 100644
28934 --- a/arch/x86/lguest/boot.c
28935 +++ b/arch/x86/lguest/boot.c
28936 @@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28937 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28938 * Launcher to reboot us.
28939 */
28940 -static void lguest_restart(char *reason)
28941 +static __noreturn void lguest_restart(char *reason)
28942 {
28943 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28944 + BUG();
28945 }
28946
28947 /*G:050
28948 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28949 index 00933d5..3a64af9 100644
28950 --- a/arch/x86/lib/atomic64_386_32.S
28951 +++ b/arch/x86/lib/atomic64_386_32.S
28952 @@ -48,6 +48,10 @@ BEGIN(read)
28953 movl (v), %eax
28954 movl 4(v), %edx
28955 RET_ENDP
28956 +BEGIN(read_unchecked)
28957 + movl (v), %eax
28958 + movl 4(v), %edx
28959 +RET_ENDP
28960 #undef v
28961
28962 #define v %esi
28963 @@ -55,6 +59,10 @@ BEGIN(set)
28964 movl %ebx, (v)
28965 movl %ecx, 4(v)
28966 RET_ENDP
28967 +BEGIN(set_unchecked)
28968 + movl %ebx, (v)
28969 + movl %ecx, 4(v)
28970 +RET_ENDP
28971 #undef v
28972
28973 #define v %esi
28974 @@ -70,6 +78,20 @@ RET_ENDP
28975 BEGIN(add)
28976 addl %eax, (v)
28977 adcl %edx, 4(v)
28978 +
28979 +#ifdef CONFIG_PAX_REFCOUNT
28980 + jno 0f
28981 + subl %eax, (v)
28982 + sbbl %edx, 4(v)
28983 + int $4
28984 +0:
28985 + _ASM_EXTABLE(0b, 0b)
28986 +#endif
28987 +
28988 +RET_ENDP
28989 +BEGIN(add_unchecked)
28990 + addl %eax, (v)
28991 + adcl %edx, 4(v)
28992 RET_ENDP
28993 #undef v
28994
28995 @@ -77,6 +99,24 @@ RET_ENDP
28996 BEGIN(add_return)
28997 addl (v), %eax
28998 adcl 4(v), %edx
28999 +
29000 +#ifdef CONFIG_PAX_REFCOUNT
29001 + into
29002 +1234:
29003 + _ASM_EXTABLE(1234b, 2f)
29004 +#endif
29005 +
29006 + movl %eax, (v)
29007 + movl %edx, 4(v)
29008 +
29009 +#ifdef CONFIG_PAX_REFCOUNT
29010 +2:
29011 +#endif
29012 +
29013 +RET_ENDP
29014 +BEGIN(add_return_unchecked)
29015 + addl (v), %eax
29016 + adcl 4(v), %edx
29017 movl %eax, (v)
29018 movl %edx, 4(v)
29019 RET_ENDP
29020 @@ -86,6 +126,20 @@ RET_ENDP
29021 BEGIN(sub)
29022 subl %eax, (v)
29023 sbbl %edx, 4(v)
29024 +
29025 +#ifdef CONFIG_PAX_REFCOUNT
29026 + jno 0f
29027 + addl %eax, (v)
29028 + adcl %edx, 4(v)
29029 + int $4
29030 +0:
29031 + _ASM_EXTABLE(0b, 0b)
29032 +#endif
29033 +
29034 +RET_ENDP
29035 +BEGIN(sub_unchecked)
29036 + subl %eax, (v)
29037 + sbbl %edx, 4(v)
29038 RET_ENDP
29039 #undef v
29040
29041 @@ -96,6 +150,27 @@ BEGIN(sub_return)
29042 sbbl $0, %edx
29043 addl (v), %eax
29044 adcl 4(v), %edx
29045 +
29046 +#ifdef CONFIG_PAX_REFCOUNT
29047 + into
29048 +1234:
29049 + _ASM_EXTABLE(1234b, 2f)
29050 +#endif
29051 +
29052 + movl %eax, (v)
29053 + movl %edx, 4(v)
29054 +
29055 +#ifdef CONFIG_PAX_REFCOUNT
29056 +2:
29057 +#endif
29058 +
29059 +RET_ENDP
29060 +BEGIN(sub_return_unchecked)
29061 + negl %edx
29062 + negl %eax
29063 + sbbl $0, %edx
29064 + addl (v), %eax
29065 + adcl 4(v), %edx
29066 movl %eax, (v)
29067 movl %edx, 4(v)
29068 RET_ENDP
29069 @@ -105,6 +180,20 @@ RET_ENDP
29070 BEGIN(inc)
29071 addl $1, (v)
29072 adcl $0, 4(v)
29073 +
29074 +#ifdef CONFIG_PAX_REFCOUNT
29075 + jno 0f
29076 + subl $1, (v)
29077 + sbbl $0, 4(v)
29078 + int $4
29079 +0:
29080 + _ASM_EXTABLE(0b, 0b)
29081 +#endif
29082 +
29083 +RET_ENDP
29084 +BEGIN(inc_unchecked)
29085 + addl $1, (v)
29086 + adcl $0, 4(v)
29087 RET_ENDP
29088 #undef v
29089
29090 @@ -114,6 +203,26 @@ BEGIN(inc_return)
29091 movl 4(v), %edx
29092 addl $1, %eax
29093 adcl $0, %edx
29094 +
29095 +#ifdef CONFIG_PAX_REFCOUNT
29096 + into
29097 +1234:
29098 + _ASM_EXTABLE(1234b, 2f)
29099 +#endif
29100 +
29101 + movl %eax, (v)
29102 + movl %edx, 4(v)
29103 +
29104 +#ifdef CONFIG_PAX_REFCOUNT
29105 +2:
29106 +#endif
29107 +
29108 +RET_ENDP
29109 +BEGIN(inc_return_unchecked)
29110 + movl (v), %eax
29111 + movl 4(v), %edx
29112 + addl $1, %eax
29113 + adcl $0, %edx
29114 movl %eax, (v)
29115 movl %edx, 4(v)
29116 RET_ENDP
29117 @@ -123,6 +232,20 @@ RET_ENDP
29118 BEGIN(dec)
29119 subl $1, (v)
29120 sbbl $0, 4(v)
29121 +
29122 +#ifdef CONFIG_PAX_REFCOUNT
29123 + jno 0f
29124 + addl $1, (v)
29125 + adcl $0, 4(v)
29126 + int $4
29127 +0:
29128 + _ASM_EXTABLE(0b, 0b)
29129 +#endif
29130 +
29131 +RET_ENDP
29132 +BEGIN(dec_unchecked)
29133 + subl $1, (v)
29134 + sbbl $0, 4(v)
29135 RET_ENDP
29136 #undef v
29137
29138 @@ -132,6 +255,26 @@ BEGIN(dec_return)
29139 movl 4(v), %edx
29140 subl $1, %eax
29141 sbbl $0, %edx
29142 +
29143 +#ifdef CONFIG_PAX_REFCOUNT
29144 + into
29145 +1234:
29146 + _ASM_EXTABLE(1234b, 2f)
29147 +#endif
29148 +
29149 + movl %eax, (v)
29150 + movl %edx, 4(v)
29151 +
29152 +#ifdef CONFIG_PAX_REFCOUNT
29153 +2:
29154 +#endif
29155 +
29156 +RET_ENDP
29157 +BEGIN(dec_return_unchecked)
29158 + movl (v), %eax
29159 + movl 4(v), %edx
29160 + subl $1, %eax
29161 + sbbl $0, %edx
29162 movl %eax, (v)
29163 movl %edx, 4(v)
29164 RET_ENDP
29165 @@ -143,6 +286,13 @@ BEGIN(add_unless)
29166 adcl %edx, %edi
29167 addl (v), %eax
29168 adcl 4(v), %edx
29169 +
29170 +#ifdef CONFIG_PAX_REFCOUNT
29171 + into
29172 +1234:
29173 + _ASM_EXTABLE(1234b, 2f)
29174 +#endif
29175 +
29176 cmpl %eax, %ecx
29177 je 3f
29178 1:
29179 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
29180 1:
29181 addl $1, %eax
29182 adcl $0, %edx
29183 +
29184 +#ifdef CONFIG_PAX_REFCOUNT
29185 + into
29186 +1234:
29187 + _ASM_EXTABLE(1234b, 2f)
29188 +#endif
29189 +
29190 movl %eax, (v)
29191 movl %edx, 4(v)
29192 movl $1, %eax
29193 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
29194 movl 4(v), %edx
29195 subl $1, %eax
29196 sbbl $0, %edx
29197 +
29198 +#ifdef CONFIG_PAX_REFCOUNT
29199 + into
29200 +1234:
29201 + _ASM_EXTABLE(1234b, 1f)
29202 +#endif
29203 +
29204 js 1f
29205 movl %eax, (v)
29206 movl %edx, 4(v)
29207 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
29208 index f5cc9eb..51fa319 100644
29209 --- a/arch/x86/lib/atomic64_cx8_32.S
29210 +++ b/arch/x86/lib/atomic64_cx8_32.S
29211 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
29212 CFI_STARTPROC
29213
29214 read64 %ecx
29215 + pax_force_retaddr
29216 ret
29217 CFI_ENDPROC
29218 ENDPROC(atomic64_read_cx8)
29219
29220 +ENTRY(atomic64_read_unchecked_cx8)
29221 + CFI_STARTPROC
29222 +
29223 + read64 %ecx
29224 + pax_force_retaddr
29225 + ret
29226 + CFI_ENDPROC
29227 +ENDPROC(atomic64_read_unchecked_cx8)
29228 +
29229 ENTRY(atomic64_set_cx8)
29230 CFI_STARTPROC
29231
29232 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
29233 cmpxchg8b (%esi)
29234 jne 1b
29235
29236 + pax_force_retaddr
29237 ret
29238 CFI_ENDPROC
29239 ENDPROC(atomic64_set_cx8)
29240
29241 +ENTRY(atomic64_set_unchecked_cx8)
29242 + CFI_STARTPROC
29243 +
29244 +1:
29245 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
29246 + * are atomic on 586 and newer */
29247 + cmpxchg8b (%esi)
29248 + jne 1b
29249 +
29250 + pax_force_retaddr
29251 + ret
29252 + CFI_ENDPROC
29253 +ENDPROC(atomic64_set_unchecked_cx8)
29254 +
29255 ENTRY(atomic64_xchg_cx8)
29256 CFI_STARTPROC
29257
29258 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
29259 cmpxchg8b (%esi)
29260 jne 1b
29261
29262 + pax_force_retaddr
29263 ret
29264 CFI_ENDPROC
29265 ENDPROC(atomic64_xchg_cx8)
29266
29267 -.macro addsub_return func ins insc
29268 -ENTRY(atomic64_\func\()_return_cx8)
29269 +.macro addsub_return func ins insc unchecked=""
29270 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29271 CFI_STARTPROC
29272 SAVE ebp
29273 SAVE ebx
29274 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
29275 movl %edx, %ecx
29276 \ins\()l %esi, %ebx
29277 \insc\()l %edi, %ecx
29278 +
29279 +.ifb \unchecked
29280 +#ifdef CONFIG_PAX_REFCOUNT
29281 + into
29282 +2:
29283 + _ASM_EXTABLE(2b, 3f)
29284 +#endif
29285 +.endif
29286 +
29287 LOCK_PREFIX
29288 cmpxchg8b (%ebp)
29289 jne 1b
29290 -
29291 -10:
29292 movl %ebx, %eax
29293 movl %ecx, %edx
29294 +
29295 +.ifb \unchecked
29296 +#ifdef CONFIG_PAX_REFCOUNT
29297 +3:
29298 +#endif
29299 +.endif
29300 +
29301 RESTORE edi
29302 RESTORE esi
29303 RESTORE ebx
29304 RESTORE ebp
29305 + pax_force_retaddr
29306 ret
29307 CFI_ENDPROC
29308 -ENDPROC(atomic64_\func\()_return_cx8)
29309 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29310 .endm
29311
29312 addsub_return add add adc
29313 addsub_return sub sub sbb
29314 +addsub_return add add adc _unchecked
29315 +addsub_return sub sub sbb _unchecked
29316
29317 -.macro incdec_return func ins insc
29318 -ENTRY(atomic64_\func\()_return_cx8)
29319 +.macro incdec_return func ins insc unchecked=""
29320 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29321 CFI_STARTPROC
29322 SAVE ebx
29323
29324 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
29325 movl %edx, %ecx
29326 \ins\()l $1, %ebx
29327 \insc\()l $0, %ecx
29328 +
29329 +.ifb \unchecked
29330 +#ifdef CONFIG_PAX_REFCOUNT
29331 + into
29332 +2:
29333 + _ASM_EXTABLE(2b, 3f)
29334 +#endif
29335 +.endif
29336 +
29337 LOCK_PREFIX
29338 cmpxchg8b (%esi)
29339 jne 1b
29340
29341 -10:
29342 movl %ebx, %eax
29343 movl %ecx, %edx
29344 +
29345 +.ifb \unchecked
29346 +#ifdef CONFIG_PAX_REFCOUNT
29347 +3:
29348 +#endif
29349 +.endif
29350 +
29351 RESTORE ebx
29352 + pax_force_retaddr
29353 ret
29354 CFI_ENDPROC
29355 -ENDPROC(atomic64_\func\()_return_cx8)
29356 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29357 .endm
29358
29359 incdec_return inc add adc
29360 incdec_return dec sub sbb
29361 +incdec_return inc add adc _unchecked
29362 +incdec_return dec sub sbb _unchecked
29363
29364 ENTRY(atomic64_dec_if_positive_cx8)
29365 CFI_STARTPROC
29366 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
29367 movl %edx, %ecx
29368 subl $1, %ebx
29369 sbb $0, %ecx
29370 +
29371 +#ifdef CONFIG_PAX_REFCOUNT
29372 + into
29373 +1234:
29374 + _ASM_EXTABLE(1234b, 2f)
29375 +#endif
29376 +
29377 js 2f
29378 LOCK_PREFIX
29379 cmpxchg8b (%esi)
29380 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
29381 movl %ebx, %eax
29382 movl %ecx, %edx
29383 RESTORE ebx
29384 + pax_force_retaddr
29385 ret
29386 CFI_ENDPROC
29387 ENDPROC(atomic64_dec_if_positive_cx8)
29388 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
29389 movl %edx, %ecx
29390 addl %ebp, %ebx
29391 adcl %edi, %ecx
29392 +
29393 +#ifdef CONFIG_PAX_REFCOUNT
29394 + into
29395 +1234:
29396 + _ASM_EXTABLE(1234b, 3f)
29397 +#endif
29398 +
29399 LOCK_PREFIX
29400 cmpxchg8b (%esi)
29401 jne 1b
29402 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
29403 CFI_ADJUST_CFA_OFFSET -8
29404 RESTORE ebx
29405 RESTORE ebp
29406 + pax_force_retaddr
29407 ret
29408 4:
29409 cmpl %edx, 4(%esp)
29410 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
29411 xorl %ecx, %ecx
29412 addl $1, %ebx
29413 adcl %edx, %ecx
29414 +
29415 +#ifdef CONFIG_PAX_REFCOUNT
29416 + into
29417 +1234:
29418 + _ASM_EXTABLE(1234b, 3f)
29419 +#endif
29420 +
29421 LOCK_PREFIX
29422 cmpxchg8b (%esi)
29423 jne 1b
29424 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
29425 movl $1, %eax
29426 3:
29427 RESTORE ebx
29428 + pax_force_retaddr
29429 ret
29430 CFI_ENDPROC
29431 ENDPROC(atomic64_inc_not_zero_cx8)
29432 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
29433 index e78b8eee..7e173a8 100644
29434 --- a/arch/x86/lib/checksum_32.S
29435 +++ b/arch/x86/lib/checksum_32.S
29436 @@ -29,7 +29,8 @@
29437 #include <asm/dwarf2.h>
29438 #include <asm/errno.h>
29439 #include <asm/asm.h>
29440 -
29441 +#include <asm/segment.h>
29442 +
29443 /*
29444 * computes a partial checksum, e.g. for TCP/UDP fragments
29445 */
29446 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
29447
29448 #define ARGBASE 16
29449 #define FP 12
29450 -
29451 -ENTRY(csum_partial_copy_generic)
29452 +
29453 +ENTRY(csum_partial_copy_generic_to_user)
29454 CFI_STARTPROC
29455 +
29456 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29457 + pushl_cfi %gs
29458 + popl_cfi %es
29459 + jmp csum_partial_copy_generic
29460 +#endif
29461 +
29462 +ENTRY(csum_partial_copy_generic_from_user)
29463 +
29464 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29465 + pushl_cfi %gs
29466 + popl_cfi %ds
29467 +#endif
29468 +
29469 +ENTRY(csum_partial_copy_generic)
29470 subl $4,%esp
29471 CFI_ADJUST_CFA_OFFSET 4
29472 pushl_cfi %edi
29473 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
29474 jmp 4f
29475 SRC(1: movw (%esi), %bx )
29476 addl $2, %esi
29477 -DST( movw %bx, (%edi) )
29478 +DST( movw %bx, %es:(%edi) )
29479 addl $2, %edi
29480 addw %bx, %ax
29481 adcl $0, %eax
29482 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
29483 SRC(1: movl (%esi), %ebx )
29484 SRC( movl 4(%esi), %edx )
29485 adcl %ebx, %eax
29486 -DST( movl %ebx, (%edi) )
29487 +DST( movl %ebx, %es:(%edi) )
29488 adcl %edx, %eax
29489 -DST( movl %edx, 4(%edi) )
29490 +DST( movl %edx, %es:4(%edi) )
29491
29492 SRC( movl 8(%esi), %ebx )
29493 SRC( movl 12(%esi), %edx )
29494 adcl %ebx, %eax
29495 -DST( movl %ebx, 8(%edi) )
29496 +DST( movl %ebx, %es:8(%edi) )
29497 adcl %edx, %eax
29498 -DST( movl %edx, 12(%edi) )
29499 +DST( movl %edx, %es:12(%edi) )
29500
29501 SRC( movl 16(%esi), %ebx )
29502 SRC( movl 20(%esi), %edx )
29503 adcl %ebx, %eax
29504 -DST( movl %ebx, 16(%edi) )
29505 +DST( movl %ebx, %es:16(%edi) )
29506 adcl %edx, %eax
29507 -DST( movl %edx, 20(%edi) )
29508 +DST( movl %edx, %es:20(%edi) )
29509
29510 SRC( movl 24(%esi), %ebx )
29511 SRC( movl 28(%esi), %edx )
29512 adcl %ebx, %eax
29513 -DST( movl %ebx, 24(%edi) )
29514 +DST( movl %ebx, %es:24(%edi) )
29515 adcl %edx, %eax
29516 -DST( movl %edx, 28(%edi) )
29517 +DST( movl %edx, %es:28(%edi) )
29518
29519 lea 32(%esi), %esi
29520 lea 32(%edi), %edi
29521 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
29522 shrl $2, %edx # This clears CF
29523 SRC(3: movl (%esi), %ebx )
29524 adcl %ebx, %eax
29525 -DST( movl %ebx, (%edi) )
29526 +DST( movl %ebx, %es:(%edi) )
29527 lea 4(%esi), %esi
29528 lea 4(%edi), %edi
29529 dec %edx
29530 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
29531 jb 5f
29532 SRC( movw (%esi), %cx )
29533 leal 2(%esi), %esi
29534 -DST( movw %cx, (%edi) )
29535 +DST( movw %cx, %es:(%edi) )
29536 leal 2(%edi), %edi
29537 je 6f
29538 shll $16,%ecx
29539 SRC(5: movb (%esi), %cl )
29540 -DST( movb %cl, (%edi) )
29541 +DST( movb %cl, %es:(%edi) )
29542 6: addl %ecx, %eax
29543 adcl $0, %eax
29544 7:
29545 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
29546
29547 6001:
29548 movl ARGBASE+20(%esp), %ebx # src_err_ptr
29549 - movl $-EFAULT, (%ebx)
29550 + movl $-EFAULT, %ss:(%ebx)
29551
29552 # zero the complete destination - computing the rest
29553 # is too much work
29554 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
29555
29556 6002:
29557 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29558 - movl $-EFAULT,(%ebx)
29559 + movl $-EFAULT,%ss:(%ebx)
29560 jmp 5000b
29561
29562 .previous
29563
29564 + pushl_cfi %ss
29565 + popl_cfi %ds
29566 + pushl_cfi %ss
29567 + popl_cfi %es
29568 popl_cfi %ebx
29569 CFI_RESTORE ebx
29570 popl_cfi %esi
29571 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
29572 popl_cfi %ecx # equivalent to addl $4,%esp
29573 ret
29574 CFI_ENDPROC
29575 -ENDPROC(csum_partial_copy_generic)
29576 +ENDPROC(csum_partial_copy_generic_to_user)
29577
29578 #else
29579
29580 /* Version for PentiumII/PPro */
29581
29582 #define ROUND1(x) \
29583 + nop; nop; nop; \
29584 SRC(movl x(%esi), %ebx ) ; \
29585 addl %ebx, %eax ; \
29586 - DST(movl %ebx, x(%edi) ) ;
29587 + DST(movl %ebx, %es:x(%edi)) ;
29588
29589 #define ROUND(x) \
29590 + nop; nop; nop; \
29591 SRC(movl x(%esi), %ebx ) ; \
29592 adcl %ebx, %eax ; \
29593 - DST(movl %ebx, x(%edi) ) ;
29594 + DST(movl %ebx, %es:x(%edi)) ;
29595
29596 #define ARGBASE 12
29597 -
29598 -ENTRY(csum_partial_copy_generic)
29599 +
29600 +ENTRY(csum_partial_copy_generic_to_user)
29601 CFI_STARTPROC
29602 +
29603 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29604 + pushl_cfi %gs
29605 + popl_cfi %es
29606 + jmp csum_partial_copy_generic
29607 +#endif
29608 +
29609 +ENTRY(csum_partial_copy_generic_from_user)
29610 +
29611 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29612 + pushl_cfi %gs
29613 + popl_cfi %ds
29614 +#endif
29615 +
29616 +ENTRY(csum_partial_copy_generic)
29617 pushl_cfi %ebx
29618 CFI_REL_OFFSET ebx, 0
29619 pushl_cfi %edi
29620 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29621 subl %ebx, %edi
29622 lea -1(%esi),%edx
29623 andl $-32,%edx
29624 - lea 3f(%ebx,%ebx), %ebx
29625 + lea 3f(%ebx,%ebx,2), %ebx
29626 testl %esi, %esi
29627 jmp *%ebx
29628 1: addl $64,%esi
29629 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29630 jb 5f
29631 SRC( movw (%esi), %dx )
29632 leal 2(%esi), %esi
29633 -DST( movw %dx, (%edi) )
29634 +DST( movw %dx, %es:(%edi) )
29635 leal 2(%edi), %edi
29636 je 6f
29637 shll $16,%edx
29638 5:
29639 SRC( movb (%esi), %dl )
29640 -DST( movb %dl, (%edi) )
29641 +DST( movb %dl, %es:(%edi) )
29642 6: addl %edx, %eax
29643 adcl $0, %eax
29644 7:
29645 .section .fixup, "ax"
29646 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29647 - movl $-EFAULT, (%ebx)
29648 + movl $-EFAULT, %ss:(%ebx)
29649 # zero the complete destination (computing the rest is too much work)
29650 movl ARGBASE+8(%esp),%edi # dst
29651 movl ARGBASE+12(%esp),%ecx # len
29652 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29653 rep; stosb
29654 jmp 7b
29655 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29656 - movl $-EFAULT, (%ebx)
29657 + movl $-EFAULT, %ss:(%ebx)
29658 jmp 7b
29659 .previous
29660
29661 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29662 + pushl_cfi %ss
29663 + popl_cfi %ds
29664 + pushl_cfi %ss
29665 + popl_cfi %es
29666 +#endif
29667 +
29668 popl_cfi %esi
29669 CFI_RESTORE esi
29670 popl_cfi %edi
29671 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29672 CFI_RESTORE ebx
29673 ret
29674 CFI_ENDPROC
29675 -ENDPROC(csum_partial_copy_generic)
29676 +ENDPROC(csum_partial_copy_generic_to_user)
29677
29678 #undef ROUND
29679 #undef ROUND1
29680 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29681 index f2145cf..cea889d 100644
29682 --- a/arch/x86/lib/clear_page_64.S
29683 +++ b/arch/x86/lib/clear_page_64.S
29684 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29685 movl $4096/8,%ecx
29686 xorl %eax,%eax
29687 rep stosq
29688 + pax_force_retaddr
29689 ret
29690 CFI_ENDPROC
29691 ENDPROC(clear_page_c)
29692 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29693 movl $4096,%ecx
29694 xorl %eax,%eax
29695 rep stosb
29696 + pax_force_retaddr
29697 ret
29698 CFI_ENDPROC
29699 ENDPROC(clear_page_c_e)
29700 @@ -43,6 +45,7 @@ ENTRY(clear_page)
29701 leaq 64(%rdi),%rdi
29702 jnz .Lloop
29703 nop
29704 + pax_force_retaddr
29705 ret
29706 CFI_ENDPROC
29707 .Lclear_page_end:
29708 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
29709
29710 #include <asm/cpufeature.h>
29711
29712 - .section .altinstr_replacement,"ax"
29713 + .section .altinstr_replacement,"a"
29714 1: .byte 0xeb /* jmp <disp8> */
29715 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29716 2: .byte 0xeb /* jmp <disp8> */
29717 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29718 index 40a1725..5d12ac4 100644
29719 --- a/arch/x86/lib/cmpxchg16b_emu.S
29720 +++ b/arch/x86/lib/cmpxchg16b_emu.S
29721 @@ -8,6 +8,7 @@
29722 #include <linux/linkage.h>
29723 #include <asm/dwarf2.h>
29724 #include <asm/percpu.h>
29725 +#include <asm/alternative-asm.h>
29726
29727 .text
29728
29729 @@ -46,12 +47,14 @@ CFI_STARTPROC
29730 CFI_REMEMBER_STATE
29731 popfq_cfi
29732 mov $1, %al
29733 + pax_force_retaddr
29734 ret
29735
29736 CFI_RESTORE_STATE
29737 .Lnot_same:
29738 popfq_cfi
29739 xor %al,%al
29740 + pax_force_retaddr
29741 ret
29742
29743 CFI_ENDPROC
29744 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29745 index 176cca6..e0d658e 100644
29746 --- a/arch/x86/lib/copy_page_64.S
29747 +++ b/arch/x86/lib/copy_page_64.S
29748 @@ -9,6 +9,7 @@ copy_page_rep:
29749 CFI_STARTPROC
29750 movl $4096/8, %ecx
29751 rep movsq
29752 + pax_force_retaddr
29753 ret
29754 CFI_ENDPROC
29755 ENDPROC(copy_page_rep)
29756 @@ -24,8 +25,8 @@ ENTRY(copy_page)
29757 CFI_ADJUST_CFA_OFFSET 2*8
29758 movq %rbx, (%rsp)
29759 CFI_REL_OFFSET rbx, 0
29760 - movq %r12, 1*8(%rsp)
29761 - CFI_REL_OFFSET r12, 1*8
29762 + movq %r13, 1*8(%rsp)
29763 + CFI_REL_OFFSET r13, 1*8
29764
29765 movl $(4096/64)-5, %ecx
29766 .p2align 4
29767 @@ -38,7 +39,7 @@ ENTRY(copy_page)
29768 movq 0x8*4(%rsi), %r9
29769 movq 0x8*5(%rsi), %r10
29770 movq 0x8*6(%rsi), %r11
29771 - movq 0x8*7(%rsi), %r12
29772 + movq 0x8*7(%rsi), %r13
29773
29774 prefetcht0 5*64(%rsi)
29775
29776 @@ -49,7 +50,7 @@ ENTRY(copy_page)
29777 movq %r9, 0x8*4(%rdi)
29778 movq %r10, 0x8*5(%rdi)
29779 movq %r11, 0x8*6(%rdi)
29780 - movq %r12, 0x8*7(%rdi)
29781 + movq %r13, 0x8*7(%rdi)
29782
29783 leaq 64 (%rsi), %rsi
29784 leaq 64 (%rdi), %rdi
29785 @@ -68,7 +69,7 @@ ENTRY(copy_page)
29786 movq 0x8*4(%rsi), %r9
29787 movq 0x8*5(%rsi), %r10
29788 movq 0x8*6(%rsi), %r11
29789 - movq 0x8*7(%rsi), %r12
29790 + movq 0x8*7(%rsi), %r13
29791
29792 movq %rax, 0x8*0(%rdi)
29793 movq %rbx, 0x8*1(%rdi)
29794 @@ -77,7 +78,7 @@ ENTRY(copy_page)
29795 movq %r9, 0x8*4(%rdi)
29796 movq %r10, 0x8*5(%rdi)
29797 movq %r11, 0x8*6(%rdi)
29798 - movq %r12, 0x8*7(%rdi)
29799 + movq %r13, 0x8*7(%rdi)
29800
29801 leaq 64(%rdi), %rdi
29802 leaq 64(%rsi), %rsi
29803 @@ -85,10 +86,11 @@ ENTRY(copy_page)
29804
29805 movq (%rsp), %rbx
29806 CFI_RESTORE rbx
29807 - movq 1*8(%rsp), %r12
29808 - CFI_RESTORE r12
29809 + movq 1*8(%rsp), %r13
29810 + CFI_RESTORE r13
29811 addq $2*8, %rsp
29812 CFI_ADJUST_CFA_OFFSET -2*8
29813 + pax_force_retaddr
29814 ret
29815 .Lcopy_page_end:
29816 CFI_ENDPROC
29817 @@ -99,7 +101,7 @@ ENDPROC(copy_page)
29818
29819 #include <asm/cpufeature.h>
29820
29821 - .section .altinstr_replacement,"ax"
29822 + .section .altinstr_replacement,"a"
29823 1: .byte 0xeb /* jmp <disp8> */
29824 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29825 2:
29826 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29827 index dee945d..a84067b 100644
29828 --- a/arch/x86/lib/copy_user_64.S
29829 +++ b/arch/x86/lib/copy_user_64.S
29830 @@ -18,31 +18,7 @@
29831 #include <asm/alternative-asm.h>
29832 #include <asm/asm.h>
29833 #include <asm/smap.h>
29834 -
29835 -/*
29836 - * By placing feature2 after feature1 in altinstructions section, we logically
29837 - * implement:
29838 - * If CPU has feature2, jmp to alt2 is used
29839 - * else if CPU has feature1, jmp to alt1 is used
29840 - * else jmp to orig is used.
29841 - */
29842 - .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29843 -0:
29844 - .byte 0xe9 /* 32bit jump */
29845 - .long \orig-1f /* by default jump to orig */
29846 -1:
29847 - .section .altinstr_replacement,"ax"
29848 -2: .byte 0xe9 /* near jump with 32bit immediate */
29849 - .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29850 -3: .byte 0xe9 /* near jump with 32bit immediate */
29851 - .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29852 - .previous
29853 -
29854 - .section .altinstructions,"a"
29855 - altinstruction_entry 0b,2b,\feature1,5,5
29856 - altinstruction_entry 0b,3b,\feature2,5,5
29857 - .previous
29858 - .endm
29859 +#include <asm/pgtable.h>
29860
29861 .macro ALIGN_DESTINATION
29862 #ifdef FIX_ALIGNMENT
29863 @@ -70,52 +46,6 @@
29864 #endif
29865 .endm
29866
29867 -/* Standard copy_to_user with segment limit checking */
29868 -ENTRY(_copy_to_user)
29869 - CFI_STARTPROC
29870 - GET_THREAD_INFO(%rax)
29871 - movq %rdi,%rcx
29872 - addq %rdx,%rcx
29873 - jc bad_to_user
29874 - cmpq TI_addr_limit(%rax),%rcx
29875 - ja bad_to_user
29876 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29877 - copy_user_generic_unrolled,copy_user_generic_string, \
29878 - copy_user_enhanced_fast_string
29879 - CFI_ENDPROC
29880 -ENDPROC(_copy_to_user)
29881 -
29882 -/* Standard copy_from_user with segment limit checking */
29883 -ENTRY(_copy_from_user)
29884 - CFI_STARTPROC
29885 - GET_THREAD_INFO(%rax)
29886 - movq %rsi,%rcx
29887 - addq %rdx,%rcx
29888 - jc bad_from_user
29889 - cmpq TI_addr_limit(%rax),%rcx
29890 - ja bad_from_user
29891 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29892 - copy_user_generic_unrolled,copy_user_generic_string, \
29893 - copy_user_enhanced_fast_string
29894 - CFI_ENDPROC
29895 -ENDPROC(_copy_from_user)
29896 -
29897 - .section .fixup,"ax"
29898 - /* must zero dest */
29899 -ENTRY(bad_from_user)
29900 -bad_from_user:
29901 - CFI_STARTPROC
29902 - movl %edx,%ecx
29903 - xorl %eax,%eax
29904 - rep
29905 - stosb
29906 -bad_to_user:
29907 - movl %edx,%eax
29908 - ret
29909 - CFI_ENDPROC
29910 -ENDPROC(bad_from_user)
29911 - .previous
29912 -
29913 /*
29914 * copy_user_generic_unrolled - memory copy with exception handling.
29915 * This version is for CPUs like P4 that don't have efficient micro
29916 @@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29917 */
29918 ENTRY(copy_user_generic_unrolled)
29919 CFI_STARTPROC
29920 + ASM_PAX_OPEN_USERLAND
29921 ASM_STAC
29922 cmpl $8,%edx
29923 jb 20f /* less then 8 bytes, go to byte copy loop */
29924 @@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29925 jnz 21b
29926 23: xor %eax,%eax
29927 ASM_CLAC
29928 + ASM_PAX_CLOSE_USERLAND
29929 + pax_force_retaddr
29930 ret
29931
29932 .section .fixup,"ax"
29933 @@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29934 */
29935 ENTRY(copy_user_generic_string)
29936 CFI_STARTPROC
29937 + ASM_PAX_OPEN_USERLAND
29938 ASM_STAC
29939 cmpl $8,%edx
29940 jb 2f /* less than 8 bytes, go to byte copy loop */
29941 @@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
29942 movsb
29943 xorl %eax,%eax
29944 ASM_CLAC
29945 + ASM_PAX_CLOSE_USERLAND
29946 + pax_force_retaddr
29947 ret
29948
29949 .section .fixup,"ax"
29950 @@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
29951 */
29952 ENTRY(copy_user_enhanced_fast_string)
29953 CFI_STARTPROC
29954 + ASM_PAX_OPEN_USERLAND
29955 ASM_STAC
29956 movl %edx,%ecx
29957 1: rep
29958 movsb
29959 xorl %eax,%eax
29960 ASM_CLAC
29961 + ASM_PAX_CLOSE_USERLAND
29962 + pax_force_retaddr
29963 ret
29964
29965 .section .fixup,"ax"
29966 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29967 index 6a4f43c..c70fb52 100644
29968 --- a/arch/x86/lib/copy_user_nocache_64.S
29969 +++ b/arch/x86/lib/copy_user_nocache_64.S
29970 @@ -8,6 +8,7 @@
29971
29972 #include <linux/linkage.h>
29973 #include <asm/dwarf2.h>
29974 +#include <asm/alternative-asm.h>
29975
29976 #define FIX_ALIGNMENT 1
29977
29978 @@ -16,6 +17,7 @@
29979 #include <asm/thread_info.h>
29980 #include <asm/asm.h>
29981 #include <asm/smap.h>
29982 +#include <asm/pgtable.h>
29983
29984 .macro ALIGN_DESTINATION
29985 #ifdef FIX_ALIGNMENT
29986 @@ -49,6 +51,16 @@
29987 */
29988 ENTRY(__copy_user_nocache)
29989 CFI_STARTPROC
29990 +
29991 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29992 + mov pax_user_shadow_base,%rcx
29993 + cmp %rcx,%rsi
29994 + jae 1f
29995 + add %rcx,%rsi
29996 +1:
29997 +#endif
29998 +
29999 + ASM_PAX_OPEN_USERLAND
30000 ASM_STAC
30001 cmpl $8,%edx
30002 jb 20f /* less then 8 bytes, go to byte copy loop */
30003 @@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
30004 jnz 21b
30005 23: xorl %eax,%eax
30006 ASM_CLAC
30007 + ASM_PAX_CLOSE_USERLAND
30008 sfence
30009 + pax_force_retaddr
30010 ret
30011
30012 .section .fixup,"ax"
30013 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
30014 index 2419d5f..fe52d0e 100644
30015 --- a/arch/x86/lib/csum-copy_64.S
30016 +++ b/arch/x86/lib/csum-copy_64.S
30017 @@ -9,6 +9,7 @@
30018 #include <asm/dwarf2.h>
30019 #include <asm/errno.h>
30020 #include <asm/asm.h>
30021 +#include <asm/alternative-asm.h>
30022
30023 /*
30024 * Checksum copy with exception handling.
30025 @@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
30026 CFI_ADJUST_CFA_OFFSET 7*8
30027 movq %rbx, 2*8(%rsp)
30028 CFI_REL_OFFSET rbx, 2*8
30029 - movq %r12, 3*8(%rsp)
30030 - CFI_REL_OFFSET r12, 3*8
30031 + movq %r15, 3*8(%rsp)
30032 + CFI_REL_OFFSET r15, 3*8
30033 movq %r14, 4*8(%rsp)
30034 CFI_REL_OFFSET r14, 4*8
30035 movq %r13, 5*8(%rsp)
30036 @@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
30037 movl %edx, %ecx
30038
30039 xorl %r9d, %r9d
30040 - movq %rcx, %r12
30041 + movq %rcx, %r15
30042
30043 - shrq $6, %r12
30044 + shrq $6, %r15
30045 jz .Lhandle_tail /* < 64 */
30046
30047 clc
30048
30049 /* main loop. clear in 64 byte blocks */
30050 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
30051 - /* r11: temp3, rdx: temp4, r12 loopcnt */
30052 + /* r11: temp3, rdx: temp4, r15 loopcnt */
30053 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
30054 .p2align 4
30055 .Lloop:
30056 @@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
30057 adcq %r14, %rax
30058 adcq %r13, %rax
30059
30060 - decl %r12d
30061 + decl %r15d
30062
30063 dest
30064 movq %rbx, (%rsi)
30065 @@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
30066 .Lende:
30067 movq 2*8(%rsp), %rbx
30068 CFI_RESTORE rbx
30069 - movq 3*8(%rsp), %r12
30070 - CFI_RESTORE r12
30071 + movq 3*8(%rsp), %r15
30072 + CFI_RESTORE r15
30073 movq 4*8(%rsp), %r14
30074 CFI_RESTORE r14
30075 movq 5*8(%rsp), %r13
30076 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
30077 CFI_RESTORE rbp
30078 addq $7*8, %rsp
30079 CFI_ADJUST_CFA_OFFSET -7*8
30080 + pax_force_retaddr
30081 ret
30082 CFI_RESTORE_STATE
30083
30084 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
30085 index 1318f75..44c30fd 100644
30086 --- a/arch/x86/lib/csum-wrappers_64.c
30087 +++ b/arch/x86/lib/csum-wrappers_64.c
30088 @@ -52,10 +52,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
30089 len -= 2;
30090 }
30091 }
30092 + pax_open_userland();
30093 stac();
30094 - isum = csum_partial_copy_generic((__force const void *)src,
30095 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
30096 dst, len, isum, errp, NULL);
30097 clac();
30098 + pax_close_userland();
30099 if (unlikely(*errp))
30100 goto out_err;
30101
30102 @@ -109,10 +111,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
30103 }
30104
30105 *errp = 0;
30106 + pax_open_userland();
30107 stac();
30108 - ret = csum_partial_copy_generic(src, (void __force *)dst,
30109 + ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
30110 len, isum, NULL, errp);
30111 clac();
30112 + pax_close_userland();
30113 return ret;
30114 }
30115 EXPORT_SYMBOL(csum_partial_copy_to_user);
30116 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
30117 index a451235..1daa956 100644
30118 --- a/arch/x86/lib/getuser.S
30119 +++ b/arch/x86/lib/getuser.S
30120 @@ -33,17 +33,40 @@
30121 #include <asm/thread_info.h>
30122 #include <asm/asm.h>
30123 #include <asm/smap.h>
30124 +#include <asm/segment.h>
30125 +#include <asm/pgtable.h>
30126 +#include <asm/alternative-asm.h>
30127 +
30128 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30129 +#define __copyuser_seg gs;
30130 +#else
30131 +#define __copyuser_seg
30132 +#endif
30133
30134 .text
30135 ENTRY(__get_user_1)
30136 CFI_STARTPROC
30137 +
30138 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30139 GET_THREAD_INFO(%_ASM_DX)
30140 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30141 jae bad_get_user
30142 ASM_STAC
30143 -1: movzbl (%_ASM_AX),%edx
30144 +
30145 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30146 + mov pax_user_shadow_base,%_ASM_DX
30147 + cmp %_ASM_DX,%_ASM_AX
30148 + jae 1234f
30149 + add %_ASM_DX,%_ASM_AX
30150 +1234:
30151 +#endif
30152 +
30153 +#endif
30154 +
30155 +1: __copyuser_seg movzbl (%_ASM_AX),%edx
30156 xor %eax,%eax
30157 ASM_CLAC
30158 + pax_force_retaddr
30159 ret
30160 CFI_ENDPROC
30161 ENDPROC(__get_user_1)
30162 @@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
30163 ENTRY(__get_user_2)
30164 CFI_STARTPROC
30165 add $1,%_ASM_AX
30166 +
30167 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30168 jc bad_get_user
30169 GET_THREAD_INFO(%_ASM_DX)
30170 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30171 jae bad_get_user
30172 ASM_STAC
30173 -2: movzwl -1(%_ASM_AX),%edx
30174 +
30175 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30176 + mov pax_user_shadow_base,%_ASM_DX
30177 + cmp %_ASM_DX,%_ASM_AX
30178 + jae 1234f
30179 + add %_ASM_DX,%_ASM_AX
30180 +1234:
30181 +#endif
30182 +
30183 +#endif
30184 +
30185 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
30186 xor %eax,%eax
30187 ASM_CLAC
30188 + pax_force_retaddr
30189 ret
30190 CFI_ENDPROC
30191 ENDPROC(__get_user_2)
30192 @@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
30193 ENTRY(__get_user_4)
30194 CFI_STARTPROC
30195 add $3,%_ASM_AX
30196 +
30197 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30198 jc bad_get_user
30199 GET_THREAD_INFO(%_ASM_DX)
30200 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30201 jae bad_get_user
30202 ASM_STAC
30203 -3: movl -3(%_ASM_AX),%edx
30204 +
30205 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30206 + mov pax_user_shadow_base,%_ASM_DX
30207 + cmp %_ASM_DX,%_ASM_AX
30208 + jae 1234f
30209 + add %_ASM_DX,%_ASM_AX
30210 +1234:
30211 +#endif
30212 +
30213 +#endif
30214 +
30215 +3: __copyuser_seg movl -3(%_ASM_AX),%edx
30216 xor %eax,%eax
30217 ASM_CLAC
30218 + pax_force_retaddr
30219 ret
30220 CFI_ENDPROC
30221 ENDPROC(__get_user_4)
30222 @@ -86,10 +137,20 @@ ENTRY(__get_user_8)
30223 GET_THREAD_INFO(%_ASM_DX)
30224 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30225 jae bad_get_user
30226 +
30227 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30228 + mov pax_user_shadow_base,%_ASM_DX
30229 + cmp %_ASM_DX,%_ASM_AX
30230 + jae 1234f
30231 + add %_ASM_DX,%_ASM_AX
30232 +1234:
30233 +#endif
30234 +
30235 ASM_STAC
30236 4: movq -7(%_ASM_AX),%rdx
30237 xor %eax,%eax
30238 ASM_CLAC
30239 + pax_force_retaddr
30240 ret
30241 #else
30242 add $7,%_ASM_AX
30243 @@ -98,10 +159,11 @@ ENTRY(__get_user_8)
30244 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30245 jae bad_get_user_8
30246 ASM_STAC
30247 -4: movl -7(%_ASM_AX),%edx
30248 -5: movl -3(%_ASM_AX),%ecx
30249 +4: __copyuser_seg movl -7(%_ASM_AX),%edx
30250 +5: __copyuser_seg movl -3(%_ASM_AX),%ecx
30251 xor %eax,%eax
30252 ASM_CLAC
30253 + pax_force_retaddr
30254 ret
30255 #endif
30256 CFI_ENDPROC
30257 @@ -113,6 +175,7 @@ bad_get_user:
30258 xor %edx,%edx
30259 mov $(-EFAULT),%_ASM_AX
30260 ASM_CLAC
30261 + pax_force_retaddr
30262 ret
30263 CFI_ENDPROC
30264 END(bad_get_user)
30265 @@ -124,6 +187,7 @@ bad_get_user_8:
30266 xor %ecx,%ecx
30267 mov $(-EFAULT),%_ASM_AX
30268 ASM_CLAC
30269 + pax_force_retaddr
30270 ret
30271 CFI_ENDPROC
30272 END(bad_get_user_8)
30273 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
30274 index 54fcffe..7be149e 100644
30275 --- a/arch/x86/lib/insn.c
30276 +++ b/arch/x86/lib/insn.c
30277 @@ -20,8 +20,10 @@
30278
30279 #ifdef __KERNEL__
30280 #include <linux/string.h>
30281 +#include <asm/pgtable_types.h>
30282 #else
30283 #include <string.h>
30284 +#define ktla_ktva(addr) addr
30285 #endif
30286 #include <asm/inat.h>
30287 #include <asm/insn.h>
30288 @@ -53,8 +55,8 @@
30289 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
30290 {
30291 memset(insn, 0, sizeof(*insn));
30292 - insn->kaddr = kaddr;
30293 - insn->next_byte = kaddr;
30294 + insn->kaddr = ktla_ktva(kaddr);
30295 + insn->next_byte = ktla_ktva(kaddr);
30296 insn->x86_64 = x86_64 ? 1 : 0;
30297 insn->opnd_bytes = 4;
30298 if (x86_64)
30299 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
30300 index 05a95e7..326f2fa 100644
30301 --- a/arch/x86/lib/iomap_copy_64.S
30302 +++ b/arch/x86/lib/iomap_copy_64.S
30303 @@ -17,6 +17,7 @@
30304
30305 #include <linux/linkage.h>
30306 #include <asm/dwarf2.h>
30307 +#include <asm/alternative-asm.h>
30308
30309 /*
30310 * override generic version in lib/iomap_copy.c
30311 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
30312 CFI_STARTPROC
30313 movl %edx,%ecx
30314 rep movsd
30315 + pax_force_retaddr
30316 ret
30317 CFI_ENDPROC
30318 ENDPROC(__iowrite32_copy)
30319 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
30320 index 56313a3..0db417e 100644
30321 --- a/arch/x86/lib/memcpy_64.S
30322 +++ b/arch/x86/lib/memcpy_64.S
30323 @@ -24,7 +24,7 @@
30324 * This gets patched over the unrolled variant (below) via the
30325 * alternative instructions framework:
30326 */
30327 - .section .altinstr_replacement, "ax", @progbits
30328 + .section .altinstr_replacement, "a", @progbits
30329 .Lmemcpy_c:
30330 movq %rdi, %rax
30331 movq %rdx, %rcx
30332 @@ -33,6 +33,7 @@
30333 rep movsq
30334 movl %edx, %ecx
30335 rep movsb
30336 + pax_force_retaddr
30337 ret
30338 .Lmemcpy_e:
30339 .previous
30340 @@ -44,11 +45,12 @@
30341 * This gets patched over the unrolled variant (below) via the
30342 * alternative instructions framework:
30343 */
30344 - .section .altinstr_replacement, "ax", @progbits
30345 + .section .altinstr_replacement, "a", @progbits
30346 .Lmemcpy_c_e:
30347 movq %rdi, %rax
30348 movq %rdx, %rcx
30349 rep movsb
30350 + pax_force_retaddr
30351 ret
30352 .Lmemcpy_e_e:
30353 .previous
30354 @@ -136,6 +138,7 @@ ENTRY(memcpy)
30355 movq %r9, 1*8(%rdi)
30356 movq %r10, -2*8(%rdi, %rdx)
30357 movq %r11, -1*8(%rdi, %rdx)
30358 + pax_force_retaddr
30359 retq
30360 .p2align 4
30361 .Lless_16bytes:
30362 @@ -148,6 +151,7 @@ ENTRY(memcpy)
30363 movq -1*8(%rsi, %rdx), %r9
30364 movq %r8, 0*8(%rdi)
30365 movq %r9, -1*8(%rdi, %rdx)
30366 + pax_force_retaddr
30367 retq
30368 .p2align 4
30369 .Lless_8bytes:
30370 @@ -161,6 +165,7 @@ ENTRY(memcpy)
30371 movl -4(%rsi, %rdx), %r8d
30372 movl %ecx, (%rdi)
30373 movl %r8d, -4(%rdi, %rdx)
30374 + pax_force_retaddr
30375 retq
30376 .p2align 4
30377 .Lless_3bytes:
30378 @@ -179,6 +184,7 @@ ENTRY(memcpy)
30379 movb %cl, (%rdi)
30380
30381 .Lend:
30382 + pax_force_retaddr
30383 retq
30384 CFI_ENDPROC
30385 ENDPROC(memcpy)
30386 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
30387 index 65268a6..dd1de11 100644
30388 --- a/arch/x86/lib/memmove_64.S
30389 +++ b/arch/x86/lib/memmove_64.S
30390 @@ -202,14 +202,16 @@ ENTRY(memmove)
30391 movb (%rsi), %r11b
30392 movb %r11b, (%rdi)
30393 13:
30394 + pax_force_retaddr
30395 retq
30396 CFI_ENDPROC
30397
30398 - .section .altinstr_replacement,"ax"
30399 + .section .altinstr_replacement,"a"
30400 .Lmemmove_begin_forward_efs:
30401 /* Forward moving data. */
30402 movq %rdx, %rcx
30403 rep movsb
30404 + pax_force_retaddr
30405 retq
30406 .Lmemmove_end_forward_efs:
30407 .previous
30408 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
30409 index 2dcb380..2eb79fe 100644
30410 --- a/arch/x86/lib/memset_64.S
30411 +++ b/arch/x86/lib/memset_64.S
30412 @@ -16,7 +16,7 @@
30413 *
30414 * rax original destination
30415 */
30416 - .section .altinstr_replacement, "ax", @progbits
30417 + .section .altinstr_replacement, "a", @progbits
30418 .Lmemset_c:
30419 movq %rdi,%r9
30420 movq %rdx,%rcx
30421 @@ -30,6 +30,7 @@
30422 movl %edx,%ecx
30423 rep stosb
30424 movq %r9,%rax
30425 + pax_force_retaddr
30426 ret
30427 .Lmemset_e:
30428 .previous
30429 @@ -45,13 +46,14 @@
30430 *
30431 * rax original destination
30432 */
30433 - .section .altinstr_replacement, "ax", @progbits
30434 + .section .altinstr_replacement, "a", @progbits
30435 .Lmemset_c_e:
30436 movq %rdi,%r9
30437 movb %sil,%al
30438 movq %rdx,%rcx
30439 rep stosb
30440 movq %r9,%rax
30441 + pax_force_retaddr
30442 ret
30443 .Lmemset_e_e:
30444 .previous
30445 @@ -118,6 +120,7 @@ ENTRY(__memset)
30446
30447 .Lende:
30448 movq %r10,%rax
30449 + pax_force_retaddr
30450 ret
30451
30452 CFI_RESTORE_STATE
30453 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
30454 index c9f2d9b..e7fd2c0 100644
30455 --- a/arch/x86/lib/mmx_32.c
30456 +++ b/arch/x86/lib/mmx_32.c
30457 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30458 {
30459 void *p;
30460 int i;
30461 + unsigned long cr0;
30462
30463 if (unlikely(in_interrupt()))
30464 return __memcpy(to, from, len);
30465 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30466 kernel_fpu_begin();
30467
30468 __asm__ __volatile__ (
30469 - "1: prefetch (%0)\n" /* This set is 28 bytes */
30470 - " prefetch 64(%0)\n"
30471 - " prefetch 128(%0)\n"
30472 - " prefetch 192(%0)\n"
30473 - " prefetch 256(%0)\n"
30474 + "1: prefetch (%1)\n" /* This set is 28 bytes */
30475 + " prefetch 64(%1)\n"
30476 + " prefetch 128(%1)\n"
30477 + " prefetch 192(%1)\n"
30478 + " prefetch 256(%1)\n"
30479 "2: \n"
30480 ".section .fixup, \"ax\"\n"
30481 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30482 + "3: \n"
30483 +
30484 +#ifdef CONFIG_PAX_KERNEXEC
30485 + " movl %%cr0, %0\n"
30486 + " movl %0, %%eax\n"
30487 + " andl $0xFFFEFFFF, %%eax\n"
30488 + " movl %%eax, %%cr0\n"
30489 +#endif
30490 +
30491 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30492 +
30493 +#ifdef CONFIG_PAX_KERNEXEC
30494 + " movl %0, %%cr0\n"
30495 +#endif
30496 +
30497 " jmp 2b\n"
30498 ".previous\n"
30499 _ASM_EXTABLE(1b, 3b)
30500 - : : "r" (from));
30501 + : "=&r" (cr0) : "r" (from) : "ax");
30502
30503 for ( ; i > 5; i--) {
30504 __asm__ __volatile__ (
30505 - "1: prefetch 320(%0)\n"
30506 - "2: movq (%0), %%mm0\n"
30507 - " movq 8(%0), %%mm1\n"
30508 - " movq 16(%0), %%mm2\n"
30509 - " movq 24(%0), %%mm3\n"
30510 - " movq %%mm0, (%1)\n"
30511 - " movq %%mm1, 8(%1)\n"
30512 - " movq %%mm2, 16(%1)\n"
30513 - " movq %%mm3, 24(%1)\n"
30514 - " movq 32(%0), %%mm0\n"
30515 - " movq 40(%0), %%mm1\n"
30516 - " movq 48(%0), %%mm2\n"
30517 - " movq 56(%0), %%mm3\n"
30518 - " movq %%mm0, 32(%1)\n"
30519 - " movq %%mm1, 40(%1)\n"
30520 - " movq %%mm2, 48(%1)\n"
30521 - " movq %%mm3, 56(%1)\n"
30522 + "1: prefetch 320(%1)\n"
30523 + "2: movq (%1), %%mm0\n"
30524 + " movq 8(%1), %%mm1\n"
30525 + " movq 16(%1), %%mm2\n"
30526 + " movq 24(%1), %%mm3\n"
30527 + " movq %%mm0, (%2)\n"
30528 + " movq %%mm1, 8(%2)\n"
30529 + " movq %%mm2, 16(%2)\n"
30530 + " movq %%mm3, 24(%2)\n"
30531 + " movq 32(%1), %%mm0\n"
30532 + " movq 40(%1), %%mm1\n"
30533 + " movq 48(%1), %%mm2\n"
30534 + " movq 56(%1), %%mm3\n"
30535 + " movq %%mm0, 32(%2)\n"
30536 + " movq %%mm1, 40(%2)\n"
30537 + " movq %%mm2, 48(%2)\n"
30538 + " movq %%mm3, 56(%2)\n"
30539 ".section .fixup, \"ax\"\n"
30540 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30541 + "3:\n"
30542 +
30543 +#ifdef CONFIG_PAX_KERNEXEC
30544 + " movl %%cr0, %0\n"
30545 + " movl %0, %%eax\n"
30546 + " andl $0xFFFEFFFF, %%eax\n"
30547 + " movl %%eax, %%cr0\n"
30548 +#endif
30549 +
30550 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30551 +
30552 +#ifdef CONFIG_PAX_KERNEXEC
30553 + " movl %0, %%cr0\n"
30554 +#endif
30555 +
30556 " jmp 2b\n"
30557 ".previous\n"
30558 _ASM_EXTABLE(1b, 3b)
30559 - : : "r" (from), "r" (to) : "memory");
30560 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30561
30562 from += 64;
30563 to += 64;
30564 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
30565 static void fast_copy_page(void *to, void *from)
30566 {
30567 int i;
30568 + unsigned long cr0;
30569
30570 kernel_fpu_begin();
30571
30572 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
30573 * but that is for later. -AV
30574 */
30575 __asm__ __volatile__(
30576 - "1: prefetch (%0)\n"
30577 - " prefetch 64(%0)\n"
30578 - " prefetch 128(%0)\n"
30579 - " prefetch 192(%0)\n"
30580 - " prefetch 256(%0)\n"
30581 + "1: prefetch (%1)\n"
30582 + " prefetch 64(%1)\n"
30583 + " prefetch 128(%1)\n"
30584 + " prefetch 192(%1)\n"
30585 + " prefetch 256(%1)\n"
30586 "2: \n"
30587 ".section .fixup, \"ax\"\n"
30588 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30589 + "3: \n"
30590 +
30591 +#ifdef CONFIG_PAX_KERNEXEC
30592 + " movl %%cr0, %0\n"
30593 + " movl %0, %%eax\n"
30594 + " andl $0xFFFEFFFF, %%eax\n"
30595 + " movl %%eax, %%cr0\n"
30596 +#endif
30597 +
30598 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30599 +
30600 +#ifdef CONFIG_PAX_KERNEXEC
30601 + " movl %0, %%cr0\n"
30602 +#endif
30603 +
30604 " jmp 2b\n"
30605 ".previous\n"
30606 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30607 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30608
30609 for (i = 0; i < (4096-320)/64; i++) {
30610 __asm__ __volatile__ (
30611 - "1: prefetch 320(%0)\n"
30612 - "2: movq (%0), %%mm0\n"
30613 - " movntq %%mm0, (%1)\n"
30614 - " movq 8(%0), %%mm1\n"
30615 - " movntq %%mm1, 8(%1)\n"
30616 - " movq 16(%0), %%mm2\n"
30617 - " movntq %%mm2, 16(%1)\n"
30618 - " movq 24(%0), %%mm3\n"
30619 - " movntq %%mm3, 24(%1)\n"
30620 - " movq 32(%0), %%mm4\n"
30621 - " movntq %%mm4, 32(%1)\n"
30622 - " movq 40(%0), %%mm5\n"
30623 - " movntq %%mm5, 40(%1)\n"
30624 - " movq 48(%0), %%mm6\n"
30625 - " movntq %%mm6, 48(%1)\n"
30626 - " movq 56(%0), %%mm7\n"
30627 - " movntq %%mm7, 56(%1)\n"
30628 + "1: prefetch 320(%1)\n"
30629 + "2: movq (%1), %%mm0\n"
30630 + " movntq %%mm0, (%2)\n"
30631 + " movq 8(%1), %%mm1\n"
30632 + " movntq %%mm1, 8(%2)\n"
30633 + " movq 16(%1), %%mm2\n"
30634 + " movntq %%mm2, 16(%2)\n"
30635 + " movq 24(%1), %%mm3\n"
30636 + " movntq %%mm3, 24(%2)\n"
30637 + " movq 32(%1), %%mm4\n"
30638 + " movntq %%mm4, 32(%2)\n"
30639 + " movq 40(%1), %%mm5\n"
30640 + " movntq %%mm5, 40(%2)\n"
30641 + " movq 48(%1), %%mm6\n"
30642 + " movntq %%mm6, 48(%2)\n"
30643 + " movq 56(%1), %%mm7\n"
30644 + " movntq %%mm7, 56(%2)\n"
30645 ".section .fixup, \"ax\"\n"
30646 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30647 + "3:\n"
30648 +
30649 +#ifdef CONFIG_PAX_KERNEXEC
30650 + " movl %%cr0, %0\n"
30651 + " movl %0, %%eax\n"
30652 + " andl $0xFFFEFFFF, %%eax\n"
30653 + " movl %%eax, %%cr0\n"
30654 +#endif
30655 +
30656 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30657 +
30658 +#ifdef CONFIG_PAX_KERNEXEC
30659 + " movl %0, %%cr0\n"
30660 +#endif
30661 +
30662 " jmp 2b\n"
30663 ".previous\n"
30664 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30665 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30666
30667 from += 64;
30668 to += 64;
30669 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30670 static void fast_copy_page(void *to, void *from)
30671 {
30672 int i;
30673 + unsigned long cr0;
30674
30675 kernel_fpu_begin();
30676
30677 __asm__ __volatile__ (
30678 - "1: prefetch (%0)\n"
30679 - " prefetch 64(%0)\n"
30680 - " prefetch 128(%0)\n"
30681 - " prefetch 192(%0)\n"
30682 - " prefetch 256(%0)\n"
30683 + "1: prefetch (%1)\n"
30684 + " prefetch 64(%1)\n"
30685 + " prefetch 128(%1)\n"
30686 + " prefetch 192(%1)\n"
30687 + " prefetch 256(%1)\n"
30688 "2: \n"
30689 ".section .fixup, \"ax\"\n"
30690 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30691 + "3: \n"
30692 +
30693 +#ifdef CONFIG_PAX_KERNEXEC
30694 + " movl %%cr0, %0\n"
30695 + " movl %0, %%eax\n"
30696 + " andl $0xFFFEFFFF, %%eax\n"
30697 + " movl %%eax, %%cr0\n"
30698 +#endif
30699 +
30700 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30701 +
30702 +#ifdef CONFIG_PAX_KERNEXEC
30703 + " movl %0, %%cr0\n"
30704 +#endif
30705 +
30706 " jmp 2b\n"
30707 ".previous\n"
30708 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30709 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30710
30711 for (i = 0; i < 4096/64; i++) {
30712 __asm__ __volatile__ (
30713 - "1: prefetch 320(%0)\n"
30714 - "2: movq (%0), %%mm0\n"
30715 - " movq 8(%0), %%mm1\n"
30716 - " movq 16(%0), %%mm2\n"
30717 - " movq 24(%0), %%mm3\n"
30718 - " movq %%mm0, (%1)\n"
30719 - " movq %%mm1, 8(%1)\n"
30720 - " movq %%mm2, 16(%1)\n"
30721 - " movq %%mm3, 24(%1)\n"
30722 - " movq 32(%0), %%mm0\n"
30723 - " movq 40(%0), %%mm1\n"
30724 - " movq 48(%0), %%mm2\n"
30725 - " movq 56(%0), %%mm3\n"
30726 - " movq %%mm0, 32(%1)\n"
30727 - " movq %%mm1, 40(%1)\n"
30728 - " movq %%mm2, 48(%1)\n"
30729 - " movq %%mm3, 56(%1)\n"
30730 + "1: prefetch 320(%1)\n"
30731 + "2: movq (%1), %%mm0\n"
30732 + " movq 8(%1), %%mm1\n"
30733 + " movq 16(%1), %%mm2\n"
30734 + " movq 24(%1), %%mm3\n"
30735 + " movq %%mm0, (%2)\n"
30736 + " movq %%mm1, 8(%2)\n"
30737 + " movq %%mm2, 16(%2)\n"
30738 + " movq %%mm3, 24(%2)\n"
30739 + " movq 32(%1), %%mm0\n"
30740 + " movq 40(%1), %%mm1\n"
30741 + " movq 48(%1), %%mm2\n"
30742 + " movq 56(%1), %%mm3\n"
30743 + " movq %%mm0, 32(%2)\n"
30744 + " movq %%mm1, 40(%2)\n"
30745 + " movq %%mm2, 48(%2)\n"
30746 + " movq %%mm3, 56(%2)\n"
30747 ".section .fixup, \"ax\"\n"
30748 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30749 + "3:\n"
30750 +
30751 +#ifdef CONFIG_PAX_KERNEXEC
30752 + " movl %%cr0, %0\n"
30753 + " movl %0, %%eax\n"
30754 + " andl $0xFFFEFFFF, %%eax\n"
30755 + " movl %%eax, %%cr0\n"
30756 +#endif
30757 +
30758 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30759 +
30760 +#ifdef CONFIG_PAX_KERNEXEC
30761 + " movl %0, %%cr0\n"
30762 +#endif
30763 +
30764 " jmp 2b\n"
30765 ".previous\n"
30766 _ASM_EXTABLE(1b, 3b)
30767 - : : "r" (from), "r" (to) : "memory");
30768 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30769
30770 from += 64;
30771 to += 64;
30772 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30773 index f6d13ee..d789440 100644
30774 --- a/arch/x86/lib/msr-reg.S
30775 +++ b/arch/x86/lib/msr-reg.S
30776 @@ -3,6 +3,7 @@
30777 #include <asm/dwarf2.h>
30778 #include <asm/asm.h>
30779 #include <asm/msr.h>
30780 +#include <asm/alternative-asm.h>
30781
30782 #ifdef CONFIG_X86_64
30783 /*
30784 @@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30785 movl %edi, 28(%r10)
30786 popq_cfi %rbp
30787 popq_cfi %rbx
30788 + pax_force_retaddr
30789 ret
30790 3:
30791 CFI_RESTORE_STATE
30792 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30793 index fc6ba17..d4d989d 100644
30794 --- a/arch/x86/lib/putuser.S
30795 +++ b/arch/x86/lib/putuser.S
30796 @@ -16,7 +16,9 @@
30797 #include <asm/errno.h>
30798 #include <asm/asm.h>
30799 #include <asm/smap.h>
30800 -
30801 +#include <asm/segment.h>
30802 +#include <asm/pgtable.h>
30803 +#include <asm/alternative-asm.h>
30804
30805 /*
30806 * __put_user_X
30807 @@ -30,57 +32,125 @@
30808 * as they get called from within inline assembly.
30809 */
30810
30811 -#define ENTER CFI_STARTPROC ; \
30812 - GET_THREAD_INFO(%_ASM_BX)
30813 -#define EXIT ASM_CLAC ; \
30814 - ret ; \
30815 +#define ENTER CFI_STARTPROC
30816 +#define EXIT ASM_CLAC ; \
30817 + pax_force_retaddr ; \
30818 + ret ; \
30819 CFI_ENDPROC
30820
30821 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30822 +#define _DEST %_ASM_CX,%_ASM_BX
30823 +#else
30824 +#define _DEST %_ASM_CX
30825 +#endif
30826 +
30827 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30828 +#define __copyuser_seg gs;
30829 +#else
30830 +#define __copyuser_seg
30831 +#endif
30832 +
30833 .text
30834 ENTRY(__put_user_1)
30835 ENTER
30836 +
30837 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30838 + GET_THREAD_INFO(%_ASM_BX)
30839 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30840 jae bad_put_user
30841 ASM_STAC
30842 -1: movb %al,(%_ASM_CX)
30843 +
30844 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30845 + mov pax_user_shadow_base,%_ASM_BX
30846 + cmp %_ASM_BX,%_ASM_CX
30847 + jb 1234f
30848 + xor %ebx,%ebx
30849 +1234:
30850 +#endif
30851 +
30852 +#endif
30853 +
30854 +1: __copyuser_seg movb %al,(_DEST)
30855 xor %eax,%eax
30856 EXIT
30857 ENDPROC(__put_user_1)
30858
30859 ENTRY(__put_user_2)
30860 ENTER
30861 +
30862 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30863 + GET_THREAD_INFO(%_ASM_BX)
30864 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30865 sub $1,%_ASM_BX
30866 cmp %_ASM_BX,%_ASM_CX
30867 jae bad_put_user
30868 ASM_STAC
30869 -2: movw %ax,(%_ASM_CX)
30870 +
30871 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30872 + mov pax_user_shadow_base,%_ASM_BX
30873 + cmp %_ASM_BX,%_ASM_CX
30874 + jb 1234f
30875 + xor %ebx,%ebx
30876 +1234:
30877 +#endif
30878 +
30879 +#endif
30880 +
30881 +2: __copyuser_seg movw %ax,(_DEST)
30882 xor %eax,%eax
30883 EXIT
30884 ENDPROC(__put_user_2)
30885
30886 ENTRY(__put_user_4)
30887 ENTER
30888 +
30889 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30890 + GET_THREAD_INFO(%_ASM_BX)
30891 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30892 sub $3,%_ASM_BX
30893 cmp %_ASM_BX,%_ASM_CX
30894 jae bad_put_user
30895 ASM_STAC
30896 -3: movl %eax,(%_ASM_CX)
30897 +
30898 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30899 + mov pax_user_shadow_base,%_ASM_BX
30900 + cmp %_ASM_BX,%_ASM_CX
30901 + jb 1234f
30902 + xor %ebx,%ebx
30903 +1234:
30904 +#endif
30905 +
30906 +#endif
30907 +
30908 +3: __copyuser_seg movl %eax,(_DEST)
30909 xor %eax,%eax
30910 EXIT
30911 ENDPROC(__put_user_4)
30912
30913 ENTRY(__put_user_8)
30914 ENTER
30915 +
30916 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30917 + GET_THREAD_INFO(%_ASM_BX)
30918 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30919 sub $7,%_ASM_BX
30920 cmp %_ASM_BX,%_ASM_CX
30921 jae bad_put_user
30922 ASM_STAC
30923 -4: mov %_ASM_AX,(%_ASM_CX)
30924 +
30925 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30926 + mov pax_user_shadow_base,%_ASM_BX
30927 + cmp %_ASM_BX,%_ASM_CX
30928 + jb 1234f
30929 + xor %ebx,%ebx
30930 +1234:
30931 +#endif
30932 +
30933 +#endif
30934 +
30935 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
30936 #ifdef CONFIG_X86_32
30937 -5: movl %edx,4(%_ASM_CX)
30938 +5: __copyuser_seg movl %edx,4(_DEST)
30939 #endif
30940 xor %eax,%eax
30941 EXIT
30942 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30943 index 5dff5f0..cadebf4 100644
30944 --- a/arch/x86/lib/rwsem.S
30945 +++ b/arch/x86/lib/rwsem.S
30946 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30947 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30948 CFI_RESTORE __ASM_REG(dx)
30949 restore_common_regs
30950 + pax_force_retaddr
30951 ret
30952 CFI_ENDPROC
30953 ENDPROC(call_rwsem_down_read_failed)
30954 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30955 movq %rax,%rdi
30956 call rwsem_down_write_failed
30957 restore_common_regs
30958 + pax_force_retaddr
30959 ret
30960 CFI_ENDPROC
30961 ENDPROC(call_rwsem_down_write_failed)
30962 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30963 movq %rax,%rdi
30964 call rwsem_wake
30965 restore_common_regs
30966 -1: ret
30967 +1: pax_force_retaddr
30968 + ret
30969 CFI_ENDPROC
30970 ENDPROC(call_rwsem_wake)
30971
30972 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30973 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30974 CFI_RESTORE __ASM_REG(dx)
30975 restore_common_regs
30976 + pax_force_retaddr
30977 ret
30978 CFI_ENDPROC
30979 ENDPROC(call_rwsem_downgrade_wake)
30980 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30981 index b30b5eb..2b57052 100644
30982 --- a/arch/x86/lib/thunk_64.S
30983 +++ b/arch/x86/lib/thunk_64.S
30984 @@ -9,6 +9,7 @@
30985 #include <asm/dwarf2.h>
30986 #include <asm/calling.h>
30987 #include <asm/asm.h>
30988 +#include <asm/alternative-asm.h>
30989
30990 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
30991 .macro THUNK name, func, put_ret_addr_in_rdi=0
30992 @@ -16,11 +17,11 @@
30993 \name:
30994 CFI_STARTPROC
30995
30996 - /* this one pushes 9 elems, the next one would be %rIP */
30997 - SAVE_ARGS
30998 + /* this one pushes 15+1 elems, the next one would be %rIP */
30999 + SAVE_ARGS 8
31000
31001 .if \put_ret_addr_in_rdi
31002 - movq_cfi_restore 9*8, rdi
31003 + movq_cfi_restore RIP, rdi
31004 .endif
31005
31006 call \func
31007 @@ -47,9 +48,10 @@
31008
31009 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
31010 CFI_STARTPROC
31011 - SAVE_ARGS
31012 + SAVE_ARGS 8
31013 restore:
31014 - RESTORE_ARGS
31015 + RESTORE_ARGS 1,8
31016 + pax_force_retaddr
31017 ret
31018 CFI_ENDPROC
31019 _ASM_NOKPROBE(restore)
31020 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
31021 index e2f5e21..4b22130 100644
31022 --- a/arch/x86/lib/usercopy_32.c
31023 +++ b/arch/x86/lib/usercopy_32.c
31024 @@ -42,11 +42,13 @@ do { \
31025 int __d0; \
31026 might_fault(); \
31027 __asm__ __volatile__( \
31028 + __COPYUSER_SET_ES \
31029 ASM_STAC "\n" \
31030 "0: rep; stosl\n" \
31031 " movl %2,%0\n" \
31032 "1: rep; stosb\n" \
31033 "2: " ASM_CLAC "\n" \
31034 + __COPYUSER_RESTORE_ES \
31035 ".section .fixup,\"ax\"\n" \
31036 "3: lea 0(%2,%0,4),%0\n" \
31037 " jmp 2b\n" \
31038 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
31039
31040 #ifdef CONFIG_X86_INTEL_USERCOPY
31041 static unsigned long
31042 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
31043 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
31044 {
31045 int d0, d1;
31046 __asm__ __volatile__(
31047 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31048 " .align 2,0x90\n"
31049 "3: movl 0(%4), %%eax\n"
31050 "4: movl 4(%4), %%edx\n"
31051 - "5: movl %%eax, 0(%3)\n"
31052 - "6: movl %%edx, 4(%3)\n"
31053 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
31054 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
31055 "7: movl 8(%4), %%eax\n"
31056 "8: movl 12(%4),%%edx\n"
31057 - "9: movl %%eax, 8(%3)\n"
31058 - "10: movl %%edx, 12(%3)\n"
31059 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
31060 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
31061 "11: movl 16(%4), %%eax\n"
31062 "12: movl 20(%4), %%edx\n"
31063 - "13: movl %%eax, 16(%3)\n"
31064 - "14: movl %%edx, 20(%3)\n"
31065 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
31066 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
31067 "15: movl 24(%4), %%eax\n"
31068 "16: movl 28(%4), %%edx\n"
31069 - "17: movl %%eax, 24(%3)\n"
31070 - "18: movl %%edx, 28(%3)\n"
31071 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
31072 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
31073 "19: movl 32(%4), %%eax\n"
31074 "20: movl 36(%4), %%edx\n"
31075 - "21: movl %%eax, 32(%3)\n"
31076 - "22: movl %%edx, 36(%3)\n"
31077 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
31078 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
31079 "23: movl 40(%4), %%eax\n"
31080 "24: movl 44(%4), %%edx\n"
31081 - "25: movl %%eax, 40(%3)\n"
31082 - "26: movl %%edx, 44(%3)\n"
31083 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
31084 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
31085 "27: movl 48(%4), %%eax\n"
31086 "28: movl 52(%4), %%edx\n"
31087 - "29: movl %%eax, 48(%3)\n"
31088 - "30: movl %%edx, 52(%3)\n"
31089 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
31090 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
31091 "31: movl 56(%4), %%eax\n"
31092 "32: movl 60(%4), %%edx\n"
31093 - "33: movl %%eax, 56(%3)\n"
31094 - "34: movl %%edx, 60(%3)\n"
31095 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
31096 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
31097 " addl $-64, %0\n"
31098 " addl $64, %4\n"
31099 " addl $64, %3\n"
31100 @@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31101 " shrl $2, %0\n"
31102 " andl $3, %%eax\n"
31103 " cld\n"
31104 + __COPYUSER_SET_ES
31105 "99: rep; movsl\n"
31106 "36: movl %%eax, %0\n"
31107 "37: rep; movsb\n"
31108 "100:\n"
31109 + __COPYUSER_RESTORE_ES
31110 + ".section .fixup,\"ax\"\n"
31111 + "101: lea 0(%%eax,%0,4),%0\n"
31112 + " jmp 100b\n"
31113 + ".previous\n"
31114 + _ASM_EXTABLE(1b,100b)
31115 + _ASM_EXTABLE(2b,100b)
31116 + _ASM_EXTABLE(3b,100b)
31117 + _ASM_EXTABLE(4b,100b)
31118 + _ASM_EXTABLE(5b,100b)
31119 + _ASM_EXTABLE(6b,100b)
31120 + _ASM_EXTABLE(7b,100b)
31121 + _ASM_EXTABLE(8b,100b)
31122 + _ASM_EXTABLE(9b,100b)
31123 + _ASM_EXTABLE(10b,100b)
31124 + _ASM_EXTABLE(11b,100b)
31125 + _ASM_EXTABLE(12b,100b)
31126 + _ASM_EXTABLE(13b,100b)
31127 + _ASM_EXTABLE(14b,100b)
31128 + _ASM_EXTABLE(15b,100b)
31129 + _ASM_EXTABLE(16b,100b)
31130 + _ASM_EXTABLE(17b,100b)
31131 + _ASM_EXTABLE(18b,100b)
31132 + _ASM_EXTABLE(19b,100b)
31133 + _ASM_EXTABLE(20b,100b)
31134 + _ASM_EXTABLE(21b,100b)
31135 + _ASM_EXTABLE(22b,100b)
31136 + _ASM_EXTABLE(23b,100b)
31137 + _ASM_EXTABLE(24b,100b)
31138 + _ASM_EXTABLE(25b,100b)
31139 + _ASM_EXTABLE(26b,100b)
31140 + _ASM_EXTABLE(27b,100b)
31141 + _ASM_EXTABLE(28b,100b)
31142 + _ASM_EXTABLE(29b,100b)
31143 + _ASM_EXTABLE(30b,100b)
31144 + _ASM_EXTABLE(31b,100b)
31145 + _ASM_EXTABLE(32b,100b)
31146 + _ASM_EXTABLE(33b,100b)
31147 + _ASM_EXTABLE(34b,100b)
31148 + _ASM_EXTABLE(35b,100b)
31149 + _ASM_EXTABLE(36b,100b)
31150 + _ASM_EXTABLE(37b,100b)
31151 + _ASM_EXTABLE(99b,101b)
31152 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
31153 + : "1"(to), "2"(from), "0"(size)
31154 + : "eax", "edx", "memory");
31155 + return size;
31156 +}
31157 +
31158 +static unsigned long
31159 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
31160 +{
31161 + int d0, d1;
31162 + __asm__ __volatile__(
31163 + " .align 2,0x90\n"
31164 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
31165 + " cmpl $67, %0\n"
31166 + " jbe 3f\n"
31167 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
31168 + " .align 2,0x90\n"
31169 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
31170 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
31171 + "5: movl %%eax, 0(%3)\n"
31172 + "6: movl %%edx, 4(%3)\n"
31173 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
31174 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
31175 + "9: movl %%eax, 8(%3)\n"
31176 + "10: movl %%edx, 12(%3)\n"
31177 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
31178 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
31179 + "13: movl %%eax, 16(%3)\n"
31180 + "14: movl %%edx, 20(%3)\n"
31181 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
31182 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
31183 + "17: movl %%eax, 24(%3)\n"
31184 + "18: movl %%edx, 28(%3)\n"
31185 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
31186 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
31187 + "21: movl %%eax, 32(%3)\n"
31188 + "22: movl %%edx, 36(%3)\n"
31189 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
31190 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
31191 + "25: movl %%eax, 40(%3)\n"
31192 + "26: movl %%edx, 44(%3)\n"
31193 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
31194 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
31195 + "29: movl %%eax, 48(%3)\n"
31196 + "30: movl %%edx, 52(%3)\n"
31197 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
31198 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
31199 + "33: movl %%eax, 56(%3)\n"
31200 + "34: movl %%edx, 60(%3)\n"
31201 + " addl $-64, %0\n"
31202 + " addl $64, %4\n"
31203 + " addl $64, %3\n"
31204 + " cmpl $63, %0\n"
31205 + " ja 1b\n"
31206 + "35: movl %0, %%eax\n"
31207 + " shrl $2, %0\n"
31208 + " andl $3, %%eax\n"
31209 + " cld\n"
31210 + "99: rep; "__copyuser_seg" movsl\n"
31211 + "36: movl %%eax, %0\n"
31212 + "37: rep; "__copyuser_seg" movsb\n"
31213 + "100:\n"
31214 ".section .fixup,\"ax\"\n"
31215 "101: lea 0(%%eax,%0,4),%0\n"
31216 " jmp 100b\n"
31217 @@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31218 int d0, d1;
31219 __asm__ __volatile__(
31220 " .align 2,0x90\n"
31221 - "0: movl 32(%4), %%eax\n"
31222 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31223 " cmpl $67, %0\n"
31224 " jbe 2f\n"
31225 - "1: movl 64(%4), %%eax\n"
31226 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31227 " .align 2,0x90\n"
31228 - "2: movl 0(%4), %%eax\n"
31229 - "21: movl 4(%4), %%edx\n"
31230 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31231 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31232 " movl %%eax, 0(%3)\n"
31233 " movl %%edx, 4(%3)\n"
31234 - "3: movl 8(%4), %%eax\n"
31235 - "31: movl 12(%4),%%edx\n"
31236 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31237 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31238 " movl %%eax, 8(%3)\n"
31239 " movl %%edx, 12(%3)\n"
31240 - "4: movl 16(%4), %%eax\n"
31241 - "41: movl 20(%4), %%edx\n"
31242 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31243 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31244 " movl %%eax, 16(%3)\n"
31245 " movl %%edx, 20(%3)\n"
31246 - "10: movl 24(%4), %%eax\n"
31247 - "51: movl 28(%4), %%edx\n"
31248 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31249 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31250 " movl %%eax, 24(%3)\n"
31251 " movl %%edx, 28(%3)\n"
31252 - "11: movl 32(%4), %%eax\n"
31253 - "61: movl 36(%4), %%edx\n"
31254 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31255 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31256 " movl %%eax, 32(%3)\n"
31257 " movl %%edx, 36(%3)\n"
31258 - "12: movl 40(%4), %%eax\n"
31259 - "71: movl 44(%4), %%edx\n"
31260 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31261 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31262 " movl %%eax, 40(%3)\n"
31263 " movl %%edx, 44(%3)\n"
31264 - "13: movl 48(%4), %%eax\n"
31265 - "81: movl 52(%4), %%edx\n"
31266 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31267 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31268 " movl %%eax, 48(%3)\n"
31269 " movl %%edx, 52(%3)\n"
31270 - "14: movl 56(%4), %%eax\n"
31271 - "91: movl 60(%4), %%edx\n"
31272 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31273 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31274 " movl %%eax, 56(%3)\n"
31275 " movl %%edx, 60(%3)\n"
31276 " addl $-64, %0\n"
31277 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31278 " shrl $2, %0\n"
31279 " andl $3, %%eax\n"
31280 " cld\n"
31281 - "6: rep; movsl\n"
31282 + "6: rep; "__copyuser_seg" movsl\n"
31283 " movl %%eax,%0\n"
31284 - "7: rep; movsb\n"
31285 + "7: rep; "__copyuser_seg" movsb\n"
31286 "8:\n"
31287 ".section .fixup,\"ax\"\n"
31288 "9: lea 0(%%eax,%0,4),%0\n"
31289 @@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31290
31291 __asm__ __volatile__(
31292 " .align 2,0x90\n"
31293 - "0: movl 32(%4), %%eax\n"
31294 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31295 " cmpl $67, %0\n"
31296 " jbe 2f\n"
31297 - "1: movl 64(%4), %%eax\n"
31298 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31299 " .align 2,0x90\n"
31300 - "2: movl 0(%4), %%eax\n"
31301 - "21: movl 4(%4), %%edx\n"
31302 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31303 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31304 " movnti %%eax, 0(%3)\n"
31305 " movnti %%edx, 4(%3)\n"
31306 - "3: movl 8(%4), %%eax\n"
31307 - "31: movl 12(%4),%%edx\n"
31308 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31309 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31310 " movnti %%eax, 8(%3)\n"
31311 " movnti %%edx, 12(%3)\n"
31312 - "4: movl 16(%4), %%eax\n"
31313 - "41: movl 20(%4), %%edx\n"
31314 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31315 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31316 " movnti %%eax, 16(%3)\n"
31317 " movnti %%edx, 20(%3)\n"
31318 - "10: movl 24(%4), %%eax\n"
31319 - "51: movl 28(%4), %%edx\n"
31320 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31321 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31322 " movnti %%eax, 24(%3)\n"
31323 " movnti %%edx, 28(%3)\n"
31324 - "11: movl 32(%4), %%eax\n"
31325 - "61: movl 36(%4), %%edx\n"
31326 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31327 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31328 " movnti %%eax, 32(%3)\n"
31329 " movnti %%edx, 36(%3)\n"
31330 - "12: movl 40(%4), %%eax\n"
31331 - "71: movl 44(%4), %%edx\n"
31332 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31333 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31334 " movnti %%eax, 40(%3)\n"
31335 " movnti %%edx, 44(%3)\n"
31336 - "13: movl 48(%4), %%eax\n"
31337 - "81: movl 52(%4), %%edx\n"
31338 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31339 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31340 " movnti %%eax, 48(%3)\n"
31341 " movnti %%edx, 52(%3)\n"
31342 - "14: movl 56(%4), %%eax\n"
31343 - "91: movl 60(%4), %%edx\n"
31344 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31345 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31346 " movnti %%eax, 56(%3)\n"
31347 " movnti %%edx, 60(%3)\n"
31348 " addl $-64, %0\n"
31349 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31350 " shrl $2, %0\n"
31351 " andl $3, %%eax\n"
31352 " cld\n"
31353 - "6: rep; movsl\n"
31354 + "6: rep; "__copyuser_seg" movsl\n"
31355 " movl %%eax,%0\n"
31356 - "7: rep; movsb\n"
31357 + "7: rep; "__copyuser_seg" movsb\n"
31358 "8:\n"
31359 ".section .fixup,\"ax\"\n"
31360 "9: lea 0(%%eax,%0,4),%0\n"
31361 @@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
31362
31363 __asm__ __volatile__(
31364 " .align 2,0x90\n"
31365 - "0: movl 32(%4), %%eax\n"
31366 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31367 " cmpl $67, %0\n"
31368 " jbe 2f\n"
31369 - "1: movl 64(%4), %%eax\n"
31370 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31371 " .align 2,0x90\n"
31372 - "2: movl 0(%4), %%eax\n"
31373 - "21: movl 4(%4), %%edx\n"
31374 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31375 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31376 " movnti %%eax, 0(%3)\n"
31377 " movnti %%edx, 4(%3)\n"
31378 - "3: movl 8(%4), %%eax\n"
31379 - "31: movl 12(%4),%%edx\n"
31380 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31381 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31382 " movnti %%eax, 8(%3)\n"
31383 " movnti %%edx, 12(%3)\n"
31384 - "4: movl 16(%4), %%eax\n"
31385 - "41: movl 20(%4), %%edx\n"
31386 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31387 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31388 " movnti %%eax, 16(%3)\n"
31389 " movnti %%edx, 20(%3)\n"
31390 - "10: movl 24(%4), %%eax\n"
31391 - "51: movl 28(%4), %%edx\n"
31392 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31393 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31394 " movnti %%eax, 24(%3)\n"
31395 " movnti %%edx, 28(%3)\n"
31396 - "11: movl 32(%4), %%eax\n"
31397 - "61: movl 36(%4), %%edx\n"
31398 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31399 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31400 " movnti %%eax, 32(%3)\n"
31401 " movnti %%edx, 36(%3)\n"
31402 - "12: movl 40(%4), %%eax\n"
31403 - "71: movl 44(%4), %%edx\n"
31404 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31405 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31406 " movnti %%eax, 40(%3)\n"
31407 " movnti %%edx, 44(%3)\n"
31408 - "13: movl 48(%4), %%eax\n"
31409 - "81: movl 52(%4), %%edx\n"
31410 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31411 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31412 " movnti %%eax, 48(%3)\n"
31413 " movnti %%edx, 52(%3)\n"
31414 - "14: movl 56(%4), %%eax\n"
31415 - "91: movl 60(%4), %%edx\n"
31416 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31417 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31418 " movnti %%eax, 56(%3)\n"
31419 " movnti %%edx, 60(%3)\n"
31420 " addl $-64, %0\n"
31421 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
31422 " shrl $2, %0\n"
31423 " andl $3, %%eax\n"
31424 " cld\n"
31425 - "6: rep; movsl\n"
31426 + "6: rep; "__copyuser_seg" movsl\n"
31427 " movl %%eax,%0\n"
31428 - "7: rep; movsb\n"
31429 + "7: rep; "__copyuser_seg" movsb\n"
31430 "8:\n"
31431 ".section .fixup,\"ax\"\n"
31432 "9: lea 0(%%eax,%0,4),%0\n"
31433 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
31434 */
31435 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
31436 unsigned long size);
31437 -unsigned long __copy_user_intel(void __user *to, const void *from,
31438 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
31439 + unsigned long size);
31440 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
31441 unsigned long size);
31442 unsigned long __copy_user_zeroing_intel_nocache(void *to,
31443 const void __user *from, unsigned long size);
31444 #endif /* CONFIG_X86_INTEL_USERCOPY */
31445
31446 /* Generic arbitrary sized copy. */
31447 -#define __copy_user(to, from, size) \
31448 +#define __copy_user(to, from, size, prefix, set, restore) \
31449 do { \
31450 int __d0, __d1, __d2; \
31451 __asm__ __volatile__( \
31452 + set \
31453 " cmp $7,%0\n" \
31454 " jbe 1f\n" \
31455 " movl %1,%0\n" \
31456 " negl %0\n" \
31457 " andl $7,%0\n" \
31458 " subl %0,%3\n" \
31459 - "4: rep; movsb\n" \
31460 + "4: rep; "prefix"movsb\n" \
31461 " movl %3,%0\n" \
31462 " shrl $2,%0\n" \
31463 " andl $3,%3\n" \
31464 " .align 2,0x90\n" \
31465 - "0: rep; movsl\n" \
31466 + "0: rep; "prefix"movsl\n" \
31467 " movl %3,%0\n" \
31468 - "1: rep; movsb\n" \
31469 + "1: rep; "prefix"movsb\n" \
31470 "2:\n" \
31471 + restore \
31472 ".section .fixup,\"ax\"\n" \
31473 "5: addl %3,%0\n" \
31474 " jmp 2b\n" \
31475 @@ -538,14 +650,14 @@ do { \
31476 " negl %0\n" \
31477 " andl $7,%0\n" \
31478 " subl %0,%3\n" \
31479 - "4: rep; movsb\n" \
31480 + "4: rep; "__copyuser_seg"movsb\n" \
31481 " movl %3,%0\n" \
31482 " shrl $2,%0\n" \
31483 " andl $3,%3\n" \
31484 " .align 2,0x90\n" \
31485 - "0: rep; movsl\n" \
31486 + "0: rep; "__copyuser_seg"movsl\n" \
31487 " movl %3,%0\n" \
31488 - "1: rep; movsb\n" \
31489 + "1: rep; "__copyuser_seg"movsb\n" \
31490 "2:\n" \
31491 ".section .fixup,\"ax\"\n" \
31492 "5: addl %3,%0\n" \
31493 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
31494 {
31495 stac();
31496 if (movsl_is_ok(to, from, n))
31497 - __copy_user(to, from, n);
31498 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
31499 else
31500 - n = __copy_user_intel(to, from, n);
31501 + n = __generic_copy_to_user_intel(to, from, n);
31502 clac();
31503 return n;
31504 }
31505 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
31506 {
31507 stac();
31508 if (movsl_is_ok(to, from, n))
31509 - __copy_user(to, from, n);
31510 + __copy_user(to, from, n, __copyuser_seg, "", "");
31511 else
31512 - n = __copy_user_intel((void __user *)to,
31513 - (const void *)from, n);
31514 + n = __generic_copy_from_user_intel(to, from, n);
31515 clac();
31516 return n;
31517 }
31518 @@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
31519 if (n > 64 && cpu_has_xmm2)
31520 n = __copy_user_intel_nocache(to, from, n);
31521 else
31522 - __copy_user(to, from, n);
31523 + __copy_user(to, from, n, __copyuser_seg, "", "");
31524 #else
31525 - __copy_user(to, from, n);
31526 + __copy_user(to, from, n, __copyuser_seg, "", "");
31527 #endif
31528 clac();
31529 return n;
31530 }
31531 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31532
31533 -/**
31534 - * copy_to_user: - Copy a block of data into user space.
31535 - * @to: Destination address, in user space.
31536 - * @from: Source address, in kernel space.
31537 - * @n: Number of bytes to copy.
31538 - *
31539 - * Context: User context only. This function may sleep.
31540 - *
31541 - * Copy data from kernel space to user space.
31542 - *
31543 - * Returns number of bytes that could not be copied.
31544 - * On success, this will be zero.
31545 - */
31546 -unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31547 +#ifdef CONFIG_PAX_MEMORY_UDEREF
31548 +void __set_fs(mm_segment_t x)
31549 {
31550 - if (access_ok(VERIFY_WRITE, to, n))
31551 - n = __copy_to_user(to, from, n);
31552 - return n;
31553 + switch (x.seg) {
31554 + case 0:
31555 + loadsegment(gs, 0);
31556 + break;
31557 + case TASK_SIZE_MAX:
31558 + loadsegment(gs, __USER_DS);
31559 + break;
31560 + case -1UL:
31561 + loadsegment(gs, __KERNEL_DS);
31562 + break;
31563 + default:
31564 + BUG();
31565 + }
31566 }
31567 -EXPORT_SYMBOL(_copy_to_user);
31568 +EXPORT_SYMBOL(__set_fs);
31569
31570 -/**
31571 - * copy_from_user: - Copy a block of data from user space.
31572 - * @to: Destination address, in kernel space.
31573 - * @from: Source address, in user space.
31574 - * @n: Number of bytes to copy.
31575 - *
31576 - * Context: User context only. This function may sleep.
31577 - *
31578 - * Copy data from user space to kernel space.
31579 - *
31580 - * Returns number of bytes that could not be copied.
31581 - * On success, this will be zero.
31582 - *
31583 - * If some data could not be copied, this function will pad the copied
31584 - * data to the requested size using zero bytes.
31585 - */
31586 -unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31587 +void set_fs(mm_segment_t x)
31588 {
31589 - if (access_ok(VERIFY_READ, from, n))
31590 - n = __copy_from_user(to, from, n);
31591 - else
31592 - memset(to, 0, n);
31593 - return n;
31594 + current_thread_info()->addr_limit = x;
31595 + __set_fs(x);
31596 }
31597 -EXPORT_SYMBOL(_copy_from_user);
31598 +EXPORT_SYMBOL(set_fs);
31599 +#endif
31600 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31601 index c905e89..01ab928 100644
31602 --- a/arch/x86/lib/usercopy_64.c
31603 +++ b/arch/x86/lib/usercopy_64.c
31604 @@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31605 might_fault();
31606 /* no memory constraint because it doesn't change any memory gcc knows
31607 about */
31608 + pax_open_userland();
31609 stac();
31610 asm volatile(
31611 " testq %[size8],%[size8]\n"
31612 @@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31613 _ASM_EXTABLE(0b,3b)
31614 _ASM_EXTABLE(1b,2b)
31615 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31616 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31617 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31618 [zero] "r" (0UL), [eight] "r" (8UL));
31619 clac();
31620 + pax_close_userland();
31621 return size;
31622 }
31623 EXPORT_SYMBOL(__clear_user);
31624 @@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31625 }
31626 EXPORT_SYMBOL(clear_user);
31627
31628 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31629 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31630 {
31631 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31632 - return copy_user_generic((__force void *)to, (__force void *)from, len);
31633 - }
31634 - return len;
31635 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31636 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31637 + return len;
31638 }
31639 EXPORT_SYMBOL(copy_in_user);
31640
31641 @@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31642 * it is not necessary to optimize tail handling.
31643 */
31644 __visible unsigned long
31645 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31646 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31647 {
31648 char c;
31649 unsigned zero_len;
31650
31651 + clac();
31652 + pax_close_userland();
31653 for (; len; --len, to++) {
31654 if (__get_user_nocheck(c, from++, sizeof(char)))
31655 break;
31656 @@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31657 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31658 if (__put_user_nocheck(c, to++, sizeof(char)))
31659 break;
31660 - clac();
31661 return len;
31662 }
31663 diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31664 index 6a19ad9..1c48f9a 100644
31665 --- a/arch/x86/mm/Makefile
31666 +++ b/arch/x86/mm/Makefile
31667 @@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31668 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31669
31670 obj-$(CONFIG_MEMTEST) += memtest.o
31671 +
31672 +quote:="
31673 +obj-$(CONFIG_X86_64) += uderef_64.o
31674 +CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31675 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31676 index 903ec1e..c4166b2 100644
31677 --- a/arch/x86/mm/extable.c
31678 +++ b/arch/x86/mm/extable.c
31679 @@ -6,12 +6,24 @@
31680 static inline unsigned long
31681 ex_insn_addr(const struct exception_table_entry *x)
31682 {
31683 - return (unsigned long)&x->insn + x->insn;
31684 + unsigned long reloc = 0;
31685 +
31686 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31687 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31688 +#endif
31689 +
31690 + return (unsigned long)&x->insn + x->insn + reloc;
31691 }
31692 static inline unsigned long
31693 ex_fixup_addr(const struct exception_table_entry *x)
31694 {
31695 - return (unsigned long)&x->fixup + x->fixup;
31696 + unsigned long reloc = 0;
31697 +
31698 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31699 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31700 +#endif
31701 +
31702 + return (unsigned long)&x->fixup + x->fixup + reloc;
31703 }
31704
31705 int fixup_exception(struct pt_regs *regs)
31706 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31707 unsigned long new_ip;
31708
31709 #ifdef CONFIG_PNPBIOS
31710 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31711 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31712 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31713 extern u32 pnp_bios_is_utter_crap;
31714 pnp_bios_is_utter_crap = 1;
31715 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31716 i += 4;
31717 p->fixup -= i;
31718 i += 4;
31719 +
31720 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31721 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31722 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31723 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31724 +#endif
31725 +
31726 }
31727 }
31728
31729 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31730 index d973e61..fb868e9 100644
31731 --- a/arch/x86/mm/fault.c
31732 +++ b/arch/x86/mm/fault.c
31733 @@ -13,12 +13,19 @@
31734 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31735 #include <linux/prefetch.h> /* prefetchw */
31736 #include <linux/context_tracking.h> /* exception_enter(), ... */
31737 +#include <linux/unistd.h>
31738 +#include <linux/compiler.h>
31739
31740 #include <asm/traps.h> /* dotraplinkage, ... */
31741 #include <asm/pgalloc.h> /* pgd_*(), ... */
31742 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31743 #include <asm/fixmap.h> /* VSYSCALL_ADDR */
31744 #include <asm/vsyscall.h> /* emulate_vsyscall */
31745 +#include <asm/tlbflush.h>
31746 +
31747 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31748 +#include <asm/stacktrace.h>
31749 +#endif
31750
31751 #define CREATE_TRACE_POINTS
31752 #include <asm/trace/exceptions.h>
31753 @@ -59,7 +66,7 @@ static nokprobe_inline int kprobes_fault(struct pt_regs *regs)
31754 int ret = 0;
31755
31756 /* kprobe_running() needs smp_processor_id() */
31757 - if (kprobes_built_in() && !user_mode_vm(regs)) {
31758 + if (kprobes_built_in() && !user_mode(regs)) {
31759 preempt_disable();
31760 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31761 ret = 1;
31762 @@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31763 return !instr_lo || (instr_lo>>1) == 1;
31764 case 0x00:
31765 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31766 - if (probe_kernel_address(instr, opcode))
31767 + if (user_mode(regs)) {
31768 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31769 + return 0;
31770 + } else if (probe_kernel_address(instr, opcode))
31771 return 0;
31772
31773 *prefetch = (instr_lo == 0xF) &&
31774 @@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31775 while (instr < max_instr) {
31776 unsigned char opcode;
31777
31778 - if (probe_kernel_address(instr, opcode))
31779 + if (user_mode(regs)) {
31780 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31781 + break;
31782 + } else if (probe_kernel_address(instr, opcode))
31783 break;
31784
31785 instr++;
31786 @@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31787 force_sig_info(si_signo, &info, tsk);
31788 }
31789
31790 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31791 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31792 +#endif
31793 +
31794 +#ifdef CONFIG_PAX_EMUTRAMP
31795 +static int pax_handle_fetch_fault(struct pt_regs *regs);
31796 +#endif
31797 +
31798 +#ifdef CONFIG_PAX_PAGEEXEC
31799 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31800 +{
31801 + pgd_t *pgd;
31802 + pud_t *pud;
31803 + pmd_t *pmd;
31804 +
31805 + pgd = pgd_offset(mm, address);
31806 + if (!pgd_present(*pgd))
31807 + return NULL;
31808 + pud = pud_offset(pgd, address);
31809 + if (!pud_present(*pud))
31810 + return NULL;
31811 + pmd = pmd_offset(pud, address);
31812 + if (!pmd_present(*pmd))
31813 + return NULL;
31814 + return pmd;
31815 +}
31816 +#endif
31817 +
31818 DEFINE_SPINLOCK(pgd_lock);
31819 LIST_HEAD(pgd_list);
31820
31821 @@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31822 for (address = VMALLOC_START & PMD_MASK;
31823 address >= TASK_SIZE && address < FIXADDR_TOP;
31824 address += PMD_SIZE) {
31825 +
31826 +#ifdef CONFIG_PAX_PER_CPU_PGD
31827 + unsigned long cpu;
31828 +#else
31829 struct page *page;
31830 +#endif
31831
31832 spin_lock(&pgd_lock);
31833 +
31834 +#ifdef CONFIG_PAX_PER_CPU_PGD
31835 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31836 + pgd_t *pgd = get_cpu_pgd(cpu, user);
31837 + pmd_t *ret;
31838 +
31839 + ret = vmalloc_sync_one(pgd, address);
31840 + if (!ret)
31841 + break;
31842 + pgd = get_cpu_pgd(cpu, kernel);
31843 +#else
31844 list_for_each_entry(page, &pgd_list, lru) {
31845 + pgd_t *pgd;
31846 spinlock_t *pgt_lock;
31847 pmd_t *ret;
31848
31849 @@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31850 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31851
31852 spin_lock(pgt_lock);
31853 - ret = vmalloc_sync_one(page_address(page), address);
31854 + pgd = page_address(page);
31855 +#endif
31856 +
31857 + ret = vmalloc_sync_one(pgd, address);
31858 +
31859 +#ifndef CONFIG_PAX_PER_CPU_PGD
31860 spin_unlock(pgt_lock);
31861 +#endif
31862
31863 if (!ret)
31864 break;
31865 @@ -281,6 +345,12 @@ static noinline int vmalloc_fault(unsigned long address)
31866 * an interrupt in the middle of a task switch..
31867 */
31868 pgd_paddr = read_cr3();
31869 +
31870 +#ifdef CONFIG_PAX_PER_CPU_PGD
31871 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31872 + vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31873 +#endif
31874 +
31875 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31876 if (!pmd_k)
31877 return -1;
31878 @@ -377,11 +447,25 @@ static noinline int vmalloc_fault(unsigned long address)
31879 * happen within a race in page table update. In the later
31880 * case just flush:
31881 */
31882 - pgd = pgd_offset(current->active_mm, address);
31883 +
31884 pgd_ref = pgd_offset_k(address);
31885 if (pgd_none(*pgd_ref))
31886 return -1;
31887
31888 +#ifdef CONFIG_PAX_PER_CPU_PGD
31889 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31890 + pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31891 + if (pgd_none(*pgd)) {
31892 + set_pgd(pgd, *pgd_ref);
31893 + arch_flush_lazy_mmu_mode();
31894 + } else {
31895 + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31896 + }
31897 + pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31898 +#else
31899 + pgd = pgd_offset(current->active_mm, address);
31900 +#endif
31901 +
31902 if (pgd_none(*pgd)) {
31903 set_pgd(pgd, *pgd_ref);
31904 arch_flush_lazy_mmu_mode();
31905 @@ -548,7 +632,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31906 static int is_errata100(struct pt_regs *regs, unsigned long address)
31907 {
31908 #ifdef CONFIG_X86_64
31909 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31910 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31911 return 1;
31912 #endif
31913 return 0;
31914 @@ -575,9 +659,9 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31915 }
31916
31917 static const char nx_warning[] = KERN_CRIT
31918 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31919 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31920 static const char smep_warning[] = KERN_CRIT
31921 -"unable to execute userspace code (SMEP?) (uid: %d)\n";
31922 +"unable to execute userspace code (SMEP?) (uid: %d, task: %s, pid: %d)\n";
31923
31924 static void
31925 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31926 @@ -586,7 +670,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31927 if (!oops_may_print())
31928 return;
31929
31930 - if (error_code & PF_INSTR) {
31931 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31932 unsigned int level;
31933 pgd_t *pgd;
31934 pte_t *pte;
31935 @@ -597,13 +681,25 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31936 pte = lookup_address_in_pgd(pgd, address, &level);
31937
31938 if (pte && pte_present(*pte) && !pte_exec(*pte))
31939 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31940 + printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31941 if (pte && pte_present(*pte) && pte_exec(*pte) &&
31942 (pgd_flags(*pgd) & _PAGE_USER) &&
31943 (read_cr4() & X86_CR4_SMEP))
31944 - printk(smep_warning, from_kuid(&init_user_ns, current_uid()));
31945 + printk(smep_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31946 }
31947
31948 +#ifdef CONFIG_PAX_KERNEXEC
31949 + if (init_mm.start_code <= address && address < init_mm.end_code) {
31950 + if (current->signal->curr_ip)
31951 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31952 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
31953 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31954 + else
31955 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31956 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31957 + }
31958 +#endif
31959 +
31960 printk(KERN_ALERT "BUG: unable to handle kernel ");
31961 if (address < PAGE_SIZE)
31962 printk(KERN_CONT "NULL pointer dereference");
31963 @@ -782,6 +878,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31964 return;
31965 }
31966 #endif
31967 +
31968 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31969 + if (pax_is_fetch_fault(regs, error_code, address)) {
31970 +
31971 +#ifdef CONFIG_PAX_EMUTRAMP
31972 + switch (pax_handle_fetch_fault(regs)) {
31973 + case 2:
31974 + return;
31975 + }
31976 +#endif
31977 +
31978 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31979 + do_group_exit(SIGKILL);
31980 + }
31981 +#endif
31982 +
31983 /* Kernel addresses are always protection faults: */
31984 if (address >= TASK_SIZE)
31985 error_code |= PF_PROT;
31986 @@ -867,7 +979,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
31987 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
31988 printk(KERN_ERR
31989 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
31990 - tsk->comm, tsk->pid, address);
31991 + tsk->comm, task_pid_nr(tsk), address);
31992 code = BUS_MCEERR_AR;
31993 }
31994 #endif
31995 @@ -921,6 +1033,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
31996 return 1;
31997 }
31998
31999 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32000 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
32001 +{
32002 + pte_t *pte;
32003 + pmd_t *pmd;
32004 + spinlock_t *ptl;
32005 + unsigned char pte_mask;
32006 +
32007 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
32008 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
32009 + return 0;
32010 +
32011 + /* PaX: it's our fault, let's handle it if we can */
32012 +
32013 + /* PaX: take a look at read faults before acquiring any locks */
32014 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
32015 + /* instruction fetch attempt from a protected page in user mode */
32016 + up_read(&mm->mmap_sem);
32017 +
32018 +#ifdef CONFIG_PAX_EMUTRAMP
32019 + switch (pax_handle_fetch_fault(regs)) {
32020 + case 2:
32021 + return 1;
32022 + }
32023 +#endif
32024 +
32025 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32026 + do_group_exit(SIGKILL);
32027 + }
32028 +
32029 + pmd = pax_get_pmd(mm, address);
32030 + if (unlikely(!pmd))
32031 + return 0;
32032 +
32033 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
32034 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
32035 + pte_unmap_unlock(pte, ptl);
32036 + return 0;
32037 + }
32038 +
32039 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
32040 + /* write attempt to a protected page in user mode */
32041 + pte_unmap_unlock(pte, ptl);
32042 + return 0;
32043 + }
32044 +
32045 +#ifdef CONFIG_SMP
32046 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
32047 +#else
32048 + if (likely(address > get_limit(regs->cs)))
32049 +#endif
32050 + {
32051 + set_pte(pte, pte_mkread(*pte));
32052 + __flush_tlb_one(address);
32053 + pte_unmap_unlock(pte, ptl);
32054 + up_read(&mm->mmap_sem);
32055 + return 1;
32056 + }
32057 +
32058 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
32059 +
32060 + /*
32061 + * PaX: fill DTLB with user rights and retry
32062 + */
32063 + __asm__ __volatile__ (
32064 + "orb %2,(%1)\n"
32065 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
32066 +/*
32067 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
32068 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
32069 + * page fault when examined during a TLB load attempt. this is true not only
32070 + * for PTEs holding a non-present entry but also present entries that will
32071 + * raise a page fault (such as those set up by PaX, or the copy-on-write
32072 + * mechanism). in effect it means that we do *not* need to flush the TLBs
32073 + * for our target pages since their PTEs are simply not in the TLBs at all.
32074 +
32075 + * the best thing in omitting it is that we gain around 15-20% speed in the
32076 + * fast path of the page fault handler and can get rid of tracing since we
32077 + * can no longer flush unintended entries.
32078 + */
32079 + "invlpg (%0)\n"
32080 +#endif
32081 + __copyuser_seg"testb $0,(%0)\n"
32082 + "xorb %3,(%1)\n"
32083 + :
32084 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
32085 + : "memory", "cc");
32086 + pte_unmap_unlock(pte, ptl);
32087 + up_read(&mm->mmap_sem);
32088 + return 1;
32089 +}
32090 +#endif
32091 +
32092 /*
32093 * Handle a spurious fault caused by a stale TLB entry.
32094 *
32095 @@ -1006,6 +1211,9 @@ int show_unhandled_signals = 1;
32096 static inline int
32097 access_error(unsigned long error_code, struct vm_area_struct *vma)
32098 {
32099 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
32100 + return 1;
32101 +
32102 if (error_code & PF_WRITE) {
32103 /* write, present and write, not present: */
32104 if (unlikely(!(vma->vm_flags & VM_WRITE)))
32105 @@ -1040,7 +1248,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
32106 if (error_code & PF_USER)
32107 return false;
32108
32109 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
32110 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
32111 return false;
32112
32113 return true;
32114 @@ -1068,6 +1276,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32115 tsk = current;
32116 mm = tsk->mm;
32117
32118 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32119 + if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
32120 + if (!search_exception_tables(regs->ip)) {
32121 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32122 + bad_area_nosemaphore(regs, error_code, address);
32123 + return;
32124 + }
32125 + if (address < pax_user_shadow_base) {
32126 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32127 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
32128 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
32129 + } else
32130 + address -= pax_user_shadow_base;
32131 + }
32132 +#endif
32133 +
32134 /*
32135 * Detect and handle instructions that would cause a page fault for
32136 * both a tracked kernel page and a userspace page.
32137 @@ -1145,7 +1369,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32138 * User-mode registers count as a user access even for any
32139 * potential system fault or CPU buglet:
32140 */
32141 - if (user_mode_vm(regs)) {
32142 + if (user_mode(regs)) {
32143 local_irq_enable();
32144 error_code |= PF_USER;
32145 flags |= FAULT_FLAG_USER;
32146 @@ -1192,6 +1416,11 @@ retry:
32147 might_sleep();
32148 }
32149
32150 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32151 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
32152 + return;
32153 +#endif
32154 +
32155 vma = find_vma(mm, address);
32156 if (unlikely(!vma)) {
32157 bad_area(regs, error_code, address);
32158 @@ -1203,18 +1432,24 @@ retry:
32159 bad_area(regs, error_code, address);
32160 return;
32161 }
32162 - if (error_code & PF_USER) {
32163 - /*
32164 - * Accessing the stack below %sp is always a bug.
32165 - * The large cushion allows instructions like enter
32166 - * and pusha to work. ("enter $65535, $31" pushes
32167 - * 32 pointers and then decrements %sp by 65535.)
32168 - */
32169 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
32170 - bad_area(regs, error_code, address);
32171 - return;
32172 - }
32173 + /*
32174 + * Accessing the stack below %sp is always a bug.
32175 + * The large cushion allows instructions like enter
32176 + * and pusha to work. ("enter $65535, $31" pushes
32177 + * 32 pointers and then decrements %sp by 65535.)
32178 + */
32179 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
32180 + bad_area(regs, error_code, address);
32181 + return;
32182 }
32183 +
32184 +#ifdef CONFIG_PAX_SEGMEXEC
32185 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
32186 + bad_area(regs, error_code, address);
32187 + return;
32188 + }
32189 +#endif
32190 +
32191 if (unlikely(expand_stack(vma, address))) {
32192 bad_area(regs, error_code, address);
32193 return;
32194 @@ -1331,3 +1566,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
32195 }
32196 NOKPROBE_SYMBOL(trace_do_page_fault);
32197 #endif /* CONFIG_TRACING */
32198 +
32199 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32200 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
32201 +{
32202 + struct mm_struct *mm = current->mm;
32203 + unsigned long ip = regs->ip;
32204 +
32205 + if (v8086_mode(regs))
32206 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
32207 +
32208 +#ifdef CONFIG_PAX_PAGEEXEC
32209 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
32210 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
32211 + return true;
32212 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
32213 + return true;
32214 + return false;
32215 + }
32216 +#endif
32217 +
32218 +#ifdef CONFIG_PAX_SEGMEXEC
32219 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
32220 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
32221 + return true;
32222 + return false;
32223 + }
32224 +#endif
32225 +
32226 + return false;
32227 +}
32228 +#endif
32229 +
32230 +#ifdef CONFIG_PAX_EMUTRAMP
32231 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
32232 +{
32233 + int err;
32234 +
32235 + do { /* PaX: libffi trampoline emulation */
32236 + unsigned char mov, jmp;
32237 + unsigned int addr1, addr2;
32238 +
32239 +#ifdef CONFIG_X86_64
32240 + if ((regs->ip + 9) >> 32)
32241 + break;
32242 +#endif
32243 +
32244 + err = get_user(mov, (unsigned char __user *)regs->ip);
32245 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32246 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32247 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32248 +
32249 + if (err)
32250 + break;
32251 +
32252 + if (mov == 0xB8 && jmp == 0xE9) {
32253 + regs->ax = addr1;
32254 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32255 + return 2;
32256 + }
32257 + } while (0);
32258 +
32259 + do { /* PaX: gcc trampoline emulation #1 */
32260 + unsigned char mov1, mov2;
32261 + unsigned short jmp;
32262 + unsigned int addr1, addr2;
32263 +
32264 +#ifdef CONFIG_X86_64
32265 + if ((regs->ip + 11) >> 32)
32266 + break;
32267 +#endif
32268 +
32269 + err = get_user(mov1, (unsigned char __user *)regs->ip);
32270 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32271 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
32272 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32273 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
32274 +
32275 + if (err)
32276 + break;
32277 +
32278 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
32279 + regs->cx = addr1;
32280 + regs->ax = addr2;
32281 + regs->ip = addr2;
32282 + return 2;
32283 + }
32284 + } while (0);
32285 +
32286 + do { /* PaX: gcc trampoline emulation #2 */
32287 + unsigned char mov, jmp;
32288 + unsigned int addr1, addr2;
32289 +
32290 +#ifdef CONFIG_X86_64
32291 + if ((regs->ip + 9) >> 32)
32292 + break;
32293 +#endif
32294 +
32295 + err = get_user(mov, (unsigned char __user *)regs->ip);
32296 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32297 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32298 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32299 +
32300 + if (err)
32301 + break;
32302 +
32303 + if (mov == 0xB9 && jmp == 0xE9) {
32304 + regs->cx = addr1;
32305 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32306 + return 2;
32307 + }
32308 + } while (0);
32309 +
32310 + return 1; /* PaX in action */
32311 +}
32312 +
32313 +#ifdef CONFIG_X86_64
32314 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
32315 +{
32316 + int err;
32317 +
32318 + do { /* PaX: libffi trampoline emulation */
32319 + unsigned short mov1, mov2, jmp1;
32320 + unsigned char stcclc, jmp2;
32321 + unsigned long addr1, addr2;
32322 +
32323 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32324 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32325 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32326 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32327 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
32328 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
32329 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
32330 +
32331 + if (err)
32332 + break;
32333 +
32334 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32335 + regs->r11 = addr1;
32336 + regs->r10 = addr2;
32337 + if (stcclc == 0xF8)
32338 + regs->flags &= ~X86_EFLAGS_CF;
32339 + else
32340 + regs->flags |= X86_EFLAGS_CF;
32341 + regs->ip = addr1;
32342 + return 2;
32343 + }
32344 + } while (0);
32345 +
32346 + do { /* PaX: gcc trampoline emulation #1 */
32347 + unsigned short mov1, mov2, jmp1;
32348 + unsigned char jmp2;
32349 + unsigned int addr1;
32350 + unsigned long addr2;
32351 +
32352 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32353 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
32354 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
32355 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
32356 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
32357 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
32358 +
32359 + if (err)
32360 + break;
32361 +
32362 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32363 + regs->r11 = addr1;
32364 + regs->r10 = addr2;
32365 + regs->ip = addr1;
32366 + return 2;
32367 + }
32368 + } while (0);
32369 +
32370 + do { /* PaX: gcc trampoline emulation #2 */
32371 + unsigned short mov1, mov2, jmp1;
32372 + unsigned char jmp2;
32373 + unsigned long addr1, addr2;
32374 +
32375 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32376 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32377 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32378 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32379 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
32380 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
32381 +
32382 + if (err)
32383 + break;
32384 +
32385 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32386 + regs->r11 = addr1;
32387 + regs->r10 = addr2;
32388 + regs->ip = addr1;
32389 + return 2;
32390 + }
32391 + } while (0);
32392 +
32393 + return 1; /* PaX in action */
32394 +}
32395 +#endif
32396 +
32397 +/*
32398 + * PaX: decide what to do with offenders (regs->ip = fault address)
32399 + *
32400 + * returns 1 when task should be killed
32401 + * 2 when gcc trampoline was detected
32402 + */
32403 +static int pax_handle_fetch_fault(struct pt_regs *regs)
32404 +{
32405 + if (v8086_mode(regs))
32406 + return 1;
32407 +
32408 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
32409 + return 1;
32410 +
32411 +#ifdef CONFIG_X86_32
32412 + return pax_handle_fetch_fault_32(regs);
32413 +#else
32414 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
32415 + return pax_handle_fetch_fault_32(regs);
32416 + else
32417 + return pax_handle_fetch_fault_64(regs);
32418 +#endif
32419 +}
32420 +#endif
32421 +
32422 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32423 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
32424 +{
32425 + long i;
32426 +
32427 + printk(KERN_ERR "PAX: bytes at PC: ");
32428 + for (i = 0; i < 20; i++) {
32429 + unsigned char c;
32430 + if (get_user(c, (unsigned char __force_user *)pc+i))
32431 + printk(KERN_CONT "?? ");
32432 + else
32433 + printk(KERN_CONT "%02x ", c);
32434 + }
32435 + printk("\n");
32436 +
32437 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
32438 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
32439 + unsigned long c;
32440 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
32441 +#ifdef CONFIG_X86_32
32442 + printk(KERN_CONT "???????? ");
32443 +#else
32444 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
32445 + printk(KERN_CONT "???????? ???????? ");
32446 + else
32447 + printk(KERN_CONT "???????????????? ");
32448 +#endif
32449 + } else {
32450 +#ifdef CONFIG_X86_64
32451 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
32452 + printk(KERN_CONT "%08x ", (unsigned int)c);
32453 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
32454 + } else
32455 +#endif
32456 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
32457 + }
32458 + }
32459 + printk("\n");
32460 +}
32461 +#endif
32462 +
32463 +/**
32464 + * probe_kernel_write(): safely attempt to write to a location
32465 + * @dst: address to write to
32466 + * @src: pointer to the data that shall be written
32467 + * @size: size of the data chunk
32468 + *
32469 + * Safely write to address @dst from the buffer at @src. If a kernel fault
32470 + * happens, handle that and return -EFAULT.
32471 + */
32472 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
32473 +{
32474 + long ret;
32475 + mm_segment_t old_fs = get_fs();
32476 +
32477 + set_fs(KERNEL_DS);
32478 + pagefault_disable();
32479 + pax_open_kernel();
32480 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
32481 + pax_close_kernel();
32482 + pagefault_enable();
32483 + set_fs(old_fs);
32484 +
32485 + return ret ? -EFAULT : 0;
32486 +}
32487 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
32488 index 207d9aef..69030980 100644
32489 --- a/arch/x86/mm/gup.c
32490 +++ b/arch/x86/mm/gup.c
32491 @@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
32492 addr = start;
32493 len = (unsigned long) nr_pages << PAGE_SHIFT;
32494 end = start + len;
32495 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
32496 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32497 (void __user *)start, len)))
32498 return 0;
32499
32500 @@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
32501 goto slow_irqon;
32502 #endif
32503
32504 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32505 + (void __user *)start, len)))
32506 + return 0;
32507 +
32508 /*
32509 * XXX: batch / limit 'nr', to avoid large irq off latency
32510 * needs some instrumenting to determine the common sizes used by
32511 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
32512 index 4500142..53a363c 100644
32513 --- a/arch/x86/mm/highmem_32.c
32514 +++ b/arch/x86/mm/highmem_32.c
32515 @@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
32516 idx = type + KM_TYPE_NR*smp_processor_id();
32517 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32518 BUG_ON(!pte_none(*(kmap_pte-idx)));
32519 +
32520 + pax_open_kernel();
32521 set_pte(kmap_pte-idx, mk_pte(page, prot));
32522 + pax_close_kernel();
32523 +
32524 arch_flush_lazy_mmu_mode();
32525
32526 return (void *)vaddr;
32527 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
32528 index 8b977eb..4732c33 100644
32529 --- a/arch/x86/mm/hugetlbpage.c
32530 +++ b/arch/x86/mm/hugetlbpage.c
32531 @@ -80,23 +80,24 @@ int pud_huge(pud_t pud)
32532 #ifdef CONFIG_HUGETLB_PAGE
32533 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
32534 unsigned long addr, unsigned long len,
32535 - unsigned long pgoff, unsigned long flags)
32536 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32537 {
32538 struct hstate *h = hstate_file(file);
32539 struct vm_unmapped_area_info info;
32540 -
32541 +
32542 info.flags = 0;
32543 info.length = len;
32544 info.low_limit = current->mm->mmap_legacy_base;
32545 info.high_limit = TASK_SIZE;
32546 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32547 info.align_offset = 0;
32548 + info.threadstack_offset = offset;
32549 return vm_unmapped_area(&info);
32550 }
32551
32552 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32553 unsigned long addr0, unsigned long len,
32554 - unsigned long pgoff, unsigned long flags)
32555 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32556 {
32557 struct hstate *h = hstate_file(file);
32558 struct vm_unmapped_area_info info;
32559 @@ -108,6 +109,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32560 info.high_limit = current->mm->mmap_base;
32561 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32562 info.align_offset = 0;
32563 + info.threadstack_offset = offset;
32564 addr = vm_unmapped_area(&info);
32565
32566 /*
32567 @@ -120,6 +122,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32568 VM_BUG_ON(addr != -ENOMEM);
32569 info.flags = 0;
32570 info.low_limit = TASK_UNMAPPED_BASE;
32571 +
32572 +#ifdef CONFIG_PAX_RANDMMAP
32573 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32574 + info.low_limit += current->mm->delta_mmap;
32575 +#endif
32576 +
32577 info.high_limit = TASK_SIZE;
32578 addr = vm_unmapped_area(&info);
32579 }
32580 @@ -134,10 +142,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32581 struct hstate *h = hstate_file(file);
32582 struct mm_struct *mm = current->mm;
32583 struct vm_area_struct *vma;
32584 + unsigned long pax_task_size = TASK_SIZE;
32585 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32586
32587 if (len & ~huge_page_mask(h))
32588 return -EINVAL;
32589 - if (len > TASK_SIZE)
32590 +
32591 +#ifdef CONFIG_PAX_SEGMEXEC
32592 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32593 + pax_task_size = SEGMEXEC_TASK_SIZE;
32594 +#endif
32595 +
32596 + pax_task_size -= PAGE_SIZE;
32597 +
32598 + if (len > pax_task_size)
32599 return -ENOMEM;
32600
32601 if (flags & MAP_FIXED) {
32602 @@ -146,19 +164,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32603 return addr;
32604 }
32605
32606 +#ifdef CONFIG_PAX_RANDMMAP
32607 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32608 +#endif
32609 +
32610 if (addr) {
32611 addr = ALIGN(addr, huge_page_size(h));
32612 vma = find_vma(mm, addr);
32613 - if (TASK_SIZE - len >= addr &&
32614 - (!vma || addr + len <= vma->vm_start))
32615 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32616 return addr;
32617 }
32618 if (mm->get_unmapped_area == arch_get_unmapped_area)
32619 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32620 - pgoff, flags);
32621 + pgoff, flags, offset);
32622 else
32623 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32624 - pgoff, flags);
32625 + pgoff, flags, offset);
32626 }
32627 #endif /* CONFIG_HUGETLB_PAGE */
32628
32629 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32630 index 66dba36..f8082ec 100644
32631 --- a/arch/x86/mm/init.c
32632 +++ b/arch/x86/mm/init.c
32633 @@ -4,6 +4,7 @@
32634 #include <linux/swap.h>
32635 #include <linux/memblock.h>
32636 #include <linux/bootmem.h> /* for max_low_pfn */
32637 +#include <linux/tboot.h>
32638
32639 #include <asm/cacheflush.h>
32640 #include <asm/e820.h>
32641 @@ -17,6 +18,8 @@
32642 #include <asm/proto.h>
32643 #include <asm/dma.h> /* for MAX_DMA_PFN */
32644 #include <asm/microcode.h>
32645 +#include <asm/desc.h>
32646 +#include <asm/bios_ebda.h>
32647
32648 /*
32649 * We need to define the tracepoints somewhere, and tlb.c
32650 @@ -570,7 +573,18 @@ void __init init_mem_mapping(void)
32651 early_ioremap_page_table_range_init();
32652 #endif
32653
32654 +#ifdef CONFIG_PAX_PER_CPU_PGD
32655 + clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32656 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32657 + KERNEL_PGD_PTRS);
32658 + clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32659 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32660 + KERNEL_PGD_PTRS);
32661 + load_cr3(get_cpu_pgd(0, kernel));
32662 +#else
32663 load_cr3(swapper_pg_dir);
32664 +#endif
32665 +
32666 __flush_tlb_all();
32667
32668 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32669 @@ -586,10 +600,40 @@ void __init init_mem_mapping(void)
32670 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32671 * mmio resources as well as potential bios/acpi data regions.
32672 */
32673 +
32674 +#ifdef CONFIG_GRKERNSEC_KMEM
32675 +static unsigned int ebda_start __read_only;
32676 +static unsigned int ebda_end __read_only;
32677 +#endif
32678 +
32679 int devmem_is_allowed(unsigned long pagenr)
32680 {
32681 - if (pagenr < 256)
32682 +#ifdef CONFIG_GRKERNSEC_KMEM
32683 + /* allow BDA */
32684 + if (!pagenr)
32685 return 1;
32686 + /* allow EBDA */
32687 + if (pagenr >= ebda_start && pagenr < ebda_end)
32688 + return 1;
32689 + /* if tboot is in use, allow access to its hardcoded serial log range */
32690 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32691 + return 1;
32692 +#else
32693 + if (!pagenr)
32694 + return 1;
32695 +#ifdef CONFIG_VM86
32696 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32697 + return 1;
32698 +#endif
32699 +#endif
32700 +
32701 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32702 + return 1;
32703 +#ifdef CONFIG_GRKERNSEC_KMEM
32704 + /* throw out everything else below 1MB */
32705 + if (pagenr <= 256)
32706 + return 0;
32707 +#endif
32708 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32709 return 0;
32710 if (!page_is_ram(pagenr))
32711 @@ -635,8 +679,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32712 #endif
32713 }
32714
32715 +#ifdef CONFIG_GRKERNSEC_KMEM
32716 +static inline void gr_init_ebda(void)
32717 +{
32718 + unsigned int ebda_addr;
32719 + unsigned int ebda_size = 0;
32720 +
32721 + ebda_addr = get_bios_ebda();
32722 + if (ebda_addr) {
32723 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32724 + ebda_size <<= 10;
32725 + }
32726 + if (ebda_addr && ebda_size) {
32727 + ebda_start = ebda_addr >> PAGE_SHIFT;
32728 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32729 + } else {
32730 + ebda_start = 0x9f000 >> PAGE_SHIFT;
32731 + ebda_end = 0xa0000 >> PAGE_SHIFT;
32732 + }
32733 +}
32734 +#else
32735 +static inline void gr_init_ebda(void) { }
32736 +#endif
32737 +
32738 void free_initmem(void)
32739 {
32740 +#ifdef CONFIG_PAX_KERNEXEC
32741 +#ifdef CONFIG_X86_32
32742 + /* PaX: limit KERNEL_CS to actual size */
32743 + unsigned long addr, limit;
32744 + struct desc_struct d;
32745 + int cpu;
32746 +#else
32747 + pgd_t *pgd;
32748 + pud_t *pud;
32749 + pmd_t *pmd;
32750 + unsigned long addr, end;
32751 +#endif
32752 +#endif
32753 +
32754 + gr_init_ebda();
32755 +
32756 +#ifdef CONFIG_PAX_KERNEXEC
32757 +#ifdef CONFIG_X86_32
32758 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32759 + limit = (limit - 1UL) >> PAGE_SHIFT;
32760 +
32761 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32762 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32763 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32764 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32765 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32766 + }
32767 +
32768 + /* PaX: make KERNEL_CS read-only */
32769 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32770 + if (!paravirt_enabled())
32771 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32772 +/*
32773 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32774 + pgd = pgd_offset_k(addr);
32775 + pud = pud_offset(pgd, addr);
32776 + pmd = pmd_offset(pud, addr);
32777 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32778 + }
32779 +*/
32780 +#ifdef CONFIG_X86_PAE
32781 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32782 +/*
32783 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32784 + pgd = pgd_offset_k(addr);
32785 + pud = pud_offset(pgd, addr);
32786 + pmd = pmd_offset(pud, addr);
32787 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32788 + }
32789 +*/
32790 +#endif
32791 +
32792 +#ifdef CONFIG_MODULES
32793 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32794 +#endif
32795 +
32796 +#else
32797 + /* PaX: make kernel code/rodata read-only, rest non-executable */
32798 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32799 + pgd = pgd_offset_k(addr);
32800 + pud = pud_offset(pgd, addr);
32801 + pmd = pmd_offset(pud, addr);
32802 + if (!pmd_present(*pmd))
32803 + continue;
32804 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32805 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32806 + else
32807 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32808 + }
32809 +
32810 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32811 + end = addr + KERNEL_IMAGE_SIZE;
32812 + for (; addr < end; addr += PMD_SIZE) {
32813 + pgd = pgd_offset_k(addr);
32814 + pud = pud_offset(pgd, addr);
32815 + pmd = pmd_offset(pud, addr);
32816 + if (!pmd_present(*pmd))
32817 + continue;
32818 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32819 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32820 + }
32821 +#endif
32822 +
32823 + flush_tlb_all();
32824 +#endif
32825 +
32826 free_init_pages("unused kernel",
32827 (unsigned long)(&__init_begin),
32828 (unsigned long)(&__init_end));
32829 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32830 index c8140e1..59257fc 100644
32831 --- a/arch/x86/mm/init_32.c
32832 +++ b/arch/x86/mm/init_32.c
32833 @@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32834 bool __read_mostly __vmalloc_start_set = false;
32835
32836 /*
32837 - * Creates a middle page table and puts a pointer to it in the
32838 - * given global directory entry. This only returns the gd entry
32839 - * in non-PAE compilation mode, since the middle layer is folded.
32840 - */
32841 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
32842 -{
32843 - pud_t *pud;
32844 - pmd_t *pmd_table;
32845 -
32846 -#ifdef CONFIG_X86_PAE
32847 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32848 - pmd_table = (pmd_t *)alloc_low_page();
32849 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32850 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32851 - pud = pud_offset(pgd, 0);
32852 - BUG_ON(pmd_table != pmd_offset(pud, 0));
32853 -
32854 - return pmd_table;
32855 - }
32856 -#endif
32857 - pud = pud_offset(pgd, 0);
32858 - pmd_table = pmd_offset(pud, 0);
32859 -
32860 - return pmd_table;
32861 -}
32862 -
32863 -/*
32864 * Create a page table and place a pointer to it in a middle page
32865 * directory entry:
32866 */
32867 @@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32868 pte_t *page_table = (pte_t *)alloc_low_page();
32869
32870 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32871 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32872 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32873 +#else
32874 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32875 +#endif
32876 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32877 }
32878
32879 return pte_offset_kernel(pmd, 0);
32880 }
32881
32882 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
32883 +{
32884 + pud_t *pud;
32885 + pmd_t *pmd_table;
32886 +
32887 + pud = pud_offset(pgd, 0);
32888 + pmd_table = pmd_offset(pud, 0);
32889 +
32890 + return pmd_table;
32891 +}
32892 +
32893 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32894 {
32895 int pgd_idx = pgd_index(vaddr);
32896 @@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32897 int pgd_idx, pmd_idx;
32898 unsigned long vaddr;
32899 pgd_t *pgd;
32900 + pud_t *pud;
32901 pmd_t *pmd;
32902 pte_t *pte = NULL;
32903 unsigned long count = page_table_range_init_count(start, end);
32904 @@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32905 pgd = pgd_base + pgd_idx;
32906
32907 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32908 - pmd = one_md_table_init(pgd);
32909 - pmd = pmd + pmd_index(vaddr);
32910 + pud = pud_offset(pgd, vaddr);
32911 + pmd = pmd_offset(pud, vaddr);
32912 +
32913 +#ifdef CONFIG_X86_PAE
32914 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32915 +#endif
32916 +
32917 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32918 pmd++, pmd_idx++) {
32919 pte = page_table_kmap_check(one_page_table_init(pmd),
32920 @@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32921 }
32922 }
32923
32924 -static inline int is_kernel_text(unsigned long addr)
32925 +static inline int is_kernel_text(unsigned long start, unsigned long end)
32926 {
32927 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32928 - return 1;
32929 - return 0;
32930 + if ((start >= ktla_ktva((unsigned long)_etext) ||
32931 + end <= ktla_ktva((unsigned long)_stext)) &&
32932 + (start >= ktla_ktva((unsigned long)_einittext) ||
32933 + end <= ktla_ktva((unsigned long)_sinittext)) &&
32934 +
32935 +#ifdef CONFIG_ACPI_SLEEP
32936 + (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32937 +#endif
32938 +
32939 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32940 + return 0;
32941 + return 1;
32942 }
32943
32944 /*
32945 @@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32946 unsigned long last_map_addr = end;
32947 unsigned long start_pfn, end_pfn;
32948 pgd_t *pgd_base = swapper_pg_dir;
32949 - int pgd_idx, pmd_idx, pte_ofs;
32950 + unsigned int pgd_idx, pmd_idx, pte_ofs;
32951 unsigned long pfn;
32952 pgd_t *pgd;
32953 + pud_t *pud;
32954 pmd_t *pmd;
32955 pte_t *pte;
32956 unsigned pages_2m, pages_4k;
32957 @@ -291,8 +295,13 @@ repeat:
32958 pfn = start_pfn;
32959 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32960 pgd = pgd_base + pgd_idx;
32961 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32962 - pmd = one_md_table_init(pgd);
32963 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32964 + pud = pud_offset(pgd, 0);
32965 + pmd = pmd_offset(pud, 0);
32966 +
32967 +#ifdef CONFIG_X86_PAE
32968 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32969 +#endif
32970
32971 if (pfn >= end_pfn)
32972 continue;
32973 @@ -304,14 +313,13 @@ repeat:
32974 #endif
32975 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32976 pmd++, pmd_idx++) {
32977 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32978 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32979
32980 /*
32981 * Map with big pages if possible, otherwise
32982 * create normal page tables:
32983 */
32984 if (use_pse) {
32985 - unsigned int addr2;
32986 pgprot_t prot = PAGE_KERNEL_LARGE;
32987 /*
32988 * first pass will use the same initial
32989 @@ -322,11 +330,7 @@ repeat:
32990 _PAGE_PSE);
32991
32992 pfn &= PMD_MASK >> PAGE_SHIFT;
32993 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
32994 - PAGE_OFFSET + PAGE_SIZE-1;
32995 -
32996 - if (is_kernel_text(addr) ||
32997 - is_kernel_text(addr2))
32998 + if (is_kernel_text(address, address + PMD_SIZE))
32999 prot = PAGE_KERNEL_LARGE_EXEC;
33000
33001 pages_2m++;
33002 @@ -343,7 +347,7 @@ repeat:
33003 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33004 pte += pte_ofs;
33005 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
33006 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
33007 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
33008 pgprot_t prot = PAGE_KERNEL;
33009 /*
33010 * first pass will use the same initial
33011 @@ -351,7 +355,7 @@ repeat:
33012 */
33013 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
33014
33015 - if (is_kernel_text(addr))
33016 + if (is_kernel_text(address, address + PAGE_SIZE))
33017 prot = PAGE_KERNEL_EXEC;
33018
33019 pages_4k++;
33020 @@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
33021
33022 pud = pud_offset(pgd, va);
33023 pmd = pmd_offset(pud, va);
33024 - if (!pmd_present(*pmd))
33025 + if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
33026 break;
33027
33028 /* should not be large page here */
33029 @@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
33030
33031 static void __init pagetable_init(void)
33032 {
33033 - pgd_t *pgd_base = swapper_pg_dir;
33034 -
33035 - permanent_kmaps_init(pgd_base);
33036 + permanent_kmaps_init(swapper_pg_dir);
33037 }
33038
33039 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL);
33040 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL);
33041 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33042
33043 /* user-defined highmem size */
33044 @@ -787,10 +789,10 @@ void __init mem_init(void)
33045 ((unsigned long)&__init_end -
33046 (unsigned long)&__init_begin) >> 10,
33047
33048 - (unsigned long)&_etext, (unsigned long)&_edata,
33049 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
33050 + (unsigned long)&_sdata, (unsigned long)&_edata,
33051 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
33052
33053 - (unsigned long)&_text, (unsigned long)&_etext,
33054 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
33055 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
33056
33057 /*
33058 @@ -884,6 +886,7 @@ void set_kernel_text_rw(void)
33059 if (!kernel_set_to_readonly)
33060 return;
33061
33062 + start = ktla_ktva(start);
33063 pr_debug("Set kernel text: %lx - %lx for read write\n",
33064 start, start+size);
33065
33066 @@ -898,6 +901,7 @@ void set_kernel_text_ro(void)
33067 if (!kernel_set_to_readonly)
33068 return;
33069
33070 + start = ktla_ktva(start);
33071 pr_debug("Set kernel text: %lx - %lx for read only\n",
33072 start, start+size);
33073
33074 @@ -926,6 +930,7 @@ void mark_rodata_ro(void)
33075 unsigned long start = PFN_ALIGN(_text);
33076 unsigned long size = PFN_ALIGN(_etext) - start;
33077
33078 + start = ktla_ktva(start);
33079 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
33080 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
33081 size >> 10);
33082 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
33083 index 4e5dfec..6fd6dc5 100644
33084 --- a/arch/x86/mm/init_64.c
33085 +++ b/arch/x86/mm/init_64.c
33086 @@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
33087 * around without checking the pgd every time.
33088 */
33089
33090 -pteval_t __supported_pte_mask __read_mostly = ~0;
33091 +pteval_t __supported_pte_mask __read_only = ~_PAGE_NX;
33092 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33093
33094 int force_personality32;
33095 @@ -184,7 +184,12 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33096
33097 for (address = start; address <= end; address += PGDIR_SIZE) {
33098 const pgd_t *pgd_ref = pgd_offset_k(address);
33099 +
33100 +#ifdef CONFIG_PAX_PER_CPU_PGD
33101 + unsigned long cpu;
33102 +#else
33103 struct page *page;
33104 +#endif
33105
33106 /*
33107 * When it is called after memory hot remove, pgd_none()
33108 @@ -195,6 +200,25 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33109 continue;
33110
33111 spin_lock(&pgd_lock);
33112 +
33113 +#ifdef CONFIG_PAX_PER_CPU_PGD
33114 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33115 + pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
33116 +
33117 + if (!pgd_none(*pgd_ref) && !pgd_none(*pgd))
33118 + BUG_ON(pgd_page_vaddr(*pgd)
33119 + != pgd_page_vaddr(*pgd_ref));
33120 +
33121 + if (removed) {
33122 + if (pgd_none(*pgd_ref) && !pgd_none(*pgd))
33123 + pgd_clear(pgd);
33124 + } else {
33125 + if (pgd_none(*pgd))
33126 + set_pgd(pgd, *pgd_ref);
33127 + }
33128 +
33129 + pgd = pgd_offset_cpu(cpu, kernel, address);
33130 +#else
33131 list_for_each_entry(page, &pgd_list, lru) {
33132 pgd_t *pgd;
33133 spinlock_t *pgt_lock;
33134 @@ -203,6 +227,7 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33135 /* the pgt_lock only for Xen */
33136 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
33137 spin_lock(pgt_lock);
33138 +#endif
33139
33140 if (!pgd_none(*pgd_ref) && !pgd_none(*pgd))
33141 BUG_ON(pgd_page_vaddr(*pgd)
33142 @@ -216,7 +241,10 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33143 set_pgd(pgd, *pgd_ref);
33144 }
33145
33146 +#ifndef CONFIG_PAX_PER_CPU_PGD
33147 spin_unlock(pgt_lock);
33148 +#endif
33149 +
33150 }
33151 spin_unlock(&pgd_lock);
33152 }
33153 @@ -249,7 +277,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
33154 {
33155 if (pgd_none(*pgd)) {
33156 pud_t *pud = (pud_t *)spp_getpage();
33157 - pgd_populate(&init_mm, pgd, pud);
33158 + pgd_populate_kernel(&init_mm, pgd, pud);
33159 if (pud != pud_offset(pgd, 0))
33160 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
33161 pud, pud_offset(pgd, 0));
33162 @@ -261,7 +289,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
33163 {
33164 if (pud_none(*pud)) {
33165 pmd_t *pmd = (pmd_t *) spp_getpage();
33166 - pud_populate(&init_mm, pud, pmd);
33167 + pud_populate_kernel(&init_mm, pud, pmd);
33168 if (pmd != pmd_offset(pud, 0))
33169 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
33170 pmd, pmd_offset(pud, 0));
33171 @@ -290,7 +318,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
33172 pmd = fill_pmd(pud, vaddr);
33173 pte = fill_pte(pmd, vaddr);
33174
33175 + pax_open_kernel();
33176 set_pte(pte, new_pte);
33177 + pax_close_kernel();
33178
33179 /*
33180 * It's enough to flush this one mapping.
33181 @@ -349,14 +379,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
33182 pgd = pgd_offset_k((unsigned long)__va(phys));
33183 if (pgd_none(*pgd)) {
33184 pud = (pud_t *) spp_getpage();
33185 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
33186 - _PAGE_USER));
33187 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
33188 }
33189 pud = pud_offset(pgd, (unsigned long)__va(phys));
33190 if (pud_none(*pud)) {
33191 pmd = (pmd_t *) spp_getpage();
33192 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
33193 - _PAGE_USER));
33194 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
33195 }
33196 pmd = pmd_offset(pud, phys);
33197 BUG_ON(!pmd_none(*pmd));
33198 @@ -597,7 +625,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
33199 prot);
33200
33201 spin_lock(&init_mm.page_table_lock);
33202 - pud_populate(&init_mm, pud, pmd);
33203 + pud_populate_kernel(&init_mm, pud, pmd);
33204 spin_unlock(&init_mm.page_table_lock);
33205 }
33206 __flush_tlb_all();
33207 @@ -638,7 +666,7 @@ kernel_physical_mapping_init(unsigned long start,
33208 page_size_mask);
33209
33210 spin_lock(&init_mm.page_table_lock);
33211 - pgd_populate(&init_mm, pgd, pud);
33212 + pgd_populate_kernel(&init_mm, pgd, pud);
33213 spin_unlock(&init_mm.page_table_lock);
33214 pgd_changed = true;
33215 }
33216 @@ -1217,8 +1245,8 @@ static struct vm_operations_struct gate_vma_ops = {
33217 static struct vm_area_struct gate_vma = {
33218 .vm_start = VSYSCALL_ADDR,
33219 .vm_end = VSYSCALL_ADDR + PAGE_SIZE,
33220 - .vm_page_prot = PAGE_READONLY_EXEC,
33221 - .vm_flags = VM_READ | VM_EXEC,
33222 + .vm_page_prot = PAGE_READONLY,
33223 + .vm_flags = VM_READ,
33224 .vm_ops = &gate_vma_ops,
33225 };
33226
33227 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
33228 index 7b179b49..6bd17777 100644
33229 --- a/arch/x86/mm/iomap_32.c
33230 +++ b/arch/x86/mm/iomap_32.c
33231 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
33232 type = kmap_atomic_idx_push();
33233 idx = type + KM_TYPE_NR * smp_processor_id();
33234 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33235 +
33236 + pax_open_kernel();
33237 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
33238 + pax_close_kernel();
33239 +
33240 arch_flush_lazy_mmu_mode();
33241
33242 return (void *)vaddr;
33243 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
33244 index af78e50..0790b03 100644
33245 --- a/arch/x86/mm/ioremap.c
33246 +++ b/arch/x86/mm/ioremap.c
33247 @@ -56,8 +56,8 @@ static int __ioremap_check_ram(unsigned long start_pfn, unsigned long nr_pages,
33248 unsigned long i;
33249
33250 for (i = 0; i < nr_pages; ++i)
33251 - if (pfn_valid(start_pfn + i) &&
33252 - !PageReserved(pfn_to_page(start_pfn + i)))
33253 + if (pfn_valid(start_pfn + i) && (start_pfn + i >= 0x100 ||
33254 + !PageReserved(pfn_to_page(start_pfn + i))))
33255 return 1;
33256
33257 WARN_ONCE(1, "ioremap on RAM pfn 0x%lx\n", start_pfn);
33258 @@ -280,7 +280,7 @@ EXPORT_SYMBOL(ioremap_prot);
33259 *
33260 * Caller must ensure there is only one unmapping for the same pointer.
33261 */
33262 -void iounmap(volatile void __iomem *addr)
33263 +void iounmap(const volatile void __iomem *addr)
33264 {
33265 struct vm_struct *p, *o;
33266
33267 @@ -334,6 +334,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33268
33269 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
33270 if (page_is_ram(start >> PAGE_SHIFT))
33271 +#ifdef CONFIG_HIGHMEM
33272 + if ((start >> PAGE_SHIFT) < max_low_pfn)
33273 +#endif
33274 return __va(phys);
33275
33276 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
33277 @@ -346,13 +349,16 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33278 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
33279 {
33280 if (page_is_ram(phys >> PAGE_SHIFT))
33281 +#ifdef CONFIG_HIGHMEM
33282 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
33283 +#endif
33284 return;
33285
33286 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
33287 return;
33288 }
33289
33290 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
33291 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
33292
33293 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
33294 {
33295 @@ -388,8 +394,7 @@ void __init early_ioremap_init(void)
33296 early_ioremap_setup();
33297
33298 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
33299 - memset(bm_pte, 0, sizeof(bm_pte));
33300 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
33301 + pmd_populate_user(&init_mm, pmd, bm_pte);
33302
33303 /*
33304 * The boot-ioremap range spans multiple pmds, for which
33305 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
33306 index b4f2e7e..96c9c3e 100644
33307 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
33308 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
33309 @@ -628,9 +628,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
33310 * memory (e.g. tracked pages)? For now, we need this to avoid
33311 * invoking kmemcheck for PnP BIOS calls.
33312 */
33313 - if (regs->flags & X86_VM_MASK)
33314 + if (v8086_mode(regs))
33315 return false;
33316 - if (regs->cs != __KERNEL_CS)
33317 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
33318 return false;
33319
33320 pte = kmemcheck_pte_lookup(address);
33321 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
33322 index 919b912..9267313 100644
33323 --- a/arch/x86/mm/mmap.c
33324 +++ b/arch/x86/mm/mmap.c
33325 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
33326 * Leave an at least ~128 MB hole with possible stack randomization.
33327 */
33328 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
33329 -#define MAX_GAP (TASK_SIZE/6*5)
33330 +#define MAX_GAP (pax_task_size/6*5)
33331
33332 static int mmap_is_legacy(void)
33333 {
33334 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
33335 return rnd << PAGE_SHIFT;
33336 }
33337
33338 -static unsigned long mmap_base(void)
33339 +static unsigned long mmap_base(struct mm_struct *mm)
33340 {
33341 unsigned long gap = rlimit(RLIMIT_STACK);
33342 + unsigned long pax_task_size = TASK_SIZE;
33343 +
33344 +#ifdef CONFIG_PAX_SEGMEXEC
33345 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
33346 + pax_task_size = SEGMEXEC_TASK_SIZE;
33347 +#endif
33348
33349 if (gap < MIN_GAP)
33350 gap = MIN_GAP;
33351 else if (gap > MAX_GAP)
33352 gap = MAX_GAP;
33353
33354 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
33355 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
33356 }
33357
33358 /*
33359 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
33360 * does, but not when emulating X86_32
33361 */
33362 -static unsigned long mmap_legacy_base(void)
33363 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
33364 {
33365 - if (mmap_is_ia32())
33366 + if (mmap_is_ia32()) {
33367 +
33368 +#ifdef CONFIG_PAX_SEGMEXEC
33369 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
33370 + return SEGMEXEC_TASK_UNMAPPED_BASE;
33371 + else
33372 +#endif
33373 +
33374 return TASK_UNMAPPED_BASE;
33375 - else
33376 + } else
33377 return TASK_UNMAPPED_BASE + mmap_rnd();
33378 }
33379
33380 @@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
33381 */
33382 void arch_pick_mmap_layout(struct mm_struct *mm)
33383 {
33384 - mm->mmap_legacy_base = mmap_legacy_base();
33385 - mm->mmap_base = mmap_base();
33386 + mm->mmap_legacy_base = mmap_legacy_base(mm);
33387 + mm->mmap_base = mmap_base(mm);
33388 +
33389 +#ifdef CONFIG_PAX_RANDMMAP
33390 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
33391 + mm->mmap_legacy_base += mm->delta_mmap;
33392 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
33393 + }
33394 +#endif
33395
33396 if (mmap_is_legacy()) {
33397 mm->mmap_base = mm->mmap_legacy_base;
33398 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
33399 index 0057a7a..95c7edd 100644
33400 --- a/arch/x86/mm/mmio-mod.c
33401 +++ b/arch/x86/mm/mmio-mod.c
33402 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
33403 break;
33404 default:
33405 {
33406 - unsigned char *ip = (unsigned char *)instptr;
33407 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
33408 my_trace->opcode = MMIO_UNKNOWN_OP;
33409 my_trace->width = 0;
33410 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
33411 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
33412 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33413 void __iomem *addr)
33414 {
33415 - static atomic_t next_id;
33416 + static atomic_unchecked_t next_id;
33417 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
33418 /* These are page-unaligned. */
33419 struct mmiotrace_map map = {
33420 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33421 .private = trace
33422 },
33423 .phys = offset,
33424 - .id = atomic_inc_return(&next_id)
33425 + .id = atomic_inc_return_unchecked(&next_id)
33426 };
33427 map.map_id = trace->id;
33428
33429 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
33430 ioremap_trace_core(offset, size, addr);
33431 }
33432
33433 -static void iounmap_trace_core(volatile void __iomem *addr)
33434 +static void iounmap_trace_core(const volatile void __iomem *addr)
33435 {
33436 struct mmiotrace_map map = {
33437 .phys = 0,
33438 @@ -328,7 +328,7 @@ not_enabled:
33439 }
33440 }
33441
33442 -void mmiotrace_iounmap(volatile void __iomem *addr)
33443 +void mmiotrace_iounmap(const volatile void __iomem *addr)
33444 {
33445 might_sleep();
33446 if (is_enabled()) /* recheck and proper locking in *_core() */
33447 diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
33448 index 1a88370..3f598b5 100644
33449 --- a/arch/x86/mm/numa.c
33450 +++ b/arch/x86/mm/numa.c
33451 @@ -499,7 +499,7 @@ static void __init numa_clear_kernel_node_hotplug(void)
33452 }
33453 }
33454
33455 -static int __init numa_register_memblks(struct numa_meminfo *mi)
33456 +static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
33457 {
33458 unsigned long uninitialized_var(pfn_align);
33459 int i, nid;
33460 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
33461 index 36de293..b820ddc 100644
33462 --- a/arch/x86/mm/pageattr.c
33463 +++ b/arch/x86/mm/pageattr.c
33464 @@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33465 */
33466 #ifdef CONFIG_PCI_BIOS
33467 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
33468 - pgprot_val(forbidden) |= _PAGE_NX;
33469 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33470 #endif
33471
33472 /*
33473 @@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33474 * Does not cover __inittext since that is gone later on. On
33475 * 64bit we do not enforce !NX on the low mapping
33476 */
33477 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
33478 - pgprot_val(forbidden) |= _PAGE_NX;
33479 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
33480 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33481
33482 +#ifdef CONFIG_DEBUG_RODATA
33483 /*
33484 * The .rodata section needs to be read-only. Using the pfn
33485 * catches all aliases.
33486 @@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33487 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
33488 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
33489 pgprot_val(forbidden) |= _PAGE_RW;
33490 +#endif
33491
33492 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
33493 /*
33494 @@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33495 }
33496 #endif
33497
33498 +#ifdef CONFIG_PAX_KERNEXEC
33499 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
33500 + pgprot_val(forbidden) |= _PAGE_RW;
33501 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33502 + }
33503 +#endif
33504 +
33505 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
33506
33507 return prot;
33508 @@ -420,23 +429,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
33509 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
33510 {
33511 /* change init_mm */
33512 + pax_open_kernel();
33513 set_pte_atomic(kpte, pte);
33514 +
33515 #ifdef CONFIG_X86_32
33516 if (!SHARED_KERNEL_PMD) {
33517 +
33518 +#ifdef CONFIG_PAX_PER_CPU_PGD
33519 + unsigned long cpu;
33520 +#else
33521 struct page *page;
33522 +#endif
33523
33524 +#ifdef CONFIG_PAX_PER_CPU_PGD
33525 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33526 + pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33527 +#else
33528 list_for_each_entry(page, &pgd_list, lru) {
33529 - pgd_t *pgd;
33530 + pgd_t *pgd = (pgd_t *)page_address(page);
33531 +#endif
33532 +
33533 pud_t *pud;
33534 pmd_t *pmd;
33535
33536 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
33537 + pgd += pgd_index(address);
33538 pud = pud_offset(pgd, address);
33539 pmd = pmd_offset(pud, address);
33540 set_pte_atomic((pte_t *)pmd, pte);
33541 }
33542 }
33543 #endif
33544 + pax_close_kernel();
33545 }
33546
33547 static int
33548 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33549 index 6574388..87e9bef 100644
33550 --- a/arch/x86/mm/pat.c
33551 +++ b/arch/x86/mm/pat.c
33552 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33553
33554 if (!entry) {
33555 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33556 - current->comm, current->pid, start, end - 1);
33557 + current->comm, task_pid_nr(current), start, end - 1);
33558 return -EINVAL;
33559 }
33560
33561 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33562
33563 while (cursor < to) {
33564 if (!devmem_is_allowed(pfn)) {
33565 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33566 - current->comm, from, to - 1);
33567 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33568 + current->comm, from, to - 1, cursor);
33569 return 0;
33570 }
33571 cursor += PAGE_SIZE;
33572 @@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33573 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33574 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33575 "for [mem %#010Lx-%#010Lx]\n",
33576 - current->comm, current->pid,
33577 + current->comm, task_pid_nr(current),
33578 cattr_name(flags),
33579 base, (unsigned long long)(base + size-1));
33580 return -EINVAL;
33581 @@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33582 flags = lookup_memtype(paddr);
33583 if (want_flags != flags) {
33584 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33585 - current->comm, current->pid,
33586 + current->comm, task_pid_nr(current),
33587 cattr_name(want_flags),
33588 (unsigned long long)paddr,
33589 (unsigned long long)(paddr + size - 1),
33590 @@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33591 free_memtype(paddr, paddr + size);
33592 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33593 " for [mem %#010Lx-%#010Lx], got %s\n",
33594 - current->comm, current->pid,
33595 + current->comm, task_pid_nr(current),
33596 cattr_name(want_flags),
33597 (unsigned long long)paddr,
33598 (unsigned long long)(paddr + size - 1),
33599 diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33600 index 415f6c4..d319983 100644
33601 --- a/arch/x86/mm/pat_rbtree.c
33602 +++ b/arch/x86/mm/pat_rbtree.c
33603 @@ -160,7 +160,7 @@ success:
33604
33605 failure:
33606 printk(KERN_INFO "%s:%d conflicting memory types "
33607 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33608 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33609 end, cattr_name(found_type), cattr_name(match->type));
33610 return -EBUSY;
33611 }
33612 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33613 index 9f0614d..92ae64a 100644
33614 --- a/arch/x86/mm/pf_in.c
33615 +++ b/arch/x86/mm/pf_in.c
33616 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33617 int i;
33618 enum reason_type rv = OTHERS;
33619
33620 - p = (unsigned char *)ins_addr;
33621 + p = (unsigned char *)ktla_ktva(ins_addr);
33622 p += skip_prefix(p, &prf);
33623 p += get_opcode(p, &opcode);
33624
33625 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33626 struct prefix_bits prf;
33627 int i;
33628
33629 - p = (unsigned char *)ins_addr;
33630 + p = (unsigned char *)ktla_ktva(ins_addr);
33631 p += skip_prefix(p, &prf);
33632 p += get_opcode(p, &opcode);
33633
33634 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33635 struct prefix_bits prf;
33636 int i;
33637
33638 - p = (unsigned char *)ins_addr;
33639 + p = (unsigned char *)ktla_ktva(ins_addr);
33640 p += skip_prefix(p, &prf);
33641 p += get_opcode(p, &opcode);
33642
33643 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33644 struct prefix_bits prf;
33645 int i;
33646
33647 - p = (unsigned char *)ins_addr;
33648 + p = (unsigned char *)ktla_ktva(ins_addr);
33649 p += skip_prefix(p, &prf);
33650 p += get_opcode(p, &opcode);
33651 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33652 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33653 struct prefix_bits prf;
33654 int i;
33655
33656 - p = (unsigned char *)ins_addr;
33657 + p = (unsigned char *)ktla_ktva(ins_addr);
33658 p += skip_prefix(p, &prf);
33659 p += get_opcode(p, &opcode);
33660 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33661 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33662 index 6fb6927..4fc13c0 100644
33663 --- a/arch/x86/mm/pgtable.c
33664 +++ b/arch/x86/mm/pgtable.c
33665 @@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33666 list_del(&page->lru);
33667 }
33668
33669 -#define UNSHARED_PTRS_PER_PGD \
33670 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33671 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33672 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33673
33674 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33675 +{
33676 + unsigned int count = USER_PGD_PTRS;
33677
33678 + if (!pax_user_shadow_base)
33679 + return;
33680 +
33681 + while (count--)
33682 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33683 +}
33684 +#endif
33685 +
33686 +#ifdef CONFIG_PAX_PER_CPU_PGD
33687 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33688 +{
33689 + unsigned int count = USER_PGD_PTRS;
33690 +
33691 + while (count--) {
33692 + pgd_t pgd;
33693 +
33694 +#ifdef CONFIG_X86_64
33695 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33696 +#else
33697 + pgd = *src++;
33698 +#endif
33699 +
33700 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33701 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33702 +#endif
33703 +
33704 + *dst++ = pgd;
33705 + }
33706 +
33707 +}
33708 +#endif
33709 +
33710 +#ifdef CONFIG_X86_64
33711 +#define pxd_t pud_t
33712 +#define pyd_t pgd_t
33713 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33714 +#define pgtable_pxd_page_ctor(page) true
33715 +#define pgtable_pxd_page_dtor(page)
33716 +#define pxd_free(mm, pud) pud_free((mm), (pud))
33717 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33718 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
33719 +#define PYD_SIZE PGDIR_SIZE
33720 +#else
33721 +#define pxd_t pmd_t
33722 +#define pyd_t pud_t
33723 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33724 +#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33725 +#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33726 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
33727 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33728 +#define pyd_offset(mm, address) pud_offset((mm), (address))
33729 +#define PYD_SIZE PUD_SIZE
33730 +#endif
33731 +
33732 +#ifdef CONFIG_PAX_PER_CPU_PGD
33733 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33734 +static inline void pgd_dtor(pgd_t *pgd) {}
33735 +#else
33736 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33737 {
33738 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33739 @@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33740 pgd_list_del(pgd);
33741 spin_unlock(&pgd_lock);
33742 }
33743 +#endif
33744
33745 /*
33746 * List of all pgd's needed for non-PAE so it can invalidate entries
33747 @@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33748 * -- nyc
33749 */
33750
33751 -#ifdef CONFIG_X86_PAE
33752 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33753 /*
33754 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33755 * updating the top-level pagetable entries to guarantee the
33756 @@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33757 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33758 * and initialize the kernel pmds here.
33759 */
33760 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33761 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33762
33763 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33764 {
33765 @@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33766 */
33767 flush_tlb_mm(mm);
33768 }
33769 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33770 +#define PREALLOCATED_PXDS USER_PGD_PTRS
33771 #else /* !CONFIG_X86_PAE */
33772
33773 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33774 -#define PREALLOCATED_PMDS 0
33775 +#define PREALLOCATED_PXDS 0
33776
33777 #endif /* CONFIG_X86_PAE */
33778
33779 -static void free_pmds(pmd_t *pmds[])
33780 +static void free_pxds(pxd_t *pxds[])
33781 {
33782 int i;
33783
33784 - for(i = 0; i < PREALLOCATED_PMDS; i++)
33785 - if (pmds[i]) {
33786 - pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33787 - free_page((unsigned long)pmds[i]);
33788 + for(i = 0; i < PREALLOCATED_PXDS; i++)
33789 + if (pxds[i]) {
33790 + pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33791 + free_page((unsigned long)pxds[i]);
33792 }
33793 }
33794
33795 -static int preallocate_pmds(pmd_t *pmds[])
33796 +static int preallocate_pxds(pxd_t *pxds[])
33797 {
33798 int i;
33799 bool failed = false;
33800
33801 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33802 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33803 - if (!pmd)
33804 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33805 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33806 + if (!pxd)
33807 failed = true;
33808 - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33809 - free_page((unsigned long)pmd);
33810 - pmd = NULL;
33811 + if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33812 + free_page((unsigned long)pxd);
33813 + pxd = NULL;
33814 failed = true;
33815 }
33816 - pmds[i] = pmd;
33817 + pxds[i] = pxd;
33818 }
33819
33820 if (failed) {
33821 - free_pmds(pmds);
33822 + free_pxds(pxds);
33823 return -ENOMEM;
33824 }
33825
33826 @@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33827 * preallocate which never got a corresponding vma will need to be
33828 * freed manually.
33829 */
33830 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33831 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33832 {
33833 int i;
33834
33835 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33836 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33837 pgd_t pgd = pgdp[i];
33838
33839 if (pgd_val(pgd) != 0) {
33840 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33841 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33842
33843 - pgdp[i] = native_make_pgd(0);
33844 + set_pgd(pgdp + i, native_make_pgd(0));
33845
33846 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33847 - pmd_free(mm, pmd);
33848 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33849 + pxd_free(mm, pxd);
33850 }
33851 }
33852 }
33853
33854 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33855 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33856 {
33857 - pud_t *pud;
33858 + pyd_t *pyd;
33859 int i;
33860
33861 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33862 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33863 return;
33864
33865 - pud = pud_offset(pgd, 0);
33866 -
33867 - for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33868 - pmd_t *pmd = pmds[i];
33869 +#ifdef CONFIG_X86_64
33870 + pyd = pyd_offset(mm, 0L);
33871 +#else
33872 + pyd = pyd_offset(pgd, 0L);
33873 +#endif
33874
33875 + for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33876 + pxd_t *pxd = pxds[i];
33877 if (i >= KERNEL_PGD_BOUNDARY)
33878 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33879 - sizeof(pmd_t) * PTRS_PER_PMD);
33880 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33881 + sizeof(pxd_t) * PTRS_PER_PMD);
33882
33883 - pud_populate(mm, pud, pmd);
33884 + pyd_populate(mm, pyd, pxd);
33885 }
33886 }
33887
33888 pgd_t *pgd_alloc(struct mm_struct *mm)
33889 {
33890 pgd_t *pgd;
33891 - pmd_t *pmds[PREALLOCATED_PMDS];
33892 + pxd_t *pxds[PREALLOCATED_PXDS];
33893
33894 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33895
33896 @@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33897
33898 mm->pgd = pgd;
33899
33900 - if (preallocate_pmds(pmds) != 0)
33901 + if (preallocate_pxds(pxds) != 0)
33902 goto out_free_pgd;
33903
33904 if (paravirt_pgd_alloc(mm) != 0)
33905 - goto out_free_pmds;
33906 + goto out_free_pxds;
33907
33908 /*
33909 * Make sure that pre-populating the pmds is atomic with
33910 @@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33911 spin_lock(&pgd_lock);
33912
33913 pgd_ctor(mm, pgd);
33914 - pgd_prepopulate_pmd(mm, pgd, pmds);
33915 + pgd_prepopulate_pxd(mm, pgd, pxds);
33916
33917 spin_unlock(&pgd_lock);
33918
33919 return pgd;
33920
33921 -out_free_pmds:
33922 - free_pmds(pmds);
33923 +out_free_pxds:
33924 + free_pxds(pxds);
33925 out_free_pgd:
33926 free_page((unsigned long)pgd);
33927 out:
33928 @@ -313,7 +380,7 @@ out:
33929
33930 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33931 {
33932 - pgd_mop_up_pmds(mm, pgd);
33933 + pgd_mop_up_pxds(mm, pgd);
33934 pgd_dtor(pgd);
33935 paravirt_pgd_free(mm, pgd);
33936 free_page((unsigned long)pgd);
33937 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33938 index 75cc097..79a097f 100644
33939 --- a/arch/x86/mm/pgtable_32.c
33940 +++ b/arch/x86/mm/pgtable_32.c
33941 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33942 return;
33943 }
33944 pte = pte_offset_kernel(pmd, vaddr);
33945 +
33946 + pax_open_kernel();
33947 if (pte_val(pteval))
33948 set_pte_at(&init_mm, vaddr, pte, pteval);
33949 else
33950 pte_clear(&init_mm, vaddr, pte);
33951 + pax_close_kernel();
33952
33953 /*
33954 * It's enough to flush this one mapping.
33955 diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33956 index e666cbb..61788c45 100644
33957 --- a/arch/x86/mm/physaddr.c
33958 +++ b/arch/x86/mm/physaddr.c
33959 @@ -10,7 +10,7 @@
33960 #ifdef CONFIG_X86_64
33961
33962 #ifdef CONFIG_DEBUG_VIRTUAL
33963 -unsigned long __phys_addr(unsigned long x)
33964 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33965 {
33966 unsigned long y = x - __START_KERNEL_map;
33967
33968 @@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33969 #else
33970
33971 #ifdef CONFIG_DEBUG_VIRTUAL
33972 -unsigned long __phys_addr(unsigned long x)
33973 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33974 {
33975 unsigned long phys_addr = x - PAGE_OFFSET;
33976 /* VMALLOC_* aren't constants */
33977 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
33978 index 90555bf..f5f1828 100644
33979 --- a/arch/x86/mm/setup_nx.c
33980 +++ b/arch/x86/mm/setup_nx.c
33981 @@ -5,8 +5,10 @@
33982 #include <asm/pgtable.h>
33983 #include <asm/proto.h>
33984
33985 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33986 static int disable_nx;
33987
33988 +#ifndef CONFIG_PAX_PAGEEXEC
33989 /*
33990 * noexec = on|off
33991 *
33992 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
33993 return 0;
33994 }
33995 early_param("noexec", noexec_setup);
33996 +#endif
33997 +
33998 +#endif
33999
34000 void x86_configure_nx(void)
34001 {
34002 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34003 if (cpu_has_nx && !disable_nx)
34004 __supported_pte_mask |= _PAGE_NX;
34005 else
34006 +#endif
34007 __supported_pte_mask &= ~_PAGE_NX;
34008 }
34009
34010 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
34011 index ee61c36..e6fedeb 100644
34012 --- a/arch/x86/mm/tlb.c
34013 +++ b/arch/x86/mm/tlb.c
34014 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
34015 BUG();
34016 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
34017 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
34018 +
34019 +#ifndef CONFIG_PAX_PER_CPU_PGD
34020 load_cr3(swapper_pg_dir);
34021 +#endif
34022 +
34023 /*
34024 * This gets called in the idle path where RCU
34025 * functions differently. Tracing normally
34026 diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
34027 new file mode 100644
34028 index 0000000..dace51c
34029 --- /dev/null
34030 +++ b/arch/x86/mm/uderef_64.c
34031 @@ -0,0 +1,37 @@
34032 +#include <linux/mm.h>
34033 +#include <asm/pgtable.h>
34034 +#include <asm/uaccess.h>
34035 +
34036 +#ifdef CONFIG_PAX_MEMORY_UDEREF
34037 +/* PaX: due to the special call convention these functions must
34038 + * - remain leaf functions under all configurations,
34039 + * - never be called directly, only dereferenced from the wrappers.
34040 + */
34041 +void __pax_open_userland(void)
34042 +{
34043 + unsigned int cpu;
34044 +
34045 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
34046 + return;
34047 +
34048 + cpu = raw_get_cpu();
34049 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
34050 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
34051 + raw_put_cpu_no_resched();
34052 +}
34053 +EXPORT_SYMBOL(__pax_open_userland);
34054 +
34055 +void __pax_close_userland(void)
34056 +{
34057 + unsigned int cpu;
34058 +
34059 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
34060 + return;
34061 +
34062 + cpu = raw_get_cpu();
34063 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
34064 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
34065 + raw_put_cpu_no_resched();
34066 +}
34067 +EXPORT_SYMBOL(__pax_close_userland);
34068 +#endif
34069 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
34070 index 6440221..f84b5c7 100644
34071 --- a/arch/x86/net/bpf_jit.S
34072 +++ b/arch/x86/net/bpf_jit.S
34073 @@ -9,6 +9,7 @@
34074 */
34075 #include <linux/linkage.h>
34076 #include <asm/dwarf2.h>
34077 +#include <asm/alternative-asm.h>
34078
34079 /*
34080 * Calling convention :
34081 @@ -38,6 +39,7 @@ sk_load_word_positive_offset:
34082 jle bpf_slow_path_word
34083 mov (SKBDATA,%rsi),%eax
34084 bswap %eax /* ntohl() */
34085 + pax_force_retaddr
34086 ret
34087
34088 sk_load_half:
34089 @@ -55,6 +57,7 @@ sk_load_half_positive_offset:
34090 jle bpf_slow_path_half
34091 movzwl (SKBDATA,%rsi),%eax
34092 rol $8,%ax # ntohs()
34093 + pax_force_retaddr
34094 ret
34095
34096 sk_load_byte:
34097 @@ -69,6 +72,7 @@ sk_load_byte_positive_offset:
34098 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
34099 jle bpf_slow_path_byte
34100 movzbl (SKBDATA,%rsi),%eax
34101 + pax_force_retaddr
34102 ret
34103
34104 /* rsi contains offset and can be scratched */
34105 @@ -90,6 +94,7 @@ bpf_slow_path_word:
34106 js bpf_error
34107 mov - MAX_BPF_STACK + 32(%rbp),%eax
34108 bswap %eax
34109 + pax_force_retaddr
34110 ret
34111
34112 bpf_slow_path_half:
34113 @@ -98,12 +103,14 @@ bpf_slow_path_half:
34114 mov - MAX_BPF_STACK + 32(%rbp),%ax
34115 rol $8,%ax
34116 movzwl %ax,%eax
34117 + pax_force_retaddr
34118 ret
34119
34120 bpf_slow_path_byte:
34121 bpf_slow_path_common(1)
34122 js bpf_error
34123 movzbl - MAX_BPF_STACK + 32(%rbp),%eax
34124 + pax_force_retaddr
34125 ret
34126
34127 #define sk_negative_common(SIZE) \
34128 @@ -126,6 +133,7 @@ sk_load_word_negative_offset:
34129 sk_negative_common(4)
34130 mov (%rax), %eax
34131 bswap %eax
34132 + pax_force_retaddr
34133 ret
34134
34135 bpf_slow_path_half_neg:
34136 @@ -137,6 +145,7 @@ sk_load_half_negative_offset:
34137 mov (%rax),%ax
34138 rol $8,%ax
34139 movzwl %ax,%eax
34140 + pax_force_retaddr
34141 ret
34142
34143 bpf_slow_path_byte_neg:
34144 @@ -146,6 +155,7 @@ sk_load_byte_negative_offset:
34145 .globl sk_load_byte_negative_offset
34146 sk_negative_common(1)
34147 movzbl (%rax), %eax
34148 + pax_force_retaddr
34149 ret
34150
34151 bpf_error:
34152 @@ -156,4 +166,5 @@ bpf_error:
34153 mov - MAX_BPF_STACK + 16(%rbp),%r14
34154 mov - MAX_BPF_STACK + 24(%rbp),%r15
34155 leaveq
34156 + pax_force_retaddr
34157 ret
34158 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
34159 index 3f62734..097bf93 100644
34160 --- a/arch/x86/net/bpf_jit_comp.c
34161 +++ b/arch/x86/net/bpf_jit_comp.c
34162 @@ -13,7 +13,11 @@
34163 #include <linux/if_vlan.h>
34164 #include <asm/cacheflush.h>
34165
34166 +#ifdef CONFIG_GRKERNSEC_BPF_HARDEN
34167 +int bpf_jit_enable __read_only;
34168 +#else
34169 int bpf_jit_enable __read_mostly;
34170 +#endif
34171
34172 /*
34173 * assembly code in arch/x86/net/bpf_jit.S
34174 @@ -174,7 +178,9 @@ static inline u8 add_2reg(u8 byte, u32 dst_reg, u32 src_reg)
34175 static void jit_fill_hole(void *area, unsigned int size)
34176 {
34177 /* fill whole space with int3 instructions */
34178 + pax_open_kernel();
34179 memset(area, 0xcc, size);
34180 + pax_close_kernel();
34181 }
34182
34183 struct jit_context {
34184 @@ -894,7 +900,9 @@ common_load:
34185 pr_err("bpf_jit_compile fatal error\n");
34186 return -EFAULT;
34187 }
34188 + pax_open_kernel();
34189 memcpy(image + proglen, temp, ilen);
34190 + pax_close_kernel();
34191 }
34192 proglen += ilen;
34193 addrs[i] = proglen;
34194 @@ -966,7 +974,6 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
34195
34196 if (image) {
34197 bpf_flush_icache(header, image + proglen);
34198 - set_memory_ro((unsigned long)header, header->pages);
34199 prog->bpf_func = (void *)image;
34200 prog->jited = true;
34201 }
34202 @@ -982,7 +989,6 @@ void bpf_jit_free(struct bpf_prog *fp)
34203 if (!fp->jited)
34204 goto free_filter;
34205
34206 - set_memory_rw(addr, header->pages);
34207 bpf_jit_binary_free(header);
34208
34209 free_filter:
34210 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
34211 index 5d04be5..2beeaa2 100644
34212 --- a/arch/x86/oprofile/backtrace.c
34213 +++ b/arch/x86/oprofile/backtrace.c
34214 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
34215 struct stack_frame_ia32 *fp;
34216 unsigned long bytes;
34217
34218 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34219 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34220 if (bytes != 0)
34221 return NULL;
34222
34223 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
34224 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
34225
34226 oprofile_add_trace(bufhead[0].return_address);
34227
34228 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
34229 struct stack_frame bufhead[2];
34230 unsigned long bytes;
34231
34232 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34233 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34234 if (bytes != 0)
34235 return NULL;
34236
34237 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
34238 {
34239 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
34240
34241 - if (!user_mode_vm(regs)) {
34242 + if (!user_mode(regs)) {
34243 unsigned long stack = kernel_stack_pointer(regs);
34244 if (depth)
34245 dump_trace(NULL, regs, (unsigned long *)stack, 0,
34246 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
34247 index 1d2e639..f6ef82a 100644
34248 --- a/arch/x86/oprofile/nmi_int.c
34249 +++ b/arch/x86/oprofile/nmi_int.c
34250 @@ -23,6 +23,7 @@
34251 #include <asm/nmi.h>
34252 #include <asm/msr.h>
34253 #include <asm/apic.h>
34254 +#include <asm/pgtable.h>
34255
34256 #include "op_counter.h"
34257 #include "op_x86_model.h"
34258 @@ -785,8 +786,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
34259 if (ret)
34260 return ret;
34261
34262 - if (!model->num_virt_counters)
34263 - model->num_virt_counters = model->num_counters;
34264 + if (!model->num_virt_counters) {
34265 + pax_open_kernel();
34266 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
34267 + pax_close_kernel();
34268 + }
34269
34270 mux_init(ops);
34271
34272 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34273 index 50d86c0..7985318 100644
34274 --- a/arch/x86/oprofile/op_model_amd.c
34275 +++ b/arch/x86/oprofile/op_model_amd.c
34276 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34277 num_counters = AMD64_NUM_COUNTERS;
34278 }
34279
34280 - op_amd_spec.num_counters = num_counters;
34281 - op_amd_spec.num_controls = num_counters;
34282 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34283 + pax_open_kernel();
34284 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34285 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34286 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34287 + pax_close_kernel();
34288
34289 return 0;
34290 }
34291 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34292 index d90528e..0127e2b 100644
34293 --- a/arch/x86/oprofile/op_model_ppro.c
34294 +++ b/arch/x86/oprofile/op_model_ppro.c
34295 @@ -19,6 +19,7 @@
34296 #include <asm/msr.h>
34297 #include <asm/apic.h>
34298 #include <asm/nmi.h>
34299 +#include <asm/pgtable.h>
34300
34301 #include "op_x86_model.h"
34302 #include "op_counter.h"
34303 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34304
34305 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34306
34307 - op_arch_perfmon_spec.num_counters = num_counters;
34308 - op_arch_perfmon_spec.num_controls = num_counters;
34309 + pax_open_kernel();
34310 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34311 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34312 + pax_close_kernel();
34313 }
34314
34315 static int arch_perfmon_init(struct oprofile_operations *ignore)
34316 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34317 index 71e8a67..6a313bb 100644
34318 --- a/arch/x86/oprofile/op_x86_model.h
34319 +++ b/arch/x86/oprofile/op_x86_model.h
34320 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
34321 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34322 struct op_msrs const * const msrs);
34323 #endif
34324 -};
34325 +} __do_const;
34326
34327 struct op_counter_config;
34328
34329 diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34330 index b9958c3..24229ab 100644
34331 --- a/arch/x86/pci/intel_mid_pci.c
34332 +++ b/arch/x86/pci/intel_mid_pci.c
34333 @@ -250,7 +250,7 @@ int __init intel_mid_pci_init(void)
34334 pci_mmcfg_late_init();
34335 pcibios_enable_irq = intel_mid_pci_irq_enable;
34336 pcibios_disable_irq = intel_mid_pci_irq_disable;
34337 - pci_root_ops = intel_mid_pci_ops;
34338 + memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34339 pci_soc_mode = 1;
34340 /* Continue with standard init */
34341 return 1;
34342 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34343 index eb500c2..eab9e70 100644
34344 --- a/arch/x86/pci/irq.c
34345 +++ b/arch/x86/pci/irq.c
34346 @@ -51,7 +51,7 @@ struct irq_router {
34347 struct irq_router_handler {
34348 u16 vendor;
34349 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34350 -};
34351 +} __do_const;
34352
34353 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34354 void (*pcibios_disable_irq)(struct pci_dev *dev) = pirq_disable_irq;
34355 @@ -791,7 +791,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34356 return 0;
34357 }
34358
34359 -static __initdata struct irq_router_handler pirq_routers[] = {
34360 +static __initconst const struct irq_router_handler pirq_routers[] = {
34361 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34362 { PCI_VENDOR_ID_AL, ali_router_probe },
34363 { PCI_VENDOR_ID_ITE, ite_router_probe },
34364 @@ -818,7 +818,7 @@ static struct pci_dev *pirq_router_dev;
34365 static void __init pirq_find_router(struct irq_router *r)
34366 {
34367 struct irq_routing_table *rt = pirq_table;
34368 - struct irq_router_handler *h;
34369 + const struct irq_router_handler *h;
34370
34371 #ifdef CONFIG_PCI_BIOS
34372 if (!rt->signature) {
34373 @@ -1091,7 +1091,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34374 return 0;
34375 }
34376
34377 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34378 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34379 {
34380 .callback = fix_broken_hp_bios_irq9,
34381 .ident = "HP Pavilion N5400 Series Laptop",
34382 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34383 index 9b83b90..4112152 100644
34384 --- a/arch/x86/pci/pcbios.c
34385 +++ b/arch/x86/pci/pcbios.c
34386 @@ -79,7 +79,7 @@ union bios32 {
34387 static struct {
34388 unsigned long address;
34389 unsigned short segment;
34390 -} bios32_indirect __initdata = { 0, __KERNEL_CS };
34391 +} bios32_indirect __initconst = { 0, __PCIBIOS_CS };
34392
34393 /*
34394 * Returns the entry point for the given service, NULL on error
34395 @@ -92,37 +92,80 @@ static unsigned long __init bios32_service(unsigned long service)
34396 unsigned long length; /* %ecx */
34397 unsigned long entry; /* %edx */
34398 unsigned long flags;
34399 + struct desc_struct d, *gdt;
34400
34401 local_irq_save(flags);
34402 - __asm__("lcall *(%%edi); cld"
34403 +
34404 + gdt = get_cpu_gdt_table(smp_processor_id());
34405 +
34406 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34407 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34408 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34409 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34410 +
34411 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34412 : "=a" (return_code),
34413 "=b" (address),
34414 "=c" (length),
34415 "=d" (entry)
34416 : "0" (service),
34417 "1" (0),
34418 - "D" (&bios32_indirect));
34419 + "D" (&bios32_indirect),
34420 + "r"(__PCIBIOS_DS)
34421 + : "memory");
34422 +
34423 + pax_open_kernel();
34424 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34425 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34426 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34427 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34428 + pax_close_kernel();
34429 +
34430 local_irq_restore(flags);
34431
34432 switch (return_code) {
34433 - case 0:
34434 - return address + entry;
34435 - case 0x80: /* Not present */
34436 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34437 - return 0;
34438 - default: /* Shouldn't happen */
34439 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34440 - service, return_code);
34441 + case 0: {
34442 + int cpu;
34443 + unsigned char flags;
34444 +
34445 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34446 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34447 + printk(KERN_WARNING "bios32_service: not valid\n");
34448 return 0;
34449 + }
34450 + address = address + PAGE_OFFSET;
34451 + length += 16UL; /* some BIOSs underreport this... */
34452 + flags = 4;
34453 + if (length >= 64*1024*1024) {
34454 + length >>= PAGE_SHIFT;
34455 + flags |= 8;
34456 + }
34457 +
34458 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34459 + gdt = get_cpu_gdt_table(cpu);
34460 + pack_descriptor(&d, address, length, 0x9b, flags);
34461 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34462 + pack_descriptor(&d, address, length, 0x93, flags);
34463 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34464 + }
34465 + return entry;
34466 + }
34467 + case 0x80: /* Not present */
34468 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34469 + return 0;
34470 + default: /* Shouldn't happen */
34471 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34472 + service, return_code);
34473 + return 0;
34474 }
34475 }
34476
34477 static struct {
34478 unsigned long address;
34479 unsigned short segment;
34480 -} pci_indirect = { 0, __KERNEL_CS };
34481 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34482
34483 -static int pci_bios_present;
34484 +static int pci_bios_present __read_only;
34485
34486 static int __init check_pcibios(void)
34487 {
34488 @@ -131,11 +174,13 @@ static int __init check_pcibios(void)
34489 unsigned long flags, pcibios_entry;
34490
34491 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34492 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34493 + pci_indirect.address = pcibios_entry;
34494
34495 local_irq_save(flags);
34496 - __asm__(
34497 - "lcall *(%%edi); cld\n\t"
34498 + __asm__("movw %w6, %%ds\n\t"
34499 + "lcall *%%ss:(%%edi); cld\n\t"
34500 + "push %%ss\n\t"
34501 + "pop %%ds\n\t"
34502 "jc 1f\n\t"
34503 "xor %%ah, %%ah\n"
34504 "1:"
34505 @@ -144,7 +189,8 @@ static int __init check_pcibios(void)
34506 "=b" (ebx),
34507 "=c" (ecx)
34508 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34509 - "D" (&pci_indirect)
34510 + "D" (&pci_indirect),
34511 + "r" (__PCIBIOS_DS)
34512 : "memory");
34513 local_irq_restore(flags);
34514
34515 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34516
34517 switch (len) {
34518 case 1:
34519 - __asm__("lcall *(%%esi); cld\n\t"
34520 + __asm__("movw %w6, %%ds\n\t"
34521 + "lcall *%%ss:(%%esi); cld\n\t"
34522 + "push %%ss\n\t"
34523 + "pop %%ds\n\t"
34524 "jc 1f\n\t"
34525 "xor %%ah, %%ah\n"
34526 "1:"
34527 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34528 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34529 "b" (bx),
34530 "D" ((long)reg),
34531 - "S" (&pci_indirect));
34532 + "S" (&pci_indirect),
34533 + "r" (__PCIBIOS_DS));
34534 /*
34535 * Zero-extend the result beyond 8 bits, do not trust the
34536 * BIOS having done it:
34537 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34538 *value &= 0xff;
34539 break;
34540 case 2:
34541 - __asm__("lcall *(%%esi); cld\n\t"
34542 + __asm__("movw %w6, %%ds\n\t"
34543 + "lcall *%%ss:(%%esi); cld\n\t"
34544 + "push %%ss\n\t"
34545 + "pop %%ds\n\t"
34546 "jc 1f\n\t"
34547 "xor %%ah, %%ah\n"
34548 "1:"
34549 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34550 : "1" (PCIBIOS_READ_CONFIG_WORD),
34551 "b" (bx),
34552 "D" ((long)reg),
34553 - "S" (&pci_indirect));
34554 + "S" (&pci_indirect),
34555 + "r" (__PCIBIOS_DS));
34556 /*
34557 * Zero-extend the result beyond 16 bits, do not trust the
34558 * BIOS having done it:
34559 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34560 *value &= 0xffff;
34561 break;
34562 case 4:
34563 - __asm__("lcall *(%%esi); cld\n\t"
34564 + __asm__("movw %w6, %%ds\n\t"
34565 + "lcall *%%ss:(%%esi); cld\n\t"
34566 + "push %%ss\n\t"
34567 + "pop %%ds\n\t"
34568 "jc 1f\n\t"
34569 "xor %%ah, %%ah\n"
34570 "1:"
34571 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34572 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34573 "b" (bx),
34574 "D" ((long)reg),
34575 - "S" (&pci_indirect));
34576 + "S" (&pci_indirect),
34577 + "r" (__PCIBIOS_DS));
34578 break;
34579 }
34580
34581 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34582
34583 switch (len) {
34584 case 1:
34585 - __asm__("lcall *(%%esi); cld\n\t"
34586 + __asm__("movw %w6, %%ds\n\t"
34587 + "lcall *%%ss:(%%esi); cld\n\t"
34588 + "push %%ss\n\t"
34589 + "pop %%ds\n\t"
34590 "jc 1f\n\t"
34591 "xor %%ah, %%ah\n"
34592 "1:"
34593 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34594 "c" (value),
34595 "b" (bx),
34596 "D" ((long)reg),
34597 - "S" (&pci_indirect));
34598 + "S" (&pci_indirect),
34599 + "r" (__PCIBIOS_DS));
34600 break;
34601 case 2:
34602 - __asm__("lcall *(%%esi); cld\n\t"
34603 + __asm__("movw %w6, %%ds\n\t"
34604 + "lcall *%%ss:(%%esi); cld\n\t"
34605 + "push %%ss\n\t"
34606 + "pop %%ds\n\t"
34607 "jc 1f\n\t"
34608 "xor %%ah, %%ah\n"
34609 "1:"
34610 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34611 "c" (value),
34612 "b" (bx),
34613 "D" ((long)reg),
34614 - "S" (&pci_indirect));
34615 + "S" (&pci_indirect),
34616 + "r" (__PCIBIOS_DS));
34617 break;
34618 case 4:
34619 - __asm__("lcall *(%%esi); cld\n\t"
34620 + __asm__("movw %w6, %%ds\n\t"
34621 + "lcall *%%ss:(%%esi); cld\n\t"
34622 + "push %%ss\n\t"
34623 + "pop %%ds\n\t"
34624 "jc 1f\n\t"
34625 "xor %%ah, %%ah\n"
34626 "1:"
34627 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34628 "c" (value),
34629 "b" (bx),
34630 "D" ((long)reg),
34631 - "S" (&pci_indirect));
34632 + "S" (&pci_indirect),
34633 + "r" (__PCIBIOS_DS));
34634 break;
34635 }
34636
34637 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34638
34639 DBG("PCI: Fetching IRQ routing table... ");
34640 __asm__("push %%es\n\t"
34641 + "movw %w8, %%ds\n\t"
34642 "push %%ds\n\t"
34643 "pop %%es\n\t"
34644 - "lcall *(%%esi); cld\n\t"
34645 + "lcall *%%ss:(%%esi); cld\n\t"
34646 "pop %%es\n\t"
34647 + "push %%ss\n\t"
34648 + "pop %%ds\n"
34649 "jc 1f\n\t"
34650 "xor %%ah, %%ah\n"
34651 "1:"
34652 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34653 "1" (0),
34654 "D" ((long) &opt),
34655 "S" (&pci_indirect),
34656 - "m" (opt)
34657 + "m" (opt),
34658 + "r" (__PCIBIOS_DS)
34659 : "memory");
34660 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34661 if (ret & 0xff00)
34662 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34663 {
34664 int ret;
34665
34666 - __asm__("lcall *(%%esi); cld\n\t"
34667 + __asm__("movw %w5, %%ds\n\t"
34668 + "lcall *%%ss:(%%esi); cld\n\t"
34669 + "push %%ss\n\t"
34670 + "pop %%ds\n"
34671 "jc 1f\n\t"
34672 "xor %%ah, %%ah\n"
34673 "1:"
34674 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34675 : "0" (PCIBIOS_SET_PCI_HW_INT),
34676 "b" ((dev->bus->number << 8) | dev->devfn),
34677 "c" ((irq << 8) | (pin + 10)),
34678 - "S" (&pci_indirect));
34679 + "S" (&pci_indirect),
34680 + "r" (__PCIBIOS_DS));
34681 return !(ret & 0xff00);
34682 }
34683 EXPORT_SYMBOL(pcibios_set_irq_routing);
34684 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34685 index 40e7cda..c7e6672 100644
34686 --- a/arch/x86/platform/efi/efi_32.c
34687 +++ b/arch/x86/platform/efi/efi_32.c
34688 @@ -61,11 +61,22 @@ void __init efi_call_phys_prolog(void)
34689 {
34690 struct desc_ptr gdt_descr;
34691
34692 +#ifdef CONFIG_PAX_KERNEXEC
34693 + struct desc_struct d;
34694 +#endif
34695 +
34696 local_irq_save(efi_rt_eflags);
34697
34698 load_cr3(initial_page_table);
34699 __flush_tlb_all();
34700
34701 +#ifdef CONFIG_PAX_KERNEXEC
34702 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34703 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34704 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34705 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34706 +#endif
34707 +
34708 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34709 gdt_descr.size = GDT_SIZE - 1;
34710 load_gdt(&gdt_descr);
34711 @@ -75,11 +86,24 @@ void __init efi_call_phys_epilog(void)
34712 {
34713 struct desc_ptr gdt_descr;
34714
34715 +#ifdef CONFIG_PAX_KERNEXEC
34716 + struct desc_struct d;
34717 +
34718 + memset(&d, 0, sizeof d);
34719 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34720 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34721 +#endif
34722 +
34723 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34724 gdt_descr.size = GDT_SIZE - 1;
34725 load_gdt(&gdt_descr);
34726
34727 +#ifdef CONFIG_PAX_PER_CPU_PGD
34728 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34729 +#else
34730 load_cr3(swapper_pg_dir);
34731 +#endif
34732 +
34733 __flush_tlb_all();
34734
34735 local_irq_restore(efi_rt_eflags);
34736 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34737 index 35aecb6..46177db 100644
34738 --- a/arch/x86/platform/efi/efi_64.c
34739 +++ b/arch/x86/platform/efi/efi_64.c
34740 @@ -99,6 +99,11 @@ void __init efi_call_phys_prolog(void)
34741 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34742 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34743 }
34744 +
34745 +#ifdef CONFIG_PAX_PER_CPU_PGD
34746 + load_cr3(swapper_pg_dir);
34747 +#endif
34748 +
34749 __flush_tlb_all();
34750 }
34751
34752 @@ -116,6 +121,11 @@ void __init efi_call_phys_epilog(void)
34753 for (pgd = 0; pgd < n_pgds; pgd++)
34754 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34755 kfree(save_pgd);
34756 +
34757 +#ifdef CONFIG_PAX_PER_CPU_PGD
34758 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34759 +#endif
34760 +
34761 __flush_tlb_all();
34762 local_irq_restore(efi_flags);
34763 early_code_mapping_set_exec(0);
34764 @@ -146,8 +156,23 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
34765 unsigned npages;
34766 pgd_t *pgd;
34767
34768 - if (efi_enabled(EFI_OLD_MEMMAP))
34769 + if (efi_enabled(EFI_OLD_MEMMAP)) {
34770 + /* PaX: We need to disable the NX bit in the PGD, otherwise we won't be
34771 + * able to execute the EFI services.
34772 + */
34773 + if (__supported_pte_mask & _PAGE_NX) {
34774 + unsigned long addr = (unsigned long) __va(0);
34775 + pgd_t pe = __pgd(pgd_val(*pgd_offset_k(addr)) & ~_PAGE_NX);
34776 +
34777 + pr_alert("PAX: Disabling NX protection for low memory map. Try booting without \"efi=old_map\"\n");
34778 +#ifdef CONFIG_PAX_PER_CPU_PGD
34779 + set_pgd(pgd_offset_cpu(0, kernel, addr), pe);
34780 +#endif
34781 + set_pgd(pgd_offset_k(addr), pe);
34782 + }
34783 +
34784 return 0;
34785 + }
34786
34787 efi_scratch.efi_pgt = (pgd_t *)(unsigned long)real_mode_header->trampoline_pgd;
34788 pgd = __va(efi_scratch.efi_pgt);
34789 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34790 index 040192b..7d3300f 100644
34791 --- a/arch/x86/platform/efi/efi_stub_32.S
34792 +++ b/arch/x86/platform/efi/efi_stub_32.S
34793 @@ -6,7 +6,9 @@
34794 */
34795
34796 #include <linux/linkage.h>
34797 +#include <linux/init.h>
34798 #include <asm/page_types.h>
34799 +#include <asm/segment.h>
34800
34801 /*
34802 * efi_call_phys(void *, ...) is a function with variable parameters.
34803 @@ -20,7 +22,7 @@
34804 * service functions will comply with gcc calling convention, too.
34805 */
34806
34807 -.text
34808 +__INIT
34809 ENTRY(efi_call_phys)
34810 /*
34811 * 0. The function can only be called in Linux kernel. So CS has been
34812 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34813 * The mapping of lower virtual memory has been created in prolog and
34814 * epilog.
34815 */
34816 - movl $1f, %edx
34817 - subl $__PAGE_OFFSET, %edx
34818 - jmp *%edx
34819 +#ifdef CONFIG_PAX_KERNEXEC
34820 + movl $(__KERNEXEC_EFI_DS), %edx
34821 + mov %edx, %ds
34822 + mov %edx, %es
34823 + mov %edx, %ss
34824 + addl $2f,(1f)
34825 + ljmp *(1f)
34826 +
34827 +__INITDATA
34828 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34829 +.previous
34830 +
34831 +2:
34832 + subl $2b,(1b)
34833 +#else
34834 + jmp 1f-__PAGE_OFFSET
34835 1:
34836 +#endif
34837
34838 /*
34839 * 2. Now on the top of stack is the return
34840 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34841 * parameter 2, ..., param n. To make things easy, we save the return
34842 * address of efi_call_phys in a global variable.
34843 */
34844 - popl %edx
34845 - movl %edx, saved_return_addr
34846 - /* get the function pointer into ECX*/
34847 - popl %ecx
34848 - movl %ecx, efi_rt_function_ptr
34849 - movl $2f, %edx
34850 - subl $__PAGE_OFFSET, %edx
34851 - pushl %edx
34852 + popl (saved_return_addr)
34853 + popl (efi_rt_function_ptr)
34854
34855 /*
34856 * 3. Clear PG bit in %CR0.
34857 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34858 /*
34859 * 5. Call the physical function.
34860 */
34861 - jmp *%ecx
34862 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
34863
34864 -2:
34865 /*
34866 * 6. After EFI runtime service returns, control will return to
34867 * following instruction. We'd better readjust stack pointer first.
34868 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34869 movl %cr0, %edx
34870 orl $0x80000000, %edx
34871 movl %edx, %cr0
34872 - jmp 1f
34873 -1:
34874 +
34875 /*
34876 * 8. Now restore the virtual mode from flat mode by
34877 * adding EIP with PAGE_OFFSET.
34878 */
34879 - movl $1f, %edx
34880 - jmp *%edx
34881 +#ifdef CONFIG_PAX_KERNEXEC
34882 + movl $(__KERNEL_DS), %edx
34883 + mov %edx, %ds
34884 + mov %edx, %es
34885 + mov %edx, %ss
34886 + ljmp $(__KERNEL_CS),$1f
34887 +#else
34888 + jmp 1f+__PAGE_OFFSET
34889 +#endif
34890 1:
34891
34892 /*
34893 * 9. Balance the stack. And because EAX contain the return value,
34894 * we'd better not clobber it.
34895 */
34896 - leal efi_rt_function_ptr, %edx
34897 - movl (%edx), %ecx
34898 - pushl %ecx
34899 + pushl (efi_rt_function_ptr)
34900
34901 /*
34902 - * 10. Push the saved return address onto the stack and return.
34903 + * 10. Return to the saved return address.
34904 */
34905 - leal saved_return_addr, %edx
34906 - movl (%edx), %ecx
34907 - pushl %ecx
34908 - ret
34909 + jmpl *(saved_return_addr)
34910 ENDPROC(efi_call_phys)
34911 .previous
34912
34913 -.data
34914 +__INITDATA
34915 saved_return_addr:
34916 .long 0
34917 efi_rt_function_ptr:
34918 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34919 index 5fcda72..cd4dc41 100644
34920 --- a/arch/x86/platform/efi/efi_stub_64.S
34921 +++ b/arch/x86/platform/efi/efi_stub_64.S
34922 @@ -11,6 +11,7 @@
34923 #include <asm/msr.h>
34924 #include <asm/processor-flags.h>
34925 #include <asm/page_types.h>
34926 +#include <asm/alternative-asm.h>
34927
34928 #define SAVE_XMM \
34929 mov %rsp, %rax; \
34930 @@ -88,6 +89,7 @@ ENTRY(efi_call)
34931 RESTORE_PGT
34932 addq $48, %rsp
34933 RESTORE_XMM
34934 + pax_force_retaddr 0, 1
34935 ret
34936 ENDPROC(efi_call)
34937
34938 @@ -245,8 +247,8 @@ efi_gdt64:
34939 .long 0 /* Filled out by user */
34940 .word 0
34941 .quad 0x0000000000000000 /* NULL descriptor */
34942 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
34943 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
34944 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
34945 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
34946 .quad 0x0080890000000000 /* TS descriptor */
34947 .quad 0x0000000000000000 /* TS continued */
34948 efi_gdt64_end:
34949 diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34950 index 1bbedc4..eb795b5 100644
34951 --- a/arch/x86/platform/intel-mid/intel-mid.c
34952 +++ b/arch/x86/platform/intel-mid/intel-mid.c
34953 @@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
34954 {
34955 };
34956
34957 -static void intel_mid_reboot(void)
34958 +static void __noreturn intel_mid_reboot(void)
34959 {
34960 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34961 + BUG();
34962 }
34963
34964 static unsigned long __init intel_mid_calibrate_tsc(void)
34965 diff --git a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
34966 index 3c1c386..59a68ed 100644
34967 --- a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
34968 +++ b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
34969 @@ -13,6 +13,6 @@
34970 /* For every CPU addition a new get_<cpuname>_ops interface needs
34971 * to be added.
34972 */
34973 -extern void *get_penwell_ops(void);
34974 -extern void *get_cloverview_ops(void);
34975 -extern void *get_tangier_ops(void);
34976 +extern const void *get_penwell_ops(void);
34977 +extern const void *get_cloverview_ops(void);
34978 +extern const void *get_tangier_ops(void);
34979 diff --git a/arch/x86/platform/intel-mid/mfld.c b/arch/x86/platform/intel-mid/mfld.c
34980 index 23381d2..8ddc10e 100644
34981 --- a/arch/x86/platform/intel-mid/mfld.c
34982 +++ b/arch/x86/platform/intel-mid/mfld.c
34983 @@ -64,12 +64,12 @@ static void __init penwell_arch_setup(void)
34984 pm_power_off = mfld_power_off;
34985 }
34986
34987 -void *get_penwell_ops(void)
34988 +const void *get_penwell_ops(void)
34989 {
34990 return &penwell_ops;
34991 }
34992
34993 -void *get_cloverview_ops(void)
34994 +const void *get_cloverview_ops(void)
34995 {
34996 return &penwell_ops;
34997 }
34998 diff --git a/arch/x86/platform/intel-mid/mrfl.c b/arch/x86/platform/intel-mid/mrfl.c
34999 index aaca917..66eadbc 100644
35000 --- a/arch/x86/platform/intel-mid/mrfl.c
35001 +++ b/arch/x86/platform/intel-mid/mrfl.c
35002 @@ -97,7 +97,7 @@ static struct intel_mid_ops tangier_ops = {
35003 .arch_setup = tangier_arch_setup,
35004 };
35005
35006 -void *get_tangier_ops(void)
35007 +const void *get_tangier_ops(void)
35008 {
35009 return &tangier_ops;
35010 }
35011 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
35012 index d6ee929..3637cb5 100644
35013 --- a/arch/x86/platform/olpc/olpc_dt.c
35014 +++ b/arch/x86/platform/olpc/olpc_dt.c
35015 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
35016 return res;
35017 }
35018
35019 -static struct of_pdt_ops prom_olpc_ops __initdata = {
35020 +static struct of_pdt_ops prom_olpc_ops __initconst = {
35021 .nextprop = olpc_dt_nextprop,
35022 .getproplen = olpc_dt_getproplen,
35023 .getproperty = olpc_dt_getproperty,
35024 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
35025 index 6ec7910..ecdbb11 100644
35026 --- a/arch/x86/power/cpu.c
35027 +++ b/arch/x86/power/cpu.c
35028 @@ -137,11 +137,8 @@ static void do_fpu_end(void)
35029 static void fix_processor_context(void)
35030 {
35031 int cpu = smp_processor_id();
35032 - struct tss_struct *t = &per_cpu(init_tss, cpu);
35033 -#ifdef CONFIG_X86_64
35034 - struct desc_struct *desc = get_cpu_gdt_table(cpu);
35035 - tss_desc tss;
35036 -#endif
35037 + struct tss_struct *t = init_tss + cpu;
35038 +
35039 set_tss_desc(cpu, t); /*
35040 * This just modifies memory; should not be
35041 * necessary. But... This is necessary, because
35042 @@ -150,10 +147,6 @@ static void fix_processor_context(void)
35043 */
35044
35045 #ifdef CONFIG_X86_64
35046 - memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
35047 - tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
35048 - write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
35049 -
35050 syscall_init(); /* This sets MSR_*STAR and related */
35051 #endif
35052 load_TR_desc(); /* This does ltr */
35053 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
35054 index bad628a..a102610 100644
35055 --- a/arch/x86/realmode/init.c
35056 +++ b/arch/x86/realmode/init.c
35057 @@ -68,7 +68,13 @@ void __init setup_real_mode(void)
35058 __va(real_mode_header->trampoline_header);
35059
35060 #ifdef CONFIG_X86_32
35061 - trampoline_header->start = __pa_symbol(startup_32_smp);
35062 + trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
35063 +
35064 +#ifdef CONFIG_PAX_KERNEXEC
35065 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
35066 +#endif
35067 +
35068 + trampoline_header->boot_cs = __BOOT_CS;
35069 trampoline_header->gdt_limit = __BOOT_DS + 7;
35070 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
35071 #else
35072 @@ -84,7 +90,7 @@ void __init setup_real_mode(void)
35073 *trampoline_cr4_features = read_cr4();
35074
35075 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
35076 - trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
35077 + trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
35078 trampoline_pgd[511] = init_level4_pgt[511].pgd;
35079 #endif
35080 }
35081 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
35082 index 7c0d7be..d24dc88 100644
35083 --- a/arch/x86/realmode/rm/Makefile
35084 +++ b/arch/x86/realmode/rm/Makefile
35085 @@ -67,5 +67,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
35086
35087 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
35088 -I$(srctree)/arch/x86/boot
35089 +ifdef CONSTIFY_PLUGIN
35090 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
35091 +endif
35092 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
35093 GCOV_PROFILE := n
35094 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
35095 index a28221d..93c40f1 100644
35096 --- a/arch/x86/realmode/rm/header.S
35097 +++ b/arch/x86/realmode/rm/header.S
35098 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
35099 #endif
35100 /* APM/BIOS reboot */
35101 .long pa_machine_real_restart_asm
35102 -#ifdef CONFIG_X86_64
35103 +#ifdef CONFIG_X86_32
35104 + .long __KERNEL_CS
35105 +#else
35106 .long __KERNEL32_CS
35107 #endif
35108 END(real_mode_header)
35109 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
35110 index 48ddd76..c26749f 100644
35111 --- a/arch/x86/realmode/rm/trampoline_32.S
35112 +++ b/arch/x86/realmode/rm/trampoline_32.S
35113 @@ -24,6 +24,12 @@
35114 #include <asm/page_types.h>
35115 #include "realmode.h"
35116
35117 +#ifdef CONFIG_PAX_KERNEXEC
35118 +#define ta(X) (X)
35119 +#else
35120 +#define ta(X) (pa_ ## X)
35121 +#endif
35122 +
35123 .text
35124 .code16
35125
35126 @@ -38,8 +44,6 @@ ENTRY(trampoline_start)
35127
35128 cli # We should be safe anyway
35129
35130 - movl tr_start, %eax # where we need to go
35131 -
35132 movl $0xA5A5A5A5, trampoline_status
35133 # write marker for master knows we're running
35134
35135 @@ -55,7 +59,7 @@ ENTRY(trampoline_start)
35136 movw $1, %dx # protected mode (PE) bit
35137 lmsw %dx # into protected mode
35138
35139 - ljmpl $__BOOT_CS, $pa_startup_32
35140 + ljmpl *(trampoline_header)
35141
35142 .section ".text32","ax"
35143 .code32
35144 @@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
35145 .balign 8
35146 GLOBAL(trampoline_header)
35147 tr_start: .space 4
35148 - tr_gdt_pad: .space 2
35149 + tr_boot_cs: .space 2
35150 tr_gdt: .space 6
35151 END(trampoline_header)
35152
35153 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
35154 index dac7b20..72dbaca 100644
35155 --- a/arch/x86/realmode/rm/trampoline_64.S
35156 +++ b/arch/x86/realmode/rm/trampoline_64.S
35157 @@ -93,6 +93,7 @@ ENTRY(startup_32)
35158 movl %edx, %gs
35159
35160 movl pa_tr_cr4, %eax
35161 + andl $~X86_CR4_PCIDE, %eax
35162 movl %eax, %cr4 # Enable PAE mode
35163
35164 # Setup trampoline 4 level pagetables
35165 @@ -106,7 +107,7 @@ ENTRY(startup_32)
35166 wrmsr
35167
35168 # Enable paging and in turn activate Long Mode
35169 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
35170 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
35171 movl %eax, %cr0
35172
35173 /*
35174 diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
35175 index 9e7e147..25a4158 100644
35176 --- a/arch/x86/realmode/rm/wakeup_asm.S
35177 +++ b/arch/x86/realmode/rm/wakeup_asm.S
35178 @@ -126,11 +126,10 @@ ENTRY(wakeup_start)
35179 lgdtl pmode_gdt
35180
35181 /* This really couldn't... */
35182 - movl pmode_entry, %eax
35183 movl pmode_cr0, %ecx
35184 movl %ecx, %cr0
35185 - ljmpl $__KERNEL_CS, $pa_startup_32
35186 - /* -> jmp *%eax in trampoline_32.S */
35187 +
35188 + ljmpl *pmode_entry
35189 #else
35190 jmp trampoline_start
35191 #endif
35192 diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
35193 index 604a37e..e49702a 100644
35194 --- a/arch/x86/tools/Makefile
35195 +++ b/arch/x86/tools/Makefile
35196 @@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
35197
35198 $(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
35199
35200 -HOST_EXTRACFLAGS += -I$(srctree)/tools/include
35201 +HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
35202 hostprogs-y += relocs
35203 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
35204 PHONY += relocs
35205 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
35206 index a5efb21..97490e9 100644
35207 --- a/arch/x86/tools/relocs.c
35208 +++ b/arch/x86/tools/relocs.c
35209 @@ -1,5 +1,7 @@
35210 /* This is included from relocs_32/64.c */
35211
35212 +#include "../../../include/generated/autoconf.h"
35213 +
35214 #define ElfW(type) _ElfW(ELF_BITS, type)
35215 #define _ElfW(bits, type) __ElfW(bits, type)
35216 #define __ElfW(bits, type) Elf##bits##_##type
35217 @@ -11,6 +13,7 @@
35218 #define Elf_Sym ElfW(Sym)
35219
35220 static Elf_Ehdr ehdr;
35221 +static Elf_Phdr *phdr;
35222
35223 struct relocs {
35224 uint32_t *offset;
35225 @@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
35226 }
35227 }
35228
35229 +static void read_phdrs(FILE *fp)
35230 +{
35231 + unsigned int i;
35232 +
35233 + phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
35234 + if (!phdr) {
35235 + die("Unable to allocate %d program headers\n",
35236 + ehdr.e_phnum);
35237 + }
35238 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
35239 + die("Seek to %d failed: %s\n",
35240 + ehdr.e_phoff, strerror(errno));
35241 + }
35242 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
35243 + die("Cannot read ELF program headers: %s\n",
35244 + strerror(errno));
35245 + }
35246 + for(i = 0; i < ehdr.e_phnum; i++) {
35247 + phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
35248 + phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
35249 + phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
35250 + phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
35251 + phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
35252 + phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
35253 + phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
35254 + phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
35255 + }
35256 +
35257 +}
35258 +
35259 static void read_shdrs(FILE *fp)
35260 {
35261 - int i;
35262 + unsigned int i;
35263 Elf_Shdr shdr;
35264
35265 secs = calloc(ehdr.e_shnum, sizeof(struct section));
35266 @@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
35267
35268 static void read_strtabs(FILE *fp)
35269 {
35270 - int i;
35271 + unsigned int i;
35272 for (i = 0; i < ehdr.e_shnum; i++) {
35273 struct section *sec = &secs[i];
35274 if (sec->shdr.sh_type != SHT_STRTAB) {
35275 @@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
35276
35277 static void read_symtabs(FILE *fp)
35278 {
35279 - int i,j;
35280 + unsigned int i,j;
35281 for (i = 0; i < ehdr.e_shnum; i++) {
35282 struct section *sec = &secs[i];
35283 if (sec->shdr.sh_type != SHT_SYMTAB) {
35284 @@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
35285 }
35286
35287
35288 -static void read_relocs(FILE *fp)
35289 +static void read_relocs(FILE *fp, int use_real_mode)
35290 {
35291 - int i,j;
35292 + unsigned int i,j;
35293 + uint32_t base;
35294 +
35295 for (i = 0; i < ehdr.e_shnum; i++) {
35296 struct section *sec = &secs[i];
35297 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35298 @@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
35299 die("Cannot read symbol table: %s\n",
35300 strerror(errno));
35301 }
35302 + base = 0;
35303 +
35304 +#ifdef CONFIG_X86_32
35305 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
35306 + if (phdr[j].p_type != PT_LOAD )
35307 + continue;
35308 + 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)
35309 + continue;
35310 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
35311 + break;
35312 + }
35313 +#endif
35314 +
35315 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
35316 Elf_Rel *rel = &sec->reltab[j];
35317 - rel->r_offset = elf_addr_to_cpu(rel->r_offset);
35318 + rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35319 rel->r_info = elf_xword_to_cpu(rel->r_info);
35320 #if (SHT_REL_TYPE == SHT_RELA)
35321 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35322 @@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35323
35324 static void print_absolute_symbols(void)
35325 {
35326 - int i;
35327 + unsigned int i;
35328 const char *format;
35329
35330 if (ELF_BITS == 64)
35331 @@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35332 for (i = 0; i < ehdr.e_shnum; i++) {
35333 struct section *sec = &secs[i];
35334 char *sym_strtab;
35335 - int j;
35336 + unsigned int j;
35337
35338 if (sec->shdr.sh_type != SHT_SYMTAB) {
35339 continue;
35340 @@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35341
35342 static void print_absolute_relocs(void)
35343 {
35344 - int i, printed = 0;
35345 + unsigned int i, printed = 0;
35346 const char *format;
35347
35348 if (ELF_BITS == 64)
35349 @@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35350 struct section *sec_applies, *sec_symtab;
35351 char *sym_strtab;
35352 Elf_Sym *sh_symtab;
35353 - int j;
35354 + unsigned int j;
35355 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35356 continue;
35357 }
35358 @@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35359 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35360 Elf_Sym *sym, const char *symname))
35361 {
35362 - int i;
35363 + unsigned int i;
35364 /* Walk through the relocations */
35365 for (i = 0; i < ehdr.e_shnum; i++) {
35366 char *sym_strtab;
35367 Elf_Sym *sh_symtab;
35368 struct section *sec_applies, *sec_symtab;
35369 - int j;
35370 + unsigned int j;
35371 struct section *sec = &secs[i];
35372
35373 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35374 @@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35375 {
35376 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35377 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35378 + char *sym_strtab = sec->link->link->strtab;
35379 +
35380 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35381 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35382 + return 0;
35383 +
35384 +#ifdef CONFIG_PAX_KERNEXEC
35385 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35386 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35387 + return 0;
35388 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35389 + return 0;
35390 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35391 + return 0;
35392 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35393 + return 0;
35394 +#endif
35395
35396 switch (r_type) {
35397 case R_386_NONE:
35398 @@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35399
35400 static void emit_relocs(int as_text, int use_real_mode)
35401 {
35402 - int i;
35403 + unsigned int i;
35404 int (*write_reloc)(uint32_t, FILE *) = write32;
35405 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35406 const char *symname);
35407 @@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35408 {
35409 regex_init(use_real_mode);
35410 read_ehdr(fp);
35411 + read_phdrs(fp);
35412 read_shdrs(fp);
35413 read_strtabs(fp);
35414 read_symtabs(fp);
35415 - read_relocs(fp);
35416 + read_relocs(fp, use_real_mode);
35417 if (ELF_BITS == 64)
35418 percpu_init();
35419 if (show_absolute_syms) {
35420 diff --git a/arch/x86/um/mem_32.c b/arch/x86/um/mem_32.c
35421 index f40281e..92728c9 100644
35422 --- a/arch/x86/um/mem_32.c
35423 +++ b/arch/x86/um/mem_32.c
35424 @@ -21,7 +21,7 @@ static int __init gate_vma_init(void)
35425 gate_vma.vm_start = FIXADDR_USER_START;
35426 gate_vma.vm_end = FIXADDR_USER_END;
35427 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35428 - gate_vma.vm_page_prot = __P101;
35429 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35430
35431 return 0;
35432 }
35433 diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35434 index 80ffa5b..a33bd15 100644
35435 --- a/arch/x86/um/tls_32.c
35436 +++ b/arch/x86/um/tls_32.c
35437 @@ -260,7 +260,7 @@ out:
35438 if (unlikely(task == current &&
35439 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35440 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35441 - "without flushed TLS.", current->pid);
35442 + "without flushed TLS.", task_pid_nr(current));
35443 }
35444
35445 return 0;
35446 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35447 index 5a4affe..9e2d522 100644
35448 --- a/arch/x86/vdso/Makefile
35449 +++ b/arch/x86/vdso/Makefile
35450 @@ -174,7 +174,7 @@ quiet_cmd_vdso = VDSO $@
35451 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35452 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35453
35454 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35455 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35456 $(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic $(LTO_CFLAGS)
35457 GCOV_PROFILE := n
35458
35459 diff --git a/arch/x86/vdso/vdso2c.h b/arch/x86/vdso/vdso2c.h
35460 index 0224987..c7d65a5 100644
35461 --- a/arch/x86/vdso/vdso2c.h
35462 +++ b/arch/x86/vdso/vdso2c.h
35463 @@ -12,7 +12,7 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
35464 unsigned long load_size = -1; /* Work around bogus warning */
35465 unsigned long mapping_size;
35466 ELF(Ehdr) *hdr = (ELF(Ehdr) *)raw_addr;
35467 - int i;
35468 + unsigned int i;
35469 unsigned long j;
35470 ELF(Shdr) *symtab_hdr = NULL, *strtab_hdr, *secstrings_hdr,
35471 *alt_sec = NULL;
35472 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35473 index e904c27..b9eaa03 100644
35474 --- a/arch/x86/vdso/vdso32-setup.c
35475 +++ b/arch/x86/vdso/vdso32-setup.c
35476 @@ -14,6 +14,7 @@
35477 #include <asm/cpufeature.h>
35478 #include <asm/processor.h>
35479 #include <asm/vdso.h>
35480 +#include <asm/mman.h>
35481
35482 #ifdef CONFIG_COMPAT_VDSO
35483 #define VDSO_DEFAULT 0
35484 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35485 index 970463b..da82d3e 100644
35486 --- a/arch/x86/vdso/vma.c
35487 +++ b/arch/x86/vdso/vma.c
35488 @@ -16,10 +16,9 @@
35489 #include <asm/vdso.h>
35490 #include <asm/page.h>
35491 #include <asm/hpet.h>
35492 +#include <asm/mman.h>
35493
35494 #if defined(CONFIG_X86_64)
35495 -unsigned int __read_mostly vdso64_enabled = 1;
35496 -
35497 extern unsigned short vdso_sync_cpuid;
35498 #endif
35499
35500 @@ -101,6 +100,11 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
35501 .pages = no_pages,
35502 };
35503
35504 +#ifdef CONFIG_PAX_RANDMMAP
35505 + if (mm->pax_flags & MF_PAX_RANDMMAP)
35506 + calculate_addr = false;
35507 +#endif
35508 +
35509 if (calculate_addr) {
35510 addr = vdso_addr(current->mm->start_stack,
35511 image->size - image->sym_vvar_start);
35512 @@ -111,14 +115,14 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
35513 down_write(&mm->mmap_sem);
35514
35515 addr = get_unmapped_area(NULL, addr,
35516 - image->size - image->sym_vvar_start, 0, 0);
35517 + image->size - image->sym_vvar_start, 0, MAP_EXECUTABLE);
35518 if (IS_ERR_VALUE(addr)) {
35519 ret = addr;
35520 goto up_fail;
35521 }
35522
35523 text_start = addr - image->sym_vvar_start;
35524 - current->mm->context.vdso = (void __user *)text_start;
35525 + mm->context.vdso = text_start;
35526
35527 /*
35528 * MAYWRITE to allow gdb to COW and set breakpoints
35529 @@ -163,15 +167,12 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
35530 hpet_address >> PAGE_SHIFT,
35531 PAGE_SIZE,
35532 pgprot_noncached(PAGE_READONLY));
35533 -
35534 - if (ret)
35535 - goto up_fail;
35536 }
35537 #endif
35538
35539 up_fail:
35540 if (ret)
35541 - current->mm->context.vdso = NULL;
35542 + current->mm->context.vdso = 0;
35543
35544 up_write(&mm->mmap_sem);
35545 return ret;
35546 @@ -191,8 +192,8 @@ static int load_vdso32(void)
35547
35548 if (selected_vdso32->sym_VDSO32_SYSENTER_RETURN)
35549 current_thread_info()->sysenter_return =
35550 - current->mm->context.vdso +
35551 - selected_vdso32->sym_VDSO32_SYSENTER_RETURN;
35552 + (void __force_user *)(current->mm->context.vdso +
35553 + selected_vdso32->sym_VDSO32_SYSENTER_RETURN);
35554
35555 return 0;
35556 }
35557 @@ -201,9 +202,6 @@ static int load_vdso32(void)
35558 #ifdef CONFIG_X86_64
35559 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35560 {
35561 - if (!vdso64_enabled)
35562 - return 0;
35563 -
35564 return map_vdso(&vdso_image_64, true);
35565 }
35566
35567 @@ -212,12 +210,8 @@ int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
35568 int uses_interp)
35569 {
35570 #ifdef CONFIG_X86_X32_ABI
35571 - if (test_thread_flag(TIF_X32)) {
35572 - if (!vdso64_enabled)
35573 - return 0;
35574 -
35575 + if (test_thread_flag(TIF_X32))
35576 return map_vdso(&vdso_image_x32, true);
35577 - }
35578 #endif
35579
35580 return load_vdso32();
35581 @@ -229,12 +223,3 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35582 return load_vdso32();
35583 }
35584 #endif
35585 -
35586 -#ifdef CONFIG_X86_64
35587 -static __init int vdso_setup(char *s)
35588 -{
35589 - vdso64_enabled = simple_strtoul(s, NULL, 0);
35590 - return 0;
35591 -}
35592 -__setup("vdso=", vdso_setup);
35593 -#endif
35594 diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35595 index e88fda8..76ce7ce 100644
35596 --- a/arch/x86/xen/Kconfig
35597 +++ b/arch/x86/xen/Kconfig
35598 @@ -9,6 +9,7 @@ config XEN
35599 select XEN_HAVE_PVMMU
35600 depends on X86_64 || (X86_32 && X86_PAE)
35601 depends on X86_TSC
35602 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35603 help
35604 This is the Linux Xen port. Enabling this will allow the
35605 kernel to boot in a paravirtualized environment under the
35606 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35607 index fac5e4f..5b5cf4f 100644
35608 --- a/arch/x86/xen/enlighten.c
35609 +++ b/arch/x86/xen/enlighten.c
35610 @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35611
35612 struct shared_info xen_dummy_shared_info;
35613
35614 -void *xen_initial_gdt;
35615 -
35616 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35617 __read_mostly int xen_have_vector_callback;
35618 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35619 @@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35620 {
35621 unsigned long va = dtr->address;
35622 unsigned int size = dtr->size + 1;
35623 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35624 - unsigned long frames[pages];
35625 + unsigned long frames[65536 / PAGE_SIZE];
35626 int f;
35627
35628 /*
35629 @@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35630 {
35631 unsigned long va = dtr->address;
35632 unsigned int size = dtr->size + 1;
35633 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35634 - unsigned long frames[pages];
35635 + unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35636 int f;
35637
35638 /*
35639 @@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35640 * 8-byte entries, or 16 4k pages..
35641 */
35642
35643 - BUG_ON(size > 65536);
35644 + BUG_ON(size > GDT_SIZE);
35645 BUG_ON(va & ~PAGE_MASK);
35646
35647 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35648 @@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35649 return 0;
35650 }
35651
35652 -static void set_xen_basic_apic_ops(void)
35653 +static void __init set_xen_basic_apic_ops(void)
35654 {
35655 apic->read = xen_apic_read;
35656 apic->write = xen_apic_write;
35657 @@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35658 #endif
35659 };
35660
35661 -static void xen_reboot(int reason)
35662 +static __noreturn void xen_reboot(int reason)
35663 {
35664 struct sched_shutdown r = { .reason = reason };
35665
35666 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35667 - BUG();
35668 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35669 + BUG();
35670 }
35671
35672 -static void xen_restart(char *msg)
35673 +static __noreturn void xen_restart(char *msg)
35674 {
35675 xen_reboot(SHUTDOWN_reboot);
35676 }
35677
35678 -static void xen_emergency_restart(void)
35679 +static __noreturn void xen_emergency_restart(void)
35680 {
35681 xen_reboot(SHUTDOWN_reboot);
35682 }
35683
35684 -static void xen_machine_halt(void)
35685 +static __noreturn void xen_machine_halt(void)
35686 {
35687 xen_reboot(SHUTDOWN_poweroff);
35688 }
35689
35690 -static void xen_machine_power_off(void)
35691 +static __noreturn void xen_machine_power_off(void)
35692 {
35693 if (pm_power_off)
35694 pm_power_off();
35695 @@ -1573,7 +1569,17 @@ asmlinkage __visible void __init xen_start_kernel(void)
35696 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35697
35698 /* Work out if we support NX */
35699 - x86_configure_nx();
35700 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35701 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35702 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35703 + unsigned l, h;
35704 +
35705 + __supported_pte_mask |= _PAGE_NX;
35706 + rdmsr(MSR_EFER, l, h);
35707 + l |= EFER_NX;
35708 + wrmsr(MSR_EFER, l, h);
35709 + }
35710 +#endif
35711
35712 /* Get mfn list */
35713 xen_build_dynamic_phys_to_machine();
35714 @@ -1601,13 +1607,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
35715
35716 machine_ops = xen_machine_ops;
35717
35718 - /*
35719 - * The only reliable way to retain the initial address of the
35720 - * percpu gdt_page is to remember it here, so we can go and
35721 - * mark it RW later, when the initial percpu area is freed.
35722 - */
35723 - xen_initial_gdt = &per_cpu(gdt_page, 0);
35724 -
35725 xen_smp_init();
35726
35727 #ifdef CONFIG_ACPI_NUMA
35728 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35729 index a8a1a3d..8216142 100644
35730 --- a/arch/x86/xen/mmu.c
35731 +++ b/arch/x86/xen/mmu.c
35732 @@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35733 return val;
35734 }
35735
35736 -static pteval_t pte_pfn_to_mfn(pteval_t val)
35737 +static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35738 {
35739 if (val & _PAGE_PRESENT) {
35740 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35741 @@ -1867,7 +1867,11 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35742 * L3_k[511] -> level2_fixmap_pgt */
35743 convert_pfn_mfn(level3_kernel_pgt);
35744
35745 + convert_pfn_mfn(level3_vmalloc_start_pgt);
35746 + convert_pfn_mfn(level3_vmalloc_end_pgt);
35747 + convert_pfn_mfn(level3_vmemmap_pgt);
35748 /* L3_k[511][506] -> level1_fixmap_pgt */
35749 + /* L3_k[511][507] -> level1_vsyscall_pgt */
35750 convert_pfn_mfn(level2_fixmap_pgt);
35751 }
35752 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35753 @@ -1892,11 +1896,16 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35754 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35755 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35756 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35757 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35758 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35759 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35760 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35761 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35762 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35763 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35764 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35765 set_page_prot(level1_fixmap_pgt, PAGE_KERNEL_RO);
35766 + set_page_prot(level1_vsyscall_pgt, PAGE_KERNEL_RO);
35767
35768 /* Pin down new L4 */
35769 pin_pagetable_pfn(MMUEXT_PIN_L4_TABLE,
35770 @@ -2080,6 +2089,7 @@ static void __init xen_post_allocator_init(void)
35771 pv_mmu_ops.set_pud = xen_set_pud;
35772 #if PAGETABLE_LEVELS == 4
35773 pv_mmu_ops.set_pgd = xen_set_pgd;
35774 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35775 #endif
35776
35777 /* This will work as long as patching hasn't happened yet
35778 @@ -2158,6 +2168,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35779 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35780 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35781 .set_pgd = xen_set_pgd_hyper,
35782 + .set_pgd_batched = xen_set_pgd_hyper,
35783
35784 .alloc_pud = xen_alloc_pmd_init,
35785 .release_pud = xen_release_pmd_init,
35786 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35787 index 4c071ae..00e7049 100644
35788 --- a/arch/x86/xen/smp.c
35789 +++ b/arch/x86/xen/smp.c
35790 @@ -288,17 +288,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35791
35792 if (xen_pv_domain()) {
35793 if (!xen_feature(XENFEAT_writable_page_tables))
35794 - /* We've switched to the "real" per-cpu gdt, so make
35795 - * sure the old memory can be recycled. */
35796 - make_lowmem_page_readwrite(xen_initial_gdt);
35797 -
35798 #ifdef CONFIG_X86_32
35799 /*
35800 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35801 * expects __USER_DS
35802 */
35803 - loadsegment(ds, __USER_DS);
35804 - loadsegment(es, __USER_DS);
35805 + loadsegment(ds, __KERNEL_DS);
35806 + loadsegment(es, __KERNEL_DS);
35807 #endif
35808
35809 xen_filter_cpu_maps();
35810 @@ -379,7 +375,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35811 #ifdef CONFIG_X86_32
35812 /* Note: PVH is not yet supported on x86_32. */
35813 ctxt->user_regs.fs = __KERNEL_PERCPU;
35814 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35815 + savesegment(gs, ctxt->user_regs.gs);
35816 #endif
35817 memset(&ctxt->fpu_ctxt, 0, sizeof(ctxt->fpu_ctxt));
35818
35819 @@ -387,8 +383,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35820 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
35821 ctxt->flags = VGCF_IN_KERNEL;
35822 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35823 - ctxt->user_regs.ds = __USER_DS;
35824 - ctxt->user_regs.es = __USER_DS;
35825 + ctxt->user_regs.ds = __KERNEL_DS;
35826 + ctxt->user_regs.es = __KERNEL_DS;
35827 ctxt->user_regs.ss = __KERNEL_DS;
35828
35829 xen_copy_trap_info(ctxt->trap_ctxt);
35830 @@ -446,14 +442,13 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35831 int rc;
35832
35833 per_cpu(current_task, cpu) = idle;
35834 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
35835 #ifdef CONFIG_X86_32
35836 irq_ctx_init(cpu);
35837 #else
35838 clear_tsk_thread_flag(idle, TIF_FORK);
35839 #endif
35840 - per_cpu(kernel_stack, cpu) =
35841 - (unsigned long)task_stack_page(idle) -
35842 - KERNEL_STACK_OFFSET + THREAD_SIZE;
35843 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35844
35845 xen_setup_runstate_info(cpu);
35846 xen_setup_timer(cpu);
35847 @@ -732,7 +727,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35848
35849 void __init xen_smp_init(void)
35850 {
35851 - smp_ops = xen_smp_ops;
35852 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35853 xen_fill_possible_map();
35854 }
35855
35856 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35857 index fd92a64..1f72641 100644
35858 --- a/arch/x86/xen/xen-asm_32.S
35859 +++ b/arch/x86/xen/xen-asm_32.S
35860 @@ -99,7 +99,7 @@ ENTRY(xen_iret)
35861 pushw %fs
35862 movl $(__KERNEL_PERCPU), %eax
35863 movl %eax, %fs
35864 - movl %fs:xen_vcpu, %eax
35865 + mov PER_CPU_VAR(xen_vcpu), %eax
35866 POP_FS
35867 #else
35868 movl %ss:xen_vcpu, %eax
35869 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35870 index 674b2225..f1f5dc1 100644
35871 --- a/arch/x86/xen/xen-head.S
35872 +++ b/arch/x86/xen/xen-head.S
35873 @@ -39,6 +39,17 @@ ENTRY(startup_xen)
35874 #ifdef CONFIG_X86_32
35875 mov %esi,xen_start_info
35876 mov $init_thread_union+THREAD_SIZE,%esp
35877 +#ifdef CONFIG_SMP
35878 + movl $cpu_gdt_table,%edi
35879 + movl $__per_cpu_load,%eax
35880 + movw %ax,__KERNEL_PERCPU + 2(%edi)
35881 + rorl $16,%eax
35882 + movb %al,__KERNEL_PERCPU + 4(%edi)
35883 + movb %ah,__KERNEL_PERCPU + 7(%edi)
35884 + movl $__per_cpu_end - 1,%eax
35885 + subl $__per_cpu_start,%eax
35886 + movw %ax,__KERNEL_PERCPU + 0(%edi)
35887 +#endif
35888 #else
35889 mov %rsi,xen_start_info
35890 mov $init_thread_union+THREAD_SIZE,%rsp
35891 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35892 index 28c7e0b..2acfec7 100644
35893 --- a/arch/x86/xen/xen-ops.h
35894 +++ b/arch/x86/xen/xen-ops.h
35895 @@ -10,8 +10,6 @@
35896 extern const char xen_hypervisor_callback[];
35897 extern const char xen_failsafe_callback[];
35898
35899 -extern void *xen_initial_gdt;
35900 -
35901 struct trap_info;
35902 void xen_copy_trap_info(struct trap_info *traps);
35903
35904 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35905 index 525bd3d..ef888b1 100644
35906 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
35907 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35908 @@ -119,9 +119,9 @@
35909 ----------------------------------------------------------------------*/
35910
35911 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35912 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35913 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35914 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35915 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35916
35917 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35918 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35919 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35920 index 2f33760..835e50a 100644
35921 --- a/arch/xtensa/variants/fsf/include/variant/core.h
35922 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
35923 @@ -11,6 +11,7 @@
35924 #ifndef _XTENSA_CORE_H
35925 #define _XTENSA_CORE_H
35926
35927 +#include <linux/const.h>
35928
35929 /****************************************************************************
35930 Parameters Useful for Any Code, USER or PRIVILEGED
35931 @@ -112,9 +113,9 @@
35932 ----------------------------------------------------------------------*/
35933
35934 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35935 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35936 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35937 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35938 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35939
35940 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35941 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35942 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35943 index af00795..2bb8105 100644
35944 --- a/arch/xtensa/variants/s6000/include/variant/core.h
35945 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
35946 @@ -11,6 +11,7 @@
35947 #ifndef _XTENSA_CORE_CONFIGURATION_H
35948 #define _XTENSA_CORE_CONFIGURATION_H
35949
35950 +#include <linux/const.h>
35951
35952 /****************************************************************************
35953 Parameters Useful for Any Code, USER or PRIVILEGED
35954 @@ -118,9 +119,9 @@
35955 ----------------------------------------------------------------------*/
35956
35957 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35958 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35959 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35960 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35961 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35962
35963 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35964 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35965 diff --git a/block/bio.c b/block/bio.c
35966 index 3e6e198..5c65199 100644
35967 --- a/block/bio.c
35968 +++ b/block/bio.c
35969 @@ -1163,7 +1163,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
35970 /*
35971 * Overflow, abort
35972 */
35973 - if (end < start)
35974 + if (end < start || end - start > INT_MAX - nr_pages)
35975 return ERR_PTR(-EINVAL);
35976
35977 nr_pages += end - start;
35978 @@ -1297,7 +1297,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
35979 /*
35980 * Overflow, abort
35981 */
35982 - if (end < start)
35983 + if (end < start || end - start > INT_MAX - nr_pages)
35984 return ERR_PTR(-EINVAL);
35985
35986 nr_pages += end - start;
35987 @@ -1559,7 +1559,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
35988 const int read = bio_data_dir(bio) == READ;
35989 struct bio_map_data *bmd = bio->bi_private;
35990 int i;
35991 - char *p = bmd->sgvecs[0].iov_base;
35992 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
35993
35994 bio_for_each_segment_all(bvec, bio, i) {
35995 char *addr = page_address(bvec->bv_page);
35996 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
35997 index 0736729..2ec3b48 100644
35998 --- a/block/blk-iopoll.c
35999 +++ b/block/blk-iopoll.c
36000 @@ -74,7 +74,7 @@ void blk_iopoll_complete(struct blk_iopoll *iop)
36001 }
36002 EXPORT_SYMBOL(blk_iopoll_complete);
36003
36004 -static void blk_iopoll_softirq(struct softirq_action *h)
36005 +static __latent_entropy void blk_iopoll_softirq(void)
36006 {
36007 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
36008 int rearm = 0, budget = blk_iopoll_budget;
36009 diff --git a/block/blk-map.c b/block/blk-map.c
36010 index f890d43..97b0482 100644
36011 --- a/block/blk-map.c
36012 +++ b/block/blk-map.c
36013 @@ -300,7 +300,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
36014 if (!len || !kbuf)
36015 return -EINVAL;
36016
36017 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
36018 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
36019 if (do_copy)
36020 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
36021 else
36022 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
36023 index 53b1737..08177d2e 100644
36024 --- a/block/blk-softirq.c
36025 +++ b/block/blk-softirq.c
36026 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
36027 * Softirq action handler - move entries to local list and loop over them
36028 * while passing them to the queue registered handler.
36029 */
36030 -static void blk_done_softirq(struct softirq_action *h)
36031 +static __latent_entropy void blk_done_softirq(void)
36032 {
36033 struct list_head *cpu_list, local_list;
36034
36035 diff --git a/block/bsg.c b/block/bsg.c
36036 index 276e869..6fe4c61 100644
36037 --- a/block/bsg.c
36038 +++ b/block/bsg.c
36039 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
36040 struct sg_io_v4 *hdr, struct bsg_device *bd,
36041 fmode_t has_write_perm)
36042 {
36043 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36044 + unsigned char *cmdptr;
36045 +
36046 if (hdr->request_len > BLK_MAX_CDB) {
36047 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
36048 if (!rq->cmd)
36049 return -ENOMEM;
36050 - }
36051 + cmdptr = rq->cmd;
36052 + } else
36053 + cmdptr = tmpcmd;
36054
36055 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
36056 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
36057 hdr->request_len))
36058 return -EFAULT;
36059
36060 + if (cmdptr != rq->cmd)
36061 + memcpy(rq->cmd, cmdptr, hdr->request_len);
36062 +
36063 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
36064 if (blk_verify_command(rq->cmd, has_write_perm))
36065 return -EPERM;
36066 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
36067 index f678c73..f35aa18 100644
36068 --- a/block/compat_ioctl.c
36069 +++ b/block/compat_ioctl.c
36070 @@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
36071 cgc = compat_alloc_user_space(sizeof(*cgc));
36072 cgc32 = compat_ptr(arg);
36073
36074 - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
36075 + if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
36076 get_user(data, &cgc32->buffer) ||
36077 put_user(compat_ptr(data), &cgc->buffer) ||
36078 copy_in_user(&cgc->buflen, &cgc32->buflen,
36079 @@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
36080 err |= __get_user(f->spec1, &uf->spec1);
36081 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
36082 err |= __get_user(name, &uf->name);
36083 - f->name = compat_ptr(name);
36084 + f->name = (void __force_kernel *)compat_ptr(name);
36085 if (err) {
36086 err = -EFAULT;
36087 goto out;
36088 diff --git a/block/genhd.c b/block/genhd.c
36089 index bd30606..bbc9b90 100644
36090 --- a/block/genhd.c
36091 +++ b/block/genhd.c
36092 @@ -469,21 +469,24 @@ static char *bdevt_str(dev_t devt, char *buf)
36093
36094 /*
36095 * Register device numbers dev..(dev+range-1)
36096 - * range must be nonzero
36097 + * Noop if @range is zero.
36098 * The hash chain is sorted on range, so that subranges can override.
36099 */
36100 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
36101 struct kobject *(*probe)(dev_t, int *, void *),
36102 int (*lock)(dev_t, void *), void *data)
36103 {
36104 - kobj_map(bdev_map, devt, range, module, probe, lock, data);
36105 + if (range)
36106 + kobj_map(bdev_map, devt, range, module, probe, lock, data);
36107 }
36108
36109 EXPORT_SYMBOL(blk_register_region);
36110
36111 +/* undo blk_register_region(), noop if @range is zero */
36112 void blk_unregister_region(dev_t devt, unsigned long range)
36113 {
36114 - kobj_unmap(bdev_map, devt, range);
36115 + if (range)
36116 + kobj_unmap(bdev_map, devt, range);
36117 }
36118
36119 EXPORT_SYMBOL(blk_unregister_region);
36120 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
36121 index 56d08fd..2e07090 100644
36122 --- a/block/partitions/efi.c
36123 +++ b/block/partitions/efi.c
36124 @@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
36125 if (!gpt)
36126 return NULL;
36127
36128 + if (!le32_to_cpu(gpt->num_partition_entries))
36129 + return NULL;
36130 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
36131 + if (!pte)
36132 + return NULL;
36133 +
36134 count = le32_to_cpu(gpt->num_partition_entries) *
36135 le32_to_cpu(gpt->sizeof_partition_entry);
36136 - if (!count)
36137 - return NULL;
36138 - pte = kmalloc(count, GFP_KERNEL);
36139 - if (!pte)
36140 - return NULL;
36141 -
36142 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
36143 (u8 *) pte, count) < count) {
36144 kfree(pte);
36145 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
36146 index b0c2a61..10bb6ec 100644
36147 --- a/block/scsi_ioctl.c
36148 +++ b/block/scsi_ioctl.c
36149 @@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
36150 return put_user(0, p);
36151 }
36152
36153 -static int sg_get_timeout(struct request_queue *q)
36154 +static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
36155 {
36156 return jiffies_to_clock_t(q->sg_timeout);
36157 }
36158 @@ -227,8 +227,20 @@ EXPORT_SYMBOL(blk_verify_command);
36159 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
36160 struct sg_io_hdr *hdr, fmode_t mode)
36161 {
36162 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
36163 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36164 + unsigned char *cmdptr;
36165 +
36166 + if (rq->cmd != rq->__cmd)
36167 + cmdptr = rq->cmd;
36168 + else
36169 + cmdptr = tmpcmd;
36170 +
36171 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
36172 return -EFAULT;
36173 +
36174 + if (cmdptr != rq->cmd)
36175 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
36176 +
36177 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
36178 return -EPERM;
36179
36180 @@ -431,6 +443,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36181 int err;
36182 unsigned int in_len, out_len, bytes, opcode, cmdlen;
36183 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
36184 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36185 + unsigned char *cmdptr;
36186
36187 if (!sic)
36188 return -EINVAL;
36189 @@ -469,9 +483,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36190 */
36191 err = -EFAULT;
36192 rq->cmd_len = cmdlen;
36193 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
36194 +
36195 + if (rq->cmd != rq->__cmd)
36196 + cmdptr = rq->cmd;
36197 + else
36198 + cmdptr = tmpcmd;
36199 +
36200 + if (copy_from_user(cmdptr, sic->data, cmdlen))
36201 goto error;
36202
36203 + if (rq->cmd != cmdptr)
36204 + memcpy(rq->cmd, cmdptr, cmdlen);
36205 +
36206 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
36207 goto error;
36208
36209 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
36210 index e592c90..c566114 100644
36211 --- a/crypto/cryptd.c
36212 +++ b/crypto/cryptd.c
36213 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
36214
36215 struct cryptd_blkcipher_request_ctx {
36216 crypto_completion_t complete;
36217 -};
36218 +} __no_const;
36219
36220 struct cryptd_hash_ctx {
36221 struct crypto_shash *child;
36222 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
36223
36224 struct cryptd_aead_request_ctx {
36225 crypto_completion_t complete;
36226 -};
36227 +} __no_const;
36228
36229 static void cryptd_queue_worker(struct work_struct *work);
36230
36231 diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
36232 index 309d345..1632720 100644
36233 --- a/crypto/pcrypt.c
36234 +++ b/crypto/pcrypt.c
36235 @@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
36236 int ret;
36237
36238 pinst->kobj.kset = pcrypt_kset;
36239 - ret = kobject_add(&pinst->kobj, NULL, name);
36240 + ret = kobject_add(&pinst->kobj, NULL, "%s", name);
36241 if (!ret)
36242 kobject_uevent(&pinst->kobj, KOBJ_ADD);
36243
36244 diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
36245 index 6921c7f..78e1af7 100644
36246 --- a/drivers/acpi/acpica/hwxfsleep.c
36247 +++ b/drivers/acpi/acpica/hwxfsleep.c
36248 @@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
36249 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
36250
36251 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
36252 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36253 - acpi_hw_extended_sleep},
36254 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36255 - acpi_hw_extended_wake_prep},
36256 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
36257 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36258 + .extended_function = acpi_hw_extended_sleep},
36259 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36260 + .extended_function = acpi_hw_extended_wake_prep},
36261 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
36262 + .extended_function = acpi_hw_extended_wake}
36263 };
36264
36265 /*
36266 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
36267 index 16129c7..8b675cd 100644
36268 --- a/drivers/acpi/apei/apei-internal.h
36269 +++ b/drivers/acpi/apei/apei-internal.h
36270 @@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
36271 struct apei_exec_ins_type {
36272 u32 flags;
36273 apei_exec_ins_func_t run;
36274 -};
36275 +} __do_const;
36276
36277 struct apei_exec_context {
36278 u32 ip;
36279 diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
36280 index fc5f780..e5ac91a 100644
36281 --- a/drivers/acpi/apei/ghes.c
36282 +++ b/drivers/acpi/apei/ghes.c
36283 @@ -478,7 +478,7 @@ static void __ghes_print_estatus(const char *pfx,
36284 const struct acpi_hest_generic *generic,
36285 const struct acpi_hest_generic_status *estatus)
36286 {
36287 - static atomic_t seqno;
36288 + static atomic_unchecked_t seqno;
36289 unsigned int curr_seqno;
36290 char pfx_seq[64];
36291
36292 @@ -489,7 +489,7 @@ static void __ghes_print_estatus(const char *pfx,
36293 else
36294 pfx = KERN_ERR;
36295 }
36296 - curr_seqno = atomic_inc_return(&seqno);
36297 + curr_seqno = atomic_inc_return_unchecked(&seqno);
36298 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
36299 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
36300 pfx_seq, generic->header.source_id);
36301 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
36302 index a83e3c6..c3d617f 100644
36303 --- a/drivers/acpi/bgrt.c
36304 +++ b/drivers/acpi/bgrt.c
36305 @@ -86,8 +86,10 @@ static int __init bgrt_init(void)
36306 if (!bgrt_image)
36307 return -ENODEV;
36308
36309 - bin_attr_image.private = bgrt_image;
36310 - bin_attr_image.size = bgrt_image_size;
36311 + pax_open_kernel();
36312 + *(void **)&bin_attr_image.private = bgrt_image;
36313 + *(size_t *)&bin_attr_image.size = bgrt_image_size;
36314 + pax_close_kernel();
36315
36316 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36317 if (!bgrt_kobj)
36318 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36319 index 7556e7c..89a96bd 100644
36320 --- a/drivers/acpi/blacklist.c
36321 +++ b/drivers/acpi/blacklist.c
36322 @@ -51,7 +51,7 @@ struct acpi_blacklist_item {
36323 u32 is_critical_error;
36324 };
36325
36326 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36327 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36328
36329 /*
36330 * POLICY: If *anything* doesn't work, put it on the blacklist.
36331 @@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36332 return 0;
36333 }
36334
36335 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36336 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36337 {
36338 .callback = dmi_disable_osi_vista,
36339 .ident = "Fujitsu Siemens",
36340 diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36341 index c68e724..e863008 100644
36342 --- a/drivers/acpi/custom_method.c
36343 +++ b/drivers/acpi/custom_method.c
36344 @@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36345 struct acpi_table_header table;
36346 acpi_status status;
36347
36348 +#ifdef CONFIG_GRKERNSEC_KMEM
36349 + return -EPERM;
36350 +#endif
36351 +
36352 if (!(*ppos)) {
36353 /* parse the table header to get the table length */
36354 if (count <= sizeof(struct acpi_table_header))
36355 diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
36356 index 7db1931..302dd5f 100644
36357 --- a/drivers/acpi/device_pm.c
36358 +++ b/drivers/acpi/device_pm.c
36359 @@ -1021,6 +1021,8 @@ EXPORT_SYMBOL_GPL(acpi_subsys_freeze);
36360
36361 #endif /* CONFIG_PM_SLEEP */
36362
36363 +static void acpi_dev_pm_detach(struct device *dev, bool power_off);
36364 +
36365 static struct dev_pm_domain acpi_general_pm_domain = {
36366 .ops = {
36367 #ifdef CONFIG_PM_RUNTIME
36368 @@ -1039,6 +1041,7 @@ static struct dev_pm_domain acpi_general_pm_domain = {
36369 .restore_early = acpi_subsys_resume_early,
36370 #endif
36371 },
36372 + .detach = acpi_dev_pm_detach
36373 };
36374
36375 /**
36376 @@ -1108,7 +1111,6 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on)
36377 acpi_device_wakeup(adev, ACPI_STATE_S0, false);
36378 }
36379
36380 - dev->pm_domain->detach = acpi_dev_pm_detach;
36381 return 0;
36382 }
36383 EXPORT_SYMBOL_GPL(acpi_dev_pm_attach);
36384 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36385 index 17f9ec5..d9a455e 100644
36386 --- a/drivers/acpi/processor_idle.c
36387 +++ b/drivers/acpi/processor_idle.c
36388 @@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36389 {
36390 int i, count = CPUIDLE_DRIVER_STATE_START;
36391 struct acpi_processor_cx *cx;
36392 - struct cpuidle_state *state;
36393 + cpuidle_state_no_const *state;
36394 struct cpuidle_driver *drv = &acpi_idle_driver;
36395
36396 if (!pr->flags.power_setup_done)
36397 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36398 index 13e577c..cef11ee 100644
36399 --- a/drivers/acpi/sysfs.c
36400 +++ b/drivers/acpi/sysfs.c
36401 @@ -423,11 +423,11 @@ static u32 num_counters;
36402 static struct attribute **all_attrs;
36403 static u32 acpi_gpe_count;
36404
36405 -static struct attribute_group interrupt_stats_attr_group = {
36406 +static attribute_group_no_const interrupt_stats_attr_group = {
36407 .name = "interrupts",
36408 };
36409
36410 -static struct kobj_attribute *counter_attrs;
36411 +static kobj_attribute_no_const *counter_attrs;
36412
36413 static void delete_gpe_attr_array(void)
36414 {
36415 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36416 index 97683e4..655f6ba 100644
36417 --- a/drivers/ata/libahci.c
36418 +++ b/drivers/ata/libahci.c
36419 @@ -1252,7 +1252,7 @@ int ahci_kick_engine(struct ata_port *ap)
36420 }
36421 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36422
36423 -static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36424 +static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36425 struct ata_taskfile *tf, int is_cmd, u16 flags,
36426 unsigned long timeout_msec)
36427 {
36428 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36429 index c5ba15a..75ec7a8 100644
36430 --- a/drivers/ata/libata-core.c
36431 +++ b/drivers/ata/libata-core.c
36432 @@ -99,7 +99,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36433 static void ata_dev_xfermask(struct ata_device *dev);
36434 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36435
36436 -atomic_t ata_print_id = ATOMIC_INIT(0);
36437 +atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36438
36439 struct ata_force_param {
36440 const char *name;
36441 @@ -4797,7 +4797,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36442 struct ata_port *ap;
36443 unsigned int tag;
36444
36445 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36446 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36447 ap = qc->ap;
36448
36449 qc->flags = 0;
36450 @@ -4813,7 +4813,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36451 struct ata_port *ap;
36452 struct ata_link *link;
36453
36454 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36455 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36456 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36457 ap = qc->ap;
36458 link = qc->dev->link;
36459 @@ -5917,6 +5917,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36460 return;
36461
36462 spin_lock(&lock);
36463 + pax_open_kernel();
36464
36465 for (cur = ops->inherits; cur; cur = cur->inherits) {
36466 void **inherit = (void **)cur;
36467 @@ -5930,8 +5931,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36468 if (IS_ERR(*pp))
36469 *pp = NULL;
36470
36471 - ops->inherits = NULL;
36472 + *(struct ata_port_operations **)&ops->inherits = NULL;
36473
36474 + pax_close_kernel();
36475 spin_unlock(&lock);
36476 }
36477
36478 @@ -6127,7 +6129,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36479
36480 /* give ports names and add SCSI hosts */
36481 for (i = 0; i < host->n_ports; i++) {
36482 - host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36483 + host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36484 host->ports[i]->local_port_no = i + 1;
36485 }
36486
36487 diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36488 index 0586f66..1a8f74a 100644
36489 --- a/drivers/ata/libata-scsi.c
36490 +++ b/drivers/ata/libata-scsi.c
36491 @@ -4151,7 +4151,7 @@ int ata_sas_port_init(struct ata_port *ap)
36492
36493 if (rc)
36494 return rc;
36495 - ap->print_id = atomic_inc_return(&ata_print_id);
36496 + ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36497 return 0;
36498 }
36499 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36500 diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36501 index 5f4e0cc..ff2c347 100644
36502 --- a/drivers/ata/libata.h
36503 +++ b/drivers/ata/libata.h
36504 @@ -53,7 +53,7 @@ enum {
36505 ATA_DNXFER_QUIET = (1 << 31),
36506 };
36507
36508 -extern atomic_t ata_print_id;
36509 +extern atomic_unchecked_t ata_print_id;
36510 extern int atapi_passthru16;
36511 extern int libata_fua;
36512 extern int libata_noacpi;
36513 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36514 index 38216b9..4ec6aeb 100644
36515 --- a/drivers/ata/pata_arasan_cf.c
36516 +++ b/drivers/ata/pata_arasan_cf.c
36517 @@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36518 /* Handle platform specific quirks */
36519 if (quirk) {
36520 if (quirk & CF_BROKEN_PIO) {
36521 - ap->ops->set_piomode = NULL;
36522 + pax_open_kernel();
36523 + *(void **)&ap->ops->set_piomode = NULL;
36524 + pax_close_kernel();
36525 ap->pio_mask = 0;
36526 }
36527 if (quirk & CF_BROKEN_MWDMA)
36528 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36529 index f9b983a..887b9d8 100644
36530 --- a/drivers/atm/adummy.c
36531 +++ b/drivers/atm/adummy.c
36532 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36533 vcc->pop(vcc, skb);
36534 else
36535 dev_kfree_skb_any(skb);
36536 - atomic_inc(&vcc->stats->tx);
36537 + atomic_inc_unchecked(&vcc->stats->tx);
36538
36539 return 0;
36540 }
36541 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36542 index f1a9198..f466a4a 100644
36543 --- a/drivers/atm/ambassador.c
36544 +++ b/drivers/atm/ambassador.c
36545 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36546 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36547
36548 // VC layer stats
36549 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36550 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36551
36552 // free the descriptor
36553 kfree (tx_descr);
36554 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36555 dump_skb ("<<<", vc, skb);
36556
36557 // VC layer stats
36558 - atomic_inc(&atm_vcc->stats->rx);
36559 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36560 __net_timestamp(skb);
36561 // end of our responsibility
36562 atm_vcc->push (atm_vcc, skb);
36563 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36564 } else {
36565 PRINTK (KERN_INFO, "dropped over-size frame");
36566 // should we count this?
36567 - atomic_inc(&atm_vcc->stats->rx_drop);
36568 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36569 }
36570
36571 } else {
36572 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36573 }
36574
36575 if (check_area (skb->data, skb->len)) {
36576 - atomic_inc(&atm_vcc->stats->tx_err);
36577 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36578 return -ENOMEM; // ?
36579 }
36580
36581 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36582 index 480fa6f..947067c 100644
36583 --- a/drivers/atm/atmtcp.c
36584 +++ b/drivers/atm/atmtcp.c
36585 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36586 if (vcc->pop) vcc->pop(vcc,skb);
36587 else dev_kfree_skb(skb);
36588 if (dev_data) return 0;
36589 - atomic_inc(&vcc->stats->tx_err);
36590 + atomic_inc_unchecked(&vcc->stats->tx_err);
36591 return -ENOLINK;
36592 }
36593 size = skb->len+sizeof(struct atmtcp_hdr);
36594 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36595 if (!new_skb) {
36596 if (vcc->pop) vcc->pop(vcc,skb);
36597 else dev_kfree_skb(skb);
36598 - atomic_inc(&vcc->stats->tx_err);
36599 + atomic_inc_unchecked(&vcc->stats->tx_err);
36600 return -ENOBUFS;
36601 }
36602 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36603 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36604 if (vcc->pop) vcc->pop(vcc,skb);
36605 else dev_kfree_skb(skb);
36606 out_vcc->push(out_vcc,new_skb);
36607 - atomic_inc(&vcc->stats->tx);
36608 - atomic_inc(&out_vcc->stats->rx);
36609 + atomic_inc_unchecked(&vcc->stats->tx);
36610 + atomic_inc_unchecked(&out_vcc->stats->rx);
36611 return 0;
36612 }
36613
36614 @@ -300,7 +300,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36615 read_unlock(&vcc_sklist_lock);
36616 if (!out_vcc) {
36617 result = -EUNATCH;
36618 - atomic_inc(&vcc->stats->tx_err);
36619 + atomic_inc_unchecked(&vcc->stats->tx_err);
36620 goto done;
36621 }
36622 skb_pull(skb,sizeof(struct atmtcp_hdr));
36623 @@ -312,8 +312,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36624 __net_timestamp(new_skb);
36625 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36626 out_vcc->push(out_vcc,new_skb);
36627 - atomic_inc(&vcc->stats->tx);
36628 - atomic_inc(&out_vcc->stats->rx);
36629 + atomic_inc_unchecked(&vcc->stats->tx);
36630 + atomic_inc_unchecked(&out_vcc->stats->rx);
36631 done:
36632 if (vcc->pop) vcc->pop(vcc,skb);
36633 else dev_kfree_skb(skb);
36634 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36635 index d65975a..0b87e20 100644
36636 --- a/drivers/atm/eni.c
36637 +++ b/drivers/atm/eni.c
36638 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36639 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36640 vcc->dev->number);
36641 length = 0;
36642 - atomic_inc(&vcc->stats->rx_err);
36643 + atomic_inc_unchecked(&vcc->stats->rx_err);
36644 }
36645 else {
36646 length = ATM_CELL_SIZE-1; /* no HEC */
36647 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36648 size);
36649 }
36650 eff = length = 0;
36651 - atomic_inc(&vcc->stats->rx_err);
36652 + atomic_inc_unchecked(&vcc->stats->rx_err);
36653 }
36654 else {
36655 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36656 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36657 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36658 vcc->dev->number,vcc->vci,length,size << 2,descr);
36659 length = eff = 0;
36660 - atomic_inc(&vcc->stats->rx_err);
36661 + atomic_inc_unchecked(&vcc->stats->rx_err);
36662 }
36663 }
36664 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36665 @@ -767,7 +767,7 @@ rx_dequeued++;
36666 vcc->push(vcc,skb);
36667 pushed++;
36668 }
36669 - atomic_inc(&vcc->stats->rx);
36670 + atomic_inc_unchecked(&vcc->stats->rx);
36671 }
36672 wake_up(&eni_dev->rx_wait);
36673 }
36674 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36675 PCI_DMA_TODEVICE);
36676 if (vcc->pop) vcc->pop(vcc,skb);
36677 else dev_kfree_skb_irq(skb);
36678 - atomic_inc(&vcc->stats->tx);
36679 + atomic_inc_unchecked(&vcc->stats->tx);
36680 wake_up(&eni_dev->tx_wait);
36681 dma_complete++;
36682 }
36683 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36684 index 82f2ae0..f205c02 100644
36685 --- a/drivers/atm/firestream.c
36686 +++ b/drivers/atm/firestream.c
36687 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36688 }
36689 }
36690
36691 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36692 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36693
36694 fs_dprintk (FS_DEBUG_TXMEM, "i");
36695 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36696 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36697 #endif
36698 skb_put (skb, qe->p1 & 0xffff);
36699 ATM_SKB(skb)->vcc = atm_vcc;
36700 - atomic_inc(&atm_vcc->stats->rx);
36701 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36702 __net_timestamp(skb);
36703 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36704 atm_vcc->push (atm_vcc, skb);
36705 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36706 kfree (pe);
36707 }
36708 if (atm_vcc)
36709 - atomic_inc(&atm_vcc->stats->rx_drop);
36710 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36711 break;
36712 case 0x1f: /* Reassembly abort: no buffers. */
36713 /* Silently increment error counter. */
36714 if (atm_vcc)
36715 - atomic_inc(&atm_vcc->stats->rx_drop);
36716 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36717 break;
36718 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36719 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36720 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36721 index d4725fc..2d4ea65 100644
36722 --- a/drivers/atm/fore200e.c
36723 +++ b/drivers/atm/fore200e.c
36724 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36725 #endif
36726 /* check error condition */
36727 if (*entry->status & STATUS_ERROR)
36728 - atomic_inc(&vcc->stats->tx_err);
36729 + atomic_inc_unchecked(&vcc->stats->tx_err);
36730 else
36731 - atomic_inc(&vcc->stats->tx);
36732 + atomic_inc_unchecked(&vcc->stats->tx);
36733 }
36734 }
36735
36736 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36737 if (skb == NULL) {
36738 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36739
36740 - atomic_inc(&vcc->stats->rx_drop);
36741 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36742 return -ENOMEM;
36743 }
36744
36745 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36746
36747 dev_kfree_skb_any(skb);
36748
36749 - atomic_inc(&vcc->stats->rx_drop);
36750 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36751 return -ENOMEM;
36752 }
36753
36754 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36755
36756 vcc->push(vcc, skb);
36757 - atomic_inc(&vcc->stats->rx);
36758 + atomic_inc_unchecked(&vcc->stats->rx);
36759
36760 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36761
36762 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36763 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36764 fore200e->atm_dev->number,
36765 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36766 - atomic_inc(&vcc->stats->rx_err);
36767 + atomic_inc_unchecked(&vcc->stats->rx_err);
36768 }
36769 }
36770
36771 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36772 goto retry_here;
36773 }
36774
36775 - atomic_inc(&vcc->stats->tx_err);
36776 + atomic_inc_unchecked(&vcc->stats->tx_err);
36777
36778 fore200e->tx_sat++;
36779 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36780 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36781 index c39702b..785b73b 100644
36782 --- a/drivers/atm/he.c
36783 +++ b/drivers/atm/he.c
36784 @@ -1689,7 +1689,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36785
36786 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36787 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36788 - atomic_inc(&vcc->stats->rx_drop);
36789 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36790 goto return_host_buffers;
36791 }
36792
36793 @@ -1716,7 +1716,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36794 RBRQ_LEN_ERR(he_dev->rbrq_head)
36795 ? "LEN_ERR" : "",
36796 vcc->vpi, vcc->vci);
36797 - atomic_inc(&vcc->stats->rx_err);
36798 + atomic_inc_unchecked(&vcc->stats->rx_err);
36799 goto return_host_buffers;
36800 }
36801
36802 @@ -1768,7 +1768,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36803 vcc->push(vcc, skb);
36804 spin_lock(&he_dev->global_lock);
36805
36806 - atomic_inc(&vcc->stats->rx);
36807 + atomic_inc_unchecked(&vcc->stats->rx);
36808
36809 return_host_buffers:
36810 ++pdus_assembled;
36811 @@ -2094,7 +2094,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36812 tpd->vcc->pop(tpd->vcc, tpd->skb);
36813 else
36814 dev_kfree_skb_any(tpd->skb);
36815 - atomic_inc(&tpd->vcc->stats->tx_err);
36816 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36817 }
36818 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36819 return;
36820 @@ -2506,7 +2506,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36821 vcc->pop(vcc, skb);
36822 else
36823 dev_kfree_skb_any(skb);
36824 - atomic_inc(&vcc->stats->tx_err);
36825 + atomic_inc_unchecked(&vcc->stats->tx_err);
36826 return -EINVAL;
36827 }
36828
36829 @@ -2517,7 +2517,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36830 vcc->pop(vcc, skb);
36831 else
36832 dev_kfree_skb_any(skb);
36833 - atomic_inc(&vcc->stats->tx_err);
36834 + atomic_inc_unchecked(&vcc->stats->tx_err);
36835 return -EINVAL;
36836 }
36837 #endif
36838 @@ -2529,7 +2529,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36839 vcc->pop(vcc, skb);
36840 else
36841 dev_kfree_skb_any(skb);
36842 - atomic_inc(&vcc->stats->tx_err);
36843 + atomic_inc_unchecked(&vcc->stats->tx_err);
36844 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36845 return -ENOMEM;
36846 }
36847 @@ -2571,7 +2571,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36848 vcc->pop(vcc, skb);
36849 else
36850 dev_kfree_skb_any(skb);
36851 - atomic_inc(&vcc->stats->tx_err);
36852 + atomic_inc_unchecked(&vcc->stats->tx_err);
36853 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36854 return -ENOMEM;
36855 }
36856 @@ -2602,7 +2602,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36857 __enqueue_tpd(he_dev, tpd, cid);
36858 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36859
36860 - atomic_inc(&vcc->stats->tx);
36861 + atomic_inc_unchecked(&vcc->stats->tx);
36862
36863 return 0;
36864 }
36865 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36866 index 1dc0519..1aadaf7 100644
36867 --- a/drivers/atm/horizon.c
36868 +++ b/drivers/atm/horizon.c
36869 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36870 {
36871 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36872 // VC layer stats
36873 - atomic_inc(&vcc->stats->rx);
36874 + atomic_inc_unchecked(&vcc->stats->rx);
36875 __net_timestamp(skb);
36876 // end of our responsibility
36877 vcc->push (vcc, skb);
36878 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36879 dev->tx_iovec = NULL;
36880
36881 // VC layer stats
36882 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36883 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36884
36885 // free the skb
36886 hrz_kfree_skb (skb);
36887 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36888 index 2b24ed0..b3d6acc 100644
36889 --- a/drivers/atm/idt77252.c
36890 +++ b/drivers/atm/idt77252.c
36891 @@ -810,7 +810,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36892 else
36893 dev_kfree_skb(skb);
36894
36895 - atomic_inc(&vcc->stats->tx);
36896 + atomic_inc_unchecked(&vcc->stats->tx);
36897 }
36898
36899 atomic_dec(&scq->used);
36900 @@ -1072,13 +1072,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36901 if ((sb = dev_alloc_skb(64)) == NULL) {
36902 printk("%s: Can't allocate buffers for aal0.\n",
36903 card->name);
36904 - atomic_add(i, &vcc->stats->rx_drop);
36905 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
36906 break;
36907 }
36908 if (!atm_charge(vcc, sb->truesize)) {
36909 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36910 card->name);
36911 - atomic_add(i - 1, &vcc->stats->rx_drop);
36912 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36913 dev_kfree_skb(sb);
36914 break;
36915 }
36916 @@ -1095,7 +1095,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36917 ATM_SKB(sb)->vcc = vcc;
36918 __net_timestamp(sb);
36919 vcc->push(vcc, sb);
36920 - atomic_inc(&vcc->stats->rx);
36921 + atomic_inc_unchecked(&vcc->stats->rx);
36922
36923 cell += ATM_CELL_PAYLOAD;
36924 }
36925 @@ -1132,13 +1132,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36926 "(CDC: %08x)\n",
36927 card->name, len, rpp->len, readl(SAR_REG_CDC));
36928 recycle_rx_pool_skb(card, rpp);
36929 - atomic_inc(&vcc->stats->rx_err);
36930 + atomic_inc_unchecked(&vcc->stats->rx_err);
36931 return;
36932 }
36933 if (stat & SAR_RSQE_CRC) {
36934 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36935 recycle_rx_pool_skb(card, rpp);
36936 - atomic_inc(&vcc->stats->rx_err);
36937 + atomic_inc_unchecked(&vcc->stats->rx_err);
36938 return;
36939 }
36940 if (skb_queue_len(&rpp->queue) > 1) {
36941 @@ -1149,7 +1149,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36942 RXPRINTK("%s: Can't alloc RX skb.\n",
36943 card->name);
36944 recycle_rx_pool_skb(card, rpp);
36945 - atomic_inc(&vcc->stats->rx_err);
36946 + atomic_inc_unchecked(&vcc->stats->rx_err);
36947 return;
36948 }
36949 if (!atm_charge(vcc, skb->truesize)) {
36950 @@ -1168,7 +1168,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36951 __net_timestamp(skb);
36952
36953 vcc->push(vcc, skb);
36954 - atomic_inc(&vcc->stats->rx);
36955 + atomic_inc_unchecked(&vcc->stats->rx);
36956
36957 return;
36958 }
36959 @@ -1190,7 +1190,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36960 __net_timestamp(skb);
36961
36962 vcc->push(vcc, skb);
36963 - atomic_inc(&vcc->stats->rx);
36964 + atomic_inc_unchecked(&vcc->stats->rx);
36965
36966 if (skb->truesize > SAR_FB_SIZE_3)
36967 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36968 @@ -1301,14 +1301,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36969 if (vcc->qos.aal != ATM_AAL0) {
36970 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36971 card->name, vpi, vci);
36972 - atomic_inc(&vcc->stats->rx_drop);
36973 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36974 goto drop;
36975 }
36976
36977 if ((sb = dev_alloc_skb(64)) == NULL) {
36978 printk("%s: Can't allocate buffers for AAL0.\n",
36979 card->name);
36980 - atomic_inc(&vcc->stats->rx_err);
36981 + atomic_inc_unchecked(&vcc->stats->rx_err);
36982 goto drop;
36983 }
36984
36985 @@ -1327,7 +1327,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
36986 ATM_SKB(sb)->vcc = vcc;
36987 __net_timestamp(sb);
36988 vcc->push(vcc, sb);
36989 - atomic_inc(&vcc->stats->rx);
36990 + atomic_inc_unchecked(&vcc->stats->rx);
36991
36992 drop:
36993 skb_pull(queue, 64);
36994 @@ -1952,13 +1952,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36995
36996 if (vc == NULL) {
36997 printk("%s: NULL connection in send().\n", card->name);
36998 - atomic_inc(&vcc->stats->tx_err);
36999 + atomic_inc_unchecked(&vcc->stats->tx_err);
37000 dev_kfree_skb(skb);
37001 return -EINVAL;
37002 }
37003 if (!test_bit(VCF_TX, &vc->flags)) {
37004 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
37005 - atomic_inc(&vcc->stats->tx_err);
37006 + atomic_inc_unchecked(&vcc->stats->tx_err);
37007 dev_kfree_skb(skb);
37008 return -EINVAL;
37009 }
37010 @@ -1970,14 +1970,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37011 break;
37012 default:
37013 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
37014 - atomic_inc(&vcc->stats->tx_err);
37015 + atomic_inc_unchecked(&vcc->stats->tx_err);
37016 dev_kfree_skb(skb);
37017 return -EINVAL;
37018 }
37019
37020 if (skb_shinfo(skb)->nr_frags != 0) {
37021 printk("%s: No scatter-gather yet.\n", card->name);
37022 - atomic_inc(&vcc->stats->tx_err);
37023 + atomic_inc_unchecked(&vcc->stats->tx_err);
37024 dev_kfree_skb(skb);
37025 return -EINVAL;
37026 }
37027 @@ -1985,7 +1985,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37028
37029 err = queue_skb(card, vc, skb, oam);
37030 if (err) {
37031 - atomic_inc(&vcc->stats->tx_err);
37032 + atomic_inc_unchecked(&vcc->stats->tx_err);
37033 dev_kfree_skb(skb);
37034 return err;
37035 }
37036 @@ -2008,7 +2008,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
37037 skb = dev_alloc_skb(64);
37038 if (!skb) {
37039 printk("%s: Out of memory in send_oam().\n", card->name);
37040 - atomic_inc(&vcc->stats->tx_err);
37041 + atomic_inc_unchecked(&vcc->stats->tx_err);
37042 return -ENOMEM;
37043 }
37044 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
37045 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
37046 index 4217f29..88f547a 100644
37047 --- a/drivers/atm/iphase.c
37048 +++ b/drivers/atm/iphase.c
37049 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
37050 status = (u_short) (buf_desc_ptr->desc_mode);
37051 if (status & (RX_CER | RX_PTE | RX_OFL))
37052 {
37053 - atomic_inc(&vcc->stats->rx_err);
37054 + atomic_inc_unchecked(&vcc->stats->rx_err);
37055 IF_ERR(printk("IA: bad packet, dropping it");)
37056 if (status & RX_CER) {
37057 IF_ERR(printk(" cause: packet CRC error\n");)
37058 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
37059 len = dma_addr - buf_addr;
37060 if (len > iadev->rx_buf_sz) {
37061 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
37062 - atomic_inc(&vcc->stats->rx_err);
37063 + atomic_inc_unchecked(&vcc->stats->rx_err);
37064 goto out_free_desc;
37065 }
37066
37067 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37068 ia_vcc = INPH_IA_VCC(vcc);
37069 if (ia_vcc == NULL)
37070 {
37071 - atomic_inc(&vcc->stats->rx_err);
37072 + atomic_inc_unchecked(&vcc->stats->rx_err);
37073 atm_return(vcc, skb->truesize);
37074 dev_kfree_skb_any(skb);
37075 goto INCR_DLE;
37076 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37077 if ((length > iadev->rx_buf_sz) || (length >
37078 (skb->len - sizeof(struct cpcs_trailer))))
37079 {
37080 - atomic_inc(&vcc->stats->rx_err);
37081 + atomic_inc_unchecked(&vcc->stats->rx_err);
37082 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
37083 length, skb->len);)
37084 atm_return(vcc, skb->truesize);
37085 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37086
37087 IF_RX(printk("rx_dle_intr: skb push");)
37088 vcc->push(vcc,skb);
37089 - atomic_inc(&vcc->stats->rx);
37090 + atomic_inc_unchecked(&vcc->stats->rx);
37091 iadev->rx_pkt_cnt++;
37092 }
37093 INCR_DLE:
37094 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
37095 {
37096 struct k_sonet_stats *stats;
37097 stats = &PRIV(_ia_dev[board])->sonet_stats;
37098 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
37099 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
37100 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
37101 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
37102 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
37103 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
37104 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
37105 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
37106 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
37107 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
37108 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
37109 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
37110 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
37111 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
37112 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
37113 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
37114 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
37115 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
37116 }
37117 ia_cmds.status = 0;
37118 break;
37119 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37120 if ((desc == 0) || (desc > iadev->num_tx_desc))
37121 {
37122 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
37123 - atomic_inc(&vcc->stats->tx);
37124 + atomic_inc_unchecked(&vcc->stats->tx);
37125 if (vcc->pop)
37126 vcc->pop(vcc, skb);
37127 else
37128 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37129 ATM_DESC(skb) = vcc->vci;
37130 skb_queue_tail(&iadev->tx_dma_q, skb);
37131
37132 - atomic_inc(&vcc->stats->tx);
37133 + atomic_inc_unchecked(&vcc->stats->tx);
37134 iadev->tx_pkt_cnt++;
37135 /* Increment transaction counter */
37136 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
37137
37138 #if 0
37139 /* add flow control logic */
37140 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
37141 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
37142 if (iavcc->vc_desc_cnt > 10) {
37143 vcc->tx_quota = vcc->tx_quota * 3 / 4;
37144 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
37145 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
37146 index 93eaf8d..b4ca7da 100644
37147 --- a/drivers/atm/lanai.c
37148 +++ b/drivers/atm/lanai.c
37149 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
37150 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
37151 lanai_endtx(lanai, lvcc);
37152 lanai_free_skb(lvcc->tx.atmvcc, skb);
37153 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
37154 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
37155 }
37156
37157 /* Try to fill the buffer - don't call unless there is backlog */
37158 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
37159 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
37160 __net_timestamp(skb);
37161 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
37162 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
37163 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
37164 out:
37165 lvcc->rx.buf.ptr = end;
37166 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
37167 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37168 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
37169 "vcc %d\n", lanai->number, (unsigned int) s, vci);
37170 lanai->stats.service_rxnotaal5++;
37171 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37172 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37173 return 0;
37174 }
37175 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
37176 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37177 int bytes;
37178 read_unlock(&vcc_sklist_lock);
37179 DPRINTK("got trashed rx pdu on vci %d\n", vci);
37180 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37181 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37182 lvcc->stats.x.aal5.service_trash++;
37183 bytes = (SERVICE_GET_END(s) * 16) -
37184 (((unsigned long) lvcc->rx.buf.ptr) -
37185 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37186 }
37187 if (s & SERVICE_STREAM) {
37188 read_unlock(&vcc_sklist_lock);
37189 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37190 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37191 lvcc->stats.x.aal5.service_stream++;
37192 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
37193 "PDU on VCI %d!\n", lanai->number, vci);
37194 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37195 return 0;
37196 }
37197 DPRINTK("got rx crc error on vci %d\n", vci);
37198 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37199 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37200 lvcc->stats.x.aal5.service_rxcrc++;
37201 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
37202 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
37203 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
37204 index 9988ac9..7c52585 100644
37205 --- a/drivers/atm/nicstar.c
37206 +++ b/drivers/atm/nicstar.c
37207 @@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37208 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
37209 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
37210 card->index);
37211 - atomic_inc(&vcc->stats->tx_err);
37212 + atomic_inc_unchecked(&vcc->stats->tx_err);
37213 dev_kfree_skb_any(skb);
37214 return -EINVAL;
37215 }
37216 @@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37217 if (!vc->tx) {
37218 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
37219 card->index);
37220 - atomic_inc(&vcc->stats->tx_err);
37221 + atomic_inc_unchecked(&vcc->stats->tx_err);
37222 dev_kfree_skb_any(skb);
37223 return -EINVAL;
37224 }
37225 @@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37226 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
37227 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
37228 card->index);
37229 - atomic_inc(&vcc->stats->tx_err);
37230 + atomic_inc_unchecked(&vcc->stats->tx_err);
37231 dev_kfree_skb_any(skb);
37232 return -EINVAL;
37233 }
37234
37235 if (skb_shinfo(skb)->nr_frags != 0) {
37236 printk("nicstar%d: No scatter-gather yet.\n", card->index);
37237 - atomic_inc(&vcc->stats->tx_err);
37238 + atomic_inc_unchecked(&vcc->stats->tx_err);
37239 dev_kfree_skb_any(skb);
37240 return -EINVAL;
37241 }
37242 @@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37243 }
37244
37245 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
37246 - atomic_inc(&vcc->stats->tx_err);
37247 + atomic_inc_unchecked(&vcc->stats->tx_err);
37248 dev_kfree_skb_any(skb);
37249 return -EIO;
37250 }
37251 - atomic_inc(&vcc->stats->tx);
37252 + atomic_inc_unchecked(&vcc->stats->tx);
37253
37254 return 0;
37255 }
37256 @@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37257 printk
37258 ("nicstar%d: Can't allocate buffers for aal0.\n",
37259 card->index);
37260 - atomic_add(i, &vcc->stats->rx_drop);
37261 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
37262 break;
37263 }
37264 if (!atm_charge(vcc, sb->truesize)) {
37265 RXPRINTK
37266 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
37267 card->index);
37268 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37269 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37270 dev_kfree_skb_any(sb);
37271 break;
37272 }
37273 @@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37274 ATM_SKB(sb)->vcc = vcc;
37275 __net_timestamp(sb);
37276 vcc->push(vcc, sb);
37277 - atomic_inc(&vcc->stats->rx);
37278 + atomic_inc_unchecked(&vcc->stats->rx);
37279 cell += ATM_CELL_PAYLOAD;
37280 }
37281
37282 @@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37283 if (iovb == NULL) {
37284 printk("nicstar%d: Out of iovec buffers.\n",
37285 card->index);
37286 - atomic_inc(&vcc->stats->rx_drop);
37287 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37288 recycle_rx_buf(card, skb);
37289 return;
37290 }
37291 @@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37292 small or large buffer itself. */
37293 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
37294 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
37295 - atomic_inc(&vcc->stats->rx_err);
37296 + atomic_inc_unchecked(&vcc->stats->rx_err);
37297 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37298 NS_MAX_IOVECS);
37299 NS_PRV_IOVCNT(iovb) = 0;
37300 @@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37301 ("nicstar%d: Expected a small buffer, and this is not one.\n",
37302 card->index);
37303 which_list(card, skb);
37304 - atomic_inc(&vcc->stats->rx_err);
37305 + atomic_inc_unchecked(&vcc->stats->rx_err);
37306 recycle_rx_buf(card, skb);
37307 vc->rx_iov = NULL;
37308 recycle_iov_buf(card, iovb);
37309 @@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37310 ("nicstar%d: Expected a large buffer, and this is not one.\n",
37311 card->index);
37312 which_list(card, skb);
37313 - atomic_inc(&vcc->stats->rx_err);
37314 + atomic_inc_unchecked(&vcc->stats->rx_err);
37315 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37316 NS_PRV_IOVCNT(iovb));
37317 vc->rx_iov = NULL;
37318 @@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37319 printk(" - PDU size mismatch.\n");
37320 else
37321 printk(".\n");
37322 - atomic_inc(&vcc->stats->rx_err);
37323 + atomic_inc_unchecked(&vcc->stats->rx_err);
37324 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37325 NS_PRV_IOVCNT(iovb));
37326 vc->rx_iov = NULL;
37327 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37328 /* skb points to a small buffer */
37329 if (!atm_charge(vcc, skb->truesize)) {
37330 push_rxbufs(card, skb);
37331 - atomic_inc(&vcc->stats->rx_drop);
37332 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37333 } else {
37334 skb_put(skb, len);
37335 dequeue_sm_buf(card, skb);
37336 @@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37337 ATM_SKB(skb)->vcc = vcc;
37338 __net_timestamp(skb);
37339 vcc->push(vcc, skb);
37340 - atomic_inc(&vcc->stats->rx);
37341 + atomic_inc_unchecked(&vcc->stats->rx);
37342 }
37343 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37344 struct sk_buff *sb;
37345 @@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37346 if (len <= NS_SMBUFSIZE) {
37347 if (!atm_charge(vcc, sb->truesize)) {
37348 push_rxbufs(card, sb);
37349 - atomic_inc(&vcc->stats->rx_drop);
37350 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37351 } else {
37352 skb_put(sb, len);
37353 dequeue_sm_buf(card, sb);
37354 @@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37355 ATM_SKB(sb)->vcc = vcc;
37356 __net_timestamp(sb);
37357 vcc->push(vcc, sb);
37358 - atomic_inc(&vcc->stats->rx);
37359 + atomic_inc_unchecked(&vcc->stats->rx);
37360 }
37361
37362 push_rxbufs(card, skb);
37363 @@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37364
37365 if (!atm_charge(vcc, skb->truesize)) {
37366 push_rxbufs(card, skb);
37367 - atomic_inc(&vcc->stats->rx_drop);
37368 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37369 } else {
37370 dequeue_lg_buf(card, skb);
37371 #ifdef NS_USE_DESTRUCTORS
37372 @@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37373 ATM_SKB(skb)->vcc = vcc;
37374 __net_timestamp(skb);
37375 vcc->push(vcc, skb);
37376 - atomic_inc(&vcc->stats->rx);
37377 + atomic_inc_unchecked(&vcc->stats->rx);
37378 }
37379
37380 push_rxbufs(card, sb);
37381 @@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37382 printk
37383 ("nicstar%d: Out of huge buffers.\n",
37384 card->index);
37385 - atomic_inc(&vcc->stats->rx_drop);
37386 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37387 recycle_iovec_rx_bufs(card,
37388 (struct iovec *)
37389 iovb->data,
37390 @@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37391 card->hbpool.count++;
37392 } else
37393 dev_kfree_skb_any(hb);
37394 - atomic_inc(&vcc->stats->rx_drop);
37395 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37396 } else {
37397 /* Copy the small buffer to the huge buffer */
37398 sb = (struct sk_buff *)iov->iov_base;
37399 @@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37400 #endif /* NS_USE_DESTRUCTORS */
37401 __net_timestamp(hb);
37402 vcc->push(vcc, hb);
37403 - atomic_inc(&vcc->stats->rx);
37404 + atomic_inc_unchecked(&vcc->stats->rx);
37405 }
37406 }
37407
37408 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37409 index 21b0bc6..b5f40ba 100644
37410 --- a/drivers/atm/solos-pci.c
37411 +++ b/drivers/atm/solos-pci.c
37412 @@ -838,7 +838,7 @@ static void solos_bh(unsigned long card_arg)
37413 }
37414 atm_charge(vcc, skb->truesize);
37415 vcc->push(vcc, skb);
37416 - atomic_inc(&vcc->stats->rx);
37417 + atomic_inc_unchecked(&vcc->stats->rx);
37418 break;
37419
37420 case PKT_STATUS:
37421 @@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37422 vcc = SKB_CB(oldskb)->vcc;
37423
37424 if (vcc) {
37425 - atomic_inc(&vcc->stats->tx);
37426 + atomic_inc_unchecked(&vcc->stats->tx);
37427 solos_pop(vcc, oldskb);
37428 } else {
37429 dev_kfree_skb_irq(oldskb);
37430 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37431 index 0215934..ce9f5b1 100644
37432 --- a/drivers/atm/suni.c
37433 +++ b/drivers/atm/suni.c
37434 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37435
37436
37437 #define ADD_LIMITED(s,v) \
37438 - atomic_add((v),&stats->s); \
37439 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37440 + atomic_add_unchecked((v),&stats->s); \
37441 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37442
37443
37444 static void suni_hz(unsigned long from_timer)
37445 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37446 index 5120a96..e2572bd 100644
37447 --- a/drivers/atm/uPD98402.c
37448 +++ b/drivers/atm/uPD98402.c
37449 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37450 struct sonet_stats tmp;
37451 int error = 0;
37452
37453 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37454 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37455 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37456 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37457 if (zero && !error) {
37458 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37459
37460
37461 #define ADD_LIMITED(s,v) \
37462 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37463 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37464 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37465 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37466 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37467 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37468
37469
37470 static void stat_event(struct atm_dev *dev)
37471 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37472 if (reason & uPD98402_INT_PFM) stat_event(dev);
37473 if (reason & uPD98402_INT_PCO) {
37474 (void) GET(PCOCR); /* clear interrupt cause */
37475 - atomic_add(GET(HECCT),
37476 + atomic_add_unchecked(GET(HECCT),
37477 &PRIV(dev)->sonet_stats.uncorr_hcs);
37478 }
37479 if ((reason & uPD98402_INT_RFO) &&
37480 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37481 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37482 uPD98402_INT_LOS),PIMR); /* enable them */
37483 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37484 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37485 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37486 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37487 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37488 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37489 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37490 return 0;
37491 }
37492
37493 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37494 index 969c3c2..9b72956 100644
37495 --- a/drivers/atm/zatm.c
37496 +++ b/drivers/atm/zatm.c
37497 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37498 }
37499 if (!size) {
37500 dev_kfree_skb_irq(skb);
37501 - if (vcc) atomic_inc(&vcc->stats->rx_err);
37502 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37503 continue;
37504 }
37505 if (!atm_charge(vcc,skb->truesize)) {
37506 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37507 skb->len = size;
37508 ATM_SKB(skb)->vcc = vcc;
37509 vcc->push(vcc,skb);
37510 - atomic_inc(&vcc->stats->rx);
37511 + atomic_inc_unchecked(&vcc->stats->rx);
37512 }
37513 zout(pos & 0xffff,MTA(mbx));
37514 #if 0 /* probably a stupid idea */
37515 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37516 skb_queue_head(&zatm_vcc->backlog,skb);
37517 break;
37518 }
37519 - atomic_inc(&vcc->stats->tx);
37520 + atomic_inc_unchecked(&vcc->stats->tx);
37521 wake_up(&zatm_vcc->tx_wait);
37522 }
37523
37524 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37525 index 83e910a..b224a73 100644
37526 --- a/drivers/base/bus.c
37527 +++ b/drivers/base/bus.c
37528 @@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37529 return -EINVAL;
37530
37531 mutex_lock(&subsys->p->mutex);
37532 - list_add_tail(&sif->node, &subsys->p->interfaces);
37533 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37534 if (sif->add_dev) {
37535 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37536 while ((dev = subsys_dev_iter_next(&iter)))
37537 @@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37538 subsys = sif->subsys;
37539
37540 mutex_lock(&subsys->p->mutex);
37541 - list_del_init(&sif->node);
37542 + pax_list_del_init((struct list_head *)&sif->node);
37543 if (sif->remove_dev) {
37544 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37545 while ((dev = subsys_dev_iter_next(&iter)))
37546 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37547 index 25798db..15f130e 100644
37548 --- a/drivers/base/devtmpfs.c
37549 +++ b/drivers/base/devtmpfs.c
37550 @@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37551 if (!thread)
37552 return 0;
37553
37554 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37555 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37556 if (err)
37557 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37558 else
37559 @@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37560 *err = sys_unshare(CLONE_NEWNS);
37561 if (*err)
37562 goto out;
37563 - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37564 + *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37565 if (*err)
37566 goto out;
37567 - sys_chdir("/.."); /* will traverse into overmounted root */
37568 - sys_chroot(".");
37569 + sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37570 + sys_chroot((char __force_user *)".");
37571 complete(&setup_done);
37572 while (1) {
37573 spin_lock(&req_lock);
37574 diff --git a/drivers/base/node.c b/drivers/base/node.c
37575 index 472168c..4af587e 100644
37576 --- a/drivers/base/node.c
37577 +++ b/drivers/base/node.c
37578 @@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37579 struct node_attr {
37580 struct device_attribute attr;
37581 enum node_states state;
37582 -};
37583 +} __do_const;
37584
37585 static ssize_t show_node_state(struct device *dev,
37586 struct device_attribute *attr, char *buf)
37587 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37588 index fb83d4a..4aa50ec 100644
37589 --- a/drivers/base/power/domain.c
37590 +++ b/drivers/base/power/domain.c
37591 @@ -1725,7 +1725,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37592 {
37593 struct cpuidle_driver *cpuidle_drv;
37594 struct gpd_cpuidle_data *cpuidle_data;
37595 - struct cpuidle_state *idle_state;
37596 + cpuidle_state_no_const *idle_state;
37597 int ret = 0;
37598
37599 if (IS_ERR_OR_NULL(genpd) || state < 0)
37600 @@ -1793,7 +1793,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37601 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37602 {
37603 struct gpd_cpuidle_data *cpuidle_data;
37604 - struct cpuidle_state *idle_state;
37605 + cpuidle_state_no_const *idle_state;
37606 int ret = 0;
37607
37608 if (IS_ERR_OR_NULL(genpd))
37609 diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37610 index a9d26ed..74b8405 100644
37611 --- a/drivers/base/power/sysfs.c
37612 +++ b/drivers/base/power/sysfs.c
37613 @@ -182,7 +182,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37614 return -EIO;
37615 }
37616 }
37617 - return sprintf(buf, p);
37618 + return sprintf(buf, "%s", p);
37619 }
37620
37621 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37622 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37623 index c2744b3..08fac19 100644
37624 --- a/drivers/base/power/wakeup.c
37625 +++ b/drivers/base/power/wakeup.c
37626 @@ -32,14 +32,14 @@ static bool pm_abort_suspend __read_mostly;
37627 * They need to be modified together atomically, so it's better to use one
37628 * atomic variable to hold them both.
37629 */
37630 -static atomic_t combined_event_count = ATOMIC_INIT(0);
37631 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37632
37633 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37634 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37635
37636 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37637 {
37638 - unsigned int comb = atomic_read(&combined_event_count);
37639 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
37640
37641 *cnt = (comb >> IN_PROGRESS_BITS);
37642 *inpr = comb & MAX_IN_PROGRESS;
37643 @@ -404,7 +404,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37644 ws->start_prevent_time = ws->last_time;
37645
37646 /* Increment the counter of events in progress. */
37647 - cec = atomic_inc_return(&combined_event_count);
37648 + cec = atomic_inc_return_unchecked(&combined_event_count);
37649
37650 trace_wakeup_source_activate(ws->name, cec);
37651 }
37652 @@ -530,7 +530,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37653 * Increment the counter of registered wakeup events and decrement the
37654 * couter of wakeup events in progress simultaneously.
37655 */
37656 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37657 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37658 trace_wakeup_source_deactivate(ws->name, cec);
37659
37660 split_counters(&cnt, &inpr);
37661 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37662 index 8d98a32..61d3165 100644
37663 --- a/drivers/base/syscore.c
37664 +++ b/drivers/base/syscore.c
37665 @@ -22,7 +22,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37666 void register_syscore_ops(struct syscore_ops *ops)
37667 {
37668 mutex_lock(&syscore_ops_lock);
37669 - list_add_tail(&ops->node, &syscore_ops_list);
37670 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37671 mutex_unlock(&syscore_ops_lock);
37672 }
37673 EXPORT_SYMBOL_GPL(register_syscore_ops);
37674 @@ -34,7 +34,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37675 void unregister_syscore_ops(struct syscore_ops *ops)
37676 {
37677 mutex_lock(&syscore_ops_lock);
37678 - list_del(&ops->node);
37679 + pax_list_del((struct list_head *)&ops->node);
37680 mutex_unlock(&syscore_ops_lock);
37681 }
37682 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37683 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37684 index ff20f19..018f1da 100644
37685 --- a/drivers/block/cciss.c
37686 +++ b/drivers/block/cciss.c
37687 @@ -3008,7 +3008,7 @@ static void start_io(ctlr_info_t *h)
37688 while (!list_empty(&h->reqQ)) {
37689 c = list_entry(h->reqQ.next, CommandList_struct, list);
37690 /* can't do anything if fifo is full */
37691 - if ((h->access.fifo_full(h))) {
37692 + if ((h->access->fifo_full(h))) {
37693 dev_warn(&h->pdev->dev, "fifo full\n");
37694 break;
37695 }
37696 @@ -3018,7 +3018,7 @@ static void start_io(ctlr_info_t *h)
37697 h->Qdepth--;
37698
37699 /* Tell the controller execute command */
37700 - h->access.submit_command(h, c);
37701 + h->access->submit_command(h, c);
37702
37703 /* Put job onto the completed Q */
37704 addQ(&h->cmpQ, c);
37705 @@ -3444,17 +3444,17 @@ startio:
37706
37707 static inline unsigned long get_next_completion(ctlr_info_t *h)
37708 {
37709 - return h->access.command_completed(h);
37710 + return h->access->command_completed(h);
37711 }
37712
37713 static inline int interrupt_pending(ctlr_info_t *h)
37714 {
37715 - return h->access.intr_pending(h);
37716 + return h->access->intr_pending(h);
37717 }
37718
37719 static inline long interrupt_not_for_us(ctlr_info_t *h)
37720 {
37721 - return ((h->access.intr_pending(h) == 0) ||
37722 + return ((h->access->intr_pending(h) == 0) ||
37723 (h->interrupts_enabled == 0));
37724 }
37725
37726 @@ -3487,7 +3487,7 @@ static inline u32 next_command(ctlr_info_t *h)
37727 u32 a;
37728
37729 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37730 - return h->access.command_completed(h);
37731 + return h->access->command_completed(h);
37732
37733 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37734 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37735 @@ -4044,7 +4044,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37736 trans_support & CFGTBL_Trans_use_short_tags);
37737
37738 /* Change the access methods to the performant access methods */
37739 - h->access = SA5_performant_access;
37740 + h->access = &SA5_performant_access;
37741 h->transMethod = CFGTBL_Trans_Performant;
37742
37743 return;
37744 @@ -4318,7 +4318,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37745 if (prod_index < 0)
37746 return -ENODEV;
37747 h->product_name = products[prod_index].product_name;
37748 - h->access = *(products[prod_index].access);
37749 + h->access = products[prod_index].access;
37750
37751 if (cciss_board_disabled(h)) {
37752 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37753 @@ -5050,7 +5050,7 @@ reinit_after_soft_reset:
37754 }
37755
37756 /* make sure the board interrupts are off */
37757 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37758 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37759 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37760 if (rc)
37761 goto clean2;
37762 @@ -5100,7 +5100,7 @@ reinit_after_soft_reset:
37763 * fake ones to scoop up any residual completions.
37764 */
37765 spin_lock_irqsave(&h->lock, flags);
37766 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37767 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37768 spin_unlock_irqrestore(&h->lock, flags);
37769 free_irq(h->intr[h->intr_mode], h);
37770 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37771 @@ -5120,9 +5120,9 @@ reinit_after_soft_reset:
37772 dev_info(&h->pdev->dev, "Board READY.\n");
37773 dev_info(&h->pdev->dev,
37774 "Waiting for stale completions to drain.\n");
37775 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37776 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37777 msleep(10000);
37778 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37779 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37780
37781 rc = controller_reset_failed(h->cfgtable);
37782 if (rc)
37783 @@ -5145,7 +5145,7 @@ reinit_after_soft_reset:
37784 cciss_scsi_setup(h);
37785
37786 /* Turn the interrupts on so we can service requests */
37787 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37788 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37789
37790 /* Get the firmware version */
37791 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37792 @@ -5217,7 +5217,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37793 kfree(flush_buf);
37794 if (return_code != IO_OK)
37795 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37796 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37797 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37798 free_irq(h->intr[h->intr_mode], h);
37799 }
37800
37801 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37802 index 7fda30e..2f27946 100644
37803 --- a/drivers/block/cciss.h
37804 +++ b/drivers/block/cciss.h
37805 @@ -101,7 +101,7 @@ struct ctlr_info
37806 /* information about each logical volume */
37807 drive_info_struct *drv[CISS_MAX_LUN];
37808
37809 - struct access_method access;
37810 + struct access_method *access;
37811
37812 /* queue and queue Info */
37813 struct list_head reqQ;
37814 @@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37815 }
37816
37817 static struct access_method SA5_access = {
37818 - SA5_submit_command,
37819 - SA5_intr_mask,
37820 - SA5_fifo_full,
37821 - SA5_intr_pending,
37822 - SA5_completed,
37823 + .submit_command = SA5_submit_command,
37824 + .set_intr_mask = SA5_intr_mask,
37825 + .fifo_full = SA5_fifo_full,
37826 + .intr_pending = SA5_intr_pending,
37827 + .command_completed = SA5_completed,
37828 };
37829
37830 static struct access_method SA5B_access = {
37831 - SA5_submit_command,
37832 - SA5B_intr_mask,
37833 - SA5_fifo_full,
37834 - SA5B_intr_pending,
37835 - SA5_completed,
37836 + .submit_command = SA5_submit_command,
37837 + .set_intr_mask = SA5B_intr_mask,
37838 + .fifo_full = SA5_fifo_full,
37839 + .intr_pending = SA5B_intr_pending,
37840 + .command_completed = SA5_completed,
37841 };
37842
37843 static struct access_method SA5_performant_access = {
37844 - SA5_submit_command,
37845 - SA5_performant_intr_mask,
37846 - SA5_fifo_full,
37847 - SA5_performant_intr_pending,
37848 - SA5_performant_completed,
37849 + .submit_command = SA5_submit_command,
37850 + .set_intr_mask = SA5_performant_intr_mask,
37851 + .fifo_full = SA5_fifo_full,
37852 + .intr_pending = SA5_performant_intr_pending,
37853 + .command_completed = SA5_performant_completed,
37854 };
37855
37856 struct board_type {
37857 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37858 index 2b94403..fd6ad1f 100644
37859 --- a/drivers/block/cpqarray.c
37860 +++ b/drivers/block/cpqarray.c
37861 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37862 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37863 goto Enomem4;
37864 }
37865 - hba[i]->access.set_intr_mask(hba[i], 0);
37866 + hba[i]->access->set_intr_mask(hba[i], 0);
37867 if (request_irq(hba[i]->intr, do_ida_intr,
37868 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37869 {
37870 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37871 add_timer(&hba[i]->timer);
37872
37873 /* Enable IRQ now that spinlock and rate limit timer are set up */
37874 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37875 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37876
37877 for(j=0; j<NWD; j++) {
37878 struct gendisk *disk = ida_gendisk[i][j];
37879 @@ -694,7 +694,7 @@ DBGINFO(
37880 for(i=0; i<NR_PRODUCTS; i++) {
37881 if (board_id == products[i].board_id) {
37882 c->product_name = products[i].product_name;
37883 - c->access = *(products[i].access);
37884 + c->access = products[i].access;
37885 break;
37886 }
37887 }
37888 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37889 hba[ctlr]->intr = intr;
37890 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37891 hba[ctlr]->product_name = products[j].product_name;
37892 - hba[ctlr]->access = *(products[j].access);
37893 + hba[ctlr]->access = products[j].access;
37894 hba[ctlr]->ctlr = ctlr;
37895 hba[ctlr]->board_id = board_id;
37896 hba[ctlr]->pci_dev = NULL; /* not PCI */
37897 @@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37898
37899 while((c = h->reqQ) != NULL) {
37900 /* Can't do anything if we're busy */
37901 - if (h->access.fifo_full(h) == 0)
37902 + if (h->access->fifo_full(h) == 0)
37903 return;
37904
37905 /* Get the first entry from the request Q */
37906 @@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37907 h->Qdepth--;
37908
37909 /* Tell the controller to do our bidding */
37910 - h->access.submit_command(h, c);
37911 + h->access->submit_command(h, c);
37912
37913 /* Get onto the completion Q */
37914 addQ(&h->cmpQ, c);
37915 @@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37916 unsigned long flags;
37917 __u32 a,a1;
37918
37919 - istat = h->access.intr_pending(h);
37920 + istat = h->access->intr_pending(h);
37921 /* Is this interrupt for us? */
37922 if (istat == 0)
37923 return IRQ_NONE;
37924 @@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37925 */
37926 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37927 if (istat & FIFO_NOT_EMPTY) {
37928 - while((a = h->access.command_completed(h))) {
37929 + while((a = h->access->command_completed(h))) {
37930 a1 = a; a &= ~3;
37931 if ((c = h->cmpQ) == NULL)
37932 {
37933 @@ -1448,11 +1448,11 @@ static int sendcmd(
37934 /*
37935 * Disable interrupt
37936 */
37937 - info_p->access.set_intr_mask(info_p, 0);
37938 + info_p->access->set_intr_mask(info_p, 0);
37939 /* Make sure there is room in the command FIFO */
37940 /* Actually it should be completely empty at this time. */
37941 for (i = 200000; i > 0; i--) {
37942 - temp = info_p->access.fifo_full(info_p);
37943 + temp = info_p->access->fifo_full(info_p);
37944 if (temp != 0) {
37945 break;
37946 }
37947 @@ -1465,7 +1465,7 @@ DBG(
37948 /*
37949 * Send the cmd
37950 */
37951 - info_p->access.submit_command(info_p, c);
37952 + info_p->access->submit_command(info_p, c);
37953 complete = pollcomplete(ctlr);
37954
37955 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
37956 @@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
37957 * we check the new geometry. Then turn interrupts back on when
37958 * we're done.
37959 */
37960 - host->access.set_intr_mask(host, 0);
37961 + host->access->set_intr_mask(host, 0);
37962 getgeometry(ctlr);
37963 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
37964 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
37965
37966 for(i=0; i<NWD; i++) {
37967 struct gendisk *disk = ida_gendisk[ctlr][i];
37968 @@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
37969 /* Wait (up to 2 seconds) for a command to complete */
37970
37971 for (i = 200000; i > 0; i--) {
37972 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
37973 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
37974 if (done == 0) {
37975 udelay(10); /* a short fixed delay */
37976 } else
37977 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
37978 index be73e9d..7fbf140 100644
37979 --- a/drivers/block/cpqarray.h
37980 +++ b/drivers/block/cpqarray.h
37981 @@ -99,7 +99,7 @@ struct ctlr_info {
37982 drv_info_t drv[NWD];
37983 struct proc_dir_entry *proc;
37984
37985 - struct access_method access;
37986 + struct access_method *access;
37987
37988 cmdlist_t *reqQ;
37989 cmdlist_t *cmpQ;
37990 diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c
37991 index 434c77d..6d3219a 100644
37992 --- a/drivers/block/drbd/drbd_bitmap.c
37993 +++ b/drivers/block/drbd/drbd_bitmap.c
37994 @@ -1036,7 +1036,7 @@ static void bm_page_io_async(struct drbd_bm_aio_ctx *ctx, int page_nr) __must_ho
37995 submit_bio(rw, bio);
37996 /* this should not count as user activity and cause the
37997 * resync to throttle -- see drbd_rs_should_slow_down(). */
37998 - atomic_add(len >> 9, &device->rs_sect_ev);
37999 + atomic_add_unchecked(len >> 9, &device->rs_sect_ev);
38000 }
38001 }
38002
38003 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
38004 index 9b22f8f..f2932af 100644
38005 --- a/drivers/block/drbd/drbd_int.h
38006 +++ b/drivers/block/drbd/drbd_int.h
38007 @@ -385,7 +385,7 @@ struct drbd_epoch {
38008 struct drbd_connection *connection;
38009 struct list_head list;
38010 unsigned int barrier_nr;
38011 - atomic_t epoch_size; /* increased on every request added. */
38012 + atomic_unchecked_t epoch_size; /* increased on every request added. */
38013 atomic_t active; /* increased on every req. added, and dec on every finished. */
38014 unsigned long flags;
38015 };
38016 @@ -946,7 +946,7 @@ struct drbd_device {
38017 unsigned int al_tr_number;
38018 int al_tr_cycle;
38019 wait_queue_head_t seq_wait;
38020 - atomic_t packet_seq;
38021 + atomic_unchecked_t packet_seq;
38022 unsigned int peer_seq;
38023 spinlock_t peer_seq_lock;
38024 unsigned long comm_bm_set; /* communicated number of set bits. */
38025 @@ -955,8 +955,8 @@ struct drbd_device {
38026 struct mutex own_state_mutex;
38027 struct mutex *state_mutex; /* either own_state_mutex or first_peer_device(device)->connection->cstate_mutex */
38028 char congestion_reason; /* Why we where congested... */
38029 - atomic_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
38030 - atomic_t rs_sect_ev; /* for submitted resync data rate, both */
38031 + atomic_unchecked_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
38032 + atomic_unchecked_t rs_sect_ev; /* for submitted resync data rate, both */
38033 int rs_last_sect_ev; /* counter to compare with */
38034 int rs_last_events; /* counter of read or write "events" (unit sectors)
38035 * on the lower level device when we last looked. */
38036 @@ -1567,7 +1567,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
38037 char __user *uoptval;
38038 int err;
38039
38040 - uoptval = (char __user __force *)optval;
38041 + uoptval = (char __force_user *)optval;
38042
38043 set_fs(KERNEL_DS);
38044 if (level == SOL_SOCKET)
38045 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
38046 index 973c185..05d8b1a 100644
38047 --- a/drivers/block/drbd/drbd_main.c
38048 +++ b/drivers/block/drbd/drbd_main.c
38049 @@ -1328,7 +1328,7 @@ static int _drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet
38050 p->sector = sector;
38051 p->block_id = block_id;
38052 p->blksize = blksize;
38053 - p->seq_num = cpu_to_be32(atomic_inc_return(&peer_device->device->packet_seq));
38054 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&peer_device->device->packet_seq));
38055 return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0);
38056 }
38057
38058 @@ -1634,7 +1634,7 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *
38059 return -EIO;
38060 p->sector = cpu_to_be64(req->i.sector);
38061 p->block_id = (unsigned long)req;
38062 - p->seq_num = cpu_to_be32(atomic_inc_return(&device->packet_seq));
38063 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&device->packet_seq));
38064 dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio->bi_rw);
38065 if (device->state.conn >= C_SYNC_SOURCE &&
38066 device->state.conn <= C_PAUSED_SYNC_T)
38067 @@ -1915,8 +1915,8 @@ void drbd_init_set_defaults(struct drbd_device *device)
38068 atomic_set(&device->unacked_cnt, 0);
38069 atomic_set(&device->local_cnt, 0);
38070 atomic_set(&device->pp_in_use_by_net, 0);
38071 - atomic_set(&device->rs_sect_in, 0);
38072 - atomic_set(&device->rs_sect_ev, 0);
38073 + atomic_set_unchecked(&device->rs_sect_in, 0);
38074 + atomic_set_unchecked(&device->rs_sect_ev, 0);
38075 atomic_set(&device->ap_in_flight, 0);
38076 atomic_set(&device->md_io.in_use, 0);
38077
38078 @@ -2688,8 +2688,8 @@ void drbd_destroy_connection(struct kref *kref)
38079 struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref);
38080 struct drbd_resource *resource = connection->resource;
38081
38082 - if (atomic_read(&connection->current_epoch->epoch_size) != 0)
38083 - drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size));
38084 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size) != 0)
38085 + drbd_err(connection, "epoch_size:%d\n", atomic_read_unchecked(&connection->current_epoch->epoch_size));
38086 kfree(connection->current_epoch);
38087
38088 idr_destroy(&connection->peer_devices);
38089 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
38090 index 1cd47df..57c53c0 100644
38091 --- a/drivers/block/drbd/drbd_nl.c
38092 +++ b/drivers/block/drbd/drbd_nl.c
38093 @@ -3645,13 +3645,13 @@ finish:
38094
38095 void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
38096 {
38097 - static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38098 + static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38099 struct sk_buff *msg;
38100 struct drbd_genlmsghdr *d_out;
38101 unsigned seq;
38102 int err = -ENOMEM;
38103
38104 - seq = atomic_inc_return(&drbd_genl_seq);
38105 + seq = atomic_inc_return_unchecked(&drbd_genl_seq);
38106 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
38107 if (!msg)
38108 goto failed;
38109 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
38110 index 6960fb0..215d76b 100644
38111 --- a/drivers/block/drbd/drbd_receiver.c
38112 +++ b/drivers/block/drbd/drbd_receiver.c
38113 @@ -870,7 +870,7 @@ int drbd_connected(struct drbd_peer_device *peer_device)
38114 struct drbd_device *device = peer_device->device;
38115 int err;
38116
38117 - atomic_set(&device->packet_seq, 0);
38118 + atomic_set_unchecked(&device->packet_seq, 0);
38119 device->peer_seq = 0;
38120
38121 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
38122 @@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
38123 do {
38124 next_epoch = NULL;
38125
38126 - epoch_size = atomic_read(&epoch->epoch_size);
38127 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
38128
38129 switch (ev & ~EV_CLEANUP) {
38130 case EV_PUT:
38131 @@ -1273,7 +1273,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
38132 rv = FE_DESTROYED;
38133 } else {
38134 epoch->flags = 0;
38135 - atomic_set(&epoch->epoch_size, 0);
38136 + atomic_set_unchecked(&epoch->epoch_size, 0);
38137 /* atomic_set(&epoch->active, 0); is already zero */
38138 if (rv == FE_STILL_LIVE)
38139 rv = FE_RECYCLED;
38140 @@ -1550,7 +1550,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
38141 conn_wait_active_ee_empty(connection);
38142 drbd_flush(connection);
38143
38144 - if (atomic_read(&connection->current_epoch->epoch_size)) {
38145 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38146 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
38147 if (epoch)
38148 break;
38149 @@ -1564,11 +1564,11 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
38150 }
38151
38152 epoch->flags = 0;
38153 - atomic_set(&epoch->epoch_size, 0);
38154 + atomic_set_unchecked(&epoch->epoch_size, 0);
38155 atomic_set(&epoch->active, 0);
38156
38157 spin_lock(&connection->epoch_lock);
38158 - if (atomic_read(&connection->current_epoch->epoch_size)) {
38159 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38160 list_add(&epoch->list, &connection->current_epoch->list);
38161 connection->current_epoch = epoch;
38162 connection->epochs++;
38163 @@ -1802,7 +1802,7 @@ static int recv_resync_read(struct drbd_peer_device *peer_device, sector_t secto
38164 list_add_tail(&peer_req->w.list, &device->sync_ee);
38165 spin_unlock_irq(&device->resource->req_lock);
38166
38167 - atomic_add(pi->size >> 9, &device->rs_sect_ev);
38168 + atomic_add_unchecked(pi->size >> 9, &device->rs_sect_ev);
38169 if (drbd_submit_peer_request(device, peer_req, WRITE, DRBD_FAULT_RS_WR) == 0)
38170 return 0;
38171
38172 @@ -1900,7 +1900,7 @@ static int receive_RSDataReply(struct drbd_connection *connection, struct packet
38173 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
38174 }
38175
38176 - atomic_add(pi->size >> 9, &device->rs_sect_in);
38177 + atomic_add_unchecked(pi->size >> 9, &device->rs_sect_in);
38178
38179 return err;
38180 }
38181 @@ -2290,7 +2290,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38182
38183 err = wait_for_and_update_peer_seq(peer_device, peer_seq);
38184 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
38185 - atomic_inc(&connection->current_epoch->epoch_size);
38186 + atomic_inc_unchecked(&connection->current_epoch->epoch_size);
38187 err2 = drbd_drain_block(peer_device, pi->size);
38188 if (!err)
38189 err = err2;
38190 @@ -2334,7 +2334,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38191
38192 spin_lock(&connection->epoch_lock);
38193 peer_req->epoch = connection->current_epoch;
38194 - atomic_inc(&peer_req->epoch->epoch_size);
38195 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
38196 atomic_inc(&peer_req->epoch->active);
38197 spin_unlock(&connection->epoch_lock);
38198
38199 @@ -2479,7 +2479,7 @@ bool drbd_rs_c_min_rate_throttle(struct drbd_device *device)
38200
38201 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
38202 (int)part_stat_read(&disk->part0, sectors[1]) -
38203 - atomic_read(&device->rs_sect_ev);
38204 + atomic_read_unchecked(&device->rs_sect_ev);
38205
38206 if (atomic_read(&device->ap_actlog_cnt)
38207 || !device->rs_last_events || curr_events - device->rs_last_events > 64) {
38208 @@ -2618,7 +2618,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
38209 device->use_csums = true;
38210 } else if (pi->cmd == P_OV_REPLY) {
38211 /* track progress, we may need to throttle */
38212 - atomic_add(size >> 9, &device->rs_sect_in);
38213 + atomic_add_unchecked(size >> 9, &device->rs_sect_in);
38214 peer_req->w.cb = w_e_end_ov_reply;
38215 dec_rs_pending(device);
38216 /* drbd_rs_begin_io done when we sent this request,
38217 @@ -2691,7 +2691,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
38218 goto out_free_e;
38219
38220 submit_for_resync:
38221 - atomic_add(size >> 9, &device->rs_sect_ev);
38222 + atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
38223
38224 submit:
38225 update_receiver_timing_details(connection, drbd_submit_peer_request);
38226 @@ -4564,7 +4564,7 @@ struct data_cmd {
38227 int expect_payload;
38228 size_t pkt_size;
38229 int (*fn)(struct drbd_connection *, struct packet_info *);
38230 -};
38231 +} __do_const;
38232
38233 static struct data_cmd drbd_cmd_handler[] = {
38234 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
38235 @@ -4678,7 +4678,7 @@ static void conn_disconnect(struct drbd_connection *connection)
38236 if (!list_empty(&connection->current_epoch->list))
38237 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
38238 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
38239 - atomic_set(&connection->current_epoch->epoch_size, 0);
38240 + atomic_set_unchecked(&connection->current_epoch->epoch_size, 0);
38241 connection->send.seen_any_write_yet = false;
38242
38243 drbd_info(connection, "Connection closed\n");
38244 @@ -5182,7 +5182,7 @@ static int got_IsInSync(struct drbd_connection *connection, struct packet_info *
38245 put_ldev(device);
38246 }
38247 dec_rs_pending(device);
38248 - atomic_add(blksize >> 9, &device->rs_sect_in);
38249 + atomic_add_unchecked(blksize >> 9, &device->rs_sect_in);
38250
38251 return 0;
38252 }
38253 @@ -5470,7 +5470,7 @@ static int connection_finish_peer_reqs(struct drbd_connection *connection)
38254 struct asender_cmd {
38255 size_t pkt_size;
38256 int (*fn)(struct drbd_connection *connection, struct packet_info *);
38257 -};
38258 +} __do_const;
38259
38260 static struct asender_cmd asender_tbl[] = {
38261 [P_PING] = { 0, got_Ping },
38262 diff --git a/drivers/block/drbd/drbd_worker.c b/drivers/block/drbd/drbd_worker.c
38263 index d2d1f97..6a1188f 100644
38264 --- a/drivers/block/drbd/drbd_worker.c
38265 +++ b/drivers/block/drbd/drbd_worker.c
38266 @@ -408,7 +408,7 @@ static int read_for_csum(struct drbd_peer_device *peer_device, sector_t sector,
38267 list_add_tail(&peer_req->w.list, &device->read_ee);
38268 spin_unlock_irq(&device->resource->req_lock);
38269
38270 - atomic_add(size >> 9, &device->rs_sect_ev);
38271 + atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
38272 if (drbd_submit_peer_request(device, peer_req, READ, DRBD_FAULT_RS_RD) == 0)
38273 return 0;
38274
38275 @@ -553,7 +553,7 @@ static int drbd_rs_number_requests(struct drbd_device *device)
38276 unsigned int sect_in; /* Number of sectors that came in since the last turn */
38277 int number, mxb;
38278
38279 - sect_in = atomic_xchg(&device->rs_sect_in, 0);
38280 + sect_in = atomic_xchg_unchecked(&device->rs_sect_in, 0);
38281 device->rs_in_flight -= sect_in;
38282
38283 rcu_read_lock();
38284 @@ -1594,8 +1594,8 @@ void drbd_rs_controller_reset(struct drbd_device *device)
38285 {
38286 struct fifo_buffer *plan;
38287
38288 - atomic_set(&device->rs_sect_in, 0);
38289 - atomic_set(&device->rs_sect_ev, 0);
38290 + atomic_set_unchecked(&device->rs_sect_in, 0);
38291 + atomic_set_unchecked(&device->rs_sect_ev, 0);
38292 device->rs_in_flight = 0;
38293
38294 /* Updating the RCU protected object in place is necessary since
38295 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
38296 index 6cb1beb..bf490f7 100644
38297 --- a/drivers/block/loop.c
38298 +++ b/drivers/block/loop.c
38299 @@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
38300
38301 file_start_write(file);
38302 set_fs(get_ds());
38303 - bw = file->f_op->write(file, buf, len, &pos);
38304 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
38305 set_fs(old_fs);
38306 file_end_write(file);
38307 if (likely(bw == len))
38308 diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
38309 index e2bb8af..44b8aef 100644
38310 --- a/drivers/block/nvme-core.c
38311 +++ b/drivers/block/nvme-core.c
38312 @@ -73,7 +73,6 @@ static LIST_HEAD(dev_list);
38313 static struct task_struct *nvme_thread;
38314 static struct workqueue_struct *nvme_workq;
38315 static wait_queue_head_t nvme_kthread_wait;
38316 -static struct notifier_block nvme_nb;
38317
38318 static void nvme_reset_failed_dev(struct work_struct *ws);
38319
38320 @@ -2926,6 +2925,10 @@ static struct pci_driver nvme_driver = {
38321 .err_handler = &nvme_err_handler,
38322 };
38323
38324 +static struct notifier_block nvme_nb = {
38325 + .notifier_call = &nvme_cpu_notify,
38326 +};
38327 +
38328 static int __init nvme_init(void)
38329 {
38330 int result;
38331 @@ -2942,7 +2945,6 @@ static int __init nvme_init(void)
38332 else if (result > 0)
38333 nvme_major = result;
38334
38335 - nvme_nb.notifier_call = &nvme_cpu_notify;
38336 result = register_hotcpu_notifier(&nvme_nb);
38337 if (result)
38338 goto unregister_blkdev;
38339 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
38340 index 09e628da..7607aaa 100644
38341 --- a/drivers/block/pktcdvd.c
38342 +++ b/drivers/block/pktcdvd.c
38343 @@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
38344
38345 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
38346 {
38347 - return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
38348 + return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
38349 }
38350
38351 /*
38352 @@ -1890,7 +1890,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
38353 return -EROFS;
38354 }
38355 pd->settings.fp = ti.fp;
38356 - pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
38357 + pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
38358
38359 if (ti.nwa_v) {
38360 pd->nwa = be32_to_cpu(ti.next_writable);
38361 diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
38362 index e5565fb..71be10b4 100644
38363 --- a/drivers/block/smart1,2.h
38364 +++ b/drivers/block/smart1,2.h
38365 @@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
38366 }
38367
38368 static struct access_method smart4_access = {
38369 - smart4_submit_command,
38370 - smart4_intr_mask,
38371 - smart4_fifo_full,
38372 - smart4_intr_pending,
38373 - smart4_completed,
38374 + .submit_command = smart4_submit_command,
38375 + .set_intr_mask = smart4_intr_mask,
38376 + .fifo_full = smart4_fifo_full,
38377 + .intr_pending = smart4_intr_pending,
38378 + .command_completed = smart4_completed,
38379 };
38380
38381 /*
38382 @@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
38383 }
38384
38385 static struct access_method smart2_access = {
38386 - smart2_submit_command,
38387 - smart2_intr_mask,
38388 - smart2_fifo_full,
38389 - smart2_intr_pending,
38390 - smart2_completed,
38391 + .submit_command = smart2_submit_command,
38392 + .set_intr_mask = smart2_intr_mask,
38393 + .fifo_full = smart2_fifo_full,
38394 + .intr_pending = smart2_intr_pending,
38395 + .command_completed = smart2_completed,
38396 };
38397
38398 /*
38399 @@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38400 }
38401
38402 static struct access_method smart2e_access = {
38403 - smart2e_submit_command,
38404 - smart2e_intr_mask,
38405 - smart2e_fifo_full,
38406 - smart2e_intr_pending,
38407 - smart2e_completed,
38408 + .submit_command = smart2e_submit_command,
38409 + .set_intr_mask = smart2e_intr_mask,
38410 + .fifo_full = smart2e_fifo_full,
38411 + .intr_pending = smart2e_intr_pending,
38412 + .command_completed = smart2e_completed,
38413 };
38414
38415 /*
38416 @@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38417 }
38418
38419 static struct access_method smart1_access = {
38420 - smart1_submit_command,
38421 - smart1_intr_mask,
38422 - smart1_fifo_full,
38423 - smart1_intr_pending,
38424 - smart1_completed,
38425 + .submit_command = smart1_submit_command,
38426 + .set_intr_mask = smart1_intr_mask,
38427 + .fifo_full = smart1_fifo_full,
38428 + .intr_pending = smart1_intr_pending,
38429 + .command_completed = smart1_completed,
38430 };
38431 diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38432 index f038dba..bb74c08 100644
38433 --- a/drivers/bluetooth/btwilink.c
38434 +++ b/drivers/bluetooth/btwilink.c
38435 @@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38436
38437 static int bt_ti_probe(struct platform_device *pdev)
38438 {
38439 - static struct ti_st *hst;
38440 + struct ti_st *hst;
38441 struct hci_dev *hdev;
38442 int err;
38443
38444 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38445 index 5d28a45..a538f90 100644
38446 --- a/drivers/cdrom/cdrom.c
38447 +++ b/drivers/cdrom/cdrom.c
38448 @@ -610,7 +610,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38449 ENSURE(reset, CDC_RESET);
38450 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38451 cdi->mc_flags = 0;
38452 - cdo->n_minors = 0;
38453 cdi->options = CDO_USE_FFLAGS;
38454
38455 if (autoclose == 1 && CDROM_CAN(CDC_CLOSE_TRAY))
38456 @@ -630,8 +629,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38457 else
38458 cdi->cdda_method = CDDA_OLD;
38459
38460 - if (!cdo->generic_packet)
38461 - cdo->generic_packet = cdrom_dummy_generic_packet;
38462 + if (!cdo->generic_packet) {
38463 + pax_open_kernel();
38464 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38465 + pax_close_kernel();
38466 + }
38467
38468 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38469 mutex_lock(&cdrom_mutex);
38470 @@ -652,7 +654,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38471 if (cdi->exit)
38472 cdi->exit(cdi);
38473
38474 - cdi->ops->n_minors--;
38475 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38476 }
38477
38478 @@ -2126,7 +2127,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38479 */
38480 nr = nframes;
38481 do {
38482 - cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38483 + cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38484 if (cgc.buffer)
38485 break;
38486
38487 @@ -3434,7 +3435,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38488 struct cdrom_device_info *cdi;
38489 int ret;
38490
38491 - ret = scnprintf(info + *pos, max_size - *pos, header);
38492 + ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38493 if (!ret)
38494 return 1;
38495
38496 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38497 index 584bc31..e64a12c 100644
38498 --- a/drivers/cdrom/gdrom.c
38499 +++ b/drivers/cdrom/gdrom.c
38500 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38501 .audio_ioctl = gdrom_audio_ioctl,
38502 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38503 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38504 - .n_minors = 1,
38505 };
38506
38507 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38508 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38509 index efefd12..4f1d494 100644
38510 --- a/drivers/char/Kconfig
38511 +++ b/drivers/char/Kconfig
38512 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38513
38514 config DEVKMEM
38515 bool "/dev/kmem virtual device support"
38516 - default y
38517 + default n
38518 + depends on !GRKERNSEC_KMEM
38519 help
38520 Say Y here if you want to support the /dev/kmem device. The
38521 /dev/kmem device is rarely used, but can be used for certain
38522 @@ -577,6 +578,7 @@ config DEVPORT
38523 bool
38524 depends on !M68K
38525 depends on ISA || PCI
38526 + depends on !GRKERNSEC_KMEM
38527 default y
38528
38529 source "drivers/s390/char/Kconfig"
38530 diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38531 index a48e05b..6bac831 100644
38532 --- a/drivers/char/agp/compat_ioctl.c
38533 +++ b/drivers/char/agp/compat_ioctl.c
38534 @@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38535 return -ENOMEM;
38536 }
38537
38538 - if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38539 + if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38540 sizeof(*usegment) * ureserve.seg_count)) {
38541 kfree(usegment);
38542 kfree(ksegment);
38543 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38544 index 09f17eb..8531d2f 100644
38545 --- a/drivers/char/agp/frontend.c
38546 +++ b/drivers/char/agp/frontend.c
38547 @@ -806,7 +806,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38548 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38549 return -EFAULT;
38550
38551 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38552 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38553 return -EFAULT;
38554
38555 client = agp_find_client_by_pid(reserve.pid);
38556 @@ -836,7 +836,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38557 if (segment == NULL)
38558 return -ENOMEM;
38559
38560 - if (copy_from_user(segment, (void __user *) reserve.seg_list,
38561 + if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38562 sizeof(struct agp_segment) * reserve.seg_count)) {
38563 kfree(segment);
38564 return -EFAULT;
38565 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38566 index 4f94375..413694e 100644
38567 --- a/drivers/char/genrtc.c
38568 +++ b/drivers/char/genrtc.c
38569 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38570 switch (cmd) {
38571
38572 case RTC_PLL_GET:
38573 + memset(&pll, 0, sizeof(pll));
38574 if (get_rtc_pll(&pll))
38575 return -EINVAL;
38576 else
38577 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38578 index d5d4cd8..22d561d 100644
38579 --- a/drivers/char/hpet.c
38580 +++ b/drivers/char/hpet.c
38581 @@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38582 }
38583
38584 static int
38585 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38586 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38587 struct hpet_info *info)
38588 {
38589 struct hpet_timer __iomem *timer;
38590 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38591 index f816211..89eadea 100644
38592 --- a/drivers/char/ipmi/ipmi_msghandler.c
38593 +++ b/drivers/char/ipmi/ipmi_msghandler.c
38594 @@ -438,7 +438,7 @@ struct ipmi_smi {
38595 struct proc_dir_entry *proc_dir;
38596 char proc_dir_name[10];
38597
38598 - atomic_t stats[IPMI_NUM_STATS];
38599 + atomic_unchecked_t stats[IPMI_NUM_STATS];
38600
38601 /*
38602 * run_to_completion duplicate of smb_info, smi_info
38603 @@ -470,9 +470,9 @@ static LIST_HEAD(smi_watchers);
38604 static DEFINE_MUTEX(smi_watchers_mutex);
38605
38606 #define ipmi_inc_stat(intf, stat) \
38607 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38608 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38609 #define ipmi_get_stat(intf, stat) \
38610 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38611 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38612
38613 static int is_lan_addr(struct ipmi_addr *addr)
38614 {
38615 @@ -2925,7 +2925,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38616 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38617 init_waitqueue_head(&intf->waitq);
38618 for (i = 0; i < IPMI_NUM_STATS; i++)
38619 - atomic_set(&intf->stats[i], 0);
38620 + atomic_set_unchecked(&intf->stats[i], 0);
38621
38622 intf->proc_dir = NULL;
38623
38624 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38625 index 5c4e1f6..0ea58f9 100644
38626 --- a/drivers/char/ipmi/ipmi_si_intf.c
38627 +++ b/drivers/char/ipmi/ipmi_si_intf.c
38628 @@ -285,7 +285,7 @@ struct smi_info {
38629 unsigned char slave_addr;
38630
38631 /* Counters and things for the proc filesystem. */
38632 - atomic_t stats[SI_NUM_STATS];
38633 + atomic_unchecked_t stats[SI_NUM_STATS];
38634
38635 struct task_struct *thread;
38636
38637 @@ -294,9 +294,9 @@ struct smi_info {
38638 };
38639
38640 #define smi_inc_stat(smi, stat) \
38641 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38642 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38643 #define smi_get_stat(smi, stat) \
38644 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38645 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38646
38647 #define SI_MAX_PARMS 4
38648
38649 @@ -3377,7 +3377,7 @@ static int try_smi_init(struct smi_info *new_smi)
38650 atomic_set(&new_smi->req_events, 0);
38651 new_smi->run_to_completion = false;
38652 for (i = 0; i < SI_NUM_STATS; i++)
38653 - atomic_set(&new_smi->stats[i], 0);
38654 + atomic_set_unchecked(&new_smi->stats[i], 0);
38655
38656 new_smi->interrupt_disabled = true;
38657 atomic_set(&new_smi->stop_operation, 0);
38658 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38659 index 524b707..29d07c1 100644
38660 --- a/drivers/char/mem.c
38661 +++ b/drivers/char/mem.c
38662 @@ -18,6 +18,7 @@
38663 #include <linux/raw.h>
38664 #include <linux/tty.h>
38665 #include <linux/capability.h>
38666 +#include <linux/security.h>
38667 #include <linux/ptrace.h>
38668 #include <linux/device.h>
38669 #include <linux/highmem.h>
38670 @@ -36,6 +37,10 @@
38671
38672 #define DEVPORT_MINOR 4
38673
38674 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38675 +extern const struct file_operations grsec_fops;
38676 +#endif
38677 +
38678 static inline unsigned long size_inside_page(unsigned long start,
38679 unsigned long size)
38680 {
38681 @@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38682
38683 while (cursor < to) {
38684 if (!devmem_is_allowed(pfn)) {
38685 +#ifdef CONFIG_GRKERNSEC_KMEM
38686 + gr_handle_mem_readwrite(from, to);
38687 +#else
38688 printk(KERN_INFO
38689 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38690 current->comm, from, to);
38691 +#endif
38692 return 0;
38693 }
38694 cursor += PAGE_SIZE;
38695 @@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38696 }
38697 return 1;
38698 }
38699 +#elif defined(CONFIG_GRKERNSEC_KMEM)
38700 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38701 +{
38702 + return 0;
38703 +}
38704 #else
38705 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38706 {
38707 @@ -122,6 +136,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38708
38709 while (count > 0) {
38710 unsigned long remaining;
38711 + char *temp;
38712
38713 sz = size_inside_page(p, count);
38714
38715 @@ -137,7 +152,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38716 if (!ptr)
38717 return -EFAULT;
38718
38719 - remaining = copy_to_user(buf, ptr, sz);
38720 +#ifdef CONFIG_PAX_USERCOPY
38721 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38722 + if (!temp) {
38723 + unxlate_dev_mem_ptr(p, ptr);
38724 + return -ENOMEM;
38725 + }
38726 + memcpy(temp, ptr, sz);
38727 +#else
38728 + temp = ptr;
38729 +#endif
38730 +
38731 + remaining = copy_to_user(buf, temp, sz);
38732 +
38733 +#ifdef CONFIG_PAX_USERCOPY
38734 + kfree(temp);
38735 +#endif
38736 +
38737 unxlate_dev_mem_ptr(p, ptr);
38738 if (remaining)
38739 return -EFAULT;
38740 @@ -369,9 +400,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38741 size_t count, loff_t *ppos)
38742 {
38743 unsigned long p = *ppos;
38744 - ssize_t low_count, read, sz;
38745 + ssize_t low_count, read, sz, err = 0;
38746 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38747 - int err = 0;
38748
38749 read = 0;
38750 if (p < (unsigned long) high_memory) {
38751 @@ -393,6 +423,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38752 }
38753 #endif
38754 while (low_count > 0) {
38755 + char *temp;
38756 +
38757 sz = size_inside_page(p, low_count);
38758
38759 /*
38760 @@ -402,7 +434,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38761 */
38762 kbuf = xlate_dev_kmem_ptr((char *)p);
38763
38764 - if (copy_to_user(buf, kbuf, sz))
38765 +#ifdef CONFIG_PAX_USERCOPY
38766 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38767 + if (!temp)
38768 + return -ENOMEM;
38769 + memcpy(temp, kbuf, sz);
38770 +#else
38771 + temp = kbuf;
38772 +#endif
38773 +
38774 + err = copy_to_user(buf, temp, sz);
38775 +
38776 +#ifdef CONFIG_PAX_USERCOPY
38777 + kfree(temp);
38778 +#endif
38779 +
38780 + if (err)
38781 return -EFAULT;
38782 buf += sz;
38783 p += sz;
38784 @@ -797,6 +844,9 @@ static const struct memdev {
38785 #ifdef CONFIG_PRINTK
38786 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38787 #endif
38788 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38789 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38790 +#endif
38791 };
38792
38793 static int memory_open(struct inode *inode, struct file *filp)
38794 @@ -868,7 +918,7 @@ static int __init chr_dev_init(void)
38795 continue;
38796
38797 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38798 - NULL, devlist[minor].name);
38799 + NULL, "%s", devlist[minor].name);
38800 }
38801
38802 return tty_init();
38803 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38804 index 9df78e2..01ba9ae 100644
38805 --- a/drivers/char/nvram.c
38806 +++ b/drivers/char/nvram.c
38807 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38808
38809 spin_unlock_irq(&rtc_lock);
38810
38811 - if (copy_to_user(buf, contents, tmp - contents))
38812 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38813 return -EFAULT;
38814
38815 *ppos = i;
38816 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38817 index 0ea9986..e7b07e4 100644
38818 --- a/drivers/char/pcmcia/synclink_cs.c
38819 +++ b/drivers/char/pcmcia/synclink_cs.c
38820 @@ -2345,7 +2345,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38821
38822 if (debug_level >= DEBUG_LEVEL_INFO)
38823 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38824 - __FILE__, __LINE__, info->device_name, port->count);
38825 + __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38826
38827 if (tty_port_close_start(port, tty, filp) == 0)
38828 goto cleanup;
38829 @@ -2363,7 +2363,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38830 cleanup:
38831 if (debug_level >= DEBUG_LEVEL_INFO)
38832 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38833 - tty->driver->name, port->count);
38834 + tty->driver->name, atomic_read(&port->count));
38835 }
38836
38837 /* Wait until the transmitter is empty.
38838 @@ -2505,7 +2505,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38839
38840 if (debug_level >= DEBUG_LEVEL_INFO)
38841 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38842 - __FILE__, __LINE__, tty->driver->name, port->count);
38843 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38844
38845 /* If port is closing, signal caller to try again */
38846 if (port->flags & ASYNC_CLOSING){
38847 @@ -2525,11 +2525,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38848 goto cleanup;
38849 }
38850 spin_lock(&port->lock);
38851 - port->count++;
38852 + atomic_inc(&port->count);
38853 spin_unlock(&port->lock);
38854 spin_unlock_irqrestore(&info->netlock, flags);
38855
38856 - if (port->count == 1) {
38857 + if (atomic_read(&port->count) == 1) {
38858 /* 1st open on this device, init hardware */
38859 retval = startup(info, tty);
38860 if (retval < 0)
38861 @@ -3918,7 +3918,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38862 unsigned short new_crctype;
38863
38864 /* return error if TTY interface open */
38865 - if (info->port.count)
38866 + if (atomic_read(&info->port.count))
38867 return -EBUSY;
38868
38869 switch (encoding)
38870 @@ -4022,7 +4022,7 @@ static int hdlcdev_open(struct net_device *dev)
38871
38872 /* arbitrate between network and tty opens */
38873 spin_lock_irqsave(&info->netlock, flags);
38874 - if (info->port.count != 0 || info->netcount != 0) {
38875 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38876 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38877 spin_unlock_irqrestore(&info->netlock, flags);
38878 return -EBUSY;
38879 @@ -4112,7 +4112,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38880 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38881
38882 /* return error if TTY interface open */
38883 - if (info->port.count)
38884 + if (atomic_read(&info->port.count))
38885 return -EBUSY;
38886
38887 if (cmd != SIOCWANDEV)
38888 diff --git a/drivers/char/random.c b/drivers/char/random.c
38889 index 04645c0..560e350 100644
38890 --- a/drivers/char/random.c
38891 +++ b/drivers/char/random.c
38892 @@ -289,9 +289,6 @@
38893 /*
38894 * To allow fractional bits to be tracked, the entropy_count field is
38895 * denominated in units of 1/8th bits.
38896 - *
38897 - * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38898 - * credit_entropy_bits() needs to be 64 bits wide.
38899 */
38900 #define ENTROPY_SHIFT 3
38901 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38902 @@ -439,9 +436,9 @@ struct entropy_store {
38903 };
38904
38905 static void push_to_pool(struct work_struct *work);
38906 -static __u32 input_pool_data[INPUT_POOL_WORDS];
38907 -static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
38908 -static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
38909 +static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
38910 +static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38911 +static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38912
38913 static struct entropy_store input_pool = {
38914 .poolinfo = &poolinfo_table[0],
38915 @@ -635,7 +632,7 @@ retry:
38916 /* The +2 corresponds to the /4 in the denominator */
38917
38918 do {
38919 - unsigned int anfrac = min(pnfrac, pool_size/2);
38920 + u64 anfrac = min(pnfrac, pool_size/2);
38921 unsigned int add =
38922 ((pool_size - entropy_count)*anfrac*3) >> s;
38923
38924 @@ -1207,7 +1204,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38925
38926 extract_buf(r, tmp);
38927 i = min_t(int, nbytes, EXTRACT_SIZE);
38928 - if (copy_to_user(buf, tmp, i)) {
38929 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38930 ret = -EFAULT;
38931 break;
38932 }
38933 @@ -1590,7 +1587,7 @@ static char sysctl_bootid[16];
38934 static int proc_do_uuid(struct ctl_table *table, int write,
38935 void __user *buffer, size_t *lenp, loff_t *ppos)
38936 {
38937 - struct ctl_table fake_table;
38938 + ctl_table_no_const fake_table;
38939 unsigned char buf[64], tmp_uuid[16], *uuid;
38940
38941 uuid = table->data;
38942 @@ -1620,7 +1617,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
38943 static int proc_do_entropy(struct ctl_table *table, int write,
38944 void __user *buffer, size_t *lenp, loff_t *ppos)
38945 {
38946 - struct ctl_table fake_table;
38947 + ctl_table_no_const fake_table;
38948 int entropy_count;
38949
38950 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
38951 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
38952 index 7cc1fe22..b602d6b 100644
38953 --- a/drivers/char/sonypi.c
38954 +++ b/drivers/char/sonypi.c
38955 @@ -54,6 +54,7 @@
38956
38957 #include <asm/uaccess.h>
38958 #include <asm/io.h>
38959 +#include <asm/local.h>
38960
38961 #include <linux/sonypi.h>
38962
38963 @@ -490,7 +491,7 @@ static struct sonypi_device {
38964 spinlock_t fifo_lock;
38965 wait_queue_head_t fifo_proc_list;
38966 struct fasync_struct *fifo_async;
38967 - int open_count;
38968 + local_t open_count;
38969 int model;
38970 struct input_dev *input_jog_dev;
38971 struct input_dev *input_key_dev;
38972 @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38973 static int sonypi_misc_release(struct inode *inode, struct file *file)
38974 {
38975 mutex_lock(&sonypi_device.lock);
38976 - sonypi_device.open_count--;
38977 + local_dec(&sonypi_device.open_count);
38978 mutex_unlock(&sonypi_device.lock);
38979 return 0;
38980 }
38981 @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38982 {
38983 mutex_lock(&sonypi_device.lock);
38984 /* Flush input queue on first open */
38985 - if (!sonypi_device.open_count)
38986 + if (!local_read(&sonypi_device.open_count))
38987 kfifo_reset(&sonypi_device.fifo);
38988 - sonypi_device.open_count++;
38989 + local_inc(&sonypi_device.open_count);
38990 mutex_unlock(&sonypi_device.lock);
38991
38992 return 0;
38993 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
38994 index 565a947..dcdc06e 100644
38995 --- a/drivers/char/tpm/tpm_acpi.c
38996 +++ b/drivers/char/tpm/tpm_acpi.c
38997 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
38998 virt = acpi_os_map_iomem(start, len);
38999 if (!virt) {
39000 kfree(log->bios_event_log);
39001 + log->bios_event_log = NULL;
39002 printk("%s: ERROR - Unable to map memory\n", __func__);
39003 return -EIO;
39004 }
39005
39006 - memcpy_fromio(log->bios_event_log, virt, len);
39007 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
39008
39009 acpi_os_unmap_iomem(virt, len);
39010 return 0;
39011 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
39012 index 3a56a13..f8cbd25 100644
39013 --- a/drivers/char/tpm/tpm_eventlog.c
39014 +++ b/drivers/char/tpm/tpm_eventlog.c
39015 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
39016 event = addr;
39017
39018 if ((event->event_type == 0 && event->event_size == 0) ||
39019 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
39020 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
39021 return NULL;
39022
39023 return addr;
39024 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
39025 return NULL;
39026
39027 if ((event->event_type == 0 && event->event_size == 0) ||
39028 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
39029 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
39030 return NULL;
39031
39032 (*pos)++;
39033 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
39034 int i;
39035
39036 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
39037 - seq_putc(m, data[i]);
39038 + if (!seq_putc(m, data[i]))
39039 + return -EFAULT;
39040
39041 return 0;
39042 }
39043 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
39044 index cf7a561..c319ce0 100644
39045 --- a/drivers/char/virtio_console.c
39046 +++ b/drivers/char/virtio_console.c
39047 @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
39048 if (to_user) {
39049 ssize_t ret;
39050
39051 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
39052 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
39053 if (ret)
39054 return -EFAULT;
39055 } else {
39056 @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
39057 if (!port_has_data(port) && !port->host_connected)
39058 return 0;
39059
39060 - return fill_readbuf(port, ubuf, count, true);
39061 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
39062 }
39063
39064 static int wait_port_writable(struct port *port, bool nonblock)
39065 diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
39066 index b9355da..9611f4e 100644
39067 --- a/drivers/clk/clk-composite.c
39068 +++ b/drivers/clk/clk-composite.c
39069 @@ -191,7 +191,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
39070 struct clk *clk;
39071 struct clk_init_data init;
39072 struct clk_composite *composite;
39073 - struct clk_ops *clk_composite_ops;
39074 + clk_ops_no_const *clk_composite_ops;
39075
39076 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
39077 if (!composite) {
39078 diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
39079 index dd3a78c..386d49c 100644
39080 --- a/drivers/clk/socfpga/clk-gate.c
39081 +++ b/drivers/clk/socfpga/clk-gate.c
39082 @@ -22,6 +22,7 @@
39083 #include <linux/mfd/syscon.h>
39084 #include <linux/of.h>
39085 #include <linux/regmap.h>
39086 +#include <asm/pgtable.h>
39087
39088 #include "clk.h"
39089
39090 @@ -174,7 +175,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
39091 return 0;
39092 }
39093
39094 -static struct clk_ops gateclk_ops = {
39095 +static clk_ops_no_const gateclk_ops __read_only = {
39096 .prepare = socfpga_clk_prepare,
39097 .recalc_rate = socfpga_clk_recalc_rate,
39098 .get_parent = socfpga_clk_get_parent,
39099 @@ -208,8 +209,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
39100 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
39101 socfpga_clk->hw.bit_idx = clk_gate[1];
39102
39103 - gateclk_ops.enable = clk_gate_ops.enable;
39104 - gateclk_ops.disable = clk_gate_ops.disable;
39105 + pax_open_kernel();
39106 + *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
39107 + *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
39108 + pax_close_kernel();
39109 }
39110
39111 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
39112 diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
39113 index de6da95..c98278b 100644
39114 --- a/drivers/clk/socfpga/clk-pll.c
39115 +++ b/drivers/clk/socfpga/clk-pll.c
39116 @@ -21,6 +21,7 @@
39117 #include <linux/io.h>
39118 #include <linux/of.h>
39119 #include <linux/of_address.h>
39120 +#include <asm/pgtable.h>
39121
39122 #include "clk.h"
39123
39124 @@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
39125 CLK_MGR_PLL_CLK_SRC_MASK;
39126 }
39127
39128 -static struct clk_ops clk_pll_ops = {
39129 +static clk_ops_no_const clk_pll_ops __read_only = {
39130 .recalc_rate = clk_pll_recalc_rate,
39131 .get_parent = clk_pll_get_parent,
39132 };
39133 @@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
39134 pll_clk->hw.hw.init = &init;
39135
39136 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
39137 - clk_pll_ops.enable = clk_gate_ops.enable;
39138 - clk_pll_ops.disable = clk_gate_ops.disable;
39139 + pax_open_kernel();
39140 + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
39141 + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
39142 + pax_close_kernel();
39143
39144 clk = clk_register(NULL, &pll_clk->hw.hw);
39145 if (WARN_ON(IS_ERR(clk))) {
39146 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
39147 index b0c18ed..1713a80 100644
39148 --- a/drivers/cpufreq/acpi-cpufreq.c
39149 +++ b/drivers/cpufreq/acpi-cpufreq.c
39150 @@ -675,8 +675,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39151 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
39152 per_cpu(acfreq_data, cpu) = data;
39153
39154 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
39155 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39156 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
39157 + pax_open_kernel();
39158 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39159 + pax_close_kernel();
39160 + }
39161
39162 result = acpi_processor_register_performance(data->acpi_data, cpu);
39163 if (result)
39164 @@ -809,7 +812,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39165 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
39166 break;
39167 case ACPI_ADR_SPACE_FIXED_HARDWARE:
39168 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39169 + pax_open_kernel();
39170 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39171 + pax_close_kernel();
39172 break;
39173 default:
39174 break;
39175 @@ -903,8 +908,10 @@ static void __init acpi_cpufreq_boost_init(void)
39176 if (!msrs)
39177 return;
39178
39179 - acpi_cpufreq_driver.boost_supported = true;
39180 - acpi_cpufreq_driver.boost_enabled = boost_state(0);
39181 + pax_open_kernel();
39182 + *(bool *)&acpi_cpufreq_driver.boost_supported = true;
39183 + *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
39184 + pax_close_kernel();
39185
39186 cpu_notifier_register_begin();
39187
39188 diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
39189 index f657c57..ada41b6 100644
39190 --- a/drivers/cpufreq/cpufreq-dt.c
39191 +++ b/drivers/cpufreq/cpufreq-dt.c
39192 @@ -345,6 +345,7 @@ static int dt_cpufreq_probe(struct platform_device *pdev)
39193 struct device *cpu_dev;
39194 struct regulator *cpu_reg;
39195 struct clk *cpu_clk;
39196 + void *fptr;
39197 int ret;
39198
39199 /*
39200 @@ -362,7 +363,10 @@ static int dt_cpufreq_probe(struct platform_device *pdev)
39201 if (!IS_ERR(cpu_reg))
39202 regulator_put(cpu_reg);
39203
39204 - dt_cpufreq_driver.driver_data = dev_get_platdata(&pdev->dev);
39205 + fptr = dev_get_platdata(&pdev->dev);
39206 + pax_open_kernel();
39207 + *(void **)&dt_cpufreq_driver.driver_data = fptr;
39208 + pax_close_kernel();
39209
39210 ret = cpufreq_register_driver(&dt_cpufreq_driver);
39211 if (ret)
39212 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
39213 index 4473eba..a4c9dc2 100644
39214 --- a/drivers/cpufreq/cpufreq.c
39215 +++ b/drivers/cpufreq/cpufreq.c
39216 @@ -2122,7 +2122,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
39217 }
39218
39219 mutex_lock(&cpufreq_governor_mutex);
39220 - list_del(&governor->governor_list);
39221 + pax_list_del(&governor->governor_list);
39222 mutex_unlock(&cpufreq_governor_mutex);
39223 return;
39224 }
39225 @@ -2338,7 +2338,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
39226 return NOTIFY_OK;
39227 }
39228
39229 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
39230 +static struct notifier_block cpufreq_cpu_notifier = {
39231 .notifier_call = cpufreq_cpu_callback,
39232 };
39233
39234 @@ -2378,13 +2378,17 @@ int cpufreq_boost_trigger_state(int state)
39235 return 0;
39236
39237 write_lock_irqsave(&cpufreq_driver_lock, flags);
39238 - cpufreq_driver->boost_enabled = state;
39239 + pax_open_kernel();
39240 + *(bool *)&cpufreq_driver->boost_enabled = state;
39241 + pax_close_kernel();
39242 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39243
39244 ret = cpufreq_driver->set_boost(state);
39245 if (ret) {
39246 write_lock_irqsave(&cpufreq_driver_lock, flags);
39247 - cpufreq_driver->boost_enabled = !state;
39248 + pax_open_kernel();
39249 + *(bool *)&cpufreq_driver->boost_enabled = !state;
39250 + pax_close_kernel();
39251 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39252
39253 pr_err("%s: Cannot %s BOOST\n",
39254 @@ -2441,8 +2445,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39255
39256 pr_debug("trying to register driver %s\n", driver_data->name);
39257
39258 - if (driver_data->setpolicy)
39259 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
39260 + if (driver_data->setpolicy) {
39261 + pax_open_kernel();
39262 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
39263 + pax_close_kernel();
39264 + }
39265
39266 write_lock_irqsave(&cpufreq_driver_lock, flags);
39267 if (cpufreq_driver) {
39268 @@ -2457,8 +2464,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39269 * Check if driver provides function to enable boost -
39270 * if not, use cpufreq_boost_set_sw as default
39271 */
39272 - if (!cpufreq_driver->set_boost)
39273 - cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39274 + if (!cpufreq_driver->set_boost) {
39275 + pax_open_kernel();
39276 + *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39277 + pax_close_kernel();
39278 + }
39279
39280 ret = cpufreq_sysfs_create_file(&boost.attr);
39281 if (ret) {
39282 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
39283 index 1b44496..b80ff5e 100644
39284 --- a/drivers/cpufreq/cpufreq_governor.c
39285 +++ b/drivers/cpufreq/cpufreq_governor.c
39286 @@ -245,7 +245,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39287 struct dbs_data *dbs_data;
39288 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
39289 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
39290 - struct od_ops *od_ops = NULL;
39291 + const struct od_ops *od_ops = NULL;
39292 struct od_dbs_tuners *od_tuners = NULL;
39293 struct cs_dbs_tuners *cs_tuners = NULL;
39294 struct cpu_dbs_common_info *cpu_cdbs;
39295 @@ -311,7 +311,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39296
39297 if ((cdata->governor == GOV_CONSERVATIVE) &&
39298 (!policy->governor->initialized)) {
39299 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39300 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39301
39302 cpufreq_register_notifier(cs_ops->notifier_block,
39303 CPUFREQ_TRANSITION_NOTIFIER);
39304 @@ -331,7 +331,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39305
39306 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
39307 (policy->governor->initialized == 1)) {
39308 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39309 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39310
39311 cpufreq_unregister_notifier(cs_ops->notifier_block,
39312 CPUFREQ_TRANSITION_NOTIFIER);
39313 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
39314 index cc401d1..8197340 100644
39315 --- a/drivers/cpufreq/cpufreq_governor.h
39316 +++ b/drivers/cpufreq/cpufreq_governor.h
39317 @@ -212,7 +212,7 @@ struct common_dbs_data {
39318 void (*exit)(struct dbs_data *dbs_data);
39319
39320 /* Governor specific ops, see below */
39321 - void *gov_ops;
39322 + const void *gov_ops;
39323 };
39324
39325 /* Governor Per policy data */
39326 @@ -232,7 +232,7 @@ struct od_ops {
39327 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
39328 unsigned int freq_next, unsigned int relation);
39329 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
39330 -};
39331 +} __no_const;
39332
39333 struct cs_ops {
39334 struct notifier_block *notifier_block;
39335 diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
39336 index ad3f38f..8f086cd 100644
39337 --- a/drivers/cpufreq/cpufreq_ondemand.c
39338 +++ b/drivers/cpufreq/cpufreq_ondemand.c
39339 @@ -524,7 +524,7 @@ static void od_exit(struct dbs_data *dbs_data)
39340
39341 define_get_cpu_dbs_routines(od_cpu_dbs_info);
39342
39343 -static struct od_ops od_ops = {
39344 +static struct od_ops od_ops __read_only = {
39345 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
39346 .powersave_bias_target = generic_powersave_bias_target,
39347 .freq_increase = dbs_freq_increase,
39348 @@ -579,14 +579,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
39349 (struct cpufreq_policy *, unsigned int, unsigned int),
39350 unsigned int powersave_bias)
39351 {
39352 - od_ops.powersave_bias_target = f;
39353 + pax_open_kernel();
39354 + *(void **)&od_ops.powersave_bias_target = f;
39355 + pax_close_kernel();
39356 od_set_powersave_bias(powersave_bias);
39357 }
39358 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
39359
39360 void od_unregister_powersave_bias_handler(void)
39361 {
39362 - od_ops.powersave_bias_target = generic_powersave_bias_target;
39363 + pax_open_kernel();
39364 + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
39365 + pax_close_kernel();
39366 od_set_powersave_bias(0);
39367 }
39368 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
39369 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
39370 index 27bb6d3..4cf595c 100644
39371 --- a/drivers/cpufreq/intel_pstate.c
39372 +++ b/drivers/cpufreq/intel_pstate.c
39373 @@ -133,10 +133,10 @@ struct pstate_funcs {
39374 struct cpu_defaults {
39375 struct pstate_adjust_policy pid_policy;
39376 struct pstate_funcs funcs;
39377 -};
39378 +} __do_const;
39379
39380 static struct pstate_adjust_policy pid_params;
39381 -static struct pstate_funcs pstate_funcs;
39382 +static struct pstate_funcs *pstate_funcs;
39383
39384 struct perf_limits {
39385 int no_turbo;
39386 @@ -594,18 +594,18 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
39387
39388 cpu->pstate.current_pstate = pstate;
39389
39390 - pstate_funcs.set(cpu, pstate);
39391 + pstate_funcs->set(cpu, pstate);
39392 }
39393
39394 static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39395 {
39396 - cpu->pstate.min_pstate = pstate_funcs.get_min();
39397 - cpu->pstate.max_pstate = pstate_funcs.get_max();
39398 - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39399 - cpu->pstate.scaling = pstate_funcs.get_scaling();
39400 + cpu->pstate.min_pstate = pstate_funcs->get_min();
39401 + cpu->pstate.max_pstate = pstate_funcs->get_max();
39402 + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39403 + cpu->pstate.scaling = pstate_funcs->get_scaling();
39404
39405 - if (pstate_funcs.get_vid)
39406 - pstate_funcs.get_vid(cpu);
39407 + if (pstate_funcs->get_vid)
39408 + pstate_funcs->get_vid(cpu);
39409 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
39410 }
39411
39412 @@ -875,9 +875,9 @@ static int intel_pstate_msrs_not_valid(void)
39413 rdmsrl(MSR_IA32_APERF, aperf);
39414 rdmsrl(MSR_IA32_MPERF, mperf);
39415
39416 - if (!pstate_funcs.get_max() ||
39417 - !pstate_funcs.get_min() ||
39418 - !pstate_funcs.get_turbo())
39419 + if (!pstate_funcs->get_max() ||
39420 + !pstate_funcs->get_min() ||
39421 + !pstate_funcs->get_turbo())
39422 return -ENODEV;
39423
39424 rdmsrl(MSR_IA32_APERF, tmp);
39425 @@ -891,7 +891,7 @@ static int intel_pstate_msrs_not_valid(void)
39426 return 0;
39427 }
39428
39429 -static void copy_pid_params(struct pstate_adjust_policy *policy)
39430 +static void copy_pid_params(const struct pstate_adjust_policy *policy)
39431 {
39432 pid_params.sample_rate_ms = policy->sample_rate_ms;
39433 pid_params.p_gain_pct = policy->p_gain_pct;
39434 @@ -903,12 +903,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39435
39436 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39437 {
39438 - pstate_funcs.get_max = funcs->get_max;
39439 - pstate_funcs.get_min = funcs->get_min;
39440 - pstate_funcs.get_turbo = funcs->get_turbo;
39441 - pstate_funcs.get_scaling = funcs->get_scaling;
39442 - pstate_funcs.set = funcs->set;
39443 - pstate_funcs.get_vid = funcs->get_vid;
39444 + pstate_funcs = funcs;
39445 }
39446
39447 #if IS_ENABLED(CONFIG_ACPI)
39448 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39449 index 529cfd9..0e28fff 100644
39450 --- a/drivers/cpufreq/p4-clockmod.c
39451 +++ b/drivers/cpufreq/p4-clockmod.c
39452 @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39453 case 0x0F: /* Core Duo */
39454 case 0x16: /* Celeron Core */
39455 case 0x1C: /* Atom */
39456 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39457 + pax_open_kernel();
39458 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39459 + pax_close_kernel();
39460 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39461 case 0x0D: /* Pentium M (Dothan) */
39462 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39463 + pax_open_kernel();
39464 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39465 + pax_close_kernel();
39466 /* fall through */
39467 case 0x09: /* Pentium M (Banias) */
39468 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39469 @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39470
39471 /* on P-4s, the TSC runs with constant frequency independent whether
39472 * throttling is active or not. */
39473 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39474 + pax_open_kernel();
39475 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39476 + pax_close_kernel();
39477
39478 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39479 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39480 diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39481 index 9bb42ba..b01b4a2 100644
39482 --- a/drivers/cpufreq/sparc-us3-cpufreq.c
39483 +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39484 @@ -18,14 +18,12 @@
39485 #include <asm/head.h>
39486 #include <asm/timer.h>
39487
39488 -static struct cpufreq_driver *cpufreq_us3_driver;
39489 -
39490 struct us3_freq_percpu_info {
39491 struct cpufreq_frequency_table table[4];
39492 };
39493
39494 /* Indexed by cpu number. */
39495 -static struct us3_freq_percpu_info *us3_freq_table;
39496 +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39497
39498 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39499 * in the Safari config register.
39500 @@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39501
39502 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39503 {
39504 - if (cpufreq_us3_driver)
39505 - us3_freq_target(policy, 0);
39506 + us3_freq_target(policy, 0);
39507
39508 return 0;
39509 }
39510
39511 +static int __init us3_freq_init(void);
39512 +static void __exit us3_freq_exit(void);
39513 +
39514 +static struct cpufreq_driver cpufreq_us3_driver = {
39515 + .init = us3_freq_cpu_init,
39516 + .verify = cpufreq_generic_frequency_table_verify,
39517 + .target_index = us3_freq_target,
39518 + .get = us3_freq_get,
39519 + .exit = us3_freq_cpu_exit,
39520 + .name = "UltraSPARC-III",
39521 +
39522 +};
39523 +
39524 static int __init us3_freq_init(void)
39525 {
39526 unsigned long manuf, impl, ver;
39527 - int ret;
39528
39529 if (tlb_type != cheetah && tlb_type != cheetah_plus)
39530 return -ENODEV;
39531 @@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
39532 (impl == CHEETAH_IMPL ||
39533 impl == CHEETAH_PLUS_IMPL ||
39534 impl == JAGUAR_IMPL ||
39535 - impl == PANTHER_IMPL)) {
39536 - struct cpufreq_driver *driver;
39537 -
39538 - ret = -ENOMEM;
39539 - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39540 - if (!driver)
39541 - goto err_out;
39542 -
39543 - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39544 - GFP_KERNEL);
39545 - if (!us3_freq_table)
39546 - goto err_out;
39547 -
39548 - driver->init = us3_freq_cpu_init;
39549 - driver->verify = cpufreq_generic_frequency_table_verify;
39550 - driver->target_index = us3_freq_target;
39551 - driver->get = us3_freq_get;
39552 - driver->exit = us3_freq_cpu_exit;
39553 - strcpy(driver->name, "UltraSPARC-III");
39554 -
39555 - cpufreq_us3_driver = driver;
39556 - ret = cpufreq_register_driver(driver);
39557 - if (ret)
39558 - goto err_out;
39559 -
39560 - return 0;
39561 -
39562 -err_out:
39563 - if (driver) {
39564 - kfree(driver);
39565 - cpufreq_us3_driver = NULL;
39566 - }
39567 - kfree(us3_freq_table);
39568 - us3_freq_table = NULL;
39569 - return ret;
39570 - }
39571 + impl == PANTHER_IMPL))
39572 + return cpufreq_register_driver(&cpufreq_us3_driver);
39573
39574 return -ENODEV;
39575 }
39576
39577 static void __exit us3_freq_exit(void)
39578 {
39579 - if (cpufreq_us3_driver) {
39580 - cpufreq_unregister_driver(cpufreq_us3_driver);
39581 - kfree(cpufreq_us3_driver);
39582 - cpufreq_us3_driver = NULL;
39583 - kfree(us3_freq_table);
39584 - us3_freq_table = NULL;
39585 - }
39586 + cpufreq_unregister_driver(&cpufreq_us3_driver);
39587 }
39588
39589 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39590 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39591 index 7d4a315..21bb886 100644
39592 --- a/drivers/cpufreq/speedstep-centrino.c
39593 +++ b/drivers/cpufreq/speedstep-centrino.c
39594 @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39595 !cpu_has(cpu, X86_FEATURE_EST))
39596 return -ENODEV;
39597
39598 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39599 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39600 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39601 + pax_open_kernel();
39602 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39603 + pax_close_kernel();
39604 + }
39605
39606 if (policy->cpu != 0)
39607 return -ENODEV;
39608 diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39609 index e431d11..d0b997e 100644
39610 --- a/drivers/cpuidle/driver.c
39611 +++ b/drivers/cpuidle/driver.c
39612 @@ -194,7 +194,7 @@ static int poll_idle(struct cpuidle_device *dev,
39613
39614 static void poll_idle_init(struct cpuidle_driver *drv)
39615 {
39616 - struct cpuidle_state *state = &drv->states[0];
39617 + cpuidle_state_no_const *state = &drv->states[0];
39618
39619 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39620 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39621 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39622 index fb9f511..213e6cc 100644
39623 --- a/drivers/cpuidle/governor.c
39624 +++ b/drivers/cpuidle/governor.c
39625 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39626 mutex_lock(&cpuidle_lock);
39627 if (__cpuidle_find_governor(gov->name) == NULL) {
39628 ret = 0;
39629 - list_add_tail(&gov->governor_list, &cpuidle_governors);
39630 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39631 if (!cpuidle_curr_governor ||
39632 cpuidle_curr_governor->rating < gov->rating)
39633 cpuidle_switch_governor(gov);
39634 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39635 index 97c5903..023ad23 100644
39636 --- a/drivers/cpuidle/sysfs.c
39637 +++ b/drivers/cpuidle/sysfs.c
39638 @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39639 NULL
39640 };
39641
39642 -static struct attribute_group cpuidle_attr_group = {
39643 +static attribute_group_no_const cpuidle_attr_group = {
39644 .attrs = cpuidle_default_attrs,
39645 .name = "cpuidle",
39646 };
39647 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39648 index 8d2a772..33826c9 100644
39649 --- a/drivers/crypto/hifn_795x.c
39650 +++ b/drivers/crypto/hifn_795x.c
39651 @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39652 MODULE_PARM_DESC(hifn_pll_ref,
39653 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39654
39655 -static atomic_t hifn_dev_number;
39656 +static atomic_unchecked_t hifn_dev_number;
39657
39658 #define ACRYPTO_OP_DECRYPT 0
39659 #define ACRYPTO_OP_ENCRYPT 1
39660 @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39661 goto err_out_disable_pci_device;
39662
39663 snprintf(name, sizeof(name), "hifn%d",
39664 - atomic_inc_return(&hifn_dev_number)-1);
39665 + atomic_inc_return_unchecked(&hifn_dev_number)-1);
39666
39667 err = pci_request_regions(pdev, name);
39668 if (err)
39669 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39670 index 30b538d8..1610d75 100644
39671 --- a/drivers/devfreq/devfreq.c
39672 +++ b/drivers/devfreq/devfreq.c
39673 @@ -673,7 +673,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39674 goto err_out;
39675 }
39676
39677 - list_add(&governor->node, &devfreq_governor_list);
39678 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39679
39680 list_for_each_entry(devfreq, &devfreq_list, node) {
39681 int ret = 0;
39682 @@ -761,7 +761,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39683 }
39684 }
39685
39686 - list_del(&governor->node);
39687 + pax_list_del((struct list_head *)&governor->node);
39688 err_out:
39689 mutex_unlock(&devfreq_list_lock);
39690
39691 diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
39692 index 42d4974..2714f36 100644
39693 --- a/drivers/dma/sh/shdma-base.c
39694 +++ b/drivers/dma/sh/shdma-base.c
39695 @@ -228,8 +228,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
39696 schan->slave_id = -EINVAL;
39697 }
39698
39699 - schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
39700 - sdev->desc_size, GFP_KERNEL);
39701 + schan->desc = kcalloc(sdev->desc_size,
39702 + NR_DESCS_PER_CHANNEL, GFP_KERNEL);
39703 if (!schan->desc) {
39704 ret = -ENOMEM;
39705 goto edescalloc;
39706 diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39707 index 58eb857..d7e42c8 100644
39708 --- a/drivers/dma/sh/shdmac.c
39709 +++ b/drivers/dma/sh/shdmac.c
39710 @@ -513,7 +513,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39711 return ret;
39712 }
39713
39714 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39715 +static struct notifier_block sh_dmae_nmi_notifier = {
39716 .notifier_call = sh_dmae_nmi_handler,
39717
39718 /* Run before NMI debug handler and KGDB */
39719 diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39720 index 592af5f..bb1d583 100644
39721 --- a/drivers/edac/edac_device.c
39722 +++ b/drivers/edac/edac_device.c
39723 @@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39724 */
39725 int edac_device_alloc_index(void)
39726 {
39727 - static atomic_t device_indexes = ATOMIC_INIT(0);
39728 + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39729
39730 - return atomic_inc_return(&device_indexes) - 1;
39731 + return atomic_inc_return_unchecked(&device_indexes) - 1;
39732 }
39733 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39734
39735 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39736 index a6cd361..7bdbf53 100644
39737 --- a/drivers/edac/edac_mc_sysfs.c
39738 +++ b/drivers/edac/edac_mc_sysfs.c
39739 @@ -154,7 +154,7 @@ static const char * const edac_caps[] = {
39740 struct dev_ch_attribute {
39741 struct device_attribute attr;
39742 int channel;
39743 -};
39744 +} __do_const;
39745
39746 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39747 struct dev_ch_attribute dev_attr_legacy_##_name = \
39748 @@ -1011,14 +1011,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39749 }
39750
39751 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39752 + pax_open_kernel();
39753 if (mci->get_sdram_scrub_rate) {
39754 - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39755 - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39756 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39757 + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39758 }
39759 if (mci->set_sdram_scrub_rate) {
39760 - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39761 - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39762 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39763 + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39764 }
39765 + pax_close_kernel();
39766 err = device_create_file(&mci->dev,
39767 &dev_attr_sdram_scrub_rate);
39768 if (err) {
39769 diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39770 index 2cf44b4d..6dd2dc7 100644
39771 --- a/drivers/edac/edac_pci.c
39772 +++ b/drivers/edac/edac_pci.c
39773 @@ -29,7 +29,7 @@
39774
39775 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39776 static LIST_HEAD(edac_pci_list);
39777 -static atomic_t pci_indexes = ATOMIC_INIT(0);
39778 +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39779
39780 /*
39781 * edac_pci_alloc_ctl_info
39782 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39783 */
39784 int edac_pci_alloc_index(void)
39785 {
39786 - return atomic_inc_return(&pci_indexes) - 1;
39787 + return atomic_inc_return_unchecked(&pci_indexes) - 1;
39788 }
39789 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39790
39791 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39792 index e8658e4..22746d6 100644
39793 --- a/drivers/edac/edac_pci_sysfs.c
39794 +++ b/drivers/edac/edac_pci_sysfs.c
39795 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39796 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39797 static int edac_pci_poll_msec = 1000; /* one second workq period */
39798
39799 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
39800 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39801 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39802 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39803
39804 static struct kobject *edac_pci_top_main_kobj;
39805 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39806 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39807 void *value;
39808 ssize_t(*show) (void *, char *);
39809 ssize_t(*store) (void *, const char *, size_t);
39810 -};
39811 +} __do_const;
39812
39813 /* Set of show/store abstract level functions for PCI Parity object */
39814 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39815 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39816 edac_printk(KERN_CRIT, EDAC_PCI,
39817 "Signaled System Error on %s\n",
39818 pci_name(dev));
39819 - atomic_inc(&pci_nonparity_count);
39820 + atomic_inc_unchecked(&pci_nonparity_count);
39821 }
39822
39823 if (status & (PCI_STATUS_PARITY)) {
39824 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39825 "Master Data Parity Error on %s\n",
39826 pci_name(dev));
39827
39828 - atomic_inc(&pci_parity_count);
39829 + atomic_inc_unchecked(&pci_parity_count);
39830 }
39831
39832 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39833 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39834 "Detected Parity Error on %s\n",
39835 pci_name(dev));
39836
39837 - atomic_inc(&pci_parity_count);
39838 + atomic_inc_unchecked(&pci_parity_count);
39839 }
39840 }
39841
39842 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39843 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39844 "Signaled System Error on %s\n",
39845 pci_name(dev));
39846 - atomic_inc(&pci_nonparity_count);
39847 + atomic_inc_unchecked(&pci_nonparity_count);
39848 }
39849
39850 if (status & (PCI_STATUS_PARITY)) {
39851 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39852 "Master Data Parity Error on "
39853 "%s\n", pci_name(dev));
39854
39855 - atomic_inc(&pci_parity_count);
39856 + atomic_inc_unchecked(&pci_parity_count);
39857 }
39858
39859 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39860 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39861 "Detected Parity Error on %s\n",
39862 pci_name(dev));
39863
39864 - atomic_inc(&pci_parity_count);
39865 + atomic_inc_unchecked(&pci_parity_count);
39866 }
39867 }
39868 }
39869 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39870 if (!check_pci_errors)
39871 return;
39872
39873 - before_count = atomic_read(&pci_parity_count);
39874 + before_count = atomic_read_unchecked(&pci_parity_count);
39875
39876 /* scan all PCI devices looking for a Parity Error on devices and
39877 * bridges.
39878 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39879 /* Only if operator has selected panic on PCI Error */
39880 if (edac_pci_get_panic_on_pe()) {
39881 /* If the count is different 'after' from 'before' */
39882 - if (before_count != atomic_read(&pci_parity_count))
39883 + if (before_count != atomic_read_unchecked(&pci_parity_count))
39884 panic("EDAC: PCI Parity Error");
39885 }
39886 }
39887 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39888 index 51b7e3a..aa8a3e8 100644
39889 --- a/drivers/edac/mce_amd.h
39890 +++ b/drivers/edac/mce_amd.h
39891 @@ -77,7 +77,7 @@ struct amd_decoder_ops {
39892 bool (*mc0_mce)(u16, u8);
39893 bool (*mc1_mce)(u16, u8);
39894 bool (*mc2_mce)(u16, u8);
39895 -};
39896 +} __no_const;
39897
39898 void amd_report_gart_errors(bool);
39899 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39900 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39901 index 57ea7f4..af06b76 100644
39902 --- a/drivers/firewire/core-card.c
39903 +++ b/drivers/firewire/core-card.c
39904 @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39905 const struct fw_card_driver *driver,
39906 struct device *device)
39907 {
39908 - static atomic_t index = ATOMIC_INIT(-1);
39909 + static atomic_unchecked_t index = ATOMIC_INIT(-1);
39910
39911 - card->index = atomic_inc_return(&index);
39912 + card->index = atomic_inc_return_unchecked(&index);
39913 card->driver = driver;
39914 card->device = device;
39915 card->current_tlabel = 0;
39916 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
39917
39918 void fw_core_remove_card(struct fw_card *card)
39919 {
39920 - struct fw_card_driver dummy_driver = dummy_driver_template;
39921 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
39922
39923 card->driver->update_phy_reg(card, 4,
39924 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
39925 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
39926 index 2c6d5e1..a2cca6b 100644
39927 --- a/drivers/firewire/core-device.c
39928 +++ b/drivers/firewire/core-device.c
39929 @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
39930 struct config_rom_attribute {
39931 struct device_attribute attr;
39932 u32 key;
39933 -};
39934 +} __do_const;
39935
39936 static ssize_t show_immediate(struct device *dev,
39937 struct device_attribute *dattr, char *buf)
39938 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
39939 index eb6935c..3cc2bfa 100644
39940 --- a/drivers/firewire/core-transaction.c
39941 +++ b/drivers/firewire/core-transaction.c
39942 @@ -38,6 +38,7 @@
39943 #include <linux/timer.h>
39944 #include <linux/types.h>
39945 #include <linux/workqueue.h>
39946 +#include <linux/sched.h>
39947
39948 #include <asm/byteorder.h>
39949
39950 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
39951 index e1480ff6..1a429bd 100644
39952 --- a/drivers/firewire/core.h
39953 +++ b/drivers/firewire/core.h
39954 @@ -111,6 +111,7 @@ struct fw_card_driver {
39955
39956 int (*stop_iso)(struct fw_iso_context *ctx);
39957 };
39958 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
39959
39960 void fw_card_initialize(struct fw_card *card,
39961 const struct fw_card_driver *driver, struct device *device);
39962 diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
39963 index a66a321..f6caf20 100644
39964 --- a/drivers/firewire/ohci.c
39965 +++ b/drivers/firewire/ohci.c
39966 @@ -2056,10 +2056,12 @@ static void bus_reset_work(struct work_struct *work)
39967 be32_to_cpu(ohci->next_header));
39968 }
39969
39970 +#ifndef CONFIG_GRKERNSEC
39971 if (param_remote_dma) {
39972 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
39973 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
39974 }
39975 +#endif
39976
39977 spin_unlock_irq(&ohci->lock);
39978
39979 @@ -2591,8 +2593,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
39980 unsigned long flags;
39981 int n, ret = 0;
39982
39983 +#ifndef CONFIG_GRKERNSEC
39984 if (param_remote_dma)
39985 return 0;
39986 +#endif
39987
39988 /*
39989 * FIXME: Make sure this bitmask is cleared when we clear the busReset
39990 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
39991 index 94a58a0..f5eba42 100644
39992 --- a/drivers/firmware/dmi-id.c
39993 +++ b/drivers/firmware/dmi-id.c
39994 @@ -16,7 +16,7 @@
39995 struct dmi_device_attribute{
39996 struct device_attribute dev_attr;
39997 int field;
39998 -};
39999 +} __do_const;
40000 #define to_dmi_dev_attr(_dev_attr) \
40001 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
40002
40003 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
40004 index 17afc51..0ef90cd 100644
40005 --- a/drivers/firmware/dmi_scan.c
40006 +++ b/drivers/firmware/dmi_scan.c
40007 @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
40008 if (buf == NULL)
40009 return -1;
40010
40011 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
40012 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
40013
40014 dmi_unmap(buf);
40015 return 0;
40016 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
40017 index 5b53d61..72cee96 100644
40018 --- a/drivers/firmware/efi/cper.c
40019 +++ b/drivers/firmware/efi/cper.c
40020 @@ -44,12 +44,12 @@ static char rcd_decode_str[CPER_REC_LEN];
40021 */
40022 u64 cper_next_record_id(void)
40023 {
40024 - static atomic64_t seq;
40025 + static atomic64_unchecked_t seq;
40026
40027 - if (!atomic64_read(&seq))
40028 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
40029 + if (!atomic64_read_unchecked(&seq))
40030 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
40031
40032 - return atomic64_inc_return(&seq);
40033 + return atomic64_inc_return_unchecked(&seq);
40034 }
40035 EXPORT_SYMBOL_GPL(cper_next_record_id);
40036
40037 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
40038 index 8590099..d83627a 100644
40039 --- a/drivers/firmware/efi/efi.c
40040 +++ b/drivers/firmware/efi/efi.c
40041 @@ -148,14 +148,16 @@ static struct attribute_group efi_subsys_attr_group = {
40042 };
40043
40044 static struct efivars generic_efivars;
40045 -static struct efivar_operations generic_ops;
40046 +static efivar_operations_no_const generic_ops __read_only;
40047
40048 static int generic_ops_register(void)
40049 {
40050 - generic_ops.get_variable = efi.get_variable;
40051 - generic_ops.set_variable = efi.set_variable;
40052 - generic_ops.get_next_variable = efi.get_next_variable;
40053 - generic_ops.query_variable_store = efi_query_variable_store;
40054 + pax_open_kernel();
40055 + *(void **)&generic_ops.get_variable = efi.get_variable;
40056 + *(void **)&generic_ops.set_variable = efi.set_variable;
40057 + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
40058 + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
40059 + pax_close_kernel();
40060
40061 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
40062 }
40063 diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
40064 index f256ecd..387dcb1 100644
40065 --- a/drivers/firmware/efi/efivars.c
40066 +++ b/drivers/firmware/efi/efivars.c
40067 @@ -589,7 +589,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
40068 static int
40069 create_efivars_bin_attributes(void)
40070 {
40071 - struct bin_attribute *attr;
40072 + bin_attribute_no_const *attr;
40073 int error;
40074
40075 /* new_var */
40076 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
40077 index 2f569aa..c95f4fb 100644
40078 --- a/drivers/firmware/google/memconsole.c
40079 +++ b/drivers/firmware/google/memconsole.c
40080 @@ -155,7 +155,10 @@ static int __init memconsole_init(void)
40081 if (!found_memconsole())
40082 return -ENODEV;
40083
40084 - memconsole_bin_attr.size = memconsole_length;
40085 + pax_open_kernel();
40086 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
40087 + pax_close_kernel();
40088 +
40089 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
40090 }
40091
40092 diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
40093 index fe49ec3..1ade794 100644
40094 --- a/drivers/gpio/gpio-em.c
40095 +++ b/drivers/gpio/gpio-em.c
40096 @@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
40097 struct em_gio_priv *p;
40098 struct resource *io[2], *irq[2];
40099 struct gpio_chip *gpio_chip;
40100 - struct irq_chip *irq_chip;
40101 + irq_chip_no_const *irq_chip;
40102 const char *name = dev_name(&pdev->dev);
40103 int ret;
40104
40105 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
40106 index 3784e81..73637b5 100644
40107 --- a/drivers/gpio/gpio-ich.c
40108 +++ b/drivers/gpio/gpio-ich.c
40109 @@ -94,7 +94,7 @@ struct ichx_desc {
40110 * this option allows driver caching written output values
40111 */
40112 bool use_outlvl_cache;
40113 -};
40114 +} __do_const;
40115
40116 static struct {
40117 spinlock_t lock;
40118 diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
40119 index bf6c094..6573caf 100644
40120 --- a/drivers/gpio/gpio-rcar.c
40121 +++ b/drivers/gpio/gpio-rcar.c
40122 @@ -357,7 +357,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
40123 struct gpio_rcar_priv *p;
40124 struct resource *io, *irq;
40125 struct gpio_chip *gpio_chip;
40126 - struct irq_chip *irq_chip;
40127 + irq_chip_no_const *irq_chip;
40128 struct device *dev = &pdev->dev;
40129 const char *name = dev_name(dev);
40130 int ret;
40131 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
40132 index dbf28fa..04dad4e 100644
40133 --- a/drivers/gpio/gpio-vr41xx.c
40134 +++ b/drivers/gpio/gpio-vr41xx.c
40135 @@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
40136 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
40137 maskl, pendl, maskh, pendh);
40138
40139 - atomic_inc(&irq_err_count);
40140 + atomic_inc_unchecked(&irq_err_count);
40141
40142 return -EINVAL;
40143 }
40144 diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
40145 index e8e98ca..10f416e 100644
40146 --- a/drivers/gpio/gpiolib.c
40147 +++ b/drivers/gpio/gpiolib.c
40148 @@ -537,8 +537,10 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
40149 }
40150
40151 if (gpiochip->irqchip) {
40152 - gpiochip->irqchip->irq_request_resources = NULL;
40153 - gpiochip->irqchip->irq_release_resources = NULL;
40154 + pax_open_kernel();
40155 + *(void **)&gpiochip->irqchip->irq_request_resources = NULL;
40156 + *(void **)&gpiochip->irqchip->irq_release_resources = NULL;
40157 + pax_close_kernel();
40158 gpiochip->irqchip = NULL;
40159 }
40160 }
40161 @@ -604,8 +606,11 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
40162 gpiochip->irqchip = NULL;
40163 return -EINVAL;
40164 }
40165 - irqchip->irq_request_resources = gpiochip_irq_reqres;
40166 - irqchip->irq_release_resources = gpiochip_irq_relres;
40167 +
40168 + pax_open_kernel();
40169 + *(void **)&irqchip->irq_request_resources = gpiochip_irq_reqres;
40170 + *(void **)&irqchip->irq_release_resources = gpiochip_irq_relres;
40171 + pax_close_kernel();
40172
40173 /*
40174 * Prepare the mapping since the irqchip shall be orthogonal to
40175 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
40176 index e79c8d3..a9370bc 100644
40177 --- a/drivers/gpu/drm/drm_crtc.c
40178 +++ b/drivers/gpu/drm/drm_crtc.c
40179 @@ -3900,7 +3900,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
40180 goto done;
40181 }
40182
40183 - if (copy_to_user(&enum_ptr[copied].name,
40184 + if (copy_to_user(enum_ptr[copied].name,
40185 &prop_enum->name, DRM_PROP_NAME_LEN)) {
40186 ret = -EFAULT;
40187 goto done;
40188 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
40189 index bc3da32..7289357 100644
40190 --- a/drivers/gpu/drm/drm_drv.c
40191 +++ b/drivers/gpu/drm/drm_drv.c
40192 @@ -443,7 +443,7 @@ void drm_unplug_dev(struct drm_device *dev)
40193
40194 drm_device_set_unplugged(dev);
40195
40196 - if (dev->open_count == 0) {
40197 + if (local_read(&dev->open_count) == 0) {
40198 drm_put_dev(dev);
40199 }
40200 mutex_unlock(&drm_global_mutex);
40201 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
40202 index ed7bc68..0d536af 100644
40203 --- a/drivers/gpu/drm/drm_fops.c
40204 +++ b/drivers/gpu/drm/drm_fops.c
40205 @@ -89,7 +89,7 @@ int drm_open(struct inode *inode, struct file *filp)
40206 return PTR_ERR(minor);
40207
40208 dev = minor->dev;
40209 - if (!dev->open_count++)
40210 + if (local_inc_return(&dev->open_count) == 1)
40211 need_setup = 1;
40212
40213 /* share address_space across all char-devs of a single device */
40214 @@ -106,7 +106,7 @@ int drm_open(struct inode *inode, struct file *filp)
40215 return 0;
40216
40217 err_undo:
40218 - dev->open_count--;
40219 + local_dec(&dev->open_count);
40220 drm_minor_release(minor);
40221 return retcode;
40222 }
40223 @@ -376,7 +376,7 @@ int drm_release(struct inode *inode, struct file *filp)
40224
40225 mutex_lock(&drm_global_mutex);
40226
40227 - DRM_DEBUG("open_count = %d\n", dev->open_count);
40228 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
40229
40230 mutex_lock(&dev->struct_mutex);
40231 list_del(&file_priv->lhead);
40232 @@ -389,10 +389,10 @@ int drm_release(struct inode *inode, struct file *filp)
40233 * Begin inline drm_release
40234 */
40235
40236 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
40237 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
40238 task_pid_nr(current),
40239 (long)old_encode_dev(file_priv->minor->kdev->devt),
40240 - dev->open_count);
40241 + local_read(&dev->open_count));
40242
40243 /* Release any auth tokens that might point to this file_priv,
40244 (do that under the drm_global_mutex) */
40245 @@ -465,7 +465,7 @@ int drm_release(struct inode *inode, struct file *filp)
40246 * End inline drm_release
40247 */
40248
40249 - if (!--dev->open_count) {
40250 + if (local_dec_and_test(&dev->open_count)) {
40251 retcode = drm_lastclose(dev);
40252 if (drm_device_is_unplugged(dev))
40253 drm_put_dev(dev);
40254 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
40255 index 3d2e91c..d31c4c9 100644
40256 --- a/drivers/gpu/drm/drm_global.c
40257 +++ b/drivers/gpu/drm/drm_global.c
40258 @@ -36,7 +36,7 @@
40259 struct drm_global_item {
40260 struct mutex mutex;
40261 void *object;
40262 - int refcount;
40263 + atomic_t refcount;
40264 };
40265
40266 static struct drm_global_item glob[DRM_GLOBAL_NUM];
40267 @@ -49,7 +49,7 @@ void drm_global_init(void)
40268 struct drm_global_item *item = &glob[i];
40269 mutex_init(&item->mutex);
40270 item->object = NULL;
40271 - item->refcount = 0;
40272 + atomic_set(&item->refcount, 0);
40273 }
40274 }
40275
40276 @@ -59,7 +59,7 @@ void drm_global_release(void)
40277 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
40278 struct drm_global_item *item = &glob[i];
40279 BUG_ON(item->object != NULL);
40280 - BUG_ON(item->refcount != 0);
40281 + BUG_ON(atomic_read(&item->refcount) != 0);
40282 }
40283 }
40284
40285 @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40286 struct drm_global_item *item = &glob[ref->global_type];
40287
40288 mutex_lock(&item->mutex);
40289 - if (item->refcount == 0) {
40290 + if (atomic_read(&item->refcount) == 0) {
40291 item->object = kzalloc(ref->size, GFP_KERNEL);
40292 if (unlikely(item->object == NULL)) {
40293 ret = -ENOMEM;
40294 @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40295 goto out_err;
40296
40297 }
40298 - ++item->refcount;
40299 + atomic_inc(&item->refcount);
40300 ref->object = item->object;
40301 mutex_unlock(&item->mutex);
40302 return 0;
40303 @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
40304 struct drm_global_item *item = &glob[ref->global_type];
40305
40306 mutex_lock(&item->mutex);
40307 - BUG_ON(item->refcount == 0);
40308 + BUG_ON(atomic_read(&item->refcount) == 0);
40309 BUG_ON(ref->object != item->object);
40310 - if (--item->refcount == 0) {
40311 + if (atomic_dec_and_test(&item->refcount)) {
40312 ref->release(ref);
40313 item->object = NULL;
40314 }
40315 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
40316 index 51efebd..2b70935 100644
40317 --- a/drivers/gpu/drm/drm_info.c
40318 +++ b/drivers/gpu/drm/drm_info.c
40319 @@ -76,10 +76,13 @@ int drm_vm_info(struct seq_file *m, void *data)
40320 struct drm_local_map *map;
40321 struct drm_map_list *r_list;
40322
40323 - /* Hardcoded from _DRM_FRAME_BUFFER,
40324 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
40325 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
40326 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
40327 + static const char * const types[] = {
40328 + [_DRM_FRAME_BUFFER] = "FB",
40329 + [_DRM_REGISTERS] = "REG",
40330 + [_DRM_SHM] = "SHM",
40331 + [_DRM_AGP] = "AGP",
40332 + [_DRM_SCATTER_GATHER] = "SG",
40333 + [_DRM_CONSISTENT] = "PCI"};
40334 const char *type;
40335 int i;
40336
40337 @@ -90,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
40338 map = r_list->map;
40339 if (!map)
40340 continue;
40341 - if (map->type < 0 || map->type > 5)
40342 + if (map->type >= ARRAY_SIZE(types))
40343 type = "??";
40344 else
40345 type = types[map->type];
40346 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
40347 index 2f4c4343..dd12cd2 100644
40348 --- a/drivers/gpu/drm/drm_ioc32.c
40349 +++ b/drivers/gpu/drm/drm_ioc32.c
40350 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
40351 request = compat_alloc_user_space(nbytes);
40352 if (!access_ok(VERIFY_WRITE, request, nbytes))
40353 return -EFAULT;
40354 - list = (struct drm_buf_desc *) (request + 1);
40355 + list = (struct drm_buf_desc __user *) (request + 1);
40356
40357 if (__put_user(count, &request->count)
40358 || __put_user(list, &request->list))
40359 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
40360 request = compat_alloc_user_space(nbytes);
40361 if (!access_ok(VERIFY_WRITE, request, nbytes))
40362 return -EFAULT;
40363 - list = (struct drm_buf_pub *) (request + 1);
40364 + list = (struct drm_buf_pub __user *) (request + 1);
40365
40366 if (__put_user(count, &request->count)
40367 || __put_user(list, &request->list))
40368 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
40369 return 0;
40370 }
40371
40372 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
40373 +drm_ioctl_compat_t drm_compat_ioctls[] = {
40374 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
40375 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
40376 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
40377 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
40378 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40379 {
40380 unsigned int nr = DRM_IOCTL_NR(cmd);
40381 - drm_ioctl_compat_t *fn;
40382 int ret;
40383
40384 /* Assume that ioctls without an explicit compat routine will just
40385 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40386 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
40387 return drm_ioctl(filp, cmd, arg);
40388
40389 - fn = drm_compat_ioctls[nr];
40390 -
40391 - if (fn != NULL)
40392 - ret = (*fn) (filp, cmd, arg);
40393 + if (drm_compat_ioctls[nr] != NULL)
40394 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
40395 else
40396 ret = drm_ioctl(filp, cmd, arg);
40397
40398 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
40399 index 00587a1..57a65ca 100644
40400 --- a/drivers/gpu/drm/drm_ioctl.c
40401 +++ b/drivers/gpu/drm/drm_ioctl.c
40402 @@ -642,7 +642,7 @@ long drm_ioctl(struct file *filp,
40403 struct drm_file *file_priv = filp->private_data;
40404 struct drm_device *dev;
40405 const struct drm_ioctl_desc *ioctl = NULL;
40406 - drm_ioctl_t *func;
40407 + drm_ioctl_no_const_t func;
40408 unsigned int nr = DRM_IOCTL_NR(cmd);
40409 int retcode = -EINVAL;
40410 char stack_kdata[128];
40411 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40412 index 93ec5dc..82acbaf 100644
40413 --- a/drivers/gpu/drm/i810/i810_drv.h
40414 +++ b/drivers/gpu/drm/i810/i810_drv.h
40415 @@ -110,8 +110,8 @@ typedef struct drm_i810_private {
40416 int page_flipping;
40417
40418 wait_queue_head_t irq_queue;
40419 - atomic_t irq_received;
40420 - atomic_t irq_emitted;
40421 + atomic_unchecked_t irq_received;
40422 + atomic_unchecked_t irq_emitted;
40423
40424 int front_offset;
40425 } drm_i810_private_t;
40426 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40427 index 318ade9..1f5de55 100644
40428 --- a/drivers/gpu/drm/i915/i915_dma.c
40429 +++ b/drivers/gpu/drm/i915/i915_dma.c
40430 @@ -1294,7 +1294,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40431 * locking inversion with the driver load path. And the access here is
40432 * completely racy anyway. So don't bother with locking for now.
40433 */
40434 - return dev->open_count == 0;
40435 + return local_read(&dev->open_count) == 0;
40436 }
40437
40438 static const struct vga_switcheroo_client_ops i915_switcheroo_ops = {
40439 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40440 index 1a0611b..dd1fbfc 100644
40441 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40442 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40443 @@ -866,12 +866,12 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40444 static int
40445 validate_exec_list(struct drm_device *dev,
40446 struct drm_i915_gem_exec_object2 *exec,
40447 - int count)
40448 + unsigned int count)
40449 {
40450 unsigned relocs_total = 0;
40451 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40452 unsigned invalid_flags;
40453 - int i;
40454 + unsigned int i;
40455
40456 invalid_flags = __EXEC_OBJECT_UNKNOWN_FLAGS;
40457 if (USES_FULL_PPGTT(dev))
40458 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40459 index 2e0613e..a8b94d9 100644
40460 --- a/drivers/gpu/drm/i915/i915_ioc32.c
40461 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
40462 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40463 (unsigned long)request);
40464 }
40465
40466 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40467 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
40468 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40469 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40470 [DRM_I915_GETPARAM] = compat_i915_getparam,
40471 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40472 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40473 {
40474 unsigned int nr = DRM_IOCTL_NR(cmd);
40475 - drm_ioctl_compat_t *fn = NULL;
40476 int ret;
40477
40478 if (nr < DRM_COMMAND_BASE)
40479 return drm_compat_ioctl(filp, cmd, arg);
40480
40481 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls))
40482 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40483 -
40484 - if (fn != NULL)
40485 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls)) {
40486 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40487 ret = (*fn) (filp, cmd, arg);
40488 - else
40489 + } else
40490 ret = drm_ioctl(filp, cmd, arg);
40491
40492 return ret;
40493 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40494 index 9cb5c95..9228666 100644
40495 --- a/drivers/gpu/drm/i915/intel_display.c
40496 +++ b/drivers/gpu/drm/i915/intel_display.c
40497 @@ -12811,13 +12811,13 @@ struct intel_quirk {
40498 int subsystem_vendor;
40499 int subsystem_device;
40500 void (*hook)(struct drm_device *dev);
40501 -};
40502 +} __do_const;
40503
40504 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40505 struct intel_dmi_quirk {
40506 void (*hook)(struct drm_device *dev);
40507 const struct dmi_system_id (*dmi_id_list)[];
40508 -};
40509 +} __do_const;
40510
40511 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40512 {
40513 @@ -12825,18 +12825,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40514 return 1;
40515 }
40516
40517 -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40518 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
40519 {
40520 - .dmi_id_list = &(const struct dmi_system_id[]) {
40521 - {
40522 - .callback = intel_dmi_reverse_brightness,
40523 - .ident = "NCR Corporation",
40524 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40525 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
40526 - },
40527 - },
40528 - { } /* terminating entry */
40529 + .callback = intel_dmi_reverse_brightness,
40530 + .ident = "NCR Corporation",
40531 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40532 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
40533 },
40534 + },
40535 + { } /* terminating entry */
40536 +};
40537 +
40538 +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40539 + {
40540 + .dmi_id_list = &intel_dmi_quirks_table,
40541 .hook = quirk_invert_brightness,
40542 },
40543 };
40544 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40545 index b4a2014..219ab78 100644
40546 --- a/drivers/gpu/drm/mga/mga_drv.h
40547 +++ b/drivers/gpu/drm/mga/mga_drv.h
40548 @@ -122,9 +122,9 @@ typedef struct drm_mga_private {
40549 u32 clear_cmd;
40550 u32 maccess;
40551
40552 - atomic_t vbl_received; /**< Number of vblanks received. */
40553 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40554 wait_queue_head_t fence_queue;
40555 - atomic_t last_fence_retired;
40556 + atomic_unchecked_t last_fence_retired;
40557 u32 next_fence_to_post;
40558
40559 unsigned int fb_cpp;
40560 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40561 index 729bfd5..ead8823 100644
40562 --- a/drivers/gpu/drm/mga/mga_ioc32.c
40563 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
40564 @@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40565 return 0;
40566 }
40567
40568 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
40569 +drm_ioctl_compat_t mga_compat_ioctls[] = {
40570 [DRM_MGA_INIT] = compat_mga_init,
40571 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40572 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40573 @@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40574 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40575 {
40576 unsigned int nr = DRM_IOCTL_NR(cmd);
40577 - drm_ioctl_compat_t *fn = NULL;
40578 int ret;
40579
40580 if (nr < DRM_COMMAND_BASE)
40581 return drm_compat_ioctl(filp, cmd, arg);
40582
40583 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls))
40584 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40585 -
40586 - if (fn != NULL)
40587 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls)) {
40588 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40589 ret = (*fn) (filp, cmd, arg);
40590 - else
40591 + } else
40592 ret = drm_ioctl(filp, cmd, arg);
40593
40594 return ret;
40595 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40596 index 1b071b8..de8601a 100644
40597 --- a/drivers/gpu/drm/mga/mga_irq.c
40598 +++ b/drivers/gpu/drm/mga/mga_irq.c
40599 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40600 if (crtc != 0)
40601 return 0;
40602
40603 - return atomic_read(&dev_priv->vbl_received);
40604 + return atomic_read_unchecked(&dev_priv->vbl_received);
40605 }
40606
40607
40608 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40609 /* VBLANK interrupt */
40610 if (status & MGA_VLINEPEN) {
40611 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40612 - atomic_inc(&dev_priv->vbl_received);
40613 + atomic_inc_unchecked(&dev_priv->vbl_received);
40614 drm_handle_vblank(dev, 0);
40615 handled = 1;
40616 }
40617 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40618 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40619 MGA_WRITE(MGA_PRIMEND, prim_end);
40620
40621 - atomic_inc(&dev_priv->last_fence_retired);
40622 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
40623 wake_up(&dev_priv->fence_queue);
40624 handled = 1;
40625 }
40626 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40627 * using fences.
40628 */
40629 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40630 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40631 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40632 - *sequence) <= (1 << 23)));
40633
40634 *sequence = cur_fence;
40635 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40636 index dae2c96..324dbe4 100644
40637 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40638 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40639 @@ -963,7 +963,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40640 struct bit_table {
40641 const char id;
40642 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40643 -};
40644 +} __no_const;
40645
40646 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40647
40648 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40649 index 8ae36f2..1147a30 100644
40650 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40651 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40652 @@ -121,7 +121,6 @@ struct nouveau_drm {
40653 struct drm_global_reference mem_global_ref;
40654 struct ttm_bo_global_ref bo_global_ref;
40655 struct ttm_bo_device bdev;
40656 - atomic_t validate_sequence;
40657 int (*move)(struct nouveau_channel *,
40658 struct ttm_buffer_object *,
40659 struct ttm_mem_reg *, struct ttm_mem_reg *);
40660 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40661 index 462679a..88e32a7 100644
40662 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40663 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40664 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40665 unsigned long arg)
40666 {
40667 unsigned int nr = DRM_IOCTL_NR(cmd);
40668 - drm_ioctl_compat_t *fn = NULL;
40669 + drm_ioctl_compat_t fn = NULL;
40670 int ret;
40671
40672 if (nr < DRM_COMMAND_BASE)
40673 diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40674 index 753a6de..dd66b98 100644
40675 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40676 +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40677 @@ -126,11 +126,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40678 }
40679
40680 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40681 - nouveau_vram_manager_init,
40682 - nouveau_vram_manager_fini,
40683 - nouveau_vram_manager_new,
40684 - nouveau_vram_manager_del,
40685 - nouveau_vram_manager_debug
40686 + .init = nouveau_vram_manager_init,
40687 + .takedown = nouveau_vram_manager_fini,
40688 + .get_node = nouveau_vram_manager_new,
40689 + .put_node = nouveau_vram_manager_del,
40690 + .debug = nouveau_vram_manager_debug
40691 };
40692
40693 static int
40694 @@ -194,11 +194,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40695 }
40696
40697 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40698 - nouveau_gart_manager_init,
40699 - nouveau_gart_manager_fini,
40700 - nouveau_gart_manager_new,
40701 - nouveau_gart_manager_del,
40702 - nouveau_gart_manager_debug
40703 + .init = nouveau_gart_manager_init,
40704 + .takedown = nouveau_gart_manager_fini,
40705 + .get_node = nouveau_gart_manager_new,
40706 + .put_node = nouveau_gart_manager_del,
40707 + .debug = nouveau_gart_manager_debug
40708 };
40709
40710 /*XXX*/
40711 @@ -267,11 +267,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40712 }
40713
40714 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40715 - nv04_gart_manager_init,
40716 - nv04_gart_manager_fini,
40717 - nv04_gart_manager_new,
40718 - nv04_gart_manager_del,
40719 - nv04_gart_manager_debug
40720 + .init = nv04_gart_manager_init,
40721 + .takedown = nv04_gart_manager_fini,
40722 + .get_node = nv04_gart_manager_new,
40723 + .put_node = nv04_gart_manager_del,
40724 + .debug = nv04_gart_manager_debug
40725 };
40726
40727 int
40728 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40729 index c7592ec..dd45ebc 100644
40730 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40731 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40732 @@ -72,7 +72,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40733 * locking inversion with the driver load path. And the access here is
40734 * completely racy anyway. So don't bother with locking for now.
40735 */
40736 - return dev->open_count == 0;
40737 + return local_read(&dev->open_count) == 0;
40738 }
40739
40740 static const struct vga_switcheroo_client_ops
40741 diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40742 index 9782364..89bd954 100644
40743 --- a/drivers/gpu/drm/qxl/qxl_cmd.c
40744 +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40745 @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40746 int ret;
40747
40748 mutex_lock(&qdev->async_io_mutex);
40749 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40750 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40751 if (qdev->last_sent_io_cmd > irq_num) {
40752 if (intr)
40753 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40754 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40755 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40756 else
40757 ret = wait_event_timeout(qdev->io_cmd_event,
40758 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40759 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40760 /* 0 is timeout, just bail the "hw" has gone away */
40761 if (ret <= 0)
40762 goto out;
40763 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40764 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40765 }
40766 outb(val, addr);
40767 qdev->last_sent_io_cmd = irq_num + 1;
40768 if (intr)
40769 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40770 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40771 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40772 else
40773 ret = wait_event_timeout(qdev->io_cmd_event,
40774 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40775 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40776 out:
40777 if (ret > 0)
40778 ret = 0;
40779 diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40780 index 6911b8c..89d6867 100644
40781 --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40782 +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40783 @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40784 struct drm_info_node *node = (struct drm_info_node *) m->private;
40785 struct qxl_device *qdev = node->minor->dev->dev_private;
40786
40787 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40788 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40789 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40790 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40791 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40792 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40793 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40794 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40795 seq_printf(m, "%d\n", qdev->irq_received_error);
40796 return 0;
40797 }
40798 diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40799 index 7c6cafe..460f542 100644
40800 --- a/drivers/gpu/drm/qxl/qxl_drv.h
40801 +++ b/drivers/gpu/drm/qxl/qxl_drv.h
40802 @@ -290,10 +290,10 @@ struct qxl_device {
40803 unsigned int last_sent_io_cmd;
40804
40805 /* interrupt handling */
40806 - atomic_t irq_received;
40807 - atomic_t irq_received_display;
40808 - atomic_t irq_received_cursor;
40809 - atomic_t irq_received_io_cmd;
40810 + atomic_unchecked_t irq_received;
40811 + atomic_unchecked_t irq_received_display;
40812 + atomic_unchecked_t irq_received_cursor;
40813 + atomic_unchecked_t irq_received_io_cmd;
40814 unsigned irq_received_error;
40815 wait_queue_head_t display_event;
40816 wait_queue_head_t cursor_event;
40817 diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40818 index b110883..dd06418 100644
40819 --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40820 +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40821 @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40822
40823 /* TODO copy slow path code from i915 */
40824 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40825 - 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);
40826 + 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);
40827
40828 {
40829 struct qxl_drawable *draw = fb_cmd;
40830 @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40831 struct drm_qxl_reloc reloc;
40832
40833 if (copy_from_user(&reloc,
40834 - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40835 + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40836 sizeof(reloc))) {
40837 ret = -EFAULT;
40838 goto out_free_bos;
40839 @@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40840
40841 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
40842
40843 - struct drm_qxl_command *commands =
40844 - (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40845 + struct drm_qxl_command __user *commands =
40846 + (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
40847
40848 - if (copy_from_user(&user_cmd, &commands[cmd_num],
40849 + if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40850 sizeof(user_cmd)))
40851 return -EFAULT;
40852
40853 diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40854 index 0bf1e20..42a7310 100644
40855 --- a/drivers/gpu/drm/qxl/qxl_irq.c
40856 +++ b/drivers/gpu/drm/qxl/qxl_irq.c
40857 @@ -36,19 +36,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
40858 if (!pending)
40859 return IRQ_NONE;
40860
40861 - atomic_inc(&qdev->irq_received);
40862 + atomic_inc_unchecked(&qdev->irq_received);
40863
40864 if (pending & QXL_INTERRUPT_DISPLAY) {
40865 - atomic_inc(&qdev->irq_received_display);
40866 + atomic_inc_unchecked(&qdev->irq_received_display);
40867 wake_up_all(&qdev->display_event);
40868 qxl_queue_garbage_collect(qdev, false);
40869 }
40870 if (pending & QXL_INTERRUPT_CURSOR) {
40871 - atomic_inc(&qdev->irq_received_cursor);
40872 + atomic_inc_unchecked(&qdev->irq_received_cursor);
40873 wake_up_all(&qdev->cursor_event);
40874 }
40875 if (pending & QXL_INTERRUPT_IO_CMD) {
40876 - atomic_inc(&qdev->irq_received_io_cmd);
40877 + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40878 wake_up_all(&qdev->io_cmd_event);
40879 }
40880 if (pending & QXL_INTERRUPT_ERROR) {
40881 @@ -85,10 +85,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40882 init_waitqueue_head(&qdev->io_cmd_event);
40883 INIT_WORK(&qdev->client_monitors_config_work,
40884 qxl_client_monitors_config_work_func);
40885 - atomic_set(&qdev->irq_received, 0);
40886 - atomic_set(&qdev->irq_received_display, 0);
40887 - atomic_set(&qdev->irq_received_cursor, 0);
40888 - atomic_set(&qdev->irq_received_io_cmd, 0);
40889 + atomic_set_unchecked(&qdev->irq_received, 0);
40890 + atomic_set_unchecked(&qdev->irq_received_display, 0);
40891 + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40892 + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40893 qdev->irq_received_error = 0;
40894 ret = drm_irq_install(qdev->ddev, qdev->ddev->pdev->irq);
40895 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40896 diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40897 index 0cbc4c9..0e46686 100644
40898 --- a/drivers/gpu/drm/qxl/qxl_ttm.c
40899 +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40900 @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40901 }
40902 }
40903
40904 -static struct vm_operations_struct qxl_ttm_vm_ops;
40905 +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40906 static const struct vm_operations_struct *ttm_vm_ops;
40907
40908 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40909 @@ -145,8 +145,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40910 return r;
40911 if (unlikely(ttm_vm_ops == NULL)) {
40912 ttm_vm_ops = vma->vm_ops;
40913 + pax_open_kernel();
40914 qxl_ttm_vm_ops = *ttm_vm_ops;
40915 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
40916 + pax_close_kernel();
40917 }
40918 vma->vm_ops = &qxl_ttm_vm_ops;
40919 return 0;
40920 @@ -464,25 +466,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
40921 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
40922 {
40923 #if defined(CONFIG_DEBUG_FS)
40924 - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
40925 - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
40926 - unsigned i;
40927 + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
40928 + {
40929 + .name = "qxl_mem_mm",
40930 + .show = &qxl_mm_dump_table,
40931 + },
40932 + {
40933 + .name = "qxl_surf_mm",
40934 + .show = &qxl_mm_dump_table,
40935 + }
40936 + };
40937
40938 - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
40939 - if (i == 0)
40940 - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
40941 - else
40942 - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
40943 - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
40944 - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
40945 - qxl_mem_types_list[i].driver_features = 0;
40946 - if (i == 0)
40947 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40948 - else
40949 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40950 + pax_open_kernel();
40951 + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40952 + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40953 + pax_close_kernel();
40954
40955 - }
40956 - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
40957 + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
40958 #else
40959 return 0;
40960 #endif
40961 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
40962 index 2c45ac9..5d740f8 100644
40963 --- a/drivers/gpu/drm/r128/r128_cce.c
40964 +++ b/drivers/gpu/drm/r128/r128_cce.c
40965 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
40966
40967 /* GH: Simple idle check.
40968 */
40969 - atomic_set(&dev_priv->idle_count, 0);
40970 + atomic_set_unchecked(&dev_priv->idle_count, 0);
40971
40972 /* We don't support anything other than bus-mastering ring mode,
40973 * but the ring can be in either AGP or PCI space for the ring
40974 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
40975 index 723e5d6..102dbaf 100644
40976 --- a/drivers/gpu/drm/r128/r128_drv.h
40977 +++ b/drivers/gpu/drm/r128/r128_drv.h
40978 @@ -93,14 +93,14 @@ typedef struct drm_r128_private {
40979 int is_pci;
40980 unsigned long cce_buffers_offset;
40981
40982 - atomic_t idle_count;
40983 + atomic_unchecked_t idle_count;
40984
40985 int page_flipping;
40986 int current_page;
40987 u32 crtc_offset;
40988 u32 crtc_offset_cntl;
40989
40990 - atomic_t vbl_received;
40991 + atomic_unchecked_t vbl_received;
40992
40993 u32 color_fmt;
40994 unsigned int front_offset;
40995 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
40996 index 663f38c..c689495 100644
40997 --- a/drivers/gpu/drm/r128/r128_ioc32.c
40998 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
40999 @@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
41000 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
41001 }
41002
41003 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
41004 +drm_ioctl_compat_t r128_compat_ioctls[] = {
41005 [DRM_R128_INIT] = compat_r128_init,
41006 [DRM_R128_DEPTH] = compat_r128_depth,
41007 [DRM_R128_STIPPLE] = compat_r128_stipple,
41008 @@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
41009 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41010 {
41011 unsigned int nr = DRM_IOCTL_NR(cmd);
41012 - drm_ioctl_compat_t *fn = NULL;
41013 int ret;
41014
41015 if (nr < DRM_COMMAND_BASE)
41016 return drm_compat_ioctl(filp, cmd, arg);
41017
41018 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls))
41019 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41020 -
41021 - if (fn != NULL)
41022 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls)) {
41023 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41024 ret = (*fn) (filp, cmd, arg);
41025 - else
41026 + } else
41027 ret = drm_ioctl(filp, cmd, arg);
41028
41029 return ret;
41030 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
41031 index c2ae496..30b5993 100644
41032 --- a/drivers/gpu/drm/r128/r128_irq.c
41033 +++ b/drivers/gpu/drm/r128/r128_irq.c
41034 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
41035 if (crtc != 0)
41036 return 0;
41037
41038 - return atomic_read(&dev_priv->vbl_received);
41039 + return atomic_read_unchecked(&dev_priv->vbl_received);
41040 }
41041
41042 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41043 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41044 /* VBLANK interrupt */
41045 if (status & R128_CRTC_VBLANK_INT) {
41046 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
41047 - atomic_inc(&dev_priv->vbl_received);
41048 + atomic_inc_unchecked(&dev_priv->vbl_received);
41049 drm_handle_vblank(dev, 0);
41050 return IRQ_HANDLED;
41051 }
41052 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
41053 index 575e986..66e62ca 100644
41054 --- a/drivers/gpu/drm/r128/r128_state.c
41055 +++ b/drivers/gpu/drm/r128/r128_state.c
41056 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
41057
41058 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
41059 {
41060 - if (atomic_read(&dev_priv->idle_count) == 0)
41061 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
41062 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
41063 else
41064 - atomic_set(&dev_priv->idle_count, 0);
41065 + atomic_set_unchecked(&dev_priv->idle_count, 0);
41066 }
41067
41068 #endif
41069 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
41070 index 4a85bb6..aaea819 100644
41071 --- a/drivers/gpu/drm/radeon/mkregtable.c
41072 +++ b/drivers/gpu/drm/radeon/mkregtable.c
41073 @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
41074 regex_t mask_rex;
41075 regmatch_t match[4];
41076 char buf[1024];
41077 - size_t end;
41078 + long end;
41079 int len;
41080 int done = 0;
41081 int r;
41082 unsigned o;
41083 struct offset *offset;
41084 char last_reg_s[10];
41085 - int last_reg;
41086 + unsigned long last_reg;
41087
41088 if (regcomp
41089 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
41090 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
41091 index 995a8b1..b7cb898 100644
41092 --- a/drivers/gpu/drm/radeon/radeon_device.c
41093 +++ b/drivers/gpu/drm/radeon/radeon_device.c
41094 @@ -1214,7 +1214,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
41095 * locking inversion with the driver load path. And the access here is
41096 * completely racy anyway. So don't bother with locking for now.
41097 */
41098 - return dev->open_count == 0;
41099 + return local_read(&dev->open_count) == 0;
41100 }
41101
41102 static const struct vga_switcheroo_client_ops radeon_switcheroo_ops = {
41103 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
41104 index 46bd393..6ae4719 100644
41105 --- a/drivers/gpu/drm/radeon/radeon_drv.h
41106 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
41107 @@ -264,7 +264,7 @@ typedef struct drm_radeon_private {
41108
41109 /* SW interrupt */
41110 wait_queue_head_t swi_queue;
41111 - atomic_t swi_emitted;
41112 + atomic_unchecked_t swi_emitted;
41113 int vblank_crtc;
41114 uint32_t irq_enable_reg;
41115 uint32_t r500_disp_irq_reg;
41116 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
41117 index 0b98ea1..0881827 100644
41118 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
41119 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
41120 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41121 request = compat_alloc_user_space(sizeof(*request));
41122 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
41123 || __put_user(req32.param, &request->param)
41124 - || __put_user((void __user *)(unsigned long)req32.value,
41125 + || __put_user((unsigned long)req32.value,
41126 &request->value))
41127 return -EFAULT;
41128
41129 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41130 #define compat_radeon_cp_setparam NULL
41131 #endif /* X86_64 || IA64 */
41132
41133 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41134 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
41135 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
41136 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
41137 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
41138 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41139 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41140 {
41141 unsigned int nr = DRM_IOCTL_NR(cmd);
41142 - drm_ioctl_compat_t *fn = NULL;
41143 int ret;
41144
41145 if (nr < DRM_COMMAND_BASE)
41146 return drm_compat_ioctl(filp, cmd, arg);
41147
41148 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls))
41149 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41150 -
41151 - if (fn != NULL)
41152 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls)) {
41153 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41154 ret = (*fn) (filp, cmd, arg);
41155 - else
41156 + } else
41157 ret = drm_ioctl(filp, cmd, arg);
41158
41159 return ret;
41160 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
41161 index 244b19b..c19226d 100644
41162 --- a/drivers/gpu/drm/radeon/radeon_irq.c
41163 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
41164 @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
41165 unsigned int ret;
41166 RING_LOCALS;
41167
41168 - atomic_inc(&dev_priv->swi_emitted);
41169 - ret = atomic_read(&dev_priv->swi_emitted);
41170 + atomic_inc_unchecked(&dev_priv->swi_emitted);
41171 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
41172
41173 BEGIN_RING(4);
41174 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
41175 @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
41176 drm_radeon_private_t *dev_priv =
41177 (drm_radeon_private_t *) dev->dev_private;
41178
41179 - atomic_set(&dev_priv->swi_emitted, 0);
41180 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
41181 init_waitqueue_head(&dev_priv->swi_queue);
41182
41183 dev->max_vblank_count = 0x001fffff;
41184 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
41185 index 535403e..5dd655b 100644
41186 --- a/drivers/gpu/drm/radeon/radeon_state.c
41187 +++ b/drivers/gpu/drm/radeon/radeon_state.c
41188 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
41189 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
41190 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
41191
41192 - if (copy_from_user(&depth_boxes, clear->depth_boxes,
41193 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
41194 sarea_priv->nbox * sizeof(depth_boxes[0])))
41195 return -EFAULT;
41196
41197 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
41198 {
41199 drm_radeon_private_t *dev_priv = dev->dev_private;
41200 drm_radeon_getparam_t *param = data;
41201 - int value;
41202 + int value = 0;
41203
41204 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
41205
41206 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
41207 index 8624979..65e5243 100644
41208 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
41209 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
41210 @@ -936,7 +936,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
41211 man->size = size >> PAGE_SHIFT;
41212 }
41213
41214 -static struct vm_operations_struct radeon_ttm_vm_ops;
41215 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
41216 static const struct vm_operations_struct *ttm_vm_ops = NULL;
41217
41218 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41219 @@ -977,8 +977,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
41220 }
41221 if (unlikely(ttm_vm_ops == NULL)) {
41222 ttm_vm_ops = vma->vm_ops;
41223 + pax_open_kernel();
41224 radeon_ttm_vm_ops = *ttm_vm_ops;
41225 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
41226 + pax_close_kernel();
41227 }
41228 vma->vm_ops = &radeon_ttm_vm_ops;
41229 return 0;
41230 diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41231 index 054a79f..30d9ac4 100644
41232 --- a/drivers/gpu/drm/tegra/dc.c
41233 +++ b/drivers/gpu/drm/tegra/dc.c
41234 @@ -1242,7 +1242,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41235 }
41236
41237 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41238 - dc->debugfs_files[i].data = dc;
41239 + *(void **)&dc->debugfs_files[i].data = dc;
41240
41241 err = drm_debugfs_create_files(dc->debugfs_files,
41242 ARRAY_SIZE(debugfs_files),
41243 diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
41244 index f787445..2df2c65 100644
41245 --- a/drivers/gpu/drm/tegra/dsi.c
41246 +++ b/drivers/gpu/drm/tegra/dsi.c
41247 @@ -41,7 +41,7 @@ struct tegra_dsi {
41248 struct clk *clk_lp;
41249 struct clk *clk;
41250
41251 - struct drm_info_list *debugfs_files;
41252 + drm_info_list_no_const *debugfs_files;
41253 struct drm_minor *minor;
41254 struct dentry *debugfs;
41255
41256 diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41257 index ffe2654..03c7b1c 100644
41258 --- a/drivers/gpu/drm/tegra/hdmi.c
41259 +++ b/drivers/gpu/drm/tegra/hdmi.c
41260 @@ -60,7 +60,7 @@ struct tegra_hdmi {
41261 bool stereo;
41262 bool dvi;
41263
41264 - struct drm_info_list *debugfs_files;
41265 + drm_info_list_no_const *debugfs_files;
41266 struct drm_minor *minor;
41267 struct dentry *debugfs;
41268 };
41269 diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41270 index 964387f..4eafc00 100644
41271 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41272 +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41273 @@ -146,10 +146,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41274 }
41275
41276 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41277 - ttm_bo_man_init,
41278 - ttm_bo_man_takedown,
41279 - ttm_bo_man_get_node,
41280 - ttm_bo_man_put_node,
41281 - ttm_bo_man_debug
41282 + .init = ttm_bo_man_init,
41283 + .takedown = ttm_bo_man_takedown,
41284 + .get_node = ttm_bo_man_get_node,
41285 + .put_node = ttm_bo_man_put_node,
41286 + .debug = ttm_bo_man_debug
41287 };
41288 EXPORT_SYMBOL(ttm_bo_manager_func);
41289 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41290 index a1803fb..c53f6b0 100644
41291 --- a/drivers/gpu/drm/ttm/ttm_memory.c
41292 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
41293 @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41294 zone->glob = glob;
41295 glob->zone_kernel = zone;
41296 ret = kobject_init_and_add(
41297 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41298 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41299 if (unlikely(ret != 0)) {
41300 kobject_put(&zone->kobj);
41301 return ret;
41302 @@ -348,7 +348,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41303 zone->glob = glob;
41304 glob->zone_dma32 = zone;
41305 ret = kobject_init_and_add(
41306 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41307 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41308 if (unlikely(ret != 0)) {
41309 kobject_put(&zone->kobj);
41310 return ret;
41311 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41312 index 09874d6..d6da1de 100644
41313 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41314 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41315 @@ -54,7 +54,7 @@
41316
41317 #define NUM_PAGES_TO_ALLOC (PAGE_SIZE/sizeof(struct page *))
41318 #define SMALL_ALLOCATION 16
41319 -#define FREE_ALL_PAGES (~0U)
41320 +#define FREE_ALL_PAGES (~0UL)
41321 /* times are in msecs */
41322 #define PAGE_FREE_INTERVAL 1000
41323
41324 @@ -299,14 +299,13 @@ static void ttm_pool_update_free_locked(struct ttm_page_pool *pool,
41325 * @free_all: If set to true will free all pages in pool
41326 * @gfp: GFP flags.
41327 **/
41328 -static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free,
41329 +static unsigned long ttm_page_pool_free(struct ttm_page_pool *pool, unsigned long nr_free,
41330 gfp_t gfp)
41331 {
41332 unsigned long irq_flags;
41333 struct page *p;
41334 struct page **pages_to_free;
41335 - unsigned freed_pages = 0,
41336 - npages_to_free = nr_free;
41337 + unsigned long freed_pages = 0, npages_to_free = nr_free;
41338
41339 if (NUM_PAGES_TO_ALLOC < nr_free)
41340 npages_to_free = NUM_PAGES_TO_ALLOC;
41341 @@ -366,7 +365,8 @@ restart:
41342 __list_del(&p->lru, &pool->list);
41343
41344 ttm_pool_update_free_locked(pool, freed_pages);
41345 - nr_free -= freed_pages;
41346 + if (likely(nr_free != FREE_ALL_PAGES))
41347 + nr_free -= freed_pages;
41348 }
41349
41350 spin_unlock_irqrestore(&pool->lock, irq_flags);
41351 @@ -395,7 +395,7 @@ ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41352 unsigned i;
41353 unsigned pool_offset;
41354 struct ttm_page_pool *pool;
41355 - int shrink_pages = sc->nr_to_scan;
41356 + unsigned long shrink_pages = sc->nr_to_scan;
41357 unsigned long freed = 0;
41358
41359 if (!mutex_trylock(&lock))
41360 @@ -403,7 +403,7 @@ ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41361 pool_offset = ++start_pool % NUM_POOLS;
41362 /* select start pool in round robin fashion */
41363 for (i = 0; i < NUM_POOLS; ++i) {
41364 - unsigned nr_free = shrink_pages;
41365 + unsigned long nr_free = shrink_pages;
41366 if (shrink_pages == 0)
41367 break;
41368 pool = &_manager->pools[(i + pool_offset)%NUM_POOLS];
41369 @@ -669,7 +669,7 @@ out:
41370 }
41371
41372 /* Put all pages in pages list to correct pool to wait for reuse */
41373 -static void ttm_put_pages(struct page **pages, unsigned npages, int flags,
41374 +static void ttm_put_pages(struct page **pages, unsigned long npages, int flags,
41375 enum ttm_caching_state cstate)
41376 {
41377 unsigned long irq_flags;
41378 @@ -724,7 +724,7 @@ static int ttm_get_pages(struct page **pages, unsigned npages, int flags,
41379 struct list_head plist;
41380 struct page *p = NULL;
41381 gfp_t gfp_flags = GFP_USER;
41382 - unsigned count;
41383 + unsigned long count;
41384 int r;
41385
41386 /* set zero flag for page allocation if required */
41387 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
41388 index c96db43..c367557 100644
41389 --- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
41390 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
41391 @@ -56,7 +56,7 @@
41392
41393 #define NUM_PAGES_TO_ALLOC (PAGE_SIZE/sizeof(struct page *))
41394 #define SMALL_ALLOCATION 4
41395 -#define FREE_ALL_PAGES (~0U)
41396 +#define FREE_ALL_PAGES (~0UL)
41397 /* times are in msecs */
41398 #define IS_UNDEFINED (0)
41399 #define IS_WC (1<<1)
41400 @@ -413,15 +413,14 @@ static void ttm_dma_page_put(struct dma_pool *pool, struct dma_page *d_page)
41401 * @nr_free: If set to true will free all pages in pool
41402 * @gfp: GFP flags.
41403 **/
41404 -static unsigned ttm_dma_page_pool_free(struct dma_pool *pool, unsigned nr_free,
41405 +static unsigned long ttm_dma_page_pool_free(struct dma_pool *pool, unsigned long nr_free,
41406 gfp_t gfp)
41407 {
41408 unsigned long irq_flags;
41409 struct dma_page *dma_p, *tmp;
41410 struct page **pages_to_free;
41411 struct list_head d_pages;
41412 - unsigned freed_pages = 0,
41413 - npages_to_free = nr_free;
41414 + unsigned long freed_pages = 0, npages_to_free = nr_free;
41415
41416 if (NUM_PAGES_TO_ALLOC < nr_free)
41417 npages_to_free = NUM_PAGES_TO_ALLOC;
41418 @@ -494,7 +493,8 @@ restart:
41419 /* remove range of pages from the pool */
41420 if (freed_pages) {
41421 ttm_pool_update_free_locked(pool, freed_pages);
41422 - nr_free -= freed_pages;
41423 + if (likely(nr_free != FREE_ALL_PAGES))
41424 + nr_free -= freed_pages;
41425 }
41426
41427 spin_unlock_irqrestore(&pool->lock, irq_flags);
41428 @@ -929,7 +929,7 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev)
41429 struct dma_page *d_page, *next;
41430 enum pool_type type;
41431 bool is_cached = false;
41432 - unsigned count = 0, i, npages = 0;
41433 + unsigned long count = 0, i, npages = 0;
41434 unsigned long irq_flags;
41435
41436 type = ttm_to_type(ttm->page_flags, ttm->caching_state);
41437 @@ -1007,7 +1007,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41438 static unsigned start_pool;
41439 unsigned idx = 0;
41440 unsigned pool_offset;
41441 - unsigned shrink_pages = sc->nr_to_scan;
41442 + unsigned long shrink_pages = sc->nr_to_scan;
41443 struct device_pools *p;
41444 unsigned long freed = 0;
41445
41446 @@ -1020,7 +1020,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41447 goto out;
41448 pool_offset = ++start_pool % _manager->npools;
41449 list_for_each_entry(p, &_manager->pools, pools) {
41450 - unsigned nr_free;
41451 + unsigned long nr_free;
41452
41453 if (!p->dev)
41454 continue;
41455 @@ -1034,7 +1034,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41456 sc->gfp_mask);
41457 freed += nr_free - shrink_pages;
41458
41459 - pr_debug("%s: (%s:%d) Asked to shrink %d, have %d more to go\n",
41460 + pr_debug("%s: (%s:%d) Asked to shrink %lu, have %lu more to go\n",
41461 p->pool->dev_name, p->pool->name, current->pid,
41462 nr_free, shrink_pages);
41463 }
41464 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41465 index 8cbcb45..a4d9cf7 100644
41466 --- a/drivers/gpu/drm/udl/udl_fb.c
41467 +++ b/drivers/gpu/drm/udl/udl_fb.c
41468 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41469 fb_deferred_io_cleanup(info);
41470 kfree(info->fbdefio);
41471 info->fbdefio = NULL;
41472 - info->fbops->fb_mmap = udl_fb_mmap;
41473 }
41474
41475 pr_warn("released /dev/fb%d user=%d count=%d\n",
41476 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41477 index ef8c500..01030c8 100644
41478 --- a/drivers/gpu/drm/via/via_drv.h
41479 +++ b/drivers/gpu/drm/via/via_drv.h
41480 @@ -53,7 +53,7 @@ typedef struct drm_via_ring_buffer {
41481 typedef uint32_t maskarray_t[5];
41482
41483 typedef struct drm_via_irq {
41484 - atomic_t irq_received;
41485 + atomic_unchecked_t irq_received;
41486 uint32_t pending_mask;
41487 uint32_t enable_mask;
41488 wait_queue_head_t irq_queue;
41489 @@ -77,7 +77,7 @@ typedef struct drm_via_private {
41490 struct timeval last_vblank;
41491 int last_vblank_valid;
41492 unsigned usec_per_vblank;
41493 - atomic_t vbl_received;
41494 + atomic_unchecked_t vbl_received;
41495 drm_via_state_t hc_state;
41496 char pci_buf[VIA_PCI_BUF_SIZE];
41497 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41498 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41499 index 1319433..a993b0c 100644
41500 --- a/drivers/gpu/drm/via/via_irq.c
41501 +++ b/drivers/gpu/drm/via/via_irq.c
41502 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41503 if (crtc != 0)
41504 return 0;
41505
41506 - return atomic_read(&dev_priv->vbl_received);
41507 + return atomic_read_unchecked(&dev_priv->vbl_received);
41508 }
41509
41510 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41511 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41512
41513 status = VIA_READ(VIA_REG_INTERRUPT);
41514 if (status & VIA_IRQ_VBLANK_PENDING) {
41515 - atomic_inc(&dev_priv->vbl_received);
41516 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41517 + atomic_inc_unchecked(&dev_priv->vbl_received);
41518 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41519 do_gettimeofday(&cur_vblank);
41520 if (dev_priv->last_vblank_valid) {
41521 dev_priv->usec_per_vblank =
41522 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41523 dev_priv->last_vblank = cur_vblank;
41524 dev_priv->last_vblank_valid = 1;
41525 }
41526 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41527 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41528 DRM_DEBUG("US per vblank is: %u\n",
41529 dev_priv->usec_per_vblank);
41530 }
41531 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41532
41533 for (i = 0; i < dev_priv->num_irqs; ++i) {
41534 if (status & cur_irq->pending_mask) {
41535 - atomic_inc(&cur_irq->irq_received);
41536 + atomic_inc_unchecked(&cur_irq->irq_received);
41537 wake_up(&cur_irq->irq_queue);
41538 handled = 1;
41539 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41540 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41541 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41542 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41543 masks[irq][4]));
41544 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41545 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41546 } else {
41547 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41548 (((cur_irq_sequence =
41549 - atomic_read(&cur_irq->irq_received)) -
41550 + atomic_read_unchecked(&cur_irq->irq_received)) -
41551 *sequence) <= (1 << 23)));
41552 }
41553 *sequence = cur_irq_sequence;
41554 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41555 }
41556
41557 for (i = 0; i < dev_priv->num_irqs; ++i) {
41558 - atomic_set(&cur_irq->irq_received, 0);
41559 + atomic_set_unchecked(&cur_irq->irq_received, 0);
41560 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41561 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41562 init_waitqueue_head(&cur_irq->irq_queue);
41563 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41564 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41565 case VIA_IRQ_RELATIVE:
41566 irqwait->request.sequence +=
41567 - atomic_read(&cur_irq->irq_received);
41568 + atomic_read_unchecked(&cur_irq->irq_received);
41569 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41570 case VIA_IRQ_ABSOLUTE:
41571 break;
41572 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41573 index 4ee799b..69fc0d1 100644
41574 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41575 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41576 @@ -446,7 +446,7 @@ struct vmw_private {
41577 * Fencing and IRQs.
41578 */
41579
41580 - atomic_t marker_seq;
41581 + atomic_unchecked_t marker_seq;
41582 wait_queue_head_t fence_queue;
41583 wait_queue_head_t fifo_queue;
41584 int fence_queue_waiters; /* Protected by hw_mutex */
41585 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41586 index 09e10ae..cb76c60 100644
41587 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41588 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41589 @@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41590 (unsigned int) min,
41591 (unsigned int) fifo->capabilities);
41592
41593 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41594 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41595 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41596 vmw_marker_queue_init(&fifo->marker_queue);
41597 return vmw_fifo_send_fence(dev_priv, &dummy);
41598 @@ -378,7 +378,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41599 if (reserveable)
41600 iowrite32(bytes, fifo_mem +
41601 SVGA_FIFO_RESERVED);
41602 - return fifo_mem + (next_cmd >> 2);
41603 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41604 } else {
41605 need_bounce = true;
41606 }
41607 @@ -498,7 +498,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41608
41609 fm = vmw_fifo_reserve(dev_priv, bytes);
41610 if (unlikely(fm == NULL)) {
41611 - *seqno = atomic_read(&dev_priv->marker_seq);
41612 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41613 ret = -ENOMEM;
41614 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41615 false, 3*HZ);
41616 @@ -506,7 +506,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41617 }
41618
41619 do {
41620 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41621 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41622 } while (*seqno == 0);
41623
41624 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41625 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41626 index 170b61b..fec7348 100644
41627 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41628 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41629 @@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41630 }
41631
41632 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41633 - vmw_gmrid_man_init,
41634 - vmw_gmrid_man_takedown,
41635 - vmw_gmrid_man_get_node,
41636 - vmw_gmrid_man_put_node,
41637 - vmw_gmrid_man_debug
41638 + .init = vmw_gmrid_man_init,
41639 + .takedown = vmw_gmrid_man_takedown,
41640 + .get_node = vmw_gmrid_man_get_node,
41641 + .put_node = vmw_gmrid_man_put_node,
41642 + .debug = vmw_gmrid_man_debug
41643 };
41644 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41645 index 37881ec..319065d 100644
41646 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41647 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41648 @@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41649 int ret;
41650
41651 num_clips = arg->num_clips;
41652 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41653 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41654
41655 if (unlikely(num_clips == 0))
41656 return 0;
41657 @@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41658 int ret;
41659
41660 num_clips = arg->num_clips;
41661 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41662 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41663
41664 if (unlikely(num_clips == 0))
41665 return 0;
41666 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41667 index 0c42376..6febe77 100644
41668 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41669 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41670 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41671 * emitted. Then the fence is stale and signaled.
41672 */
41673
41674 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41675 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41676 > VMW_FENCE_WRAP);
41677
41678 return ret;
41679 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41680
41681 if (fifo_idle)
41682 down_read(&fifo_state->rwsem);
41683 - signal_seq = atomic_read(&dev_priv->marker_seq);
41684 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41685 ret = 0;
41686
41687 for (;;) {
41688 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41689 index efd1ffd..0ae13ca 100644
41690 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41691 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41692 @@ -135,7 +135,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41693 while (!vmw_lag_lt(queue, us)) {
41694 spin_lock(&queue->lock);
41695 if (list_empty(&queue->head))
41696 - seqno = atomic_read(&dev_priv->marker_seq);
41697 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41698 else {
41699 marker = list_first_entry(&queue->head,
41700 struct vmw_marker, head);
41701 diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41702 index 37ac7b5..d52a5c9 100644
41703 --- a/drivers/gpu/vga/vga_switcheroo.c
41704 +++ b/drivers/gpu/vga/vga_switcheroo.c
41705 @@ -644,7 +644,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41706
41707 /* this version is for the case where the power switch is separate
41708 to the device being powered down. */
41709 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41710 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41711 {
41712 /* copy over all the bus versions */
41713 if (dev->bus && dev->bus->pm) {
41714 @@ -695,7 +695,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41715 return ret;
41716 }
41717
41718 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41719 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41720 {
41721 /* copy over all the bus versions */
41722 if (dev->bus && dev->bus->pm) {
41723 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41724 index 3402033..50b562c 100644
41725 --- a/drivers/hid/hid-core.c
41726 +++ b/drivers/hid/hid-core.c
41727 @@ -2506,7 +2506,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41728
41729 int hid_add_device(struct hid_device *hdev)
41730 {
41731 - static atomic_t id = ATOMIC_INIT(0);
41732 + static atomic_unchecked_t id = ATOMIC_INIT(0);
41733 int ret;
41734
41735 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41736 @@ -2548,7 +2548,7 @@ int hid_add_device(struct hid_device *hdev)
41737 /* XXX hack, any other cleaner solution after the driver core
41738 * is converted to allow more than 20 bytes as the device name? */
41739 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41740 - hdev->vendor, hdev->product, atomic_inc_return(&id));
41741 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41742
41743 hid_debug_register(hdev, dev_name(&hdev->dev));
41744 ret = device_add(&hdev->dev);
41745 diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
41746 index 71f5692..147d3da 100644
41747 --- a/drivers/hid/hid-logitech-dj.c
41748 +++ b/drivers/hid/hid-logitech-dj.c
41749 @@ -658,6 +658,12 @@ static int logi_dj_raw_event(struct hid_device *hdev,
41750 * device (via hid_input_report() ) and return 1 so hid-core does not do
41751 * anything else with it.
41752 */
41753 + if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
41754 + (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
41755 + dev_err(&hdev->dev, "%s: invalid device index:%d\n",
41756 + __func__, dj_report->device_index);
41757 + return false;
41758 + }
41759
41760 /* case 1) */
41761 if (data[0] != REPORT_ID_DJ_SHORT)
41762 diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
41763 index bc4269e..b6e6102 100644
41764 --- a/drivers/hid/hid-sony.c
41765 +++ b/drivers/hid/hid-sony.c
41766 @@ -798,6 +798,12 @@ union sixaxis_output_report_01 {
41767 __u8 buf[36];
41768 };
41769
41770 +#define DS4_REPORT_0x02_SIZE 37
41771 +#define DS4_REPORT_0x05_SIZE 32
41772 +#define DS4_REPORT_0x11_SIZE 78
41773 +#define DS4_REPORT_0x81_SIZE 7
41774 +#define SIXAXIS_REPORT_0xF2_SIZE 18
41775 +
41776 static spinlock_t sony_dev_list_lock;
41777 static LIST_HEAD(sony_device_list);
41778 static DEFINE_IDA(sony_device_id_allocator);
41779 @@ -811,6 +817,7 @@ struct sony_sc {
41780 struct work_struct state_worker;
41781 struct power_supply battery;
41782 int device_id;
41783 + __u8 *output_report_dmabuf;
41784
41785 #ifdef CONFIG_SONY_FF
41786 __u8 left;
41787 @@ -1142,9 +1149,20 @@ static int sixaxis_set_operational_usb(struct hid_device *hdev)
41788
41789 static int sixaxis_set_operational_bt(struct hid_device *hdev)
41790 {
41791 - unsigned char buf[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
41792 - return hid_hw_raw_request(hdev, buf[0], buf, sizeof(buf),
41793 + static const __u8 report[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
41794 + __u8 *buf;
41795 + int ret;
41796 +
41797 + buf = kmemdup(report, sizeof(report), GFP_KERNEL);
41798 + if (!buf)
41799 + return -ENOMEM;
41800 +
41801 + ret = hid_hw_raw_request(hdev, buf[0], buf, sizeof(report),
41802 HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
41803 +
41804 + kfree(buf);
41805 +
41806 + return ret;
41807 }
41808
41809 /*
41810 @@ -1153,10 +1171,19 @@ static int sixaxis_set_operational_bt(struct hid_device *hdev)
41811 */
41812 static int dualshock4_set_operational_bt(struct hid_device *hdev)
41813 {
41814 - __u8 buf[37] = { 0 };
41815 + __u8 *buf;
41816 + int ret;
41817
41818 - return hid_hw_raw_request(hdev, 0x02, buf, sizeof(buf),
41819 + buf = kmalloc(DS4_REPORT_0x02_SIZE, GFP_KERNEL);
41820 + if (!buf)
41821 + return -ENOMEM;
41822 +
41823 + ret = hid_hw_raw_request(hdev, 0x02, buf, DS4_REPORT_0x02_SIZE,
41824 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
41825 +
41826 + kfree(buf);
41827 +
41828 + return ret;
41829 }
41830
41831 static void sixaxis_set_leds_from_id(int id, __u8 values[MAX_LEDS])
41832 @@ -1471,9 +1498,7 @@ error_leds:
41833
41834 static void sixaxis_state_worker(struct work_struct *work)
41835 {
41836 - struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
41837 - int n;
41838 - union sixaxis_output_report_01 report = {
41839 + static const union sixaxis_output_report_01 default_report = {
41840 .buf = {
41841 0x01,
41842 0x00, 0xff, 0x00, 0xff, 0x00,
41843 @@ -1485,20 +1510,27 @@ static void sixaxis_state_worker(struct work_struct *work)
41844 0x00, 0x00, 0x00, 0x00, 0x00
41845 }
41846 };
41847 + struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
41848 + struct sixaxis_output_report *report =
41849 + (struct sixaxis_output_report *)sc->output_report_dmabuf;
41850 + int n;
41851 +
41852 + /* Initialize the report with default values */
41853 + memcpy(report, &default_report, sizeof(struct sixaxis_output_report));
41854
41855 #ifdef CONFIG_SONY_FF
41856 - report.data.rumble.right_motor_on = sc->right ? 1 : 0;
41857 - report.data.rumble.left_motor_force = sc->left;
41858 + report->rumble.right_motor_on = sc->right ? 1 : 0;
41859 + report->rumble.left_motor_force = sc->left;
41860 #endif
41861
41862 - report.data.leds_bitmap |= sc->led_state[0] << 1;
41863 - report.data.leds_bitmap |= sc->led_state[1] << 2;
41864 - report.data.leds_bitmap |= sc->led_state[2] << 3;
41865 - report.data.leds_bitmap |= sc->led_state[3] << 4;
41866 + report->leds_bitmap |= sc->led_state[0] << 1;
41867 + report->leds_bitmap |= sc->led_state[1] << 2;
41868 + report->leds_bitmap |= sc->led_state[2] << 3;
41869 + report->leds_bitmap |= sc->led_state[3] << 4;
41870
41871 /* Set flag for all leds off, required for 3rd party INTEC controller */
41872 - if ((report.data.leds_bitmap & 0x1E) == 0)
41873 - report.data.leds_bitmap |= 0x20;
41874 + if ((report->leds_bitmap & 0x1E) == 0)
41875 + report->leds_bitmap |= 0x20;
41876
41877 /*
41878 * The LEDs in the report are indexed in reverse order to their
41879 @@ -1511,28 +1543,30 @@ static void sixaxis_state_worker(struct work_struct *work)
41880 */
41881 for (n = 0; n < 4; n++) {
41882 if (sc->led_delay_on[n] || sc->led_delay_off[n]) {
41883 - report.data.led[3 - n].duty_off = sc->led_delay_off[n];
41884 - report.data.led[3 - n].duty_on = sc->led_delay_on[n];
41885 + report->led[3 - n].duty_off = sc->led_delay_off[n];
41886 + report->led[3 - n].duty_on = sc->led_delay_on[n];
41887 }
41888 }
41889
41890 - hid_hw_raw_request(sc->hdev, report.data.report_id, report.buf,
41891 - sizeof(report), HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
41892 + hid_hw_raw_request(sc->hdev, report->report_id, (__u8 *)report,
41893 + sizeof(struct sixaxis_output_report),
41894 + HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
41895 }
41896
41897 static void dualshock4_state_worker(struct work_struct *work)
41898 {
41899 struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
41900 struct hid_device *hdev = sc->hdev;
41901 + __u8 *buf = sc->output_report_dmabuf;
41902 int offset;
41903
41904 - __u8 buf[78] = { 0 };
41905 -
41906 if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) {
41907 + memset(buf, 0, DS4_REPORT_0x05_SIZE);
41908 buf[0] = 0x05;
41909 buf[1] = 0xFF;
41910 offset = 4;
41911 } else {
41912 + memset(buf, 0, DS4_REPORT_0x11_SIZE);
41913 buf[0] = 0x11;
41914 buf[1] = 0xB0;
41915 buf[3] = 0x0F;
41916 @@ -1560,12 +1594,33 @@ static void dualshock4_state_worker(struct work_struct *work)
41917 buf[offset++] = sc->led_delay_off[3];
41918
41919 if (sc->quirks & DUALSHOCK4_CONTROLLER_USB)
41920 - hid_hw_output_report(hdev, buf, 32);
41921 + hid_hw_output_report(hdev, buf, DS4_REPORT_0x05_SIZE);
41922 else
41923 - hid_hw_raw_request(hdev, 0x11, buf, 78,
41924 + hid_hw_raw_request(hdev, 0x11, buf, DS4_REPORT_0x11_SIZE,
41925 HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
41926 }
41927
41928 +static int sony_allocate_output_report(struct sony_sc *sc)
41929 +{
41930 + if (sc->quirks & SIXAXIS_CONTROLLER)
41931 + sc->output_report_dmabuf =
41932 + kmalloc(sizeof(union sixaxis_output_report_01),
41933 + GFP_KERNEL);
41934 + else if (sc->quirks & DUALSHOCK4_CONTROLLER_BT)
41935 + sc->output_report_dmabuf = kmalloc(DS4_REPORT_0x11_SIZE,
41936 + GFP_KERNEL);
41937 + else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB)
41938 + sc->output_report_dmabuf = kmalloc(DS4_REPORT_0x05_SIZE,
41939 + GFP_KERNEL);
41940 + else
41941 + return 0;
41942 +
41943 + if (!sc->output_report_dmabuf)
41944 + return -ENOMEM;
41945 +
41946 + return 0;
41947 +}
41948 +
41949 #ifdef CONFIG_SONY_FF
41950 static int sony_play_effect(struct input_dev *dev, void *data,
41951 struct ff_effect *effect)
41952 @@ -1754,6 +1809,7 @@ static int sony_get_bt_devaddr(struct sony_sc *sc)
41953
41954 static int sony_check_add(struct sony_sc *sc)
41955 {
41956 + __u8 *buf = NULL;
41957 int n, ret;
41958
41959 if ((sc->quirks & DUALSHOCK4_CONTROLLER_BT) ||
41960 @@ -1769,36 +1825,44 @@ static int sony_check_add(struct sony_sc *sc)
41961 return 0;
41962 }
41963 } else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) {
41964 - __u8 buf[7];
41965 + buf = kmalloc(DS4_REPORT_0x81_SIZE, GFP_KERNEL);
41966 + if (!buf)
41967 + return -ENOMEM;
41968
41969 /*
41970 * The MAC address of a DS4 controller connected via USB can be
41971 * retrieved with feature report 0x81. The address begins at
41972 * offset 1.
41973 */
41974 - ret = hid_hw_raw_request(sc->hdev, 0x81, buf, sizeof(buf),
41975 - HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
41976 + ret = hid_hw_raw_request(sc->hdev, 0x81, buf,
41977 + DS4_REPORT_0x81_SIZE, HID_FEATURE_REPORT,
41978 + HID_REQ_GET_REPORT);
41979
41980 - if (ret != 7) {
41981 + if (ret != DS4_REPORT_0x81_SIZE) {
41982 hid_err(sc->hdev, "failed to retrieve feature report 0x81 with the DualShock 4 MAC address\n");
41983 - return ret < 0 ? ret : -EINVAL;
41984 + ret = ret < 0 ? ret : -EINVAL;
41985 + goto out_free;
41986 }
41987
41988 memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address));
41989 } else if (sc->quirks & SIXAXIS_CONTROLLER_USB) {
41990 - __u8 buf[18];
41991 + buf = kmalloc(SIXAXIS_REPORT_0xF2_SIZE, GFP_KERNEL);
41992 + if (!buf)
41993 + return -ENOMEM;
41994
41995 /*
41996 * The MAC address of a Sixaxis controller connected via USB can
41997 * be retrieved with feature report 0xf2. The address begins at
41998 * offset 4.
41999 */
42000 - ret = hid_hw_raw_request(sc->hdev, 0xf2, buf, sizeof(buf),
42001 - HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
42002 + ret = hid_hw_raw_request(sc->hdev, 0xf2, buf,
42003 + SIXAXIS_REPORT_0xF2_SIZE, HID_FEATURE_REPORT,
42004 + HID_REQ_GET_REPORT);
42005
42006 - if (ret != 18) {
42007 + if (ret != SIXAXIS_REPORT_0xF2_SIZE) {
42008 hid_err(sc->hdev, "failed to retrieve feature report 0xf2 with the Sixaxis MAC address\n");
42009 - return ret < 0 ? ret : -EINVAL;
42010 + ret = ret < 0 ? ret : -EINVAL;
42011 + goto out_free;
42012 }
42013
42014 /*
42015 @@ -1811,7 +1875,13 @@ static int sony_check_add(struct sony_sc *sc)
42016 return 0;
42017 }
42018
42019 - return sony_check_add_dev_list(sc);
42020 + ret = sony_check_add_dev_list(sc);
42021 +
42022 +out_free:
42023 +
42024 + kfree(buf);
42025 +
42026 + return ret;
42027 }
42028
42029 static int sony_set_device_id(struct sony_sc *sc)
42030 @@ -1895,6 +1965,12 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
42031 return ret;
42032 }
42033
42034 + ret = sony_allocate_output_report(sc);
42035 + if (ret < 0) {
42036 + hid_err(hdev, "failed to allocate the output report buffer\n");
42037 + goto err_stop;
42038 + }
42039 +
42040 ret = sony_set_device_id(sc);
42041 if (ret < 0) {
42042 hid_err(hdev, "failed to allocate the device id\n");
42043 @@ -1984,6 +2060,7 @@ err_stop:
42044 if (sc->quirks & SONY_BATTERY_SUPPORT)
42045 sony_battery_remove(sc);
42046 sony_cancel_work_sync(sc);
42047 + kfree(sc->output_report_dmabuf);
42048 sony_remove_dev_list(sc);
42049 sony_release_device_id(sc);
42050 hid_hw_stop(hdev);
42051 @@ -2004,6 +2081,8 @@ static void sony_remove(struct hid_device *hdev)
42052
42053 sony_cancel_work_sync(sc);
42054
42055 + kfree(sc->output_report_dmabuf);
42056 +
42057 sony_remove_dev_list(sc);
42058
42059 sony_release_device_id(sc);
42060 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
42061 index c13fb5b..55a3802 100644
42062 --- a/drivers/hid/hid-wiimote-debug.c
42063 +++ b/drivers/hid/hid-wiimote-debug.c
42064 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
42065 else if (size == 0)
42066 return -EIO;
42067
42068 - if (copy_to_user(u, buf, size))
42069 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
42070 return -EFAULT;
42071
42072 *off += size;
42073 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
42074 index 433f72a..2926005 100644
42075 --- a/drivers/hv/channel.c
42076 +++ b/drivers/hv/channel.c
42077 @@ -366,8 +366,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
42078 unsigned long flags;
42079 int ret = 0;
42080
42081 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
42082 - atomic_inc(&vmbus_connection.next_gpadl_handle);
42083 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
42084 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
42085
42086 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
42087 if (ret)
42088 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
42089 index 3e4235c..877d0e5 100644
42090 --- a/drivers/hv/hv.c
42091 +++ b/drivers/hv/hv.c
42092 @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
42093 u64 output_address = (output) ? virt_to_phys(output) : 0;
42094 u32 output_address_hi = output_address >> 32;
42095 u32 output_address_lo = output_address & 0xFFFFFFFF;
42096 - void *hypercall_page = hv_context.hypercall_page;
42097 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
42098
42099 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
42100 "=a"(hv_status_lo) : "d" (control_hi),
42101 @@ -156,7 +156,7 @@ int hv_init(void)
42102 /* See if the hypercall page is already set */
42103 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
42104
42105 - virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
42106 + virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
42107
42108 if (!virtaddr)
42109 goto cleanup;
42110 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
42111 index 5e90c5d..d8fcefb 100644
42112 --- a/drivers/hv/hv_balloon.c
42113 +++ b/drivers/hv/hv_balloon.c
42114 @@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
42115
42116 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
42117 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
42118 -static atomic_t trans_id = ATOMIC_INIT(0);
42119 +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
42120
42121 static int dm_ring_size = (5 * PAGE_SIZE);
42122
42123 @@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
42124 pr_info("Memory hot add failed\n");
42125
42126 dm->state = DM_INITIALIZED;
42127 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
42128 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42129 vmbus_sendpacket(dm->dev->channel, &resp,
42130 sizeof(struct dm_hot_add_response),
42131 (unsigned long)NULL,
42132 @@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
42133 memset(&status, 0, sizeof(struct dm_status));
42134 status.hdr.type = DM_STATUS_REPORT;
42135 status.hdr.size = sizeof(struct dm_status);
42136 - status.hdr.trans_id = atomic_inc_return(&trans_id);
42137 + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42138
42139 /*
42140 * The host expects the guest to report free memory.
42141 @@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
42142 * send the status. This can happen if we were interrupted
42143 * after we picked our transaction ID.
42144 */
42145 - if (status.hdr.trans_id != atomic_read(&trans_id))
42146 + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
42147 return;
42148
42149 /*
42150 @@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
42151 */
42152
42153 do {
42154 - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
42155 + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42156 ret = vmbus_sendpacket(dm_device.dev->channel,
42157 bl_resp,
42158 bl_resp->hdr.size,
42159 @@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
42160
42161 memset(&resp, 0, sizeof(struct dm_unballoon_response));
42162 resp.hdr.type = DM_UNBALLOON_RESPONSE;
42163 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
42164 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42165 resp.hdr.size = sizeof(struct dm_unballoon_response);
42166
42167 vmbus_sendpacket(dm_device.dev->channel, &resp,
42168 @@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
42169 memset(&version_req, 0, sizeof(struct dm_version_request));
42170 version_req.hdr.type = DM_VERSION_REQUEST;
42171 version_req.hdr.size = sizeof(struct dm_version_request);
42172 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42173 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42174 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
42175 version_req.is_last_attempt = 1;
42176
42177 @@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
42178 memset(&version_req, 0, sizeof(struct dm_version_request));
42179 version_req.hdr.type = DM_VERSION_REQUEST;
42180 version_req.hdr.size = sizeof(struct dm_version_request);
42181 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42182 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42183 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
42184 version_req.is_last_attempt = 0;
42185
42186 @@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
42187 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
42188 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
42189 cap_msg.hdr.size = sizeof(struct dm_capabilities);
42190 - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
42191 + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42192
42193 cap_msg.caps.cap_bits.balloon = 1;
42194 cap_msg.caps.cap_bits.hot_add = 1;
42195 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
42196 index c386d8d..d6004c4 100644
42197 --- a/drivers/hv/hyperv_vmbus.h
42198 +++ b/drivers/hv/hyperv_vmbus.h
42199 @@ -611,7 +611,7 @@ enum vmbus_connect_state {
42200 struct vmbus_connection {
42201 enum vmbus_connect_state conn_state;
42202
42203 - atomic_t next_gpadl_handle;
42204 + atomic_unchecked_t next_gpadl_handle;
42205
42206 /*
42207 * Represents channel interrupts. Each bit position represents a
42208 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
42209 index 4d6b269..2e23b86 100644
42210 --- a/drivers/hv/vmbus_drv.c
42211 +++ b/drivers/hv/vmbus_drv.c
42212 @@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
42213 {
42214 int ret = 0;
42215
42216 - static atomic_t device_num = ATOMIC_INIT(0);
42217 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
42218
42219 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
42220 - atomic_inc_return(&device_num));
42221 + atomic_inc_return_unchecked(&device_num));
42222
42223 child_device_obj->device.bus = &hv_bus;
42224 child_device_obj->device.parent = &hv_acpi_dev->dev;
42225 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
42226 index 579bdf9..75118b5 100644
42227 --- a/drivers/hwmon/acpi_power_meter.c
42228 +++ b/drivers/hwmon/acpi_power_meter.c
42229 @@ -116,7 +116,7 @@ struct sensor_template {
42230 struct device_attribute *devattr,
42231 const char *buf, size_t count);
42232 int index;
42233 -};
42234 +} __do_const;
42235
42236 /* Averaging interval */
42237 static int update_avg_interval(struct acpi_power_meter_resource *resource)
42238 @@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
42239 struct sensor_template *attrs)
42240 {
42241 struct device *dev = &resource->acpi_dev->dev;
42242 - struct sensor_device_attribute *sensors =
42243 + sensor_device_attribute_no_const *sensors =
42244 &resource->sensors[resource->num_sensors];
42245 int res = 0;
42246
42247 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
42248 index 3288f13..71cfb4e 100644
42249 --- a/drivers/hwmon/applesmc.c
42250 +++ b/drivers/hwmon/applesmc.c
42251 @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
42252 {
42253 struct applesmc_node_group *grp;
42254 struct applesmc_dev_attr *node;
42255 - struct attribute *attr;
42256 + attribute_no_const *attr;
42257 int ret, i;
42258
42259 for (grp = groups; grp->format; grp++) {
42260 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
42261 index cccef87..06ce8ec 100644
42262 --- a/drivers/hwmon/asus_atk0110.c
42263 +++ b/drivers/hwmon/asus_atk0110.c
42264 @@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
42265 struct atk_sensor_data {
42266 struct list_head list;
42267 struct atk_data *data;
42268 - struct device_attribute label_attr;
42269 - struct device_attribute input_attr;
42270 - struct device_attribute limit1_attr;
42271 - struct device_attribute limit2_attr;
42272 + device_attribute_no_const label_attr;
42273 + device_attribute_no_const input_attr;
42274 + device_attribute_no_const limit1_attr;
42275 + device_attribute_no_const limit2_attr;
42276 char label_attr_name[ATTR_NAME_SIZE];
42277 char input_attr_name[ATTR_NAME_SIZE];
42278 char limit1_attr_name[ATTR_NAME_SIZE];
42279 @@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
42280 static struct device_attribute atk_name_attr =
42281 __ATTR(name, 0444, atk_name_show, NULL);
42282
42283 -static void atk_init_attribute(struct device_attribute *attr, char *name,
42284 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
42285 sysfs_show_func show)
42286 {
42287 sysfs_attr_init(&attr->attr);
42288 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
42289 index d76f0b7..55ae976 100644
42290 --- a/drivers/hwmon/coretemp.c
42291 +++ b/drivers/hwmon/coretemp.c
42292 @@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
42293 return NOTIFY_OK;
42294 }
42295
42296 -static struct notifier_block coretemp_cpu_notifier __refdata = {
42297 +static struct notifier_block coretemp_cpu_notifier = {
42298 .notifier_call = coretemp_cpu_callback,
42299 };
42300
42301 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
42302 index 7a8a6fb..015c1fd 100644
42303 --- a/drivers/hwmon/ibmaem.c
42304 +++ b/drivers/hwmon/ibmaem.c
42305 @@ -924,7 +924,7 @@ static int aem_register_sensors(struct aem_data *data,
42306 struct aem_rw_sensor_template *rw)
42307 {
42308 struct device *dev = &data->pdev->dev;
42309 - struct sensor_device_attribute *sensors = data->sensors;
42310 + sensor_device_attribute_no_const *sensors = data->sensors;
42311 int err;
42312
42313 /* Set up read-only sensors */
42314 diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
42315 index 14c82da..09b25d7 100644
42316 --- a/drivers/hwmon/iio_hwmon.c
42317 +++ b/drivers/hwmon/iio_hwmon.c
42318 @@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
42319 {
42320 struct device *dev = &pdev->dev;
42321 struct iio_hwmon_state *st;
42322 - struct sensor_device_attribute *a;
42323 + sensor_device_attribute_no_const *a;
42324 int ret, i;
42325 int in_i = 1, temp_i = 1, curr_i = 1;
42326 enum iio_chan_type type;
42327 diff --git a/drivers/hwmon/nct6683.c b/drivers/hwmon/nct6683.c
42328 index 7710f46..427a28d 100644
42329 --- a/drivers/hwmon/nct6683.c
42330 +++ b/drivers/hwmon/nct6683.c
42331 @@ -397,11 +397,11 @@ static struct attribute_group *
42332 nct6683_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42333 int repeat)
42334 {
42335 - struct sensor_device_attribute_2 *a2;
42336 - struct sensor_device_attribute *a;
42337 + sensor_device_attribute_2_no_const *a2;
42338 + sensor_device_attribute_no_const *a;
42339 struct sensor_device_template **t;
42340 struct sensor_device_attr_u *su;
42341 - struct attribute_group *group;
42342 + attribute_group_no_const *group;
42343 struct attribute **attrs;
42344 int i, j, count;
42345
42346 diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
42347 index 504cbdd..35d6f25 100644
42348 --- a/drivers/hwmon/nct6775.c
42349 +++ b/drivers/hwmon/nct6775.c
42350 @@ -943,10 +943,10 @@ static struct attribute_group *
42351 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42352 int repeat)
42353 {
42354 - struct attribute_group *group;
42355 + attribute_group_no_const *group;
42356 struct sensor_device_attr_u *su;
42357 - struct sensor_device_attribute *a;
42358 - struct sensor_device_attribute_2 *a2;
42359 + sensor_device_attribute_no_const *a;
42360 + sensor_device_attribute_2_no_const *a2;
42361 struct attribute **attrs;
42362 struct sensor_device_template **t;
42363 int i, count;
42364 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
42365 index 291d11f..3f0dbbd 100644
42366 --- a/drivers/hwmon/pmbus/pmbus_core.c
42367 +++ b/drivers/hwmon/pmbus/pmbus_core.c
42368 @@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
42369 return 0;
42370 }
42371
42372 -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42373 +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
42374 const char *name,
42375 umode_t mode,
42376 ssize_t (*show)(struct device *dev,
42377 @@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42378 dev_attr->store = store;
42379 }
42380
42381 -static void pmbus_attr_init(struct sensor_device_attribute *a,
42382 +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
42383 const char *name,
42384 umode_t mode,
42385 ssize_t (*show)(struct device *dev,
42386 @@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
42387 u16 reg, u8 mask)
42388 {
42389 struct pmbus_boolean *boolean;
42390 - struct sensor_device_attribute *a;
42391 + sensor_device_attribute_no_const *a;
42392
42393 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
42394 if (!boolean)
42395 @@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
42396 bool update, bool readonly)
42397 {
42398 struct pmbus_sensor *sensor;
42399 - struct device_attribute *a;
42400 + device_attribute_no_const *a;
42401
42402 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
42403 if (!sensor)
42404 @@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
42405 const char *lstring, int index)
42406 {
42407 struct pmbus_label *label;
42408 - struct device_attribute *a;
42409 + device_attribute_no_const *a;
42410
42411 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
42412 if (!label)
42413 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
42414 index 97cd45a..ac54d8b 100644
42415 --- a/drivers/hwmon/sht15.c
42416 +++ b/drivers/hwmon/sht15.c
42417 @@ -169,7 +169,7 @@ struct sht15_data {
42418 int supply_uv;
42419 bool supply_uv_valid;
42420 struct work_struct update_supply_work;
42421 - atomic_t interrupt_handled;
42422 + atomic_unchecked_t interrupt_handled;
42423 };
42424
42425 /**
42426 @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
42427 ret = gpio_direction_input(data->pdata->gpio_data);
42428 if (ret)
42429 return ret;
42430 - atomic_set(&data->interrupt_handled, 0);
42431 + atomic_set_unchecked(&data->interrupt_handled, 0);
42432
42433 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42434 if (gpio_get_value(data->pdata->gpio_data) == 0) {
42435 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
42436 /* Only relevant if the interrupt hasn't occurred. */
42437 - if (!atomic_read(&data->interrupt_handled))
42438 + if (!atomic_read_unchecked(&data->interrupt_handled))
42439 schedule_work(&data->read_work);
42440 }
42441 ret = wait_event_timeout(data->wait_queue,
42442 @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
42443
42444 /* First disable the interrupt */
42445 disable_irq_nosync(irq);
42446 - atomic_inc(&data->interrupt_handled);
42447 + atomic_inc_unchecked(&data->interrupt_handled);
42448 /* Then schedule a reading work struct */
42449 if (data->state != SHT15_READING_NOTHING)
42450 schedule_work(&data->read_work);
42451 @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
42452 * If not, then start the interrupt again - care here as could
42453 * have gone low in meantime so verify it hasn't!
42454 */
42455 - atomic_set(&data->interrupt_handled, 0);
42456 + atomic_set_unchecked(&data->interrupt_handled, 0);
42457 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42458 /* If still not occurred or another handler was scheduled */
42459 if (gpio_get_value(data->pdata->gpio_data)
42460 - || atomic_read(&data->interrupt_handled))
42461 + || atomic_read_unchecked(&data->interrupt_handled))
42462 return;
42463 }
42464
42465 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
42466 index 8df43c5..b07b91d 100644
42467 --- a/drivers/hwmon/via-cputemp.c
42468 +++ b/drivers/hwmon/via-cputemp.c
42469 @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
42470 return NOTIFY_OK;
42471 }
42472
42473 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
42474 +static struct notifier_block via_cputemp_cpu_notifier = {
42475 .notifier_call = via_cputemp_cpu_callback,
42476 };
42477
42478 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
42479 index 65e3240..e6c511d 100644
42480 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
42481 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
42482 @@ -39,7 +39,7 @@
42483 extern struct i2c_adapter amd756_smbus;
42484
42485 static struct i2c_adapter *s4882_adapter;
42486 -static struct i2c_algorithm *s4882_algo;
42487 +static i2c_algorithm_no_const *s4882_algo;
42488
42489 /* Wrapper access functions for multiplexed SMBus */
42490 static DEFINE_MUTEX(amd756_lock);
42491 diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
42492 index b19a310..d6eece0 100644
42493 --- a/drivers/i2c/busses/i2c-diolan-u2c.c
42494 +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
42495 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
42496 /* usb layer */
42497
42498 /* Send command to device, and get response. */
42499 -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42500 +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42501 {
42502 int ret = 0;
42503 int actual;
42504 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
42505 index 88eda09..cf40434 100644
42506 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
42507 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
42508 @@ -37,7 +37,7 @@
42509 extern struct i2c_adapter *nforce2_smbus;
42510
42511 static struct i2c_adapter *s4985_adapter;
42512 -static struct i2c_algorithm *s4985_algo;
42513 +static i2c_algorithm_no_const *s4985_algo;
42514
42515 /* Wrapper access functions for multiplexed SMBus */
42516 static DEFINE_MUTEX(nforce2_lock);
42517 diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
42518 index 71c7a39..71dd3e0 100644
42519 --- a/drivers/i2c/i2c-dev.c
42520 +++ b/drivers/i2c/i2c-dev.c
42521 @@ -272,7 +272,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
42522 break;
42523 }
42524
42525 - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
42526 + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
42527 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
42528 if (IS_ERR(rdwr_pa[i].buf)) {
42529 res = PTR_ERR(rdwr_pa[i].buf);
42530 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
42531 index 0b510ba..4fbb5085 100644
42532 --- a/drivers/ide/ide-cd.c
42533 +++ b/drivers/ide/ide-cd.c
42534 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
42535 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
42536 if ((unsigned long)buf & alignment
42537 || blk_rq_bytes(rq) & q->dma_pad_mask
42538 - || object_is_on_stack(buf))
42539 + || object_starts_on_stack(buf))
42540 drive->dma = 0;
42541 }
42542 }
42543 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
42544 index af3e76d..96dfe5e 100644
42545 --- a/drivers/iio/industrialio-core.c
42546 +++ b/drivers/iio/industrialio-core.c
42547 @@ -555,7 +555,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
42548 }
42549
42550 static
42551 -int __iio_device_attr_init(struct device_attribute *dev_attr,
42552 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
42553 const char *postfix,
42554 struct iio_chan_spec const *chan,
42555 ssize_t (*readfunc)(struct device *dev,
42556 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
42557 index e28a494..f7c2671 100644
42558 --- a/drivers/infiniband/core/cm.c
42559 +++ b/drivers/infiniband/core/cm.c
42560 @@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
42561
42562 struct cm_counter_group {
42563 struct kobject obj;
42564 - atomic_long_t counter[CM_ATTR_COUNT];
42565 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
42566 };
42567
42568 struct cm_counter_attribute {
42569 @@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
42570 struct ib_mad_send_buf *msg = NULL;
42571 int ret;
42572
42573 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42574 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42575 counter[CM_REQ_COUNTER]);
42576
42577 /* Quick state check to discard duplicate REQs. */
42578 @@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
42579 if (!cm_id_priv)
42580 return;
42581
42582 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42583 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42584 counter[CM_REP_COUNTER]);
42585 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
42586 if (ret)
42587 @@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
42588 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
42589 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
42590 spin_unlock_irq(&cm_id_priv->lock);
42591 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42592 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42593 counter[CM_RTU_COUNTER]);
42594 goto out;
42595 }
42596 @@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
42597 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
42598 dreq_msg->local_comm_id);
42599 if (!cm_id_priv) {
42600 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42601 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42602 counter[CM_DREQ_COUNTER]);
42603 cm_issue_drep(work->port, work->mad_recv_wc);
42604 return -EINVAL;
42605 @@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
42606 case IB_CM_MRA_REP_RCVD:
42607 break;
42608 case IB_CM_TIMEWAIT:
42609 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42610 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42611 counter[CM_DREQ_COUNTER]);
42612 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42613 goto unlock;
42614 @@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
42615 cm_free_msg(msg);
42616 goto deref;
42617 case IB_CM_DREQ_RCVD:
42618 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42619 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42620 counter[CM_DREQ_COUNTER]);
42621 goto unlock;
42622 default:
42623 @@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
42624 ib_modify_mad(cm_id_priv->av.port->mad_agent,
42625 cm_id_priv->msg, timeout)) {
42626 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
42627 - atomic_long_inc(&work->port->
42628 + atomic_long_inc_unchecked(&work->port->
42629 counter_group[CM_RECV_DUPLICATES].
42630 counter[CM_MRA_COUNTER]);
42631 goto out;
42632 @@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
42633 break;
42634 case IB_CM_MRA_REQ_RCVD:
42635 case IB_CM_MRA_REP_RCVD:
42636 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42637 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42638 counter[CM_MRA_COUNTER]);
42639 /* fall through */
42640 default:
42641 @@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
42642 case IB_CM_LAP_IDLE:
42643 break;
42644 case IB_CM_MRA_LAP_SENT:
42645 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42646 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42647 counter[CM_LAP_COUNTER]);
42648 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42649 goto unlock;
42650 @@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
42651 cm_free_msg(msg);
42652 goto deref;
42653 case IB_CM_LAP_RCVD:
42654 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42655 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42656 counter[CM_LAP_COUNTER]);
42657 goto unlock;
42658 default:
42659 @@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
42660 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
42661 if (cur_cm_id_priv) {
42662 spin_unlock_irq(&cm.lock);
42663 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42664 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42665 counter[CM_SIDR_REQ_COUNTER]);
42666 goto out; /* Duplicate message. */
42667 }
42668 @@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42669 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42670 msg->retries = 1;
42671
42672 - atomic_long_add(1 + msg->retries,
42673 + atomic_long_add_unchecked(1 + msg->retries,
42674 &port->counter_group[CM_XMIT].counter[attr_index]);
42675 if (msg->retries)
42676 - atomic_long_add(msg->retries,
42677 + atomic_long_add_unchecked(msg->retries,
42678 &port->counter_group[CM_XMIT_RETRIES].
42679 counter[attr_index]);
42680
42681 @@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42682 }
42683
42684 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42685 - atomic_long_inc(&port->counter_group[CM_RECV].
42686 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42687 counter[attr_id - CM_ATTR_ID_OFFSET]);
42688
42689 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42690 @@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42691 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42692
42693 return sprintf(buf, "%ld\n",
42694 - atomic_long_read(&group->counter[cm_attr->index]));
42695 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42696 }
42697
42698 static const struct sysfs_ops cm_counter_ops = {
42699 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42700 index 9f5ad7c..588cd84 100644
42701 --- a/drivers/infiniband/core/fmr_pool.c
42702 +++ b/drivers/infiniband/core/fmr_pool.c
42703 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
42704
42705 struct task_struct *thread;
42706
42707 - atomic_t req_ser;
42708 - atomic_t flush_ser;
42709 + atomic_unchecked_t req_ser;
42710 + atomic_unchecked_t flush_ser;
42711
42712 wait_queue_head_t force_wait;
42713 };
42714 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42715 struct ib_fmr_pool *pool = pool_ptr;
42716
42717 do {
42718 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42719 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42720 ib_fmr_batch_release(pool);
42721
42722 - atomic_inc(&pool->flush_ser);
42723 + atomic_inc_unchecked(&pool->flush_ser);
42724 wake_up_interruptible(&pool->force_wait);
42725
42726 if (pool->flush_function)
42727 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42728 }
42729
42730 set_current_state(TASK_INTERRUPTIBLE);
42731 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42732 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42733 !kthread_should_stop())
42734 schedule();
42735 __set_current_state(TASK_RUNNING);
42736 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42737 pool->dirty_watermark = params->dirty_watermark;
42738 pool->dirty_len = 0;
42739 spin_lock_init(&pool->pool_lock);
42740 - atomic_set(&pool->req_ser, 0);
42741 - atomic_set(&pool->flush_ser, 0);
42742 + atomic_set_unchecked(&pool->req_ser, 0);
42743 + atomic_set_unchecked(&pool->flush_ser, 0);
42744 init_waitqueue_head(&pool->force_wait);
42745
42746 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42747 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42748 }
42749 spin_unlock_irq(&pool->pool_lock);
42750
42751 - serial = atomic_inc_return(&pool->req_ser);
42752 + serial = atomic_inc_return_unchecked(&pool->req_ser);
42753 wake_up_process(pool->thread);
42754
42755 if (wait_event_interruptible(pool->force_wait,
42756 - atomic_read(&pool->flush_ser) - serial >= 0))
42757 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42758 return -EINTR;
42759
42760 return 0;
42761 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42762 } else {
42763 list_add_tail(&fmr->list, &pool->dirty_list);
42764 if (++pool->dirty_len >= pool->dirty_watermark) {
42765 - atomic_inc(&pool->req_ser);
42766 + atomic_inc_unchecked(&pool->req_ser);
42767 wake_up_process(pool->thread);
42768 }
42769 }
42770 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42771 index ec7a298..8742e59 100644
42772 --- a/drivers/infiniband/hw/cxgb4/mem.c
42773 +++ b/drivers/infiniband/hw/cxgb4/mem.c
42774 @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42775 int err;
42776 struct fw_ri_tpte tpt;
42777 u32 stag_idx;
42778 - static atomic_t key;
42779 + static atomic_unchecked_t key;
42780
42781 if (c4iw_fatal_error(rdev))
42782 return -EIO;
42783 @@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42784 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42785 rdev->stats.stag.max = rdev->stats.stag.cur;
42786 mutex_unlock(&rdev->stats.lock);
42787 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42788 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42789 }
42790 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42791 __func__, stag_state, type, pdid, stag_idx);
42792 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42793 index 79b3dbc..96e5fcc 100644
42794 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
42795 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42796 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42797 struct ib_atomic_eth *ateth;
42798 struct ipath_ack_entry *e;
42799 u64 vaddr;
42800 - atomic64_t *maddr;
42801 + atomic64_unchecked_t *maddr;
42802 u64 sdata;
42803 u32 rkey;
42804 u8 next;
42805 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42806 IB_ACCESS_REMOTE_ATOMIC)))
42807 goto nack_acc_unlck;
42808 /* Perform atomic OP and save result. */
42809 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42810 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42811 sdata = be64_to_cpu(ateth->swap_data);
42812 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42813 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42814 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42815 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42816 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42817 be64_to_cpu(ateth->compare_data),
42818 sdata);
42819 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42820 index 1f95bba..9530f87 100644
42821 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42822 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42823 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42824 unsigned long flags;
42825 struct ib_wc wc;
42826 u64 sdata;
42827 - atomic64_t *maddr;
42828 + atomic64_unchecked_t *maddr;
42829 enum ib_wc_status send_status;
42830
42831 /*
42832 @@ -382,11 +382,11 @@ again:
42833 IB_ACCESS_REMOTE_ATOMIC)))
42834 goto acc_err;
42835 /* Perform atomic OP and save result. */
42836 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42837 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42838 sdata = wqe->wr.wr.atomic.compare_add;
42839 *(u64 *) sqp->s_sge.sge.vaddr =
42840 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42841 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42842 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42843 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42844 sdata, wqe->wr.wr.atomic.swap);
42845 goto send_comp;
42846 diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42847 index 82a7dd8..8fb6ba6 100644
42848 --- a/drivers/infiniband/hw/mlx4/mad.c
42849 +++ b/drivers/infiniband/hw/mlx4/mad.c
42850 @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42851
42852 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42853 {
42854 - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42855 + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42856 cpu_to_be64(0xff00000000000000LL);
42857 }
42858
42859 diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42860 index ed327e6..ca1739e0 100644
42861 --- a/drivers/infiniband/hw/mlx4/mcg.c
42862 +++ b/drivers/infiniband/hw/mlx4/mcg.c
42863 @@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42864 {
42865 char name[20];
42866
42867 - atomic_set(&ctx->tid, 0);
42868 + atomic_set_unchecked(&ctx->tid, 0);
42869 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42870 ctx->mcg_wq = create_singlethread_workqueue(name);
42871 if (!ctx->mcg_wq)
42872 diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42873 index 6eb743f..a7b0f6d 100644
42874 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42875 +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42876 @@ -426,7 +426,7 @@ struct mlx4_ib_demux_ctx {
42877 struct list_head mcg_mgid0_list;
42878 struct workqueue_struct *mcg_wq;
42879 struct mlx4_ib_demux_pv_ctx **tun;
42880 - atomic_t tid;
42881 + atomic_unchecked_t tid;
42882 int flushing; /* flushing the work queue */
42883 };
42884
42885 diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42886 index 9d3e5c1..6f166df 100644
42887 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42888 +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42889 @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42890 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42891 }
42892
42893 -int mthca_QUERY_FW(struct mthca_dev *dev)
42894 +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42895 {
42896 struct mthca_mailbox *mailbox;
42897 u32 *outbox;
42898 @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42899 CMD_TIME_CLASS_B);
42900 }
42901
42902 -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42903 +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42904 int num_mtt)
42905 {
42906 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42907 @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42908 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42909 }
42910
42911 -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42912 +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42913 int eq_num)
42914 {
42915 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42916 @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42917 CMD_TIME_CLASS_B);
42918 }
42919
42920 -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42921 +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42922 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42923 void *in_mad, void *response_mad)
42924 {
42925 diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42926 index ded76c1..0cf0a08 100644
42927 --- a/drivers/infiniband/hw/mthca/mthca_main.c
42928 +++ b/drivers/infiniband/hw/mthca/mthca_main.c
42929 @@ -692,7 +692,7 @@ err_close:
42930 return err;
42931 }
42932
42933 -static int mthca_setup_hca(struct mthca_dev *dev)
42934 +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42935 {
42936 int err;
42937
42938 diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42939 index ed9a989..6aa5dc2 100644
42940 --- a/drivers/infiniband/hw/mthca/mthca_mr.c
42941 +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42942 @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42943 * through the bitmaps)
42944 */
42945
42946 -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42947 +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42948 {
42949 int o;
42950 int m;
42951 @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42952 return key;
42953 }
42954
42955 -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42956 +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42957 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42958 {
42959 struct mthca_mailbox *mailbox;
42960 @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42961 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42962 }
42963
42964 -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42965 +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42966 u64 *buffer_list, int buffer_size_shift,
42967 int list_len, u64 iova, u64 total_size,
42968 u32 access, struct mthca_mr *mr)
42969 diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42970 index 415f8e1..e34214e 100644
42971 --- a/drivers/infiniband/hw/mthca/mthca_provider.c
42972 +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42973 @@ -764,7 +764,7 @@ unlock:
42974 return 0;
42975 }
42976
42977 -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42978 +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42979 {
42980 struct mthca_dev *dev = to_mdev(ibcq->device);
42981 struct mthca_cq *cq = to_mcq(ibcq);
42982 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42983 index 3b2a6dc..bce26ff 100644
42984 --- a/drivers/infiniband/hw/nes/nes.c
42985 +++ b/drivers/infiniband/hw/nes/nes.c
42986 @@ -97,7 +97,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
42987 LIST_HEAD(nes_adapter_list);
42988 static LIST_HEAD(nes_dev_list);
42989
42990 -atomic_t qps_destroyed;
42991 +atomic_unchecked_t qps_destroyed;
42992
42993 static unsigned int ee_flsh_adapter;
42994 static unsigned int sysfs_nonidx_addr;
42995 @@ -278,7 +278,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
42996 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
42997 struct nes_adapter *nesadapter = nesdev->nesadapter;
42998
42999 - atomic_inc(&qps_destroyed);
43000 + atomic_inc_unchecked(&qps_destroyed);
43001
43002 /* Free the control structures */
43003
43004 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
43005 index bd9d132..70d84f4 100644
43006 --- a/drivers/infiniband/hw/nes/nes.h
43007 +++ b/drivers/infiniband/hw/nes/nes.h
43008 @@ -180,17 +180,17 @@ extern unsigned int nes_debug_level;
43009 extern unsigned int wqm_quanta;
43010 extern struct list_head nes_adapter_list;
43011
43012 -extern atomic_t cm_connects;
43013 -extern atomic_t cm_accepts;
43014 -extern atomic_t cm_disconnects;
43015 -extern atomic_t cm_closes;
43016 -extern atomic_t cm_connecteds;
43017 -extern atomic_t cm_connect_reqs;
43018 -extern atomic_t cm_rejects;
43019 -extern atomic_t mod_qp_timouts;
43020 -extern atomic_t qps_created;
43021 -extern atomic_t qps_destroyed;
43022 -extern atomic_t sw_qps_destroyed;
43023 +extern atomic_unchecked_t cm_connects;
43024 +extern atomic_unchecked_t cm_accepts;
43025 +extern atomic_unchecked_t cm_disconnects;
43026 +extern atomic_unchecked_t cm_closes;
43027 +extern atomic_unchecked_t cm_connecteds;
43028 +extern atomic_unchecked_t cm_connect_reqs;
43029 +extern atomic_unchecked_t cm_rejects;
43030 +extern atomic_unchecked_t mod_qp_timouts;
43031 +extern atomic_unchecked_t qps_created;
43032 +extern atomic_unchecked_t qps_destroyed;
43033 +extern atomic_unchecked_t sw_qps_destroyed;
43034 extern u32 mh_detected;
43035 extern u32 mh_pauses_sent;
43036 extern u32 cm_packets_sent;
43037 @@ -199,16 +199,16 @@ extern u32 cm_packets_created;
43038 extern u32 cm_packets_received;
43039 extern u32 cm_packets_dropped;
43040 extern u32 cm_packets_retrans;
43041 -extern atomic_t cm_listens_created;
43042 -extern atomic_t cm_listens_destroyed;
43043 +extern atomic_unchecked_t cm_listens_created;
43044 +extern atomic_unchecked_t cm_listens_destroyed;
43045 extern u32 cm_backlog_drops;
43046 -extern atomic_t cm_loopbacks;
43047 -extern atomic_t cm_nodes_created;
43048 -extern atomic_t cm_nodes_destroyed;
43049 -extern atomic_t cm_accel_dropped_pkts;
43050 -extern atomic_t cm_resets_recvd;
43051 -extern atomic_t pau_qps_created;
43052 -extern atomic_t pau_qps_destroyed;
43053 +extern atomic_unchecked_t cm_loopbacks;
43054 +extern atomic_unchecked_t cm_nodes_created;
43055 +extern atomic_unchecked_t cm_nodes_destroyed;
43056 +extern atomic_unchecked_t cm_accel_dropped_pkts;
43057 +extern atomic_unchecked_t cm_resets_recvd;
43058 +extern atomic_unchecked_t pau_qps_created;
43059 +extern atomic_unchecked_t pau_qps_destroyed;
43060
43061 extern u32 int_mod_timer_init;
43062 extern u32 int_mod_cq_depth_256;
43063 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
43064 index 6f09a72..cf4399d 100644
43065 --- a/drivers/infiniband/hw/nes/nes_cm.c
43066 +++ b/drivers/infiniband/hw/nes/nes_cm.c
43067 @@ -69,14 +69,14 @@ u32 cm_packets_dropped;
43068 u32 cm_packets_retrans;
43069 u32 cm_packets_created;
43070 u32 cm_packets_received;
43071 -atomic_t cm_listens_created;
43072 -atomic_t cm_listens_destroyed;
43073 +atomic_unchecked_t cm_listens_created;
43074 +atomic_unchecked_t cm_listens_destroyed;
43075 u32 cm_backlog_drops;
43076 -atomic_t cm_loopbacks;
43077 -atomic_t cm_nodes_created;
43078 -atomic_t cm_nodes_destroyed;
43079 -atomic_t cm_accel_dropped_pkts;
43080 -atomic_t cm_resets_recvd;
43081 +atomic_unchecked_t cm_loopbacks;
43082 +atomic_unchecked_t cm_nodes_created;
43083 +atomic_unchecked_t cm_nodes_destroyed;
43084 +atomic_unchecked_t cm_accel_dropped_pkts;
43085 +atomic_unchecked_t cm_resets_recvd;
43086
43087 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
43088 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
43089 @@ -135,28 +135,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
43090 /* instance of function pointers for client API */
43091 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
43092 static struct nes_cm_ops nes_cm_api = {
43093 - mini_cm_accelerated,
43094 - mini_cm_listen,
43095 - mini_cm_del_listen,
43096 - mini_cm_connect,
43097 - mini_cm_close,
43098 - mini_cm_accept,
43099 - mini_cm_reject,
43100 - mini_cm_recv_pkt,
43101 - mini_cm_dealloc_core,
43102 - mini_cm_get,
43103 - mini_cm_set
43104 + .accelerated = mini_cm_accelerated,
43105 + .listen = mini_cm_listen,
43106 + .stop_listener = mini_cm_del_listen,
43107 + .connect = mini_cm_connect,
43108 + .close = mini_cm_close,
43109 + .accept = mini_cm_accept,
43110 + .reject = mini_cm_reject,
43111 + .recv_pkt = mini_cm_recv_pkt,
43112 + .destroy_cm_core = mini_cm_dealloc_core,
43113 + .get = mini_cm_get,
43114 + .set = mini_cm_set
43115 };
43116
43117 static struct nes_cm_core *g_cm_core;
43118
43119 -atomic_t cm_connects;
43120 -atomic_t cm_accepts;
43121 -atomic_t cm_disconnects;
43122 -atomic_t cm_closes;
43123 -atomic_t cm_connecteds;
43124 -atomic_t cm_connect_reqs;
43125 -atomic_t cm_rejects;
43126 +atomic_unchecked_t cm_connects;
43127 +atomic_unchecked_t cm_accepts;
43128 +atomic_unchecked_t cm_disconnects;
43129 +atomic_unchecked_t cm_closes;
43130 +atomic_unchecked_t cm_connecteds;
43131 +atomic_unchecked_t cm_connect_reqs;
43132 +atomic_unchecked_t cm_rejects;
43133
43134 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
43135 {
43136 @@ -1436,7 +1436,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
43137 kfree(listener);
43138 listener = NULL;
43139 ret = 0;
43140 - atomic_inc(&cm_listens_destroyed);
43141 + atomic_inc_unchecked(&cm_listens_destroyed);
43142 } else {
43143 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
43144 }
43145 @@ -1637,7 +1637,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
43146 cm_node->rem_mac);
43147
43148 add_hte_node(cm_core, cm_node);
43149 - atomic_inc(&cm_nodes_created);
43150 + atomic_inc_unchecked(&cm_nodes_created);
43151
43152 return cm_node;
43153 }
43154 @@ -1698,7 +1698,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
43155 }
43156
43157 atomic_dec(&cm_core->node_cnt);
43158 - atomic_inc(&cm_nodes_destroyed);
43159 + atomic_inc_unchecked(&cm_nodes_destroyed);
43160 nesqp = cm_node->nesqp;
43161 if (nesqp) {
43162 nesqp->cm_node = NULL;
43163 @@ -1762,7 +1762,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
43164
43165 static void drop_packet(struct sk_buff *skb)
43166 {
43167 - atomic_inc(&cm_accel_dropped_pkts);
43168 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
43169 dev_kfree_skb_any(skb);
43170 }
43171
43172 @@ -1825,7 +1825,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
43173 {
43174
43175 int reset = 0; /* whether to send reset in case of err.. */
43176 - atomic_inc(&cm_resets_recvd);
43177 + atomic_inc_unchecked(&cm_resets_recvd);
43178 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
43179 " refcnt=%d\n", cm_node, cm_node->state,
43180 atomic_read(&cm_node->ref_count));
43181 @@ -2492,7 +2492,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
43182 rem_ref_cm_node(cm_node->cm_core, cm_node);
43183 return NULL;
43184 }
43185 - atomic_inc(&cm_loopbacks);
43186 + atomic_inc_unchecked(&cm_loopbacks);
43187 loopbackremotenode->loopbackpartner = cm_node;
43188 loopbackremotenode->tcp_cntxt.rcv_wscale =
43189 NES_CM_DEFAULT_RCV_WND_SCALE;
43190 @@ -2773,7 +2773,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
43191 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
43192 else {
43193 rem_ref_cm_node(cm_core, cm_node);
43194 - atomic_inc(&cm_accel_dropped_pkts);
43195 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
43196 dev_kfree_skb_any(skb);
43197 }
43198 break;
43199 @@ -3081,7 +3081,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43200
43201 if ((cm_id) && (cm_id->event_handler)) {
43202 if (issue_disconn) {
43203 - atomic_inc(&cm_disconnects);
43204 + atomic_inc_unchecked(&cm_disconnects);
43205 cm_event.event = IW_CM_EVENT_DISCONNECT;
43206 cm_event.status = disconn_status;
43207 cm_event.local_addr = cm_id->local_addr;
43208 @@ -3103,7 +3103,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43209 }
43210
43211 if (issue_close) {
43212 - atomic_inc(&cm_closes);
43213 + atomic_inc_unchecked(&cm_closes);
43214 nes_disconnect(nesqp, 1);
43215
43216 cm_id->provider_data = nesqp;
43217 @@ -3241,7 +3241,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43218
43219 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
43220 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
43221 - atomic_inc(&cm_accepts);
43222 + atomic_inc_unchecked(&cm_accepts);
43223
43224 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
43225 netdev_refcnt_read(nesvnic->netdev));
43226 @@ -3439,7 +3439,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
43227 struct nes_cm_core *cm_core;
43228 u8 *start_buff;
43229
43230 - atomic_inc(&cm_rejects);
43231 + atomic_inc_unchecked(&cm_rejects);
43232 cm_node = (struct nes_cm_node *)cm_id->provider_data;
43233 loopback = cm_node->loopbackpartner;
43234 cm_core = cm_node->cm_core;
43235 @@ -3504,7 +3504,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43236 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
43237 ntohs(laddr->sin_port));
43238
43239 - atomic_inc(&cm_connects);
43240 + atomic_inc_unchecked(&cm_connects);
43241 nesqp->active_conn = 1;
43242
43243 /* cache the cm_id in the qp */
43244 @@ -3649,7 +3649,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
43245 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
43246 return err;
43247 }
43248 - atomic_inc(&cm_listens_created);
43249 + atomic_inc_unchecked(&cm_listens_created);
43250 }
43251
43252 cm_id->add_ref(cm_id);
43253 @@ -3756,7 +3756,7 @@ static void cm_event_connected(struct nes_cm_event *event)
43254
43255 if (nesqp->destroyed)
43256 return;
43257 - atomic_inc(&cm_connecteds);
43258 + atomic_inc_unchecked(&cm_connecteds);
43259 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
43260 " local port 0x%04X. jiffies = %lu.\n",
43261 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
43262 @@ -3941,7 +3941,7 @@ static void cm_event_reset(struct nes_cm_event *event)
43263
43264 cm_id->add_ref(cm_id);
43265 ret = cm_id->event_handler(cm_id, &cm_event);
43266 - atomic_inc(&cm_closes);
43267 + atomic_inc_unchecked(&cm_closes);
43268 cm_event.event = IW_CM_EVENT_CLOSE;
43269 cm_event.status = 0;
43270 cm_event.provider_data = cm_id->provider_data;
43271 @@ -3981,7 +3981,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
43272 return;
43273 cm_id = cm_node->cm_id;
43274
43275 - atomic_inc(&cm_connect_reqs);
43276 + atomic_inc_unchecked(&cm_connect_reqs);
43277 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43278 cm_node, cm_id, jiffies);
43279
43280 @@ -4030,7 +4030,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
43281 return;
43282 cm_id = cm_node->cm_id;
43283
43284 - atomic_inc(&cm_connect_reqs);
43285 + atomic_inc_unchecked(&cm_connect_reqs);
43286 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43287 cm_node, cm_id, jiffies);
43288
43289 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
43290 index 4166452..fc952c3 100644
43291 --- a/drivers/infiniband/hw/nes/nes_mgt.c
43292 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
43293 @@ -40,8 +40,8 @@
43294 #include "nes.h"
43295 #include "nes_mgt.h"
43296
43297 -atomic_t pau_qps_created;
43298 -atomic_t pau_qps_destroyed;
43299 +atomic_unchecked_t pau_qps_created;
43300 +atomic_unchecked_t pau_qps_destroyed;
43301
43302 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
43303 {
43304 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
43305 {
43306 struct sk_buff *skb;
43307 unsigned long flags;
43308 - atomic_inc(&pau_qps_destroyed);
43309 + atomic_inc_unchecked(&pau_qps_destroyed);
43310
43311 /* Free packets that have not yet been forwarded */
43312 /* Lock is acquired by skb_dequeue when removing the skb */
43313 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
43314 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
43315 skb_queue_head_init(&nesqp->pau_list);
43316 spin_lock_init(&nesqp->pau_lock);
43317 - atomic_inc(&pau_qps_created);
43318 + atomic_inc_unchecked(&pau_qps_created);
43319 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
43320 }
43321
43322 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
43323 index 49eb511..a774366 100644
43324 --- a/drivers/infiniband/hw/nes/nes_nic.c
43325 +++ b/drivers/infiniband/hw/nes/nes_nic.c
43326 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
43327 target_stat_values[++index] = mh_detected;
43328 target_stat_values[++index] = mh_pauses_sent;
43329 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
43330 - target_stat_values[++index] = atomic_read(&cm_connects);
43331 - target_stat_values[++index] = atomic_read(&cm_accepts);
43332 - target_stat_values[++index] = atomic_read(&cm_disconnects);
43333 - target_stat_values[++index] = atomic_read(&cm_connecteds);
43334 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
43335 - target_stat_values[++index] = atomic_read(&cm_rejects);
43336 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
43337 - target_stat_values[++index] = atomic_read(&qps_created);
43338 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
43339 - target_stat_values[++index] = atomic_read(&qps_destroyed);
43340 - target_stat_values[++index] = atomic_read(&cm_closes);
43341 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
43342 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
43343 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
43344 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
43345 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
43346 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
43347 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
43348 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
43349 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
43350 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
43351 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
43352 target_stat_values[++index] = cm_packets_sent;
43353 target_stat_values[++index] = cm_packets_bounced;
43354 target_stat_values[++index] = cm_packets_created;
43355 target_stat_values[++index] = cm_packets_received;
43356 target_stat_values[++index] = cm_packets_dropped;
43357 target_stat_values[++index] = cm_packets_retrans;
43358 - target_stat_values[++index] = atomic_read(&cm_listens_created);
43359 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
43360 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
43361 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
43362 target_stat_values[++index] = cm_backlog_drops;
43363 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
43364 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
43365 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
43366 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
43367 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
43368 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
43369 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
43370 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
43371 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
43372 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
43373 target_stat_values[++index] = nesadapter->free_4kpbl;
43374 target_stat_values[++index] = nesadapter->free_256pbl;
43375 target_stat_values[++index] = int_mod_timer_init;
43376 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
43377 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
43378 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
43379 - target_stat_values[++index] = atomic_read(&pau_qps_created);
43380 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
43381 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
43382 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
43383 }
43384
43385 /**
43386 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
43387 index fef067c..6a25ccd 100644
43388 --- a/drivers/infiniband/hw/nes/nes_verbs.c
43389 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
43390 @@ -46,9 +46,9 @@
43391
43392 #include <rdma/ib_umem.h>
43393
43394 -atomic_t mod_qp_timouts;
43395 -atomic_t qps_created;
43396 -atomic_t sw_qps_destroyed;
43397 +atomic_unchecked_t mod_qp_timouts;
43398 +atomic_unchecked_t qps_created;
43399 +atomic_unchecked_t sw_qps_destroyed;
43400
43401 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
43402
43403 @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
43404 if (init_attr->create_flags)
43405 return ERR_PTR(-EINVAL);
43406
43407 - atomic_inc(&qps_created);
43408 + atomic_inc_unchecked(&qps_created);
43409 switch (init_attr->qp_type) {
43410 case IB_QPT_RC:
43411 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
43412 @@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
43413 struct iw_cm_event cm_event;
43414 int ret = 0;
43415
43416 - atomic_inc(&sw_qps_destroyed);
43417 + atomic_inc_unchecked(&sw_qps_destroyed);
43418 nesqp->destroyed = 1;
43419
43420 /* Blow away the connection if it exists. */
43421 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
43422 index c00ae09..04e91be 100644
43423 --- a/drivers/infiniband/hw/qib/qib.h
43424 +++ b/drivers/infiniband/hw/qib/qib.h
43425 @@ -52,6 +52,7 @@
43426 #include <linux/kref.h>
43427 #include <linux/sched.h>
43428 #include <linux/kthread.h>
43429 +#include <linux/slab.h>
43430
43431 #include "qib_common.h"
43432 #include "qib_verbs.h"
43433 diff --git a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
43434 index cdc7df4..a2fdfdb 100644
43435 --- a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
43436 +++ b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
43437 @@ -156,7 +156,7 @@ static size_t ipoib_get_size(const struct net_device *dev)
43438 nla_total_size(2); /* IFLA_IPOIB_UMCAST */
43439 }
43440
43441 -static struct rtnl_link_ops ipoib_link_ops __read_mostly = {
43442 +static struct rtnl_link_ops ipoib_link_ops = {
43443 .kind = "ipoib",
43444 .maxtype = IFLA_IPOIB_MAX,
43445 .policy = ipoib_policy,
43446 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
43447 index e29c04e..adbf68c 100644
43448 --- a/drivers/input/gameport/gameport.c
43449 +++ b/drivers/input/gameport/gameport.c
43450 @@ -527,14 +527,14 @@ EXPORT_SYMBOL(gameport_set_phys);
43451 */
43452 static void gameport_init_port(struct gameport *gameport)
43453 {
43454 - static atomic_t gameport_no = ATOMIC_INIT(0);
43455 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
43456
43457 __module_get(THIS_MODULE);
43458
43459 mutex_init(&gameport->drv_mutex);
43460 device_initialize(&gameport->dev);
43461 dev_set_name(&gameport->dev, "gameport%lu",
43462 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
43463 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
43464 gameport->dev.bus = &gameport_bus;
43465 gameport->dev.release = gameport_release_port;
43466 if (gameport->parent)
43467 diff --git a/drivers/input/input.c b/drivers/input/input.c
43468 index 0f175f5..4c481c0 100644
43469 --- a/drivers/input/input.c
43470 +++ b/drivers/input/input.c
43471 @@ -1775,7 +1775,7 @@ EXPORT_SYMBOL_GPL(input_class);
43472 */
43473 struct input_dev *input_allocate_device(void)
43474 {
43475 - static atomic_t input_no = ATOMIC_INIT(0);
43476 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
43477 struct input_dev *dev;
43478
43479 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
43480 @@ -1790,7 +1790,7 @@ struct input_dev *input_allocate_device(void)
43481 INIT_LIST_HEAD(&dev->node);
43482
43483 dev_set_name(&dev->dev, "input%lu",
43484 - (unsigned long) atomic_inc_return(&input_no) - 1);
43485 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
43486
43487 __module_get(THIS_MODULE);
43488 }
43489 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
43490 index 4a95b22..874c182 100644
43491 --- a/drivers/input/joystick/sidewinder.c
43492 +++ b/drivers/input/joystick/sidewinder.c
43493 @@ -30,6 +30,7 @@
43494 #include <linux/kernel.h>
43495 #include <linux/module.h>
43496 #include <linux/slab.h>
43497 +#include <linux/sched.h>
43498 #include <linux/input.h>
43499 #include <linux/gameport.h>
43500 #include <linux/jiffies.h>
43501 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
43502 index fc55f0d..11e2aa6 100644
43503 --- a/drivers/input/joystick/xpad.c
43504 +++ b/drivers/input/joystick/xpad.c
43505 @@ -886,7 +886,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
43506
43507 static int xpad_led_probe(struct usb_xpad *xpad)
43508 {
43509 - static atomic_t led_seq = ATOMIC_INIT(0);
43510 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
43511 long led_no;
43512 struct xpad_led *led;
43513 struct led_classdev *led_cdev;
43514 @@ -899,7 +899,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
43515 if (!led)
43516 return -ENOMEM;
43517
43518 - led_no = (long)atomic_inc_return(&led_seq) - 1;
43519 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
43520
43521 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
43522 led->xpad = xpad;
43523 diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
43524 index afed8e2..3aa8a18 100644
43525 --- a/drivers/input/misc/ims-pcu.c
43526 +++ b/drivers/input/misc/ims-pcu.c
43527 @@ -1851,7 +1851,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
43528
43529 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43530 {
43531 - static atomic_t device_no = ATOMIC_INIT(0);
43532 + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
43533
43534 const struct ims_pcu_device_info *info;
43535 int error;
43536 @@ -1882,7 +1882,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43537 }
43538
43539 /* Device appears to be operable, complete initialization */
43540 - pcu->device_no = atomic_inc_return(&device_no) - 1;
43541 + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
43542
43543 /*
43544 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
43545 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
43546 index f4cf664..3204fda 100644
43547 --- a/drivers/input/mouse/psmouse.h
43548 +++ b/drivers/input/mouse/psmouse.h
43549 @@ -117,7 +117,7 @@ struct psmouse_attribute {
43550 ssize_t (*set)(struct psmouse *psmouse, void *data,
43551 const char *buf, size_t count);
43552 bool protect;
43553 -};
43554 +} __do_const;
43555 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
43556
43557 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
43558 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
43559 index b604564..3f14ae4 100644
43560 --- a/drivers/input/mousedev.c
43561 +++ b/drivers/input/mousedev.c
43562 @@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
43563
43564 spin_unlock_irq(&client->packet_lock);
43565
43566 - if (copy_to_user(buffer, data, count))
43567 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
43568 return -EFAULT;
43569
43570 return count;
43571 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
43572 index d399b8b..4913ede 100644
43573 --- a/drivers/input/serio/serio.c
43574 +++ b/drivers/input/serio/serio.c
43575 @@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
43576 */
43577 static void serio_init_port(struct serio *serio)
43578 {
43579 - static atomic_t serio_no = ATOMIC_INIT(0);
43580 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
43581
43582 __module_get(THIS_MODULE);
43583
43584 @@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
43585 mutex_init(&serio->drv_mutex);
43586 device_initialize(&serio->dev);
43587 dev_set_name(&serio->dev, "serio%lu",
43588 - (unsigned long)atomic_inc_return(&serio_no) - 1);
43589 + (unsigned long)atomic_inc_return_unchecked(&serio_no) - 1);
43590 serio->dev.bus = &serio_bus;
43591 serio->dev.release = serio_release_port;
43592 serio->dev.groups = serio_device_attr_groups;
43593 diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
43594 index c9a02fe..0debc75 100644
43595 --- a/drivers/input/serio/serio_raw.c
43596 +++ b/drivers/input/serio/serio_raw.c
43597 @@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
43598
43599 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43600 {
43601 - static atomic_t serio_raw_no = ATOMIC_INIT(0);
43602 + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
43603 struct serio_raw *serio_raw;
43604 int err;
43605
43606 @@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43607 }
43608
43609 snprintf(serio_raw->name, sizeof(serio_raw->name),
43610 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
43611 + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
43612 kref_init(&serio_raw->kref);
43613 INIT_LIST_HEAD(&serio_raw->client_list);
43614 init_waitqueue_head(&serio_raw->wait);
43615 diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
43616 index 505a9ad..f0b1b6e 100644
43617 --- a/drivers/iommu/amd_iommu.c
43618 +++ b/drivers/iommu/amd_iommu.c
43619 @@ -823,11 +823,21 @@ static void copy_cmd_to_buffer(struct amd_iommu *iommu,
43620
43621 static void build_completion_wait(struct iommu_cmd *cmd, u64 address)
43622 {
43623 + phys_addr_t physaddr;
43624 WARN_ON(address & 0x7ULL);
43625
43626 memset(cmd, 0, sizeof(*cmd));
43627 - cmd->data[0] = lower_32_bits(__pa(address)) | CMD_COMPL_WAIT_STORE_MASK;
43628 - cmd->data[1] = upper_32_bits(__pa(address));
43629 +
43630 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
43631 + if (object_starts_on_stack(address)) {
43632 + void *adjbuf = (void *)address - current->stack + current->lowmem_stack;
43633 + physaddr = __pa((u64)adjbuf);
43634 + } else
43635 +#endif
43636 + physaddr = __pa(address);
43637 +
43638 + cmd->data[0] = lower_32_bits(physaddr) | CMD_COMPL_WAIT_STORE_MASK;
43639 + cmd->data[1] = upper_32_bits(physaddr);
43640 cmd->data[2] = 1;
43641 CMD_SET_TYPE(cmd, CMD_COMPL_WAIT);
43642 }
43643 diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
43644 index 60558f7..5a02369 100644
43645 --- a/drivers/iommu/arm-smmu.c
43646 +++ b/drivers/iommu/arm-smmu.c
43647 @@ -934,7 +934,7 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain,
43648 cfg->irptndx = cfg->cbndx;
43649 }
43650
43651 - ACCESS_ONCE(smmu_domain->smmu) = smmu;
43652 + ACCESS_ONCE_RW(smmu_domain->smmu) = smmu;
43653 arm_smmu_init_context_bank(smmu_domain);
43654 spin_unlock_irqrestore(&smmu_domain->lock, flags);
43655
43656 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
43657 index ed8b048..7fbcc01 100644
43658 --- a/drivers/iommu/iommu.c
43659 +++ b/drivers/iommu/iommu.c
43660 @@ -802,7 +802,7 @@ static int iommu_bus_notifier(struct notifier_block *nb,
43661 static int iommu_bus_init(struct bus_type *bus, const struct iommu_ops *ops)
43662 {
43663 int err;
43664 - struct notifier_block *nb;
43665 + notifier_block_no_const *nb;
43666 struct iommu_callback_data cb = {
43667 .ops = ops,
43668 };
43669 diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
43670 index 74a1767..5a359e8 100644
43671 --- a/drivers/iommu/irq_remapping.c
43672 +++ b/drivers/iommu/irq_remapping.c
43673 @@ -361,7 +361,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
43674 void panic_if_irq_remap(const char *msg)
43675 {
43676 if (irq_remapping_enabled)
43677 - panic(msg);
43678 + panic("%s", msg);
43679 }
43680
43681 static void ir_ack_apic_edge(struct irq_data *data)
43682 @@ -382,10 +382,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
43683
43684 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43685 {
43686 - chip->irq_print_chip = ir_print_prefix;
43687 - chip->irq_ack = ir_ack_apic_edge;
43688 - chip->irq_eoi = ir_ack_apic_level;
43689 - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43690 + pax_open_kernel();
43691 + *(void **)&chip->irq_print_chip = ir_print_prefix;
43692 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
43693 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
43694 + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43695 + pax_close_kernel();
43696 }
43697
43698 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43699 diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43700 index 38493ff..001538b 100644
43701 --- a/drivers/irqchip/irq-gic.c
43702 +++ b/drivers/irqchip/irq-gic.c
43703 @@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43704 * Supported arch specific GIC irq extension.
43705 * Default make them NULL.
43706 */
43707 -struct irq_chip gic_arch_extn = {
43708 +irq_chip_no_const gic_arch_extn = {
43709 .irq_eoi = NULL,
43710 .irq_mask = NULL,
43711 .irq_unmask = NULL,
43712 @@ -311,7 +311,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43713 chained_irq_exit(chip, desc);
43714 }
43715
43716 -static struct irq_chip gic_chip = {
43717 +static irq_chip_no_const gic_chip __read_only = {
43718 .name = "GIC",
43719 .irq_mask = gic_mask_irq,
43720 .irq_unmask = gic_unmask_irq,
43721 diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
43722 index 8777065..a4a9967 100644
43723 --- a/drivers/irqchip/irq-renesas-irqc.c
43724 +++ b/drivers/irqchip/irq-renesas-irqc.c
43725 @@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
43726 struct irqc_priv *p;
43727 struct resource *io;
43728 struct resource *irq;
43729 - struct irq_chip *irq_chip;
43730 + irq_chip_no_const *irq_chip;
43731 const char *name = dev_name(&pdev->dev);
43732 int ret;
43733 int k;
43734 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43735 index 6a2df32..dc962f1 100644
43736 --- a/drivers/isdn/capi/capi.c
43737 +++ b/drivers/isdn/capi/capi.c
43738 @@ -81,8 +81,8 @@ struct capiminor {
43739
43740 struct capi20_appl *ap;
43741 u32 ncci;
43742 - atomic_t datahandle;
43743 - atomic_t msgid;
43744 + atomic_unchecked_t datahandle;
43745 + atomic_unchecked_t msgid;
43746
43747 struct tty_port port;
43748 int ttyinstop;
43749 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43750 capimsg_setu16(s, 2, mp->ap->applid);
43751 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43752 capimsg_setu8 (s, 5, CAPI_RESP);
43753 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43754 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43755 capimsg_setu32(s, 8, mp->ncci);
43756 capimsg_setu16(s, 12, datahandle);
43757 }
43758 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43759 mp->outbytes -= len;
43760 spin_unlock_bh(&mp->outlock);
43761
43762 - datahandle = atomic_inc_return(&mp->datahandle);
43763 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43764 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43765 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43766 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43767 capimsg_setu16(skb->data, 2, mp->ap->applid);
43768 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43769 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43770 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43771 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43772 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43773 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43774 capimsg_setu16(skb->data, 16, len); /* Data length */
43775 diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43776 index aecec6d..11e13c5 100644
43777 --- a/drivers/isdn/gigaset/bas-gigaset.c
43778 +++ b/drivers/isdn/gigaset/bas-gigaset.c
43779 @@ -2565,22 +2565,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43780
43781
43782 static const struct gigaset_ops gigops = {
43783 - gigaset_write_cmd,
43784 - gigaset_write_room,
43785 - gigaset_chars_in_buffer,
43786 - gigaset_brkchars,
43787 - gigaset_init_bchannel,
43788 - gigaset_close_bchannel,
43789 - gigaset_initbcshw,
43790 - gigaset_freebcshw,
43791 - gigaset_reinitbcshw,
43792 - gigaset_initcshw,
43793 - gigaset_freecshw,
43794 - gigaset_set_modem_ctrl,
43795 - gigaset_baud_rate,
43796 - gigaset_set_line_ctrl,
43797 - gigaset_isoc_send_skb,
43798 - gigaset_isoc_input,
43799 + .write_cmd = gigaset_write_cmd,
43800 + .write_room = gigaset_write_room,
43801 + .chars_in_buffer = gigaset_chars_in_buffer,
43802 + .brkchars = gigaset_brkchars,
43803 + .init_bchannel = gigaset_init_bchannel,
43804 + .close_bchannel = gigaset_close_bchannel,
43805 + .initbcshw = gigaset_initbcshw,
43806 + .freebcshw = gigaset_freebcshw,
43807 + .reinitbcshw = gigaset_reinitbcshw,
43808 + .initcshw = gigaset_initcshw,
43809 + .freecshw = gigaset_freecshw,
43810 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43811 + .baud_rate = gigaset_baud_rate,
43812 + .set_line_ctrl = gigaset_set_line_ctrl,
43813 + .send_skb = gigaset_isoc_send_skb,
43814 + .handle_input = gigaset_isoc_input,
43815 };
43816
43817 /* bas_gigaset_init
43818 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43819 index 600c79b..3752bab 100644
43820 --- a/drivers/isdn/gigaset/interface.c
43821 +++ b/drivers/isdn/gigaset/interface.c
43822 @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43823 }
43824 tty->driver_data = cs;
43825
43826 - ++cs->port.count;
43827 + atomic_inc(&cs->port.count);
43828
43829 - if (cs->port.count == 1) {
43830 + if (atomic_read(&cs->port.count) == 1) {
43831 tty_port_tty_set(&cs->port, tty);
43832 cs->port.low_latency = 1;
43833 }
43834 @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43835
43836 if (!cs->connected)
43837 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43838 - else if (!cs->port.count)
43839 + else if (!atomic_read(&cs->port.count))
43840 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43841 - else if (!--cs->port.count)
43842 + else if (!atomic_dec_return(&cs->port.count))
43843 tty_port_tty_set(&cs->port, NULL);
43844
43845 mutex_unlock(&cs->mutex);
43846 diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43847 index 8c91fd5..14f13ce 100644
43848 --- a/drivers/isdn/gigaset/ser-gigaset.c
43849 +++ b/drivers/isdn/gigaset/ser-gigaset.c
43850 @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43851 }
43852
43853 static const struct gigaset_ops ops = {
43854 - gigaset_write_cmd,
43855 - gigaset_write_room,
43856 - gigaset_chars_in_buffer,
43857 - gigaset_brkchars,
43858 - gigaset_init_bchannel,
43859 - gigaset_close_bchannel,
43860 - gigaset_initbcshw,
43861 - gigaset_freebcshw,
43862 - gigaset_reinitbcshw,
43863 - gigaset_initcshw,
43864 - gigaset_freecshw,
43865 - gigaset_set_modem_ctrl,
43866 - gigaset_baud_rate,
43867 - gigaset_set_line_ctrl,
43868 - gigaset_m10x_send_skb, /* asyncdata.c */
43869 - gigaset_m10x_input, /* asyncdata.c */
43870 + .write_cmd = gigaset_write_cmd,
43871 + .write_room = gigaset_write_room,
43872 + .chars_in_buffer = gigaset_chars_in_buffer,
43873 + .brkchars = gigaset_brkchars,
43874 + .init_bchannel = gigaset_init_bchannel,
43875 + .close_bchannel = gigaset_close_bchannel,
43876 + .initbcshw = gigaset_initbcshw,
43877 + .freebcshw = gigaset_freebcshw,
43878 + .reinitbcshw = gigaset_reinitbcshw,
43879 + .initcshw = gigaset_initcshw,
43880 + .freecshw = gigaset_freecshw,
43881 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43882 + .baud_rate = gigaset_baud_rate,
43883 + .set_line_ctrl = gigaset_set_line_ctrl,
43884 + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43885 + .handle_input = gigaset_m10x_input, /* asyncdata.c */
43886 };
43887
43888
43889 diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43890 index a8e652d..edadaa4 100644
43891 --- a/drivers/isdn/gigaset/usb-gigaset.c
43892 +++ b/drivers/isdn/gigaset/usb-gigaset.c
43893 @@ -548,7 +548,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43894 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43895 memcpy(cs->hw.usb->bchars, buf, 6);
43896 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43897 - 0, 0, &buf, 6, 2000);
43898 + 0, 0, buf, 6, 2000);
43899 }
43900
43901 static void gigaset_freebcshw(struct bc_state *bcs)
43902 @@ -867,22 +867,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43903 }
43904
43905 static const struct gigaset_ops ops = {
43906 - gigaset_write_cmd,
43907 - gigaset_write_room,
43908 - gigaset_chars_in_buffer,
43909 - gigaset_brkchars,
43910 - gigaset_init_bchannel,
43911 - gigaset_close_bchannel,
43912 - gigaset_initbcshw,
43913 - gigaset_freebcshw,
43914 - gigaset_reinitbcshw,
43915 - gigaset_initcshw,
43916 - gigaset_freecshw,
43917 - gigaset_set_modem_ctrl,
43918 - gigaset_baud_rate,
43919 - gigaset_set_line_ctrl,
43920 - gigaset_m10x_send_skb,
43921 - gigaset_m10x_input,
43922 + .write_cmd = gigaset_write_cmd,
43923 + .write_room = gigaset_write_room,
43924 + .chars_in_buffer = gigaset_chars_in_buffer,
43925 + .brkchars = gigaset_brkchars,
43926 + .init_bchannel = gigaset_init_bchannel,
43927 + .close_bchannel = gigaset_close_bchannel,
43928 + .initbcshw = gigaset_initbcshw,
43929 + .freebcshw = gigaset_freebcshw,
43930 + .reinitbcshw = gigaset_reinitbcshw,
43931 + .initcshw = gigaset_initcshw,
43932 + .freecshw = gigaset_freecshw,
43933 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43934 + .baud_rate = gigaset_baud_rate,
43935 + .set_line_ctrl = gigaset_set_line_ctrl,
43936 + .send_skb = gigaset_m10x_send_skb,
43937 + .handle_input = gigaset_m10x_input,
43938 };
43939
43940 /*
43941 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43942 index 4d9b195..455075c 100644
43943 --- a/drivers/isdn/hardware/avm/b1.c
43944 +++ b/drivers/isdn/hardware/avm/b1.c
43945 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43946 }
43947 if (left) {
43948 if (t4file->user) {
43949 - if (copy_from_user(buf, dp, left))
43950 + if (left > sizeof buf || copy_from_user(buf, dp, left))
43951 return -EFAULT;
43952 } else {
43953 memcpy(buf, dp, left);
43954 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43955 }
43956 if (left) {
43957 if (config->user) {
43958 - if (copy_from_user(buf, dp, left))
43959 + if (left > sizeof buf || copy_from_user(buf, dp, left))
43960 return -EFAULT;
43961 } else {
43962 memcpy(buf, dp, left);
43963 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43964 index 9b856e1..fa03c92 100644
43965 --- a/drivers/isdn/i4l/isdn_common.c
43966 +++ b/drivers/isdn/i4l/isdn_common.c
43967 @@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43968 } else
43969 return -EINVAL;
43970 case IIOCDBGVAR:
43971 + if (!capable(CAP_SYS_RAWIO))
43972 + return -EPERM;
43973 if (arg) {
43974 if (copy_to_user(argp, &dev, sizeof(ulong)))
43975 return -EFAULT;
43976 diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
43977 index 91d5730..336523e 100644
43978 --- a/drivers/isdn/i4l/isdn_concap.c
43979 +++ b/drivers/isdn/i4l/isdn_concap.c
43980 @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
43981 }
43982
43983 struct concap_device_ops isdn_concap_reliable_dl_dops = {
43984 - &isdn_concap_dl_data_req,
43985 - &isdn_concap_dl_connect_req,
43986 - &isdn_concap_dl_disconn_req
43987 + .data_req = &isdn_concap_dl_data_req,
43988 + .connect_req = &isdn_concap_dl_connect_req,
43989 + .disconn_req = &isdn_concap_dl_disconn_req
43990 };
43991
43992 /* The following should better go into a dedicated source file such that
43993 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
43994 index bc91261..2ef7e36 100644
43995 --- a/drivers/isdn/i4l/isdn_tty.c
43996 +++ b/drivers/isdn/i4l/isdn_tty.c
43997 @@ -1503,9 +1503,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
43998
43999 #ifdef ISDN_DEBUG_MODEM_OPEN
44000 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
44001 - port->count);
44002 + atomic_read(&port->count));
44003 #endif
44004 - port->count++;
44005 + atomic_inc(&port->count);
44006 port->tty = tty;
44007 /*
44008 * Start up serial port
44009 @@ -1549,7 +1549,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44010 #endif
44011 return;
44012 }
44013 - if ((tty->count == 1) && (port->count != 1)) {
44014 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
44015 /*
44016 * Uh, oh. tty->count is 1, which means that the tty
44017 * structure will be freed. Info->count should always
44018 @@ -1558,15 +1558,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44019 * serial port won't be shutdown.
44020 */
44021 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
44022 - "info->count is %d\n", port->count);
44023 - port->count = 1;
44024 + "info->count is %d\n", atomic_read(&port->count));
44025 + atomic_set(&port->count, 1);
44026 }
44027 - if (--port->count < 0) {
44028 + if (atomic_dec_return(&port->count) < 0) {
44029 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
44030 - info->line, port->count);
44031 - port->count = 0;
44032 + info->line, atomic_read(&port->count));
44033 + atomic_set(&port->count, 0);
44034 }
44035 - if (port->count) {
44036 + if (atomic_read(&port->count)) {
44037 #ifdef ISDN_DEBUG_MODEM_OPEN
44038 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
44039 #endif
44040 @@ -1620,7 +1620,7 @@ isdn_tty_hangup(struct tty_struct *tty)
44041 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
44042 return;
44043 isdn_tty_shutdown(info);
44044 - port->count = 0;
44045 + atomic_set(&port->count, 0);
44046 port->flags &= ~ASYNC_NORMAL_ACTIVE;
44047 port->tty = NULL;
44048 wake_up_interruptible(&port->open_wait);
44049 @@ -1965,7 +1965,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
44050 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
44051 modem_info *info = &dev->mdm.info[i];
44052
44053 - if (info->port.count == 0)
44054 + if (atomic_read(&info->port.count) == 0)
44055 continue;
44056 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
44057 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
44058 diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
44059 index e2d4e58..40cd045 100644
44060 --- a/drivers/isdn/i4l/isdn_x25iface.c
44061 +++ b/drivers/isdn/i4l/isdn_x25iface.c
44062 @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
44063
44064
44065 static struct concap_proto_ops ix25_pops = {
44066 - &isdn_x25iface_proto_new,
44067 - &isdn_x25iface_proto_del,
44068 - &isdn_x25iface_proto_restart,
44069 - &isdn_x25iface_proto_close,
44070 - &isdn_x25iface_xmit,
44071 - &isdn_x25iface_receive,
44072 - &isdn_x25iface_connect_ind,
44073 - &isdn_x25iface_disconn_ind
44074 + .proto_new = &isdn_x25iface_proto_new,
44075 + .proto_del = &isdn_x25iface_proto_del,
44076 + .restart = &isdn_x25iface_proto_restart,
44077 + .close = &isdn_x25iface_proto_close,
44078 + .encap_and_xmit = &isdn_x25iface_xmit,
44079 + .data_ind = &isdn_x25iface_receive,
44080 + .connect_ind = &isdn_x25iface_connect_ind,
44081 + .disconn_ind = &isdn_x25iface_disconn_ind
44082 };
44083
44084 /* error message helper function */
44085 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
44086 index 6a7447c..cae33fe 100644
44087 --- a/drivers/isdn/icn/icn.c
44088 +++ b/drivers/isdn/icn/icn.c
44089 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
44090 if (count > len)
44091 count = len;
44092 if (user) {
44093 - if (copy_from_user(msg, buf, count))
44094 + if (count > sizeof msg || copy_from_user(msg, buf, count))
44095 return -EFAULT;
44096 } else
44097 memcpy(msg, buf, count);
44098 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
44099 index 87f7dff..7300125 100644
44100 --- a/drivers/isdn/mISDN/dsp_cmx.c
44101 +++ b/drivers/isdn/mISDN/dsp_cmx.c
44102 @@ -1625,7 +1625,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
44103 static u16 dsp_count; /* last sample count */
44104 static int dsp_count_valid; /* if we have last sample count */
44105
44106 -void
44107 +void __intentional_overflow(-1)
44108 dsp_cmx_send(void *arg)
44109 {
44110 struct dsp_conf *conf;
44111 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
44112 index f58a354..fbae176 100644
44113 --- a/drivers/leds/leds-clevo-mail.c
44114 +++ b/drivers/leds/leds-clevo-mail.c
44115 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
44116 * detected as working, but in reality it is not) as low as
44117 * possible.
44118 */
44119 -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
44120 +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
44121 {
44122 .callback = clevo_mail_led_dmi_callback,
44123 .ident = "Clevo D410J",
44124 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
44125 index 046cb70..6b20d39 100644
44126 --- a/drivers/leds/leds-ss4200.c
44127 +++ b/drivers/leds/leds-ss4200.c
44128 @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
44129 * detected as working, but in reality it is not) as low as
44130 * possible.
44131 */
44132 -static struct dmi_system_id nas_led_whitelist[] __initdata = {
44133 +static struct dmi_system_id nas_led_whitelist[] __initconst = {
44134 {
44135 .callback = ss4200_led_dmi_callback,
44136 .ident = "Intel SS4200-E",
44137 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
44138 index 6590558..a74c5dd 100644
44139 --- a/drivers/lguest/core.c
44140 +++ b/drivers/lguest/core.c
44141 @@ -96,9 +96,17 @@ static __init int map_switcher(void)
44142 * The end address needs +1 because __get_vm_area allocates an
44143 * extra guard page, so we need space for that.
44144 */
44145 +
44146 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
44147 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44148 + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
44149 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44150 +#else
44151 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44152 VM_ALLOC, switcher_addr, switcher_addr
44153 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44154 +#endif
44155 +
44156 if (!switcher_vma) {
44157 err = -ENOMEM;
44158 printk("lguest: could not map switcher pages high\n");
44159 @@ -121,7 +129,7 @@ static __init int map_switcher(void)
44160 * Now the Switcher is mapped at the right address, we can't fail!
44161 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
44162 */
44163 - memcpy(switcher_vma->addr, start_switcher_text,
44164 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
44165 end_switcher_text - start_switcher_text);
44166
44167 printk(KERN_INFO "lguest: mapped switcher at %p\n",
44168 diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
44169 index e8b55c3..3514c37 100644
44170 --- a/drivers/lguest/page_tables.c
44171 +++ b/drivers/lguest/page_tables.c
44172 @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
44173 /*:*/
44174
44175 #ifdef CONFIG_X86_PAE
44176 -static void release_pmd(pmd_t *spmd)
44177 +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
44178 {
44179 /* If the entry's not present, there's nothing to release. */
44180 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
44181 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
44182 index 922a1ac..9dd0c2a 100644
44183 --- a/drivers/lguest/x86/core.c
44184 +++ b/drivers/lguest/x86/core.c
44185 @@ -59,7 +59,7 @@ static struct {
44186 /* Offset from where switcher.S was compiled to where we've copied it */
44187 static unsigned long switcher_offset(void)
44188 {
44189 - return switcher_addr - (unsigned long)start_switcher_text;
44190 + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
44191 }
44192
44193 /* This cpu's struct lguest_pages (after the Switcher text page) */
44194 @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
44195 * These copies are pretty cheap, so we do them unconditionally: */
44196 /* Save the current Host top-level page directory.
44197 */
44198 +
44199 +#ifdef CONFIG_PAX_PER_CPU_PGD
44200 + pages->state.host_cr3 = read_cr3();
44201 +#else
44202 pages->state.host_cr3 = __pa(current->mm->pgd);
44203 +#endif
44204 +
44205 /*
44206 * Set up the Guest's page tables to see this CPU's pages (and no
44207 * other CPU's pages).
44208 @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
44209 * compiled-in switcher code and the high-mapped copy we just made.
44210 */
44211 for (i = 0; i < IDT_ENTRIES; i++)
44212 - default_idt_entries[i] += switcher_offset();
44213 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
44214
44215 /*
44216 * Set up the Switcher's per-cpu areas.
44217 @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
44218 * it will be undisturbed when we switch. To change %cs and jump we
44219 * need this structure to feed to Intel's "lcall" instruction.
44220 */
44221 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
44222 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
44223 lguest_entry.segment = LGUEST_CS;
44224
44225 /*
44226 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
44227 index 40634b0..4f5855e 100644
44228 --- a/drivers/lguest/x86/switcher_32.S
44229 +++ b/drivers/lguest/x86/switcher_32.S
44230 @@ -87,6 +87,7 @@
44231 #include <asm/page.h>
44232 #include <asm/segment.h>
44233 #include <asm/lguest.h>
44234 +#include <asm/processor-flags.h>
44235
44236 // We mark the start of the code to copy
44237 // It's placed in .text tho it's never run here
44238 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
44239 // Changes type when we load it: damn Intel!
44240 // For after we switch over our page tables
44241 // That entry will be read-only: we'd crash.
44242 +
44243 +#ifdef CONFIG_PAX_KERNEXEC
44244 + mov %cr0, %edx
44245 + xor $X86_CR0_WP, %edx
44246 + mov %edx, %cr0
44247 +#endif
44248 +
44249 movl $(GDT_ENTRY_TSS*8), %edx
44250 ltr %dx
44251
44252 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
44253 // Let's clear it again for our return.
44254 // The GDT descriptor of the Host
44255 // Points to the table after two "size" bytes
44256 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
44257 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
44258 // Clear "used" from type field (byte 5, bit 2)
44259 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
44260 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
44261 +
44262 +#ifdef CONFIG_PAX_KERNEXEC
44263 + mov %cr0, %eax
44264 + xor $X86_CR0_WP, %eax
44265 + mov %eax, %cr0
44266 +#endif
44267
44268 // Once our page table's switched, the Guest is live!
44269 // The Host fades as we run this final step.
44270 @@ -295,13 +309,12 @@ deliver_to_host:
44271 // I consulted gcc, and it gave
44272 // These instructions, which I gladly credit:
44273 leal (%edx,%ebx,8), %eax
44274 - movzwl (%eax),%edx
44275 - movl 4(%eax), %eax
44276 - xorw %ax, %ax
44277 - orl %eax, %edx
44278 + movl 4(%eax), %edx
44279 + movw (%eax), %dx
44280 // Now the address of the handler's in %edx
44281 // We call it now: its "iret" drops us home.
44282 - jmp *%edx
44283 + ljmp $__KERNEL_CS, $1f
44284 +1: jmp *%edx
44285
44286 // Every interrupt can come to us here
44287 // But we must truly tell each apart.
44288 diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
44289 index a08e3ee..df8ade2 100644
44290 --- a/drivers/md/bcache/closure.h
44291 +++ b/drivers/md/bcache/closure.h
44292 @@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
44293 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
44294 struct workqueue_struct *wq)
44295 {
44296 - BUG_ON(object_is_on_stack(cl));
44297 + BUG_ON(object_starts_on_stack(cl));
44298 closure_set_ip(cl);
44299 cl->fn = fn;
44300 cl->wq = wq;
44301 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
44302 index da3604e..7789cb4c 100644
44303 --- a/drivers/md/bitmap.c
44304 +++ b/drivers/md/bitmap.c
44305 @@ -1771,7 +1771,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
44306 chunk_kb ? "KB" : "B");
44307 if (bitmap->storage.file) {
44308 seq_printf(seq, ", file: ");
44309 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
44310 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
44311 }
44312
44313 seq_printf(seq, "\n");
44314 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
44315 index 0be9381..114262b 100644
44316 --- a/drivers/md/dm-ioctl.c
44317 +++ b/drivers/md/dm-ioctl.c
44318 @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
44319 cmd == DM_LIST_VERSIONS_CMD)
44320 return 0;
44321
44322 - if ((cmd == DM_DEV_CREATE_CMD)) {
44323 + if (cmd == DM_DEV_CREATE_CMD) {
44324 if (!*param->name) {
44325 DMWARN("name not supplied when creating device");
44326 return -EINVAL;
44327 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
44328 index 7dfdb5c..4caada6 100644
44329 --- a/drivers/md/dm-raid1.c
44330 +++ b/drivers/md/dm-raid1.c
44331 @@ -40,7 +40,7 @@ enum dm_raid1_error {
44332
44333 struct mirror {
44334 struct mirror_set *ms;
44335 - atomic_t error_count;
44336 + atomic_unchecked_t error_count;
44337 unsigned long error_type;
44338 struct dm_dev *dev;
44339 sector_t offset;
44340 @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
44341 struct mirror *m;
44342
44343 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
44344 - if (!atomic_read(&m->error_count))
44345 + if (!atomic_read_unchecked(&m->error_count))
44346 return m;
44347
44348 return NULL;
44349 @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
44350 * simple way to tell if a device has encountered
44351 * errors.
44352 */
44353 - atomic_inc(&m->error_count);
44354 + atomic_inc_unchecked(&m->error_count);
44355
44356 if (test_and_set_bit(error_type, &m->error_type))
44357 return;
44358 @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
44359 struct mirror *m = get_default_mirror(ms);
44360
44361 do {
44362 - if (likely(!atomic_read(&m->error_count)))
44363 + if (likely(!atomic_read_unchecked(&m->error_count)))
44364 return m;
44365
44366 if (m-- == ms->mirror)
44367 @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
44368 {
44369 struct mirror *default_mirror = get_default_mirror(m->ms);
44370
44371 - return !atomic_read(&default_mirror->error_count);
44372 + return !atomic_read_unchecked(&default_mirror->error_count);
44373 }
44374
44375 static int mirror_available(struct mirror_set *ms, struct bio *bio)
44376 @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
44377 */
44378 if (likely(region_in_sync(ms, region, 1)))
44379 m = choose_mirror(ms, bio->bi_iter.bi_sector);
44380 - else if (m && atomic_read(&m->error_count))
44381 + else if (m && atomic_read_unchecked(&m->error_count))
44382 m = NULL;
44383
44384 if (likely(m))
44385 @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
44386 }
44387
44388 ms->mirror[mirror].ms = ms;
44389 - atomic_set(&(ms->mirror[mirror].error_count), 0);
44390 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
44391 ms->mirror[mirror].error_type = 0;
44392 ms->mirror[mirror].offset = offset;
44393
44394 @@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
44395 */
44396 static char device_status_char(struct mirror *m)
44397 {
44398 - if (!atomic_read(&(m->error_count)))
44399 + if (!atomic_read_unchecked(&(m->error_count)))
44400 return 'A';
44401
44402 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
44403 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
44404 index 87f86c7..a1a4100 100644
44405 --- a/drivers/md/dm-stats.c
44406 +++ b/drivers/md/dm-stats.c
44407 @@ -382,7 +382,7 @@ do_sync_free:
44408 synchronize_rcu_expedited();
44409 dm_stat_free(&s->rcu_head);
44410 } else {
44411 - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
44412 + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
44413 call_rcu(&s->rcu_head, dm_stat_free);
44414 }
44415 return 0;
44416 @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
44417 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
44418 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
44419 ));
44420 - ACCESS_ONCE(last->last_sector) = end_sector;
44421 - ACCESS_ONCE(last->last_rw) = bi_rw;
44422 + ACCESS_ONCE_RW(last->last_sector) = end_sector;
44423 + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
44424 }
44425
44426 rcu_read_lock();
44427 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
44428 index f8b37d4..5c5cafd 100644
44429 --- a/drivers/md/dm-stripe.c
44430 +++ b/drivers/md/dm-stripe.c
44431 @@ -21,7 +21,7 @@ struct stripe {
44432 struct dm_dev *dev;
44433 sector_t physical_start;
44434
44435 - atomic_t error_count;
44436 + atomic_unchecked_t error_count;
44437 };
44438
44439 struct stripe_c {
44440 @@ -188,7 +188,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
44441 kfree(sc);
44442 return r;
44443 }
44444 - atomic_set(&(sc->stripe[i].error_count), 0);
44445 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
44446 }
44447
44448 ti->private = sc;
44449 @@ -332,7 +332,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
44450 DMEMIT("%d ", sc->stripes);
44451 for (i = 0; i < sc->stripes; i++) {
44452 DMEMIT("%s ", sc->stripe[i].dev->name);
44453 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
44454 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
44455 'D' : 'A';
44456 }
44457 buffer[i] = '\0';
44458 @@ -377,8 +377,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
44459 */
44460 for (i = 0; i < sc->stripes; i++)
44461 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
44462 - atomic_inc(&(sc->stripe[i].error_count));
44463 - if (atomic_read(&(sc->stripe[i].error_count)) <
44464 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
44465 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
44466 DM_IO_ERROR_THRESHOLD)
44467 schedule_work(&sc->trigger_event);
44468 }
44469 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
44470 index b2bd1eb..38f7a44 100644
44471 --- a/drivers/md/dm-table.c
44472 +++ b/drivers/md/dm-table.c
44473 @@ -303,7 +303,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
44474 if (!dev_size)
44475 return 0;
44476
44477 - if ((start >= dev_size) || (start + len > dev_size)) {
44478 + if ((start >= dev_size) || (len > dev_size - start)) {
44479 DMWARN("%s: %s too small for target: "
44480 "start=%llu, len=%llu, dev_size=%llu",
44481 dm_device_name(ti->table->md), bdevname(bdev, b),
44482 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
44483 index e9d33ad..dae9880d 100644
44484 --- a/drivers/md/dm-thin-metadata.c
44485 +++ b/drivers/md/dm-thin-metadata.c
44486 @@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44487 {
44488 pmd->info.tm = pmd->tm;
44489 pmd->info.levels = 2;
44490 - pmd->info.value_type.context = pmd->data_sm;
44491 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44492 pmd->info.value_type.size = sizeof(__le64);
44493 pmd->info.value_type.inc = data_block_inc;
44494 pmd->info.value_type.dec = data_block_dec;
44495 @@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44496
44497 pmd->bl_info.tm = pmd->tm;
44498 pmd->bl_info.levels = 1;
44499 - pmd->bl_info.value_type.context = pmd->data_sm;
44500 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44501 pmd->bl_info.value_type.size = sizeof(__le64);
44502 pmd->bl_info.value_type.inc = data_block_inc;
44503 pmd->bl_info.value_type.dec = data_block_dec;
44504 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
44505 index 58f3927..bfbad3e 100644
44506 --- a/drivers/md/dm.c
44507 +++ b/drivers/md/dm.c
44508 @@ -183,9 +183,9 @@ struct mapped_device {
44509 /*
44510 * Event handling.
44511 */
44512 - atomic_t event_nr;
44513 + atomic_unchecked_t event_nr;
44514 wait_queue_head_t eventq;
44515 - atomic_t uevent_seq;
44516 + atomic_unchecked_t uevent_seq;
44517 struct list_head uevent_list;
44518 spinlock_t uevent_lock; /* Protect access to uevent_list */
44519
44520 @@ -2071,8 +2071,8 @@ static struct mapped_device *alloc_dev(int minor)
44521 spin_lock_init(&md->deferred_lock);
44522 atomic_set(&md->holders, 1);
44523 atomic_set(&md->open_count, 0);
44524 - atomic_set(&md->event_nr, 0);
44525 - atomic_set(&md->uevent_seq, 0);
44526 + atomic_set_unchecked(&md->event_nr, 0);
44527 + atomic_set_unchecked(&md->uevent_seq, 0);
44528 INIT_LIST_HEAD(&md->uevent_list);
44529 INIT_LIST_HEAD(&md->table_devices);
44530 spin_lock_init(&md->uevent_lock);
44531 @@ -2228,7 +2228,7 @@ static void event_callback(void *context)
44532
44533 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
44534
44535 - atomic_inc(&md->event_nr);
44536 + atomic_inc_unchecked(&md->event_nr);
44537 wake_up(&md->eventq);
44538 }
44539
44540 @@ -2921,18 +2921,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
44541
44542 uint32_t dm_next_uevent_seq(struct mapped_device *md)
44543 {
44544 - return atomic_add_return(1, &md->uevent_seq);
44545 + return atomic_add_return_unchecked(1, &md->uevent_seq);
44546 }
44547
44548 uint32_t dm_get_event_nr(struct mapped_device *md)
44549 {
44550 - return atomic_read(&md->event_nr);
44551 + return atomic_read_unchecked(&md->event_nr);
44552 }
44553
44554 int dm_wait_event(struct mapped_device *md, int event_nr)
44555 {
44556 return wait_event_interruptible(md->eventq,
44557 - (event_nr != atomic_read(&md->event_nr)));
44558 + (event_nr != atomic_read_unchecked(&md->event_nr)));
44559 }
44560
44561 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
44562 diff --git a/drivers/md/md.c b/drivers/md/md.c
44563 index 9233c71..ed5243a 100644
44564 --- a/drivers/md/md.c
44565 +++ b/drivers/md/md.c
44566 @@ -190,10 +190,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
44567 * start build, activate spare
44568 */
44569 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
44570 -static atomic_t md_event_count;
44571 +static atomic_unchecked_t md_event_count;
44572 void md_new_event(struct mddev *mddev)
44573 {
44574 - atomic_inc(&md_event_count);
44575 + atomic_inc_unchecked(&md_event_count);
44576 wake_up(&md_event_waiters);
44577 }
44578 EXPORT_SYMBOL_GPL(md_new_event);
44579 @@ -203,7 +203,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
44580 */
44581 static void md_new_event_inintr(struct mddev *mddev)
44582 {
44583 - atomic_inc(&md_event_count);
44584 + atomic_inc_unchecked(&md_event_count);
44585 wake_up(&md_event_waiters);
44586 }
44587
44588 @@ -1426,7 +1426,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
44589 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
44590 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
44591 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
44592 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44593 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44594
44595 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
44596 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
44597 @@ -1677,7 +1677,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
44598 else
44599 sb->resync_offset = cpu_to_le64(0);
44600
44601 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
44602 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
44603
44604 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
44605 sb->size = cpu_to_le64(mddev->dev_sectors);
44606 @@ -2547,7 +2547,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
44607 static ssize_t
44608 errors_show(struct md_rdev *rdev, char *page)
44609 {
44610 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
44611 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
44612 }
44613
44614 static ssize_t
44615 @@ -2556,7 +2556,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
44616 char *e;
44617 unsigned long n = simple_strtoul(buf, &e, 10);
44618 if (*buf && (*e == 0 || *e == '\n')) {
44619 - atomic_set(&rdev->corrected_errors, n);
44620 + atomic_set_unchecked(&rdev->corrected_errors, n);
44621 return len;
44622 }
44623 return -EINVAL;
44624 @@ -3000,8 +3000,8 @@ int md_rdev_init(struct md_rdev *rdev)
44625 rdev->sb_loaded = 0;
44626 rdev->bb_page = NULL;
44627 atomic_set(&rdev->nr_pending, 0);
44628 - atomic_set(&rdev->read_errors, 0);
44629 - atomic_set(&rdev->corrected_errors, 0);
44630 + atomic_set_unchecked(&rdev->read_errors, 0);
44631 + atomic_set_unchecked(&rdev->corrected_errors, 0);
44632
44633 INIT_LIST_HEAD(&rdev->same_set);
44634 init_waitqueue_head(&rdev->blocked_wait);
44635 @@ -6855,7 +6855,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
44636
44637 spin_unlock(&pers_lock);
44638 seq_printf(seq, "\n");
44639 - seq->poll_event = atomic_read(&md_event_count);
44640 + seq->poll_event = atomic_read_unchecked(&md_event_count);
44641 return 0;
44642 }
44643 if (v == (void*)2) {
44644 @@ -6958,7 +6958,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
44645 return error;
44646
44647 seq = file->private_data;
44648 - seq->poll_event = atomic_read(&md_event_count);
44649 + seq->poll_event = atomic_read_unchecked(&md_event_count);
44650 return error;
44651 }
44652
44653 @@ -6975,7 +6975,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
44654 /* always allow read */
44655 mask = POLLIN | POLLRDNORM;
44656
44657 - if (seq->poll_event != atomic_read(&md_event_count))
44658 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
44659 mask |= POLLERR | POLLPRI;
44660 return mask;
44661 }
44662 @@ -7022,7 +7022,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
44663 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
44664 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
44665 (int)part_stat_read(&disk->part0, sectors[1]) -
44666 - atomic_read(&disk->sync_io);
44667 + atomic_read_unchecked(&disk->sync_io);
44668 /* sync IO will cause sync_io to increase before the disk_stats
44669 * as sync_io is counted when a request starts, and
44670 * disk_stats is counted when it completes.
44671 diff --git a/drivers/md/md.h b/drivers/md/md.h
44672 index 03cec5b..0a658c1 100644
44673 --- a/drivers/md/md.h
44674 +++ b/drivers/md/md.h
44675 @@ -94,13 +94,13 @@ struct md_rdev {
44676 * only maintained for arrays that
44677 * support hot removal
44678 */
44679 - atomic_t read_errors; /* number of consecutive read errors that
44680 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
44681 * we have tried to ignore.
44682 */
44683 struct timespec last_read_error; /* monotonic time since our
44684 * last read error
44685 */
44686 - atomic_t corrected_errors; /* number of corrected read errors,
44687 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44688 * for reporting to userspace and storing
44689 * in superblock.
44690 */
44691 @@ -448,7 +448,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44692
44693 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44694 {
44695 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44696 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44697 }
44698
44699 struct md_personality
44700 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44701 index 786b689..ea8c956 100644
44702 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
44703 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44704 @@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44705 * Flick into a mode where all blocks get allocated in the new area.
44706 */
44707 smm->begin = old_len;
44708 - memcpy(sm, &bootstrap_ops, sizeof(*sm));
44709 + memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44710
44711 /*
44712 * Extend.
44713 @@ -710,7 +710,7 @@ out:
44714 /*
44715 * Switch back to normal behaviour.
44716 */
44717 - memcpy(sm, &ops, sizeof(*sm));
44718 + memcpy((void *)sm, &ops, sizeof(*sm));
44719 return r;
44720 }
44721
44722 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44723 index 3e6d115..ffecdeb 100644
44724 --- a/drivers/md/persistent-data/dm-space-map.h
44725 +++ b/drivers/md/persistent-data/dm-space-map.h
44726 @@ -71,6 +71,7 @@ struct dm_space_map {
44727 dm_sm_threshold_fn fn,
44728 void *context);
44729 };
44730 +typedef struct dm_space_map __no_const dm_space_map_no_const;
44731
44732 /*----------------------------------------------------------------*/
44733
44734 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44735 index 40b35be..a327e11 100644
44736 --- a/drivers/md/raid1.c
44737 +++ b/drivers/md/raid1.c
44738 @@ -1931,7 +1931,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44739 if (r1_sync_page_io(rdev, sect, s,
44740 bio->bi_io_vec[idx].bv_page,
44741 READ) != 0)
44742 - atomic_add(s, &rdev->corrected_errors);
44743 + atomic_add_unchecked(s, &rdev->corrected_errors);
44744 }
44745 sectors -= s;
44746 sect += s;
44747 @@ -2164,7 +2164,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44748 !test_bit(Faulty, &rdev->flags)) {
44749 if (r1_sync_page_io(rdev, sect, s,
44750 conf->tmppage, READ)) {
44751 - atomic_add(s, &rdev->corrected_errors);
44752 + atomic_add_unchecked(s, &rdev->corrected_errors);
44753 printk(KERN_INFO
44754 "md/raid1:%s: read error corrected "
44755 "(%d sectors at %llu on %s)\n",
44756 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44757 index 32e282f..5cec803 100644
44758 --- a/drivers/md/raid10.c
44759 +++ b/drivers/md/raid10.c
44760 @@ -1944,7 +1944,7 @@ static void end_sync_read(struct bio *bio, int error)
44761 /* The write handler will notice the lack of
44762 * R10BIO_Uptodate and record any errors etc
44763 */
44764 - atomic_add(r10_bio->sectors,
44765 + atomic_add_unchecked(r10_bio->sectors,
44766 &conf->mirrors[d].rdev->corrected_errors);
44767
44768 /* for reconstruct, we always reschedule after a read.
44769 @@ -2301,7 +2301,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44770 {
44771 struct timespec cur_time_mon;
44772 unsigned long hours_since_last;
44773 - unsigned int read_errors = atomic_read(&rdev->read_errors);
44774 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44775
44776 ktime_get_ts(&cur_time_mon);
44777
44778 @@ -2323,9 +2323,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44779 * overflowing the shift of read_errors by hours_since_last.
44780 */
44781 if (hours_since_last >= 8 * sizeof(read_errors))
44782 - atomic_set(&rdev->read_errors, 0);
44783 + atomic_set_unchecked(&rdev->read_errors, 0);
44784 else
44785 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44786 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44787 }
44788
44789 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44790 @@ -2379,8 +2379,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44791 return;
44792
44793 check_decay_read_errors(mddev, rdev);
44794 - atomic_inc(&rdev->read_errors);
44795 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
44796 + atomic_inc_unchecked(&rdev->read_errors);
44797 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44798 char b[BDEVNAME_SIZE];
44799 bdevname(rdev->bdev, b);
44800
44801 @@ -2388,7 +2388,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44802 "md/raid10:%s: %s: Raid device exceeded "
44803 "read_error threshold [cur %d:max %d]\n",
44804 mdname(mddev), b,
44805 - atomic_read(&rdev->read_errors), max_read_errors);
44806 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44807 printk(KERN_NOTICE
44808 "md/raid10:%s: %s: Failing raid device\n",
44809 mdname(mddev), b);
44810 @@ -2543,7 +2543,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44811 sect +
44812 choose_data_offset(r10_bio, rdev)),
44813 bdevname(rdev->bdev, b));
44814 - atomic_add(s, &rdev->corrected_errors);
44815 + atomic_add_unchecked(s, &rdev->corrected_errors);
44816 }
44817
44818 rdev_dec_pending(rdev, mddev);
44819 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44820 index 9c66e59..42a8eac 100644
44821 --- a/drivers/md/raid5.c
44822 +++ b/drivers/md/raid5.c
44823 @@ -1730,6 +1730,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
44824 return 1;
44825 }
44826
44827 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44828 +static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
44829 +#endif
44830 +
44831 static int grow_stripes(struct r5conf *conf, int num)
44832 {
44833 struct kmem_cache *sc;
44834 @@ -1741,7 +1745,11 @@ static int grow_stripes(struct r5conf *conf, int num)
44835 "raid%d-%s", conf->level, mdname(conf->mddev));
44836 else
44837 sprintf(conf->cache_name[0],
44838 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44839 + "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
44840 +#else
44841 "raid%d-%p", conf->level, conf->mddev);
44842 +#endif
44843 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
44844
44845 conf->active_name = 0;
44846 @@ -2017,21 +2025,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44847 mdname(conf->mddev), STRIPE_SECTORS,
44848 (unsigned long long)s,
44849 bdevname(rdev->bdev, b));
44850 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44851 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44852 clear_bit(R5_ReadError, &sh->dev[i].flags);
44853 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44854 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44855 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44856
44857 - if (atomic_read(&rdev->read_errors))
44858 - atomic_set(&rdev->read_errors, 0);
44859 + if (atomic_read_unchecked(&rdev->read_errors))
44860 + atomic_set_unchecked(&rdev->read_errors, 0);
44861 } else {
44862 const char *bdn = bdevname(rdev->bdev, b);
44863 int retry = 0;
44864 int set_bad = 0;
44865
44866 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44867 - atomic_inc(&rdev->read_errors);
44868 + atomic_inc_unchecked(&rdev->read_errors);
44869 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44870 printk_ratelimited(
44871 KERN_WARNING
44872 @@ -2059,7 +2067,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44873 mdname(conf->mddev),
44874 (unsigned long long)s,
44875 bdn);
44876 - } else if (atomic_read(&rdev->read_errors)
44877 + } else if (atomic_read_unchecked(&rdev->read_errors)
44878 > conf->max_nr_stripes)
44879 printk(KERN_WARNING
44880 "md/raid:%s: Too many read errors, failing device %s.\n",
44881 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44882 index 983db75..ef9248c 100644
44883 --- a/drivers/media/dvb-core/dvbdev.c
44884 +++ b/drivers/media/dvb-core/dvbdev.c
44885 @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44886 const struct dvb_device *template, void *priv, int type)
44887 {
44888 struct dvb_device *dvbdev;
44889 - struct file_operations *dvbdevfops;
44890 + file_operations_no_const *dvbdevfops;
44891 struct device *clsdev;
44892 int minor;
44893 int id;
44894 diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
44895 index 6ad22b6..6e90e2a 100644
44896 --- a/drivers/media/dvb-frontends/af9033.h
44897 +++ b/drivers/media/dvb-frontends/af9033.h
44898 @@ -96,6 +96,6 @@ struct af9033_ops {
44899 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
44900 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
44901 int onoff);
44902 -};
44903 +} __no_const;
44904
44905 #endif /* AF9033_H */
44906 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44907 index 9b6c3bb..baeb5c7 100644
44908 --- a/drivers/media/dvb-frontends/dib3000.h
44909 +++ b/drivers/media/dvb-frontends/dib3000.h
44910 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44911 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44912 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44913 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44914 -};
44915 +} __no_const;
44916
44917 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44918 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44919 diff --git a/drivers/media/dvb-frontends/dib7000p.h b/drivers/media/dvb-frontends/dib7000p.h
44920 index 1fea0e9..321ce8f 100644
44921 --- a/drivers/media/dvb-frontends/dib7000p.h
44922 +++ b/drivers/media/dvb-frontends/dib7000p.h
44923 @@ -64,7 +64,7 @@ struct dib7000p_ops {
44924 int (*get_adc_power)(struct dvb_frontend *fe);
44925 int (*slave_reset)(struct dvb_frontend *fe);
44926 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg);
44927 -};
44928 +} __no_const;
44929
44930 #if IS_ENABLED(CONFIG_DVB_DIB7000P)
44931 void *dib7000p_attach(struct dib7000p_ops *ops);
44932 diff --git a/drivers/media/dvb-frontends/dib8000.h b/drivers/media/dvb-frontends/dib8000.h
44933 index 84cc103..5780c54 100644
44934 --- a/drivers/media/dvb-frontends/dib8000.h
44935 +++ b/drivers/media/dvb-frontends/dib8000.h
44936 @@ -61,7 +61,7 @@ struct dib8000_ops {
44937 int (*pid_filter_ctrl)(struct dvb_frontend *fe, u8 onoff);
44938 int (*pid_filter)(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff);
44939 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib8000_config *cfg);
44940 -};
44941 +} __no_const;
44942
44943 #if IS_ENABLED(CONFIG_DVB_DIB8000)
44944 void *dib8000_attach(struct dib8000_ops *ops);
44945 diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44946 index ce27e6d..b70435a 100644
44947 --- a/drivers/media/pci/cx88/cx88-video.c
44948 +++ b/drivers/media/pci/cx88/cx88-video.c
44949 @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44950
44951 /* ------------------------------------------------------------------ */
44952
44953 -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44954 -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44955 -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44956 +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44957 +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44958 +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44959
44960 module_param_array(video_nr, int, NULL, 0444);
44961 module_param_array(vbi_nr, int, NULL, 0444);
44962 diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44963 index 802642d..5534900 100644
44964 --- a/drivers/media/pci/ivtv/ivtv-driver.c
44965 +++ b/drivers/media/pci/ivtv/ivtv-driver.c
44966 @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44967 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44968
44969 /* ivtv instance counter */
44970 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
44971 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44972
44973 /* Parameter declarations */
44974 static int cardtype[IVTV_MAX_CARDS];
44975 diff --git a/drivers/media/pci/solo6x10/solo6x10-core.c b/drivers/media/pci/solo6x10/solo6x10-core.c
44976 index 8cbe6b4..ea3601c 100644
44977 --- a/drivers/media/pci/solo6x10/solo6x10-core.c
44978 +++ b/drivers/media/pci/solo6x10/solo6x10-core.c
44979 @@ -424,7 +424,7 @@ static void solo_device_release(struct device *dev)
44980
44981 static int solo_sysfs_init(struct solo_dev *solo_dev)
44982 {
44983 - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
44984 + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
44985 struct device *dev = &solo_dev->dev;
44986 const char *driver;
44987 int i;
44988 diff --git a/drivers/media/pci/solo6x10/solo6x10-g723.c b/drivers/media/pci/solo6x10/solo6x10-g723.c
44989 index c7141f2..5301fec 100644
44990 --- a/drivers/media/pci/solo6x10/solo6x10-g723.c
44991 +++ b/drivers/media/pci/solo6x10/solo6x10-g723.c
44992 @@ -351,7 +351,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
44993
44994 int solo_g723_init(struct solo_dev *solo_dev)
44995 {
44996 - static struct snd_device_ops ops = { NULL };
44997 + static struct snd_device_ops ops = { };
44998 struct snd_card *card;
44999 struct snd_kcontrol_new kctl;
45000 char name[32];
45001 diff --git a/drivers/media/pci/solo6x10/solo6x10-p2m.c b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45002 index 8c84846..27b4f83 100644
45003 --- a/drivers/media/pci/solo6x10/solo6x10-p2m.c
45004 +++ b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45005 @@ -73,7 +73,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
45006
45007 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
45008 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
45009 - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
45010 + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
45011 if (p2m_id < 0)
45012 p2m_id = -p2m_id;
45013 }
45014 diff --git a/drivers/media/pci/solo6x10/solo6x10.h b/drivers/media/pci/solo6x10/solo6x10.h
45015 index 72017b7..dd37ae6 100644
45016 --- a/drivers/media/pci/solo6x10/solo6x10.h
45017 +++ b/drivers/media/pci/solo6x10/solo6x10.h
45018 @@ -219,7 +219,7 @@ struct solo_dev {
45019
45020 /* P2M DMA Engine */
45021 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
45022 - atomic_t p2m_count;
45023 + atomic_unchecked_t p2m_count;
45024 int p2m_jiffies;
45025 unsigned int p2m_timeouts;
45026
45027 diff --git a/drivers/media/pci/tw68/tw68-core.c b/drivers/media/pci/tw68/tw68-core.c
45028 index 63f0b64..a017c1c 100644
45029 --- a/drivers/media/pci/tw68/tw68-core.c
45030 +++ b/drivers/media/pci/tw68/tw68-core.c
45031 @@ -60,7 +60,7 @@ static unsigned int card[] = {[0 ... (TW68_MAXBOARDS - 1)] = UNSET };
45032 module_param_array(card, int, NULL, 0444);
45033 MODULE_PARM_DESC(card, "card type");
45034
45035 -static atomic_t tw68_instance = ATOMIC_INIT(0);
45036 +static atomic_unchecked_t tw68_instance = ATOMIC_INIT(0);
45037
45038 /* ------------------------------------------------------------------ */
45039
45040 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
45041 index 64ab6fb..ef4a8b9 100644
45042 --- a/drivers/media/platform/omap/omap_vout.c
45043 +++ b/drivers/media/platform/omap/omap_vout.c
45044 @@ -63,7 +63,6 @@ enum omap_vout_channels {
45045 OMAP_VIDEO2,
45046 };
45047
45048 -static struct videobuf_queue_ops video_vbq_ops;
45049 /* Variables configurable through module params*/
45050 static u32 video1_numbuffers = 3;
45051 static u32 video2_numbuffers = 3;
45052 @@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
45053 {
45054 struct videobuf_queue *q;
45055 struct omap_vout_device *vout = NULL;
45056 + static struct videobuf_queue_ops video_vbq_ops = {
45057 + .buf_setup = omap_vout_buffer_setup,
45058 + .buf_prepare = omap_vout_buffer_prepare,
45059 + .buf_release = omap_vout_buffer_release,
45060 + .buf_queue = omap_vout_buffer_queue,
45061 + };
45062
45063 vout = video_drvdata(file);
45064 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
45065 @@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
45066 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
45067
45068 q = &vout->vbq;
45069 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
45070 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
45071 - video_vbq_ops.buf_release = omap_vout_buffer_release;
45072 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
45073 spin_lock_init(&vout->vbq_lock);
45074
45075 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
45076 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
45077 index fb2acc5..a2fcbdc4 100644
45078 --- a/drivers/media/platform/s5p-tv/mixer.h
45079 +++ b/drivers/media/platform/s5p-tv/mixer.h
45080 @@ -156,7 +156,7 @@ struct mxr_layer {
45081 /** layer index (unique identifier) */
45082 int idx;
45083 /** callbacks for layer methods */
45084 - struct mxr_layer_ops ops;
45085 + struct mxr_layer_ops *ops;
45086 /** format array */
45087 const struct mxr_format **fmt_array;
45088 /** size of format array */
45089 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45090 index 74344c7..a39e70e 100644
45091 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45092 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45093 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
45094 {
45095 struct mxr_layer *layer;
45096 int ret;
45097 - struct mxr_layer_ops ops = {
45098 + static struct mxr_layer_ops ops = {
45099 .release = mxr_graph_layer_release,
45100 .buffer_set = mxr_graph_buffer_set,
45101 .stream_set = mxr_graph_stream_set,
45102 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
45103 index b713403..53cb5ad 100644
45104 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
45105 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
45106 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
45107 layer->update_buf = next;
45108 }
45109
45110 - layer->ops.buffer_set(layer, layer->update_buf);
45111 + layer->ops->buffer_set(layer, layer->update_buf);
45112
45113 if (done && done != layer->shadow_buf)
45114 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
45115 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
45116 index b4d2696..91df48e 100644
45117 --- a/drivers/media/platform/s5p-tv/mixer_video.c
45118 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
45119 @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
45120 layer->geo.src.height = layer->geo.src.full_height;
45121
45122 mxr_geometry_dump(mdev, &layer->geo);
45123 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45124 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45125 mxr_geometry_dump(mdev, &layer->geo);
45126 }
45127
45128 @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
45129 layer->geo.dst.full_width = mbus_fmt.width;
45130 layer->geo.dst.full_height = mbus_fmt.height;
45131 layer->geo.dst.field = mbus_fmt.field;
45132 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45133 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45134
45135 mxr_geometry_dump(mdev, &layer->geo);
45136 }
45137 @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
45138 /* set source size to highest accepted value */
45139 geo->src.full_width = max(geo->dst.full_width, pix->width);
45140 geo->src.full_height = max(geo->dst.full_height, pix->height);
45141 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45142 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45143 mxr_geometry_dump(mdev, &layer->geo);
45144 /* set cropping to total visible screen */
45145 geo->src.width = pix->width;
45146 @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
45147 geo->src.x_offset = 0;
45148 geo->src.y_offset = 0;
45149 /* assure consistency of geometry */
45150 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45151 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45152 mxr_geometry_dump(mdev, &layer->geo);
45153 /* set full size to lowest possible value */
45154 geo->src.full_width = 0;
45155 geo->src.full_height = 0;
45156 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45157 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45158 mxr_geometry_dump(mdev, &layer->geo);
45159
45160 /* returning results */
45161 @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
45162 target->width = s->r.width;
45163 target->height = s->r.height;
45164
45165 - layer->ops.fix_geometry(layer, stage, s->flags);
45166 + layer->ops->fix_geometry(layer, stage, s->flags);
45167
45168 /* retrieve update selection rectangle */
45169 res.left = target->x_offset;
45170 @@ -954,13 +954,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
45171 mxr_output_get(mdev);
45172
45173 mxr_layer_update_output(layer);
45174 - layer->ops.format_set(layer);
45175 + layer->ops->format_set(layer);
45176 /* enabling layer in hardware */
45177 spin_lock_irqsave(&layer->enq_slock, flags);
45178 layer->state = MXR_LAYER_STREAMING;
45179 spin_unlock_irqrestore(&layer->enq_slock, flags);
45180
45181 - layer->ops.stream_set(layer, MXR_ENABLE);
45182 + layer->ops->stream_set(layer, MXR_ENABLE);
45183 mxr_streamer_get(mdev);
45184
45185 return 0;
45186 @@ -1030,7 +1030,7 @@ static void stop_streaming(struct vb2_queue *vq)
45187 spin_unlock_irqrestore(&layer->enq_slock, flags);
45188
45189 /* disabling layer in hardware */
45190 - layer->ops.stream_set(layer, MXR_DISABLE);
45191 + layer->ops->stream_set(layer, MXR_DISABLE);
45192 /* remove one streamer */
45193 mxr_streamer_put(mdev);
45194 /* allow changes in output configuration */
45195 @@ -1068,8 +1068,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
45196
45197 void mxr_layer_release(struct mxr_layer *layer)
45198 {
45199 - if (layer->ops.release)
45200 - layer->ops.release(layer);
45201 + if (layer->ops->release)
45202 + layer->ops->release(layer);
45203 }
45204
45205 void mxr_base_layer_release(struct mxr_layer *layer)
45206 @@ -1095,7 +1095,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
45207
45208 layer->mdev = mdev;
45209 layer->idx = idx;
45210 - layer->ops = *ops;
45211 + layer->ops = ops;
45212
45213 spin_lock_init(&layer->enq_slock);
45214 INIT_LIST_HEAD(&layer->enq_list);
45215 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45216 index c9388c4..ce71ece 100644
45217 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45218 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45219 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
45220 {
45221 struct mxr_layer *layer;
45222 int ret;
45223 - struct mxr_layer_ops ops = {
45224 + static struct mxr_layer_ops ops = {
45225 .release = mxr_vp_layer_release,
45226 .buffer_set = mxr_vp_buffer_set,
45227 .stream_set = mxr_vp_stream_set,
45228 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
45229 index 82affae..42833ec 100644
45230 --- a/drivers/media/radio/radio-cadet.c
45231 +++ b/drivers/media/radio/radio-cadet.c
45232 @@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45233 unsigned char readbuf[RDS_BUFFER];
45234 int i = 0;
45235
45236 + if (count > RDS_BUFFER)
45237 + return -EFAULT;
45238 mutex_lock(&dev->lock);
45239 if (dev->rdsstat == 0)
45240 cadet_start_rds(dev);
45241 @@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45242 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
45243 mutex_unlock(&dev->lock);
45244
45245 - if (i && copy_to_user(data, readbuf, i))
45246 - return -EFAULT;
45247 + if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
45248 + i = -EFAULT;
45249 +
45250 return i;
45251 }
45252
45253 diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
45254 index 5236035..c622c74 100644
45255 --- a/drivers/media/radio/radio-maxiradio.c
45256 +++ b/drivers/media/radio/radio-maxiradio.c
45257 @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
45258 /* TEA5757 pin mappings */
45259 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
45260
45261 -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
45262 +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
45263
45264 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
45265 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
45266 diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
45267 index 050b3bb..79f62b9 100644
45268 --- a/drivers/media/radio/radio-shark.c
45269 +++ b/drivers/media/radio/radio-shark.c
45270 @@ -79,7 +79,7 @@ struct shark_device {
45271 u32 last_val;
45272 };
45273
45274 -static atomic_t shark_instance = ATOMIC_INIT(0);
45275 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45276
45277 static void shark_write_val(struct snd_tea575x *tea, u32 val)
45278 {
45279 diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
45280 index 8654e0d..0608a64 100644
45281 --- a/drivers/media/radio/radio-shark2.c
45282 +++ b/drivers/media/radio/radio-shark2.c
45283 @@ -74,7 +74,7 @@ struct shark_device {
45284 u8 *transfer_buffer;
45285 };
45286
45287 -static atomic_t shark_instance = ATOMIC_INIT(0);
45288 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45289
45290 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
45291 {
45292 diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
45293 index 633022b..7f10754 100644
45294 --- a/drivers/media/radio/radio-si476x.c
45295 +++ b/drivers/media/radio/radio-si476x.c
45296 @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
45297 struct si476x_radio *radio;
45298 struct v4l2_ctrl *ctrl;
45299
45300 - static atomic_t instance = ATOMIC_INIT(0);
45301 + static atomic_unchecked_t instance = ATOMIC_INIT(0);
45302
45303 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
45304 if (!radio)
45305 diff --git a/drivers/media/usb/dvb-usb/cinergyT2-core.c b/drivers/media/usb/dvb-usb/cinergyT2-core.c
45306 index 9fd1527..8927230 100644
45307 --- a/drivers/media/usb/dvb-usb/cinergyT2-core.c
45308 +++ b/drivers/media/usb/dvb-usb/cinergyT2-core.c
45309 @@ -50,29 +50,73 @@ static struct dvb_usb_device_properties cinergyt2_properties;
45310
45311 static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable)
45312 {
45313 - char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 };
45314 - char result[64];
45315 - return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result,
45316 - sizeof(result), 0);
45317 + char *buf;
45318 + char *result;
45319 + int retval;
45320 +
45321 + buf = kmalloc(2, GFP_KERNEL);
45322 + if (buf == NULL)
45323 + return -ENOMEM;
45324 + result = kmalloc(64, GFP_KERNEL);
45325 + if (result == NULL) {
45326 + kfree(buf);
45327 + return -ENOMEM;
45328 + }
45329 +
45330 + buf[0] = CINERGYT2_EP1_CONTROL_STREAM_TRANSFER;
45331 + buf[1] = enable ? 1 : 0;
45332 +
45333 + retval = dvb_usb_generic_rw(adap->dev, buf, 2, result, 64, 0);
45334 +
45335 + kfree(buf);
45336 + kfree(result);
45337 + return retval;
45338 }
45339
45340 static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)
45341 {
45342 - char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 };
45343 - char state[3];
45344 - return dvb_usb_generic_rw(d, buf, sizeof(buf), state, sizeof(state), 0);
45345 + char *buf;
45346 + char *state;
45347 + int retval;
45348 +
45349 + buf = kmalloc(2, GFP_KERNEL);
45350 + if (buf == NULL)
45351 + return -ENOMEM;
45352 + state = kmalloc(3, GFP_KERNEL);
45353 + if (state == NULL) {
45354 + kfree(buf);
45355 + return -ENOMEM;
45356 + }
45357 +
45358 + buf[0] = CINERGYT2_EP1_SLEEP_MODE;
45359 + buf[1] = enable ? 1 : 0;
45360 +
45361 + retval = dvb_usb_generic_rw(d, buf, 2, state, 3, 0);
45362 +
45363 + kfree(buf);
45364 + kfree(state);
45365 + return retval;
45366 }
45367
45368 static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
45369 {
45370 - char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION };
45371 - char state[3];
45372 + char *query;
45373 + char *state;
45374 int ret;
45375 + query = kmalloc(1, GFP_KERNEL);
45376 + if (query == NULL)
45377 + return -ENOMEM;
45378 + state = kmalloc(3, GFP_KERNEL);
45379 + if (state == NULL) {
45380 + kfree(query);
45381 + return -ENOMEM;
45382 + }
45383 +
45384 + query[0] = CINERGYT2_EP1_GET_FIRMWARE_VERSION;
45385
45386 adap->fe_adap[0].fe = cinergyt2_fe_attach(adap->dev);
45387
45388 - ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state,
45389 - sizeof(state), 0);
45390 + ret = dvb_usb_generic_rw(adap->dev, query, 1, state, 3, 0);
45391 if (ret < 0) {
45392 deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep "
45393 "state info\n");
45394 @@ -80,7 +124,8 @@ static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
45395
45396 /* Copy this pointer as we are gonna need it in the release phase */
45397 cinergyt2_usb_device = adap->dev;
45398 -
45399 + kfree(query);
45400 + kfree(state);
45401 return 0;
45402 }
45403
45404 @@ -141,12 +186,23 @@ static int repeatable_keys[] = {
45405 static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45406 {
45407 struct cinergyt2_state *st = d->priv;
45408 - u8 key[5] = {0, 0, 0, 0, 0}, cmd = CINERGYT2_EP1_GET_RC_EVENTS;
45409 + u8 *key, *cmd;
45410 int i;
45411
45412 + cmd = kmalloc(1, GFP_KERNEL);
45413 + if (cmd == NULL)
45414 + return -EINVAL;
45415 + key = kzalloc(5, GFP_KERNEL);
45416 + if (key == NULL) {
45417 + kfree(cmd);
45418 + return -EINVAL;
45419 + }
45420 +
45421 + cmd[0] = CINERGYT2_EP1_GET_RC_EVENTS;
45422 +
45423 *state = REMOTE_NO_KEY_PRESSED;
45424
45425 - dvb_usb_generic_rw(d, &cmd, 1, key, sizeof(key), 0);
45426 + dvb_usb_generic_rw(d, cmd, 1, key, 5, 0);
45427 if (key[4] == 0xff) {
45428 /* key repeat */
45429 st->rc_counter++;
45430 @@ -157,12 +213,12 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45431 *event = d->last_event;
45432 deb_rc("repeat key, event %x\n",
45433 *event);
45434 - return 0;
45435 + goto out;
45436 }
45437 }
45438 deb_rc("repeated key (non repeatable)\n");
45439 }
45440 - return 0;
45441 + goto out;
45442 }
45443
45444 /* hack to pass checksum on the custom field */
45445 @@ -174,6 +230,9 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45446
45447 deb_rc("key: %*ph\n", 5, key);
45448 }
45449 +out:
45450 + kfree(cmd);
45451 + kfree(key);
45452 return 0;
45453 }
45454
45455 diff --git a/drivers/media/usb/dvb-usb/cinergyT2-fe.c b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45456 index c890fe4..f9b2ae6 100644
45457 --- a/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45458 +++ b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45459 @@ -145,103 +145,176 @@ static int cinergyt2_fe_read_status(struct dvb_frontend *fe,
45460 fe_status_t *status)
45461 {
45462 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45463 - struct dvbt_get_status_msg result;
45464 - u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45465 + struct dvbt_get_status_msg *result;
45466 + u8 *cmd;
45467 int ret;
45468
45469 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&result,
45470 - sizeof(result), 0);
45471 + cmd = kmalloc(1, GFP_KERNEL);
45472 + if (cmd == NULL)
45473 + return -ENOMEM;
45474 + result = kmalloc(sizeof(*result), GFP_KERNEL);
45475 + if (result == NULL) {
45476 + kfree(cmd);
45477 + return -ENOMEM;
45478 + }
45479 +
45480 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45481 +
45482 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)result,
45483 + sizeof(*result), 0);
45484 if (ret < 0)
45485 - return ret;
45486 + goto out;
45487
45488 *status = 0;
45489
45490 - if (0xffff - le16_to_cpu(result.gain) > 30)
45491 + if (0xffff - le16_to_cpu(result->gain) > 30)
45492 *status |= FE_HAS_SIGNAL;
45493 - if (result.lock_bits & (1 << 6))
45494 + if (result->lock_bits & (1 << 6))
45495 *status |= FE_HAS_LOCK;
45496 - if (result.lock_bits & (1 << 5))
45497 + if (result->lock_bits & (1 << 5))
45498 *status |= FE_HAS_SYNC;
45499 - if (result.lock_bits & (1 << 4))
45500 + if (result->lock_bits & (1 << 4))
45501 *status |= FE_HAS_CARRIER;
45502 - if (result.lock_bits & (1 << 1))
45503 + if (result->lock_bits & (1 << 1))
45504 *status |= FE_HAS_VITERBI;
45505
45506 if ((*status & (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) !=
45507 (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC))
45508 *status &= ~FE_HAS_LOCK;
45509
45510 - return 0;
45511 +out:
45512 + kfree(cmd);
45513 + kfree(result);
45514 + return ret;
45515 }
45516
45517 static int cinergyt2_fe_read_ber(struct dvb_frontend *fe, u32 *ber)
45518 {
45519 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45520 - struct dvbt_get_status_msg status;
45521 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45522 + struct dvbt_get_status_msg *status;
45523 + char *cmd;
45524 int ret;
45525
45526 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45527 - sizeof(status), 0);
45528 + cmd = kmalloc(1, GFP_KERNEL);
45529 + if (cmd == NULL)
45530 + return -ENOMEM;
45531 + status = kmalloc(sizeof(*status), GFP_KERNEL);
45532 + if (status == NULL) {
45533 + kfree(cmd);
45534 + return -ENOMEM;
45535 + }
45536 +
45537 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45538 +
45539 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45540 + sizeof(*status), 0);
45541 if (ret < 0)
45542 - return ret;
45543 + goto out;
45544
45545 - *ber = le32_to_cpu(status.viterbi_error_rate);
45546 + *ber = le32_to_cpu(status->viterbi_error_rate);
45547 +out:
45548 + kfree(cmd);
45549 + kfree(status);
45550 return 0;
45551 }
45552
45553 static int cinergyt2_fe_read_unc_blocks(struct dvb_frontend *fe, u32 *unc)
45554 {
45555 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45556 - struct dvbt_get_status_msg status;
45557 - u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45558 + struct dvbt_get_status_msg *status;
45559 + u8 *cmd;
45560 int ret;
45561
45562 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&status,
45563 - sizeof(status), 0);
45564 + cmd = kmalloc(1, GFP_KERNEL);
45565 + if (cmd == NULL)
45566 + return -ENOMEM;
45567 + status = kmalloc(sizeof(*status), GFP_KERNEL);
45568 + if (status == NULL) {
45569 + kfree(cmd);
45570 + return -ENOMEM;
45571 + }
45572 +
45573 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45574 +
45575 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)status,
45576 + sizeof(*status), 0);
45577 if (ret < 0) {
45578 err("cinergyt2_fe_read_unc_blocks() Failed! (Error=%d)\n",
45579 ret);
45580 - return ret;
45581 + goto out;
45582 }
45583 - *unc = le32_to_cpu(status.uncorrected_block_count);
45584 - return 0;
45585 + *unc = le32_to_cpu(status->uncorrected_block_count);
45586 +
45587 +out:
45588 + kfree(cmd);
45589 + kfree(status);
45590 + return ret;
45591 }
45592
45593 static int cinergyt2_fe_read_signal_strength(struct dvb_frontend *fe,
45594 u16 *strength)
45595 {
45596 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45597 - struct dvbt_get_status_msg status;
45598 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45599 + struct dvbt_get_status_msg *status;
45600 + char *cmd;
45601 int ret;
45602
45603 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45604 - sizeof(status), 0);
45605 + cmd = kmalloc(1, GFP_KERNEL);
45606 + if (cmd == NULL)
45607 + return -ENOMEM;
45608 + status = kmalloc(sizeof(*status), GFP_KERNEL);
45609 + if (status == NULL) {
45610 + kfree(cmd);
45611 + return -ENOMEM;
45612 + }
45613 +
45614 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45615 +
45616 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45617 + sizeof(*status), 0);
45618 if (ret < 0) {
45619 err("cinergyt2_fe_read_signal_strength() Failed!"
45620 " (Error=%d)\n", ret);
45621 - return ret;
45622 + goto out;
45623 }
45624 - *strength = (0xffff - le16_to_cpu(status.gain));
45625 + *strength = (0xffff - le16_to_cpu(status->gain));
45626 +
45627 +out:
45628 + kfree(cmd);
45629 + kfree(status);
45630 return 0;
45631 }
45632
45633 static int cinergyt2_fe_read_snr(struct dvb_frontend *fe, u16 *snr)
45634 {
45635 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45636 - struct dvbt_get_status_msg status;
45637 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45638 + struct dvbt_get_status_msg *status;
45639 + char *cmd;
45640 int ret;
45641
45642 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45643 - sizeof(status), 0);
45644 + cmd = kmalloc(1, GFP_KERNEL);
45645 + if (cmd == NULL)
45646 + return -ENOMEM;
45647 + status = kmalloc(sizeof(*status), GFP_KERNEL);
45648 + if (status == NULL) {
45649 + kfree(cmd);
45650 + return -ENOMEM;
45651 + }
45652 +
45653 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45654 +
45655 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45656 + sizeof(*status), 0);
45657 if (ret < 0) {
45658 err("cinergyt2_fe_read_snr() Failed! (Error=%d)\n", ret);
45659 - return ret;
45660 + goto out;
45661 }
45662 - *snr = (status.snr << 8) | status.snr;
45663 - return 0;
45664 + *snr = (status->snr << 8) | status->snr;
45665 +
45666 +out:
45667 + kfree(cmd);
45668 + kfree(status);
45669 + return ret;
45670 }
45671
45672 static int cinergyt2_fe_init(struct dvb_frontend *fe)
45673 @@ -266,35 +339,46 @@ static int cinergyt2_fe_set_frontend(struct dvb_frontend *fe)
45674 {
45675 struct dtv_frontend_properties *fep = &fe->dtv_property_cache;
45676 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45677 - struct dvbt_set_parameters_msg param;
45678 - char result[2];
45679 + struct dvbt_set_parameters_msg *param;
45680 + char *result;
45681 int err;
45682
45683 - param.cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
45684 - param.tps = cpu_to_le16(compute_tps(fep));
45685 - param.freq = cpu_to_le32(fep->frequency / 1000);
45686 - param.flags = 0;
45687 + result = kmalloc(2, GFP_KERNEL);
45688 + if (result == NULL)
45689 + return -ENOMEM;
45690 + param = kmalloc(sizeof(*param), GFP_KERNEL);
45691 + if (param == NULL) {
45692 + kfree(result);
45693 + return -ENOMEM;
45694 + }
45695 +
45696 + param->cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
45697 + param->tps = cpu_to_le16(compute_tps(fep));
45698 + param->freq = cpu_to_le32(fep->frequency / 1000);
45699 + param->flags = 0;
45700
45701 switch (fep->bandwidth_hz) {
45702 default:
45703 case 8000000:
45704 - param.bandwidth = 8;
45705 + param->bandwidth = 8;
45706 break;
45707 case 7000000:
45708 - param.bandwidth = 7;
45709 + param->bandwidth = 7;
45710 break;
45711 case 6000000:
45712 - param.bandwidth = 6;
45713 + param->bandwidth = 6;
45714 break;
45715 }
45716
45717 err = dvb_usb_generic_rw(state->d,
45718 - (char *)&param, sizeof(param),
45719 - result, sizeof(result), 0);
45720 + (char *)param, sizeof(*param),
45721 + result, 2, 0);
45722 if (err < 0)
45723 err("cinergyt2_fe_set_frontend() Failed! err=%d\n", err);
45724
45725 - return (err < 0) ? err : 0;
45726 + kfree(result);
45727 + kfree(param);
45728 + return err;
45729 }
45730
45731 static void cinergyt2_fe_release(struct dvb_frontend *fe)
45732 diff --git a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
45733 index 733a7ff..f8b52e3 100644
45734 --- a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
45735 +++ b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
45736 @@ -35,42 +35,57 @@ static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 le
45737
45738 int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type)
45739 {
45740 - struct hexline hx;
45741 - u8 reset;
45742 + struct hexline *hx;
45743 + u8 *reset;
45744 int ret,pos=0;
45745
45746 + reset = kmalloc(1, GFP_KERNEL);
45747 + if (reset == NULL)
45748 + return -ENOMEM;
45749 +
45750 + hx = kmalloc(sizeof(struct hexline), GFP_KERNEL);
45751 + if (hx == NULL) {
45752 + kfree(reset);
45753 + return -ENOMEM;
45754 + }
45755 +
45756 /* stop the CPU */
45757 - reset = 1;
45758 - if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1)
45759 + reset[0] = 1;
45760 + if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1)) != 1)
45761 err("could not stop the USB controller CPU.");
45762
45763 - while ((ret = dvb_usb_get_hexline(fw,&hx,&pos)) > 0) {
45764 - deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx.addr,hx.len,hx.chk);
45765 - ret = usb_cypress_writemem(udev,hx.addr,hx.data,hx.len);
45766 + while ((ret = dvb_usb_get_hexline(fw,hx,&pos)) > 0) {
45767 + deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx->addr,hx->len,hx->chk);
45768 + ret = usb_cypress_writemem(udev,hx->addr,hx->data,hx->len);
45769
45770 - if (ret != hx.len) {
45771 + if (ret != hx->len) {
45772 err("error while transferring firmware "
45773 "(transferred size: %d, block size: %d)",
45774 - ret,hx.len);
45775 + ret,hx->len);
45776 ret = -EINVAL;
45777 break;
45778 }
45779 }
45780 if (ret < 0) {
45781 err("firmware download failed at %d with %d",pos,ret);
45782 + kfree(reset);
45783 + kfree(hx);
45784 return ret;
45785 }
45786
45787 if (ret == 0) {
45788 /* restart the CPU */
45789 - reset = 0;
45790 - if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) {
45791 + reset[0] = 0;
45792 + if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1) != 1) {
45793 err("could not restart the USB controller CPU.");
45794 ret = -EINVAL;
45795 }
45796 } else
45797 ret = -EIO;
45798
45799 + kfree(reset);
45800 + kfree(hx);
45801 +
45802 return ret;
45803 }
45804 EXPORT_SYMBOL(usb_cypress_load_firmware);
45805 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
45806 index 1a3df10..57997a5 100644
45807 --- a/drivers/media/usb/dvb-usb/dw2102.c
45808 +++ b/drivers/media/usb/dvb-usb/dw2102.c
45809 @@ -118,7 +118,7 @@ struct su3000_state {
45810
45811 struct s6x0_state {
45812 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
45813 -};
45814 +} __no_const;
45815
45816 /* debug */
45817 static int dvb_usb_dw2102_debug;
45818 diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c
45819 index 6b0b8b6b..4038398 100644
45820 --- a/drivers/media/usb/dvb-usb/technisat-usb2.c
45821 +++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
45822 @@ -87,8 +87,11 @@ struct technisat_usb2_state {
45823 static int technisat_usb2_i2c_access(struct usb_device *udev,
45824 u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
45825 {
45826 - u8 b[64];
45827 - int ret, actual_length;
45828 + u8 *b = kmalloc(64, GFP_KERNEL);
45829 + int ret, actual_length, error = 0;
45830 +
45831 + if (b == NULL)
45832 + return -ENOMEM;
45833
45834 deb_i2c("i2c-access: %02x, tx: ", device_addr);
45835 debug_dump(tx, txlen, deb_i2c);
45836 @@ -121,7 +124,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
45837
45838 if (ret < 0) {
45839 err("i2c-error: out failed %02x = %d", device_addr, ret);
45840 - return -ENODEV;
45841 + error = -ENODEV;
45842 + goto out;
45843 }
45844
45845 ret = usb_bulk_msg(udev,
45846 @@ -129,7 +133,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
45847 b, 64, &actual_length, 1000);
45848 if (ret < 0) {
45849 err("i2c-error: in failed %02x = %d", device_addr, ret);
45850 - return -ENODEV;
45851 + error = -ENODEV;
45852 + goto out;
45853 }
45854
45855 if (b[0] != I2C_STATUS_OK) {
45856 @@ -137,8 +142,10 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
45857 /* handle tuner-i2c-nak */
45858 if (!(b[0] == I2C_STATUS_NAK &&
45859 device_addr == 0x60
45860 - /* && device_is_technisat_usb2 */))
45861 - return -ENODEV;
45862 + /* && device_is_technisat_usb2 */)) {
45863 + error = -ENODEV;
45864 + goto out;
45865 + }
45866 }
45867
45868 deb_i2c("status: %d, ", b[0]);
45869 @@ -152,7 +159,9 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
45870
45871 deb_i2c("\n");
45872
45873 - return 0;
45874 +out:
45875 + kfree(b);
45876 + return error;
45877 }
45878
45879 static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
45880 @@ -224,14 +233,16 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
45881 {
45882 int ret;
45883
45884 - u8 led[8] = {
45885 - red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
45886 - 0
45887 - };
45888 + u8 *led = kzalloc(8, GFP_KERNEL);
45889 +
45890 + if (led == NULL)
45891 + return -ENOMEM;
45892
45893 if (disable_led_control && state != TECH_LED_OFF)
45894 return 0;
45895
45896 + led[0] = red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST;
45897 +
45898 switch (state) {
45899 case TECH_LED_ON:
45900 led[1] = 0x82;
45901 @@ -263,16 +274,22 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
45902 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
45903 USB_TYPE_VENDOR | USB_DIR_OUT,
45904 0, 0,
45905 - led, sizeof(led), 500);
45906 + led, 8, 500);
45907
45908 mutex_unlock(&d->i2c_mutex);
45909 +
45910 + kfree(led);
45911 +
45912 return ret;
45913 }
45914
45915 static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 green)
45916 {
45917 int ret;
45918 - u8 b = 0;
45919 + u8 *b = kzalloc(1, GFP_KERNEL);
45920 +
45921 + if (b == NULL)
45922 + return -ENOMEM;
45923
45924 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
45925 return -EAGAIN;
45926 @@ -281,10 +298,12 @@ static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 gre
45927 SET_LED_TIMER_DIVIDER_VENDOR_REQUEST,
45928 USB_TYPE_VENDOR | USB_DIR_OUT,
45929 (red << 8) | green, 0,
45930 - &b, 1, 500);
45931 + b, 1, 500);
45932
45933 mutex_unlock(&d->i2c_mutex);
45934
45935 + kfree(b);
45936 +
45937 return ret;
45938 }
45939
45940 @@ -328,7 +347,7 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
45941 struct dvb_usb_device_description **desc, int *cold)
45942 {
45943 int ret;
45944 - u8 version[3];
45945 + u8 *version = kmalloc(3, GFP_KERNEL);
45946
45947 /* first select the interface */
45948 if (usb_set_interface(udev, 0, 1) != 0)
45949 @@ -338,11 +357,14 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
45950
45951 *cold = 0; /* by default do not download a firmware - just in case something is wrong */
45952
45953 + if (version == NULL)
45954 + return 0;
45955 +
45956 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
45957 GET_VERSION_INFO_VENDOR_REQUEST,
45958 USB_TYPE_VENDOR | USB_DIR_IN,
45959 0, 0,
45960 - version, sizeof(version), 500);
45961 + version, 3, 500);
45962
45963 if (ret < 0)
45964 *cold = 1;
45965 @@ -351,6 +373,8 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
45966 *cold = 0;
45967 }
45968
45969 + kfree(version);
45970 +
45971 return 0;
45972 }
45973
45974 @@ -591,10 +615,15 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
45975
45976 static int technisat_usb2_get_ir(struct dvb_usb_device *d)
45977 {
45978 - u8 buf[62], *b;
45979 + u8 *buf, *b;
45980 int ret;
45981 struct ir_raw_event ev;
45982
45983 + buf = kmalloc(62, GFP_KERNEL);
45984 +
45985 + if (buf == NULL)
45986 + return -ENOMEM;
45987 +
45988 buf[0] = GET_IR_DATA_VENDOR_REQUEST;
45989 buf[1] = 0x08;
45990 buf[2] = 0x8f;
45991 @@ -617,16 +646,20 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d)
45992 GET_IR_DATA_VENDOR_REQUEST,
45993 USB_TYPE_VENDOR | USB_DIR_IN,
45994 0x8080, 0,
45995 - buf, sizeof(buf), 500);
45996 + buf, 62, 500);
45997
45998 unlock:
45999 mutex_unlock(&d->i2c_mutex);
46000
46001 - if (ret < 0)
46002 + if (ret < 0) {
46003 + kfree(buf);
46004 return ret;
46005 + }
46006
46007 - if (ret == 1)
46008 + if (ret == 1) {
46009 + kfree(buf);
46010 return 0; /* no key pressed */
46011 + }
46012
46013 /* decoding */
46014 b = buf+1;
46015 @@ -653,6 +686,8 @@ unlock:
46016
46017 ir_raw_event_handle(d->rc_dev);
46018
46019 + kfree(buf);
46020 +
46021 return 1;
46022 }
46023
46024 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46025 index e502a5f..2a27f40 100644
46026 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46027 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46028 @@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46029 * by passing a very big num_planes value */
46030 uplane = compat_alloc_user_space(num_planes *
46031 sizeof(struct v4l2_plane));
46032 - kp->m.planes = (__force struct v4l2_plane *)uplane;
46033 + kp->m.planes = (__force_kernel struct v4l2_plane *)uplane;
46034
46035 while (--num_planes >= 0) {
46036 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
46037 @@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46038 if (num_planes == 0)
46039 return 0;
46040
46041 - uplane = (__force struct v4l2_plane __user *)kp->m.planes;
46042 + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
46043 if (get_user(p, &up->m.planes))
46044 return -EFAULT;
46045 uplane32 = compat_ptr(p);
46046 @@ -562,7 +562,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
46047 get_user(kp->flags, &up->flags) ||
46048 copy_from_user(&kp->fmt, &up->fmt, sizeof(up->fmt)))
46049 return -EFAULT;
46050 - kp->base = (__force void *)compat_ptr(tmp);
46051 + kp->base = (__force_kernel void *)compat_ptr(tmp);
46052 return 0;
46053 }
46054
46055 @@ -667,7 +667,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46056 n * sizeof(struct v4l2_ext_control32)))
46057 return -EFAULT;
46058 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
46059 - kp->controls = (__force struct v4l2_ext_control *)kcontrols;
46060 + kp->controls = (__force_kernel struct v4l2_ext_control *)kcontrols;
46061 while (--n >= 0) {
46062 u32 id;
46063
46064 @@ -694,7 +694,7 @@ static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46065 {
46066 struct v4l2_ext_control32 __user *ucontrols;
46067 struct v4l2_ext_control __user *kcontrols =
46068 - (__force struct v4l2_ext_control __user *)kp->controls;
46069 + (struct v4l2_ext_control __force_user *)kp->controls;
46070 int n = kp->count;
46071 compat_caddr_t p;
46072
46073 @@ -778,7 +778,7 @@ static int get_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
46074 get_user(tmp, &up->edid) ||
46075 copy_from_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
46076 return -EFAULT;
46077 - kp->edid = (__force u8 *)compat_ptr(tmp);
46078 + kp->edid = (__force_kernel u8 *)compat_ptr(tmp);
46079 return 0;
46080 }
46081
46082 diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
46083 index 015f92a..59e311e 100644
46084 --- a/drivers/media/v4l2-core/v4l2-device.c
46085 +++ b/drivers/media/v4l2-core/v4l2-device.c
46086 @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
46087 EXPORT_SYMBOL_GPL(v4l2_device_put);
46088
46089 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
46090 - atomic_t *instance)
46091 + atomic_unchecked_t *instance)
46092 {
46093 - int num = atomic_inc_return(instance) - 1;
46094 + int num = atomic_inc_return_unchecked(instance) - 1;
46095 int len = strlen(basename);
46096
46097 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
46098 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
46099 index 9ccb19a..d131468 100644
46100 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
46101 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
46102 @@ -2142,7 +2142,8 @@ struct v4l2_ioctl_info {
46103 struct file *file, void *fh, void *p);
46104 } u;
46105 void (*debug)(const void *arg, bool write_only);
46106 -};
46107 +} __do_const;
46108 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
46109
46110 /* This control needs a priority check */
46111 #define INFO_FL_PRIO (1 << 0)
46112 @@ -2326,7 +2327,7 @@ static long __video_do_ioctl(struct file *file,
46113 struct video_device *vfd = video_devdata(file);
46114 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
46115 bool write_only = false;
46116 - struct v4l2_ioctl_info default_info;
46117 + v4l2_ioctl_info_no_const default_info;
46118 const struct v4l2_ioctl_info *info;
46119 void *fh = file->private_data;
46120 struct v4l2_fh *vfh = NULL;
46121 @@ -2413,7 +2414,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46122 ret = -EINVAL;
46123 break;
46124 }
46125 - *user_ptr = (void __user *)buf->m.planes;
46126 + *user_ptr = (void __force_user *)buf->m.planes;
46127 *kernel_ptr = (void **)&buf->m.planes;
46128 *array_size = sizeof(struct v4l2_plane) * buf->length;
46129 ret = 1;
46130 @@ -2430,7 +2431,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46131 ret = -EINVAL;
46132 break;
46133 }
46134 - *user_ptr = (void __user *)edid->edid;
46135 + *user_ptr = (void __force_user *)edid->edid;
46136 *kernel_ptr = (void **)&edid->edid;
46137 *array_size = edid->blocks * 128;
46138 ret = 1;
46139 @@ -2448,7 +2449,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46140 ret = -EINVAL;
46141 break;
46142 }
46143 - *user_ptr = (void __user *)ctrls->controls;
46144 + *user_ptr = (void __force_user *)ctrls->controls;
46145 *kernel_ptr = (void **)&ctrls->controls;
46146 *array_size = sizeof(struct v4l2_ext_control)
46147 * ctrls->count;
46148 @@ -2549,7 +2550,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
46149 }
46150
46151 if (has_array_args) {
46152 - *kernel_ptr = (void __force *)user_ptr;
46153 + *kernel_ptr = (void __force_kernel *)user_ptr;
46154 if (copy_to_user(user_ptr, mbuf, array_size))
46155 err = -EFAULT;
46156 goto out_array_args;
46157 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
46158 index 187f836..679544b 100644
46159 --- a/drivers/message/fusion/mptbase.c
46160 +++ b/drivers/message/fusion/mptbase.c
46161 @@ -6746,8 +6746,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46162 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
46163 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
46164
46165 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46166 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
46167 +#else
46168 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
46169 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
46170 +#endif
46171 +
46172 /*
46173 * Rounding UP to nearest 4-kB boundary here...
46174 */
46175 @@ -6760,7 +6765,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46176 ioc->facts.GlobalCredits);
46177
46178 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
46179 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46180 + NULL, NULL);
46181 +#else
46182 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
46183 +#endif
46184 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
46185 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
46186 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
46187 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
46188 index 0707fa2..70ca794 100644
46189 --- a/drivers/message/fusion/mptsas.c
46190 +++ b/drivers/message/fusion/mptsas.c
46191 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
46192 return 0;
46193 }
46194
46195 +static inline void
46196 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
46197 +{
46198 + if (phy_info->port_details) {
46199 + phy_info->port_details->rphy = rphy;
46200 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
46201 + ioc->name, rphy));
46202 + }
46203 +
46204 + if (rphy) {
46205 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
46206 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
46207 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
46208 + ioc->name, rphy, rphy->dev.release));
46209 + }
46210 +}
46211 +
46212 /* no mutex */
46213 static void
46214 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
46215 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
46216 return NULL;
46217 }
46218
46219 -static inline void
46220 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
46221 -{
46222 - if (phy_info->port_details) {
46223 - phy_info->port_details->rphy = rphy;
46224 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
46225 - ioc->name, rphy));
46226 - }
46227 -
46228 - if (rphy) {
46229 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
46230 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
46231 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
46232 - ioc->name, rphy, rphy->dev.release));
46233 - }
46234 -}
46235 -
46236 static inline struct sas_port *
46237 mptsas_get_port(struct mptsas_phyinfo *phy_info)
46238 {
46239 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
46240 index b7d87cd..3fb36da 100644
46241 --- a/drivers/message/i2o/i2o_proc.c
46242 +++ b/drivers/message/i2o/i2o_proc.c
46243 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
46244 "Array Controller Device"
46245 };
46246
46247 -static char *chtostr(char *tmp, u8 *chars, int n)
46248 -{
46249 - tmp[0] = 0;
46250 - return strncat(tmp, (char *)chars, n);
46251 -}
46252 -
46253 static int i2o_report_query_status(struct seq_file *seq, int block_status,
46254 char *group)
46255 {
46256 @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
46257 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
46258 {
46259 struct i2o_controller *c = (struct i2o_controller *)seq->private;
46260 - static u32 work32[5];
46261 - static u8 *work8 = (u8 *) work32;
46262 - static u16 *work16 = (u16 *) work32;
46263 + u32 work32[5];
46264 + u8 *work8 = (u8 *) work32;
46265 + u16 *work16 = (u16 *) work32;
46266 int token;
46267 u32 hwcap;
46268
46269 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
46270 } *result;
46271
46272 i2o_exec_execute_ddm_table ddm_table;
46273 - char tmp[28 + 1];
46274
46275 result = kmalloc(sizeof(*result), GFP_KERNEL);
46276 if (!result)
46277 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
46278
46279 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
46280 seq_printf(seq, "%-#8x", ddm_table.module_id);
46281 - seq_printf(seq, "%-29s",
46282 - chtostr(tmp, ddm_table.module_name_version, 28));
46283 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
46284 seq_printf(seq, "%9d ", ddm_table.data_size);
46285 seq_printf(seq, "%8d", ddm_table.code_size);
46286
46287 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
46288
46289 i2o_driver_result_table *result;
46290 i2o_driver_store_table *dst;
46291 - char tmp[28 + 1];
46292
46293 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
46294 if (result == NULL)
46295 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
46296
46297 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
46298 seq_printf(seq, "%-#8x", dst->module_id);
46299 - seq_printf(seq, "%-29s",
46300 - chtostr(tmp, dst->module_name_version, 28));
46301 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
46302 + seq_printf(seq, "%-.28s", dst->module_name_version);
46303 + seq_printf(seq, "%-.8s", dst->date);
46304 seq_printf(seq, "%8d ", dst->module_size);
46305 seq_printf(seq, "%8d ", dst->mpb_size);
46306 seq_printf(seq, "0x%04x", dst->module_flags);
46307 @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
46308 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
46309 {
46310 struct i2o_device *d = (struct i2o_device *)seq->private;
46311 - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
46312 + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
46313 // == (allow) 512d bytes (max)
46314 - static u16 *work16 = (u16 *) work32;
46315 + u16 *work16 = (u16 *) work32;
46316 int token;
46317 - char tmp[16 + 1];
46318
46319 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
46320
46321 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
46322 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
46323 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
46324 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
46325 - seq_printf(seq, "Vendor info : %s\n",
46326 - chtostr(tmp, (u8 *) (work32 + 2), 16));
46327 - seq_printf(seq, "Product info : %s\n",
46328 - chtostr(tmp, (u8 *) (work32 + 6), 16));
46329 - seq_printf(seq, "Description : %s\n",
46330 - chtostr(tmp, (u8 *) (work32 + 10), 16));
46331 - seq_printf(seq, "Product rev. : %s\n",
46332 - chtostr(tmp, (u8 *) (work32 + 14), 8));
46333 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
46334 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
46335 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
46336 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
46337
46338 seq_printf(seq, "Serial number : ");
46339 print_serial_number(seq, (u8 *) (work32 + 16),
46340 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
46341 u8 pad[256]; // allow up to 256 byte (max) serial number
46342 } result;
46343
46344 - char tmp[24 + 1];
46345 -
46346 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
46347
46348 if (token < 0) {
46349 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
46350 }
46351
46352 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
46353 - seq_printf(seq, "Module name : %s\n",
46354 - chtostr(tmp, result.module_name, 24));
46355 - seq_printf(seq, "Module revision : %s\n",
46356 - chtostr(tmp, result.module_rev, 8));
46357 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
46358 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
46359
46360 seq_printf(seq, "Serial number : ");
46361 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
46362 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46363 u8 instance_number[4];
46364 } result;
46365
46366 - char tmp[64 + 1];
46367 -
46368 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
46369
46370 if (token < 0) {
46371 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46372 return 0;
46373 }
46374
46375 - seq_printf(seq, "Device name : %s\n",
46376 - chtostr(tmp, result.device_name, 64));
46377 - seq_printf(seq, "Service name : %s\n",
46378 - chtostr(tmp, result.service_name, 64));
46379 - seq_printf(seq, "Physical name : %s\n",
46380 - chtostr(tmp, result.physical_location, 64));
46381 - seq_printf(seq, "Instance number : %s\n",
46382 - chtostr(tmp, result.instance_number, 4));
46383 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
46384 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
46385 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
46386 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
46387
46388 return 0;
46389 }
46390 @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46391 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
46392 {
46393 struct i2o_device *d = (struct i2o_device *)seq->private;
46394 - static u32 work32[12];
46395 - static u16 *work16 = (u16 *) work32;
46396 - static u8 *work8 = (u8 *) work32;
46397 + u32 work32[12];
46398 + u16 *work16 = (u16 *) work32;
46399 + u8 *work8 = (u8 *) work32;
46400 int token;
46401
46402 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
46403 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
46404 index 92752fb..a7494f6 100644
46405 --- a/drivers/message/i2o/iop.c
46406 +++ b/drivers/message/i2o/iop.c
46407 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
46408
46409 spin_lock_irqsave(&c->context_list_lock, flags);
46410
46411 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
46412 - atomic_inc(&c->context_list_counter);
46413 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
46414 + atomic_inc_unchecked(&c->context_list_counter);
46415
46416 - entry->context = atomic_read(&c->context_list_counter);
46417 + entry->context = atomic_read_unchecked(&c->context_list_counter);
46418
46419 list_add(&entry->list, &c->context_list);
46420
46421 @@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
46422
46423 #if BITS_PER_LONG == 64
46424 spin_lock_init(&c->context_list_lock);
46425 - atomic_set(&c->context_list_counter, 0);
46426 + atomic_set_unchecked(&c->context_list_counter, 0);
46427 INIT_LIST_HEAD(&c->context_list);
46428 #endif
46429
46430 diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
46431 index b2c7e3b..85aa4764 100644
46432 --- a/drivers/mfd/ab8500-debugfs.c
46433 +++ b/drivers/mfd/ab8500-debugfs.c
46434 @@ -100,7 +100,7 @@ static int irq_last;
46435 static u32 *irq_count;
46436 static int num_irqs;
46437
46438 -static struct device_attribute **dev_attr;
46439 +static device_attribute_no_const **dev_attr;
46440 static char **event_name;
46441
46442 static u8 avg_sample = SAMPLE_16;
46443 diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
46444 index c880c89..45a7c68 100644
46445 --- a/drivers/mfd/max8925-i2c.c
46446 +++ b/drivers/mfd/max8925-i2c.c
46447 @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
46448 const struct i2c_device_id *id)
46449 {
46450 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
46451 - static struct max8925_chip *chip;
46452 + struct max8925_chip *chip;
46453 struct device_node *node = client->dev.of_node;
46454
46455 if (node && !pdata) {
46456 diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
46457 index 7612d89..70549c2 100644
46458 --- a/drivers/mfd/tps65910.c
46459 +++ b/drivers/mfd/tps65910.c
46460 @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
46461 struct tps65910_platform_data *pdata)
46462 {
46463 int ret = 0;
46464 - static struct regmap_irq_chip *tps6591x_irqs_chip;
46465 + struct regmap_irq_chip *tps6591x_irqs_chip;
46466
46467 if (!irq) {
46468 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
46469 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
46470 index 1b772ef..01e77d33 100644
46471 --- a/drivers/mfd/twl4030-irq.c
46472 +++ b/drivers/mfd/twl4030-irq.c
46473 @@ -34,6 +34,7 @@
46474 #include <linux/of.h>
46475 #include <linux/irqdomain.h>
46476 #include <linux/i2c/twl.h>
46477 +#include <asm/pgtable.h>
46478
46479 #include "twl-core.h"
46480
46481 @@ -729,10 +730,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
46482 * Install an irq handler for each of the SIH modules;
46483 * clone dummy irq_chip since PIH can't *do* anything
46484 */
46485 - twl4030_irq_chip = dummy_irq_chip;
46486 - twl4030_irq_chip.name = "twl4030";
46487 + pax_open_kernel();
46488 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
46489 + *(const char **)&twl4030_irq_chip.name = "twl4030";
46490
46491 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
46492 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
46493 + pax_close_kernel();
46494
46495 for (i = irq_base; i < irq_end; i++) {
46496 irq_set_chip_and_handler(i, &twl4030_irq_chip,
46497 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
46498 index 464419b..64bae8d 100644
46499 --- a/drivers/misc/c2port/core.c
46500 +++ b/drivers/misc/c2port/core.c
46501 @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
46502 goto error_idr_alloc;
46503 c2dev->id = ret;
46504
46505 - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
46506 + pax_open_kernel();
46507 + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
46508 + pax_close_kernel();
46509
46510 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
46511 "c2port%d", c2dev->id);
46512 diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
46513 index 3f2b625..945e179 100644
46514 --- a/drivers/misc/eeprom/sunxi_sid.c
46515 +++ b/drivers/misc/eeprom/sunxi_sid.c
46516 @@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
46517
46518 platform_set_drvdata(pdev, sid_data);
46519
46520 - sid_bin_attr.size = sid_data->keysize;
46521 + pax_open_kernel();
46522 + *(size_t *)&sid_bin_attr.size = sid_data->keysize;
46523 + pax_close_kernel();
46524 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
46525 return -ENODEV;
46526
46527 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
46528 index 36f5d52..32311c3 100644
46529 --- a/drivers/misc/kgdbts.c
46530 +++ b/drivers/misc/kgdbts.c
46531 @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
46532 char before[BREAK_INSTR_SIZE];
46533 char after[BREAK_INSTR_SIZE];
46534
46535 - probe_kernel_read(before, (char *)kgdbts_break_test,
46536 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
46537 BREAK_INSTR_SIZE);
46538 init_simple_test();
46539 ts.tst = plant_and_detach_test;
46540 @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
46541 /* Activate test with initial breakpoint */
46542 if (!is_early)
46543 kgdb_breakpoint();
46544 - probe_kernel_read(after, (char *)kgdbts_break_test,
46545 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
46546 BREAK_INSTR_SIZE);
46547 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
46548 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
46549 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
46550 index 3ef4627..8d00486 100644
46551 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
46552 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
46553 @@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
46554 * the lid is closed. This leads to interrupts as soon as a little move
46555 * is done.
46556 */
46557 - atomic_inc(&lis3->count);
46558 + atomic_inc_unchecked(&lis3->count);
46559
46560 wake_up_interruptible(&lis3->misc_wait);
46561 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
46562 @@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
46563 if (lis3->pm_dev)
46564 pm_runtime_get_sync(lis3->pm_dev);
46565
46566 - atomic_set(&lis3->count, 0);
46567 + atomic_set_unchecked(&lis3->count, 0);
46568 return 0;
46569 }
46570
46571 @@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
46572 add_wait_queue(&lis3->misc_wait, &wait);
46573 while (true) {
46574 set_current_state(TASK_INTERRUPTIBLE);
46575 - data = atomic_xchg(&lis3->count, 0);
46576 + data = atomic_xchg_unchecked(&lis3->count, 0);
46577 if (data)
46578 break;
46579
46580 @@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
46581 struct lis3lv02d, miscdev);
46582
46583 poll_wait(file, &lis3->misc_wait, wait);
46584 - if (atomic_read(&lis3->count))
46585 + if (atomic_read_unchecked(&lis3->count))
46586 return POLLIN | POLLRDNORM;
46587 return 0;
46588 }
46589 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
46590 index c439c82..1f20f57 100644
46591 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
46592 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
46593 @@ -297,7 +297,7 @@ struct lis3lv02d {
46594 struct input_polled_dev *idev; /* input device */
46595 struct platform_device *pdev; /* platform device */
46596 struct regulator_bulk_data regulators[2];
46597 - atomic_t count; /* interrupt count after last read */
46598 + atomic_unchecked_t count; /* interrupt count after last read */
46599 union axis_conversion ac; /* hw -> logical axis */
46600 int mapped_btns[3];
46601
46602 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
46603 index 2f30bad..c4c13d0 100644
46604 --- a/drivers/misc/sgi-gru/gruhandles.c
46605 +++ b/drivers/misc/sgi-gru/gruhandles.c
46606 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
46607 unsigned long nsec;
46608
46609 nsec = CLKS2NSEC(clks);
46610 - atomic_long_inc(&mcs_op_statistics[op].count);
46611 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
46612 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
46613 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
46614 if (mcs_op_statistics[op].max < nsec)
46615 mcs_op_statistics[op].max = nsec;
46616 }
46617 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
46618 index 4f76359..cdfcb2e 100644
46619 --- a/drivers/misc/sgi-gru/gruprocfs.c
46620 +++ b/drivers/misc/sgi-gru/gruprocfs.c
46621 @@ -32,9 +32,9 @@
46622
46623 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
46624
46625 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
46626 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
46627 {
46628 - unsigned long val = atomic_long_read(v);
46629 + unsigned long val = atomic_long_read_unchecked(v);
46630
46631 seq_printf(s, "%16lu %s\n", val, id);
46632 }
46633 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
46634
46635 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
46636 for (op = 0; op < mcsop_last; op++) {
46637 - count = atomic_long_read(&mcs_op_statistics[op].count);
46638 - total = atomic_long_read(&mcs_op_statistics[op].total);
46639 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
46640 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
46641 max = mcs_op_statistics[op].max;
46642 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
46643 count ? total / count : 0, max);
46644 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
46645 index 5c3ce24..4915ccb 100644
46646 --- a/drivers/misc/sgi-gru/grutables.h
46647 +++ b/drivers/misc/sgi-gru/grutables.h
46648 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
46649 * GRU statistics.
46650 */
46651 struct gru_stats_s {
46652 - atomic_long_t vdata_alloc;
46653 - atomic_long_t vdata_free;
46654 - atomic_long_t gts_alloc;
46655 - atomic_long_t gts_free;
46656 - atomic_long_t gms_alloc;
46657 - atomic_long_t gms_free;
46658 - atomic_long_t gts_double_allocate;
46659 - atomic_long_t assign_context;
46660 - atomic_long_t assign_context_failed;
46661 - atomic_long_t free_context;
46662 - atomic_long_t load_user_context;
46663 - atomic_long_t load_kernel_context;
46664 - atomic_long_t lock_kernel_context;
46665 - atomic_long_t unlock_kernel_context;
46666 - atomic_long_t steal_user_context;
46667 - atomic_long_t steal_kernel_context;
46668 - atomic_long_t steal_context_failed;
46669 - atomic_long_t nopfn;
46670 - atomic_long_t asid_new;
46671 - atomic_long_t asid_next;
46672 - atomic_long_t asid_wrap;
46673 - atomic_long_t asid_reuse;
46674 - atomic_long_t intr;
46675 - atomic_long_t intr_cbr;
46676 - atomic_long_t intr_tfh;
46677 - atomic_long_t intr_spurious;
46678 - atomic_long_t intr_mm_lock_failed;
46679 - atomic_long_t call_os;
46680 - atomic_long_t call_os_wait_queue;
46681 - atomic_long_t user_flush_tlb;
46682 - atomic_long_t user_unload_context;
46683 - atomic_long_t user_exception;
46684 - atomic_long_t set_context_option;
46685 - atomic_long_t check_context_retarget_intr;
46686 - atomic_long_t check_context_unload;
46687 - atomic_long_t tlb_dropin;
46688 - atomic_long_t tlb_preload_page;
46689 - atomic_long_t tlb_dropin_fail_no_asid;
46690 - atomic_long_t tlb_dropin_fail_upm;
46691 - atomic_long_t tlb_dropin_fail_invalid;
46692 - atomic_long_t tlb_dropin_fail_range_active;
46693 - atomic_long_t tlb_dropin_fail_idle;
46694 - atomic_long_t tlb_dropin_fail_fmm;
46695 - atomic_long_t tlb_dropin_fail_no_exception;
46696 - atomic_long_t tfh_stale_on_fault;
46697 - atomic_long_t mmu_invalidate_range;
46698 - atomic_long_t mmu_invalidate_page;
46699 - atomic_long_t flush_tlb;
46700 - atomic_long_t flush_tlb_gru;
46701 - atomic_long_t flush_tlb_gru_tgh;
46702 - atomic_long_t flush_tlb_gru_zero_asid;
46703 + atomic_long_unchecked_t vdata_alloc;
46704 + atomic_long_unchecked_t vdata_free;
46705 + atomic_long_unchecked_t gts_alloc;
46706 + atomic_long_unchecked_t gts_free;
46707 + atomic_long_unchecked_t gms_alloc;
46708 + atomic_long_unchecked_t gms_free;
46709 + atomic_long_unchecked_t gts_double_allocate;
46710 + atomic_long_unchecked_t assign_context;
46711 + atomic_long_unchecked_t assign_context_failed;
46712 + atomic_long_unchecked_t free_context;
46713 + atomic_long_unchecked_t load_user_context;
46714 + atomic_long_unchecked_t load_kernel_context;
46715 + atomic_long_unchecked_t lock_kernel_context;
46716 + atomic_long_unchecked_t unlock_kernel_context;
46717 + atomic_long_unchecked_t steal_user_context;
46718 + atomic_long_unchecked_t steal_kernel_context;
46719 + atomic_long_unchecked_t steal_context_failed;
46720 + atomic_long_unchecked_t nopfn;
46721 + atomic_long_unchecked_t asid_new;
46722 + atomic_long_unchecked_t asid_next;
46723 + atomic_long_unchecked_t asid_wrap;
46724 + atomic_long_unchecked_t asid_reuse;
46725 + atomic_long_unchecked_t intr;
46726 + atomic_long_unchecked_t intr_cbr;
46727 + atomic_long_unchecked_t intr_tfh;
46728 + atomic_long_unchecked_t intr_spurious;
46729 + atomic_long_unchecked_t intr_mm_lock_failed;
46730 + atomic_long_unchecked_t call_os;
46731 + atomic_long_unchecked_t call_os_wait_queue;
46732 + atomic_long_unchecked_t user_flush_tlb;
46733 + atomic_long_unchecked_t user_unload_context;
46734 + atomic_long_unchecked_t user_exception;
46735 + atomic_long_unchecked_t set_context_option;
46736 + atomic_long_unchecked_t check_context_retarget_intr;
46737 + atomic_long_unchecked_t check_context_unload;
46738 + atomic_long_unchecked_t tlb_dropin;
46739 + atomic_long_unchecked_t tlb_preload_page;
46740 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
46741 + atomic_long_unchecked_t tlb_dropin_fail_upm;
46742 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
46743 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
46744 + atomic_long_unchecked_t tlb_dropin_fail_idle;
46745 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
46746 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
46747 + atomic_long_unchecked_t tfh_stale_on_fault;
46748 + atomic_long_unchecked_t mmu_invalidate_range;
46749 + atomic_long_unchecked_t mmu_invalidate_page;
46750 + atomic_long_unchecked_t flush_tlb;
46751 + atomic_long_unchecked_t flush_tlb_gru;
46752 + atomic_long_unchecked_t flush_tlb_gru_tgh;
46753 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
46754
46755 - atomic_long_t copy_gpa;
46756 - atomic_long_t read_gpa;
46757 + atomic_long_unchecked_t copy_gpa;
46758 + atomic_long_unchecked_t read_gpa;
46759
46760 - atomic_long_t mesq_receive;
46761 - atomic_long_t mesq_receive_none;
46762 - atomic_long_t mesq_send;
46763 - atomic_long_t mesq_send_failed;
46764 - atomic_long_t mesq_noop;
46765 - atomic_long_t mesq_send_unexpected_error;
46766 - atomic_long_t mesq_send_lb_overflow;
46767 - atomic_long_t mesq_send_qlimit_reached;
46768 - atomic_long_t mesq_send_amo_nacked;
46769 - atomic_long_t mesq_send_put_nacked;
46770 - atomic_long_t mesq_page_overflow;
46771 - atomic_long_t mesq_qf_locked;
46772 - atomic_long_t mesq_qf_noop_not_full;
46773 - atomic_long_t mesq_qf_switch_head_failed;
46774 - atomic_long_t mesq_qf_unexpected_error;
46775 - atomic_long_t mesq_noop_unexpected_error;
46776 - atomic_long_t mesq_noop_lb_overflow;
46777 - atomic_long_t mesq_noop_qlimit_reached;
46778 - atomic_long_t mesq_noop_amo_nacked;
46779 - atomic_long_t mesq_noop_put_nacked;
46780 - atomic_long_t mesq_noop_page_overflow;
46781 + atomic_long_unchecked_t mesq_receive;
46782 + atomic_long_unchecked_t mesq_receive_none;
46783 + atomic_long_unchecked_t mesq_send;
46784 + atomic_long_unchecked_t mesq_send_failed;
46785 + atomic_long_unchecked_t mesq_noop;
46786 + atomic_long_unchecked_t mesq_send_unexpected_error;
46787 + atomic_long_unchecked_t mesq_send_lb_overflow;
46788 + atomic_long_unchecked_t mesq_send_qlimit_reached;
46789 + atomic_long_unchecked_t mesq_send_amo_nacked;
46790 + atomic_long_unchecked_t mesq_send_put_nacked;
46791 + atomic_long_unchecked_t mesq_page_overflow;
46792 + atomic_long_unchecked_t mesq_qf_locked;
46793 + atomic_long_unchecked_t mesq_qf_noop_not_full;
46794 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
46795 + atomic_long_unchecked_t mesq_qf_unexpected_error;
46796 + atomic_long_unchecked_t mesq_noop_unexpected_error;
46797 + atomic_long_unchecked_t mesq_noop_lb_overflow;
46798 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
46799 + atomic_long_unchecked_t mesq_noop_amo_nacked;
46800 + atomic_long_unchecked_t mesq_noop_put_nacked;
46801 + atomic_long_unchecked_t mesq_noop_page_overflow;
46802
46803 };
46804
46805 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
46806 tghop_invalidate, mcsop_last};
46807
46808 struct mcs_op_statistic {
46809 - atomic_long_t count;
46810 - atomic_long_t total;
46811 + atomic_long_unchecked_t count;
46812 + atomic_long_unchecked_t total;
46813 unsigned long max;
46814 };
46815
46816 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
46817
46818 #define STAT(id) do { \
46819 if (gru_options & OPT_STATS) \
46820 - atomic_long_inc(&gru_stats.id); \
46821 + atomic_long_inc_unchecked(&gru_stats.id); \
46822 } while (0)
46823
46824 #ifdef CONFIG_SGI_GRU_DEBUG
46825 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
46826 index c862cd4..0d176fe 100644
46827 --- a/drivers/misc/sgi-xp/xp.h
46828 +++ b/drivers/misc/sgi-xp/xp.h
46829 @@ -288,7 +288,7 @@ struct xpc_interface {
46830 xpc_notify_func, void *);
46831 void (*received) (short, int, void *);
46832 enum xp_retval (*partid_to_nasids) (short, void *);
46833 -};
46834 +} __no_const;
46835
46836 extern struct xpc_interface xpc_interface;
46837
46838 diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
46839 index 01be66d..e3a0c7e 100644
46840 --- a/drivers/misc/sgi-xp/xp_main.c
46841 +++ b/drivers/misc/sgi-xp/xp_main.c
46842 @@ -78,13 +78,13 @@ xpc_notloaded(void)
46843 }
46844
46845 struct xpc_interface xpc_interface = {
46846 - (void (*)(int))xpc_notloaded,
46847 - (void (*)(int))xpc_notloaded,
46848 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
46849 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
46850 + .connect = (void (*)(int))xpc_notloaded,
46851 + .disconnect = (void (*)(int))xpc_notloaded,
46852 + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
46853 + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
46854 void *))xpc_notloaded,
46855 - (void (*)(short, int, void *))xpc_notloaded,
46856 - (enum xp_retval(*)(short, void *))xpc_notloaded
46857 + .received = (void (*)(short, int, void *))xpc_notloaded,
46858 + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
46859 };
46860 EXPORT_SYMBOL_GPL(xpc_interface);
46861
46862 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
46863 index b94d5f7..7f494c5 100644
46864 --- a/drivers/misc/sgi-xp/xpc.h
46865 +++ b/drivers/misc/sgi-xp/xpc.h
46866 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
46867 void (*received_payload) (struct xpc_channel *, void *);
46868 void (*notify_senders_of_disconnect) (struct xpc_channel *);
46869 };
46870 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
46871
46872 /* struct xpc_partition act_state values (for XPC HB) */
46873
46874 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
46875 /* found in xpc_main.c */
46876 extern struct device *xpc_part;
46877 extern struct device *xpc_chan;
46878 -extern struct xpc_arch_operations xpc_arch_ops;
46879 +extern xpc_arch_operations_no_const xpc_arch_ops;
46880 extern int xpc_disengage_timelimit;
46881 extern int xpc_disengage_timedout;
46882 extern int xpc_activate_IRQ_rcvd;
46883 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
46884 index 82dc574..8539ab2 100644
46885 --- a/drivers/misc/sgi-xp/xpc_main.c
46886 +++ b/drivers/misc/sgi-xp/xpc_main.c
46887 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
46888 .notifier_call = xpc_system_die,
46889 };
46890
46891 -struct xpc_arch_operations xpc_arch_ops;
46892 +xpc_arch_operations_no_const xpc_arch_ops;
46893
46894 /*
46895 * Timer function to enforce the timelimit on the partition disengage.
46896 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
46897
46898 if (((die_args->trapnr == X86_TRAP_MF) ||
46899 (die_args->trapnr == X86_TRAP_XF)) &&
46900 - !user_mode_vm(die_args->regs))
46901 + !user_mode(die_args->regs))
46902 xpc_die_deactivate();
46903
46904 break;
46905 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
46906 index 1fa4c80..59447c9 100644
46907 --- a/drivers/mmc/card/block.c
46908 +++ b/drivers/mmc/card/block.c
46909 @@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
46910 if (idata->ic.postsleep_min_us)
46911 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
46912
46913 - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
46914 + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
46915 err = -EFAULT;
46916 goto cmd_rel_host;
46917 }
46918 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
46919 index 7911e05..d0f9dda 100644
46920 --- a/drivers/mmc/core/mmc_ops.c
46921 +++ b/drivers/mmc/core/mmc_ops.c
46922 @@ -267,7 +267,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
46923 void *data_buf;
46924 int is_on_stack;
46925
46926 - is_on_stack = object_is_on_stack(buf);
46927 + is_on_stack = object_starts_on_stack(buf);
46928 if (is_on_stack) {
46929 /*
46930 * dma onto stack is unsafe/nonportable, but callers to this
46931 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
46932 index 01b99e8..5c325e3 100644
46933 --- a/drivers/mmc/host/dw_mmc.h
46934 +++ b/drivers/mmc/host/dw_mmc.h
46935 @@ -265,5 +265,5 @@ struct dw_mci_drv_data {
46936 int (*parse_dt)(struct dw_mci *host);
46937 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
46938 struct dw_mci_tuning_data *tuning_data);
46939 -};
46940 +} __do_const;
46941 #endif /* _DW_MMC_H_ */
46942 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
46943 index 43af791..86f4c48 100644
46944 --- a/drivers/mmc/host/mmci.c
46945 +++ b/drivers/mmc/host/mmci.c
46946 @@ -1628,7 +1628,9 @@ static int mmci_probe(struct amba_device *dev,
46947 mmc->caps |= MMC_CAP_CMD23;
46948
46949 if (variant->busy_detect) {
46950 - mmci_ops.card_busy = mmci_card_busy;
46951 + pax_open_kernel();
46952 + *(void **)&mmci_ops.card_busy = mmci_card_busy;
46953 + pax_close_kernel();
46954 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
46955 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
46956 mmc->max_busy_timeout = 0;
46957 diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
46958 index df27bb4..2085f0b 100644
46959 --- a/drivers/mmc/host/omap_hsmmc.c
46960 +++ b/drivers/mmc/host/omap_hsmmc.c
46961 @@ -2111,7 +2111,9 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
46962
46963 if (host->pdata->controller_flags & OMAP_HSMMC_BROKEN_MULTIBLOCK_READ) {
46964 dev_info(&pdev->dev, "multiblock reads disabled due to 35xx erratum 2.1.1.128; MMC read performance may suffer\n");
46965 - omap_hsmmc_ops.multi_io_quirk = omap_hsmmc_multi_io_quirk;
46966 + pax_open_kernel();
46967 + *(void **)&omap_hsmmc_ops.multi_io_quirk = omap_hsmmc_multi_io_quirk;
46968 + pax_close_kernel();
46969 }
46970
46971 pm_runtime_enable(host->dev);
46972 diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
46973 index 587ee0e..b3bbcab 100644
46974 --- a/drivers/mmc/host/sdhci-esdhc-imx.c
46975 +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
46976 @@ -1054,9 +1054,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
46977 host->mmc->caps |= MMC_CAP_1_8V_DDR;
46978 }
46979
46980 - if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
46981 - sdhci_esdhc_ops.platform_execute_tuning =
46982 + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
46983 + pax_open_kernel();
46984 + *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
46985 esdhc_executing_tuning;
46986 + pax_close_kernel();
46987 + }
46988
46989 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
46990 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
46991 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
46992 index 0ce6eb1..8dcce1b 100644
46993 --- a/drivers/mmc/host/sdhci-s3c.c
46994 +++ b/drivers/mmc/host/sdhci-s3c.c
46995 @@ -584,9 +584,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
46996 * we can use overriding functions instead of default.
46997 */
46998 if (sc->no_divider) {
46999 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47000 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47001 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47002 + pax_open_kernel();
47003 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47004 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47005 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47006 + pax_close_kernel();
47007 }
47008
47009 /* It supports additional host capabilities if needed */
47010 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
47011 index 423666b..81ff5eb 100644
47012 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
47013 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
47014 @@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
47015 size_t totlen = 0, thislen;
47016 int ret = 0;
47017 size_t buflen = 0;
47018 - static char *buffer;
47019 + char *buffer;
47020
47021 if (!ECCBUF_SIZE) {
47022 /* We should fall back to a general writev implementation.
47023 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
47024 index b3b7ca1..5dd4634 100644
47025 --- a/drivers/mtd/nand/denali.c
47026 +++ b/drivers/mtd/nand/denali.c
47027 @@ -24,6 +24,7 @@
47028 #include <linux/slab.h>
47029 #include <linux/mtd/mtd.h>
47030 #include <linux/module.h>
47031 +#include <linux/slab.h>
47032
47033 #include "denali.h"
47034
47035 diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47036 index 959cb9b..8520fe5 100644
47037 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47038 +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47039 @@ -386,7 +386,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
47040
47041 /* first try to map the upper buffer directly */
47042 if (virt_addr_valid(this->upper_buf) &&
47043 - !object_is_on_stack(this->upper_buf)) {
47044 + !object_starts_on_stack(this->upper_buf)) {
47045 sg_init_one(sgl, this->upper_buf, this->upper_len);
47046 ret = dma_map_sg(this->dev, sgl, 1, dr);
47047 if (ret == 0)
47048 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
47049 index 51b9d6a..52af9a7 100644
47050 --- a/drivers/mtd/nftlmount.c
47051 +++ b/drivers/mtd/nftlmount.c
47052 @@ -24,6 +24,7 @@
47053 #include <asm/errno.h>
47054 #include <linux/delay.h>
47055 #include <linux/slab.h>
47056 +#include <linux/sched.h>
47057 #include <linux/mtd/mtd.h>
47058 #include <linux/mtd/nand.h>
47059 #include <linux/mtd/nftl.h>
47060 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
47061 index c23184a..4115c41 100644
47062 --- a/drivers/mtd/sm_ftl.c
47063 +++ b/drivers/mtd/sm_ftl.c
47064 @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
47065 #define SM_CIS_VENDOR_OFFSET 0x59
47066 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
47067 {
47068 - struct attribute_group *attr_group;
47069 + attribute_group_no_const *attr_group;
47070 struct attribute **attributes;
47071 struct sm_sysfs_attribute *vendor_attribute;
47072 char *vendor;
47073 diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
47074 index a5115fb..81b03f6 100644
47075 --- a/drivers/net/bonding/bond_main.c
47076 +++ b/drivers/net/bonding/bond_main.c
47077 @@ -3749,7 +3749,7 @@ int bond_3ad_xor_xmit(struct sk_buff *skb, struct net_device *dev)
47078 bond_dev_queue_xmit(bond, skb, slave->dev);
47079 } else {
47080 dev_kfree_skb_any(skb);
47081 - atomic_long_inc(&dev->tx_dropped);
47082 + atomic_long_inc_unchecked(&dev->tx_dropped);
47083 }
47084
47085 return NETDEV_TX_OK;
47086 diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
47087 index 45f09a6..f154f8d 100644
47088 --- a/drivers/net/bonding/bond_netlink.c
47089 +++ b/drivers/net/bonding/bond_netlink.c
47090 @@ -585,7 +585,7 @@ nla_put_failure:
47091 return -EMSGSIZE;
47092 }
47093
47094 -struct rtnl_link_ops bond_link_ops __read_mostly = {
47095 +struct rtnl_link_ops bond_link_ops = {
47096 .kind = "bond",
47097 .priv_size = sizeof(struct bonding),
47098 .setup = bond_setup,
47099 diff --git a/drivers/net/caif/caif_hsi.c b/drivers/net/caif/caif_hsi.c
47100 index 5e40a8b..126bfda 100644
47101 --- a/drivers/net/caif/caif_hsi.c
47102 +++ b/drivers/net/caif/caif_hsi.c
47103 @@ -1445,7 +1445,7 @@ err:
47104 return -ENODEV;
47105 }
47106
47107 -static struct rtnl_link_ops caif_hsi_link_ops __read_mostly = {
47108 +static struct rtnl_link_ops caif_hsi_link_ops = {
47109 .kind = "cfhsi",
47110 .priv_size = sizeof(struct cfhsi),
47111 .setup = cfhsi_setup,
47112 diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
47113 index 98d73aa..63ef9da 100644
47114 --- a/drivers/net/can/Kconfig
47115 +++ b/drivers/net/can/Kconfig
47116 @@ -98,7 +98,7 @@ config CAN_JANZ_ICAN3
47117
47118 config CAN_FLEXCAN
47119 tristate "Support for Freescale FLEXCAN based chips"
47120 - depends on ARM || PPC
47121 + depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
47122 ---help---
47123 Say Y here if you want to support for Freescale FlexCAN.
47124
47125 diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
47126 index 2cfe501..477d4b5 100644
47127 --- a/drivers/net/can/dev.c
47128 +++ b/drivers/net/can/dev.c
47129 @@ -868,7 +868,7 @@ static int can_newlink(struct net *src_net, struct net_device *dev,
47130 return -EOPNOTSUPP;
47131 }
47132
47133 -static struct rtnl_link_ops can_link_ops __read_mostly = {
47134 +static struct rtnl_link_ops can_link_ops = {
47135 .kind = "can",
47136 .maxtype = IFLA_CAN_MAX,
47137 .policy = can_policy,
47138 diff --git a/drivers/net/can/vcan.c b/drivers/net/can/vcan.c
47139 index 4e94057..32032ff 100644
47140 --- a/drivers/net/can/vcan.c
47141 +++ b/drivers/net/can/vcan.c
47142 @@ -166,7 +166,7 @@ static void vcan_setup(struct net_device *dev)
47143 dev->destructor = free_netdev;
47144 }
47145
47146 -static struct rtnl_link_ops vcan_link_ops __read_mostly = {
47147 +static struct rtnl_link_ops vcan_link_ops = {
47148 .kind = "vcan",
47149 .setup = vcan_setup,
47150 };
47151 diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
47152 index ff435fb..d408b1f 100644
47153 --- a/drivers/net/dummy.c
47154 +++ b/drivers/net/dummy.c
47155 @@ -149,7 +149,7 @@ static int dummy_validate(struct nlattr *tb[], struct nlattr *data[])
47156 return 0;
47157 }
47158
47159 -static struct rtnl_link_ops dummy_link_ops __read_mostly = {
47160 +static struct rtnl_link_ops dummy_link_ops = {
47161 .kind = "dummy",
47162 .setup = dummy_setup,
47163 .validate = dummy_validate,
47164 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
47165 index 1d162cc..b546a75 100644
47166 --- a/drivers/net/ethernet/8390/ax88796.c
47167 +++ b/drivers/net/ethernet/8390/ax88796.c
47168 @@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
47169 if (ax->plat->reg_offsets)
47170 ei_local->reg_offset = ax->plat->reg_offsets;
47171 else {
47172 + resource_size_t _mem_size = mem_size;
47173 + do_div(_mem_size, 0x18);
47174 ei_local->reg_offset = ax->reg_offsets;
47175 for (ret = 0; ret < 0x18; ret++)
47176 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
47177 + ax->reg_offsets[ret] = _mem_size * ret;
47178 }
47179
47180 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
47181 diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
47182 index 4efc435..4ab9e14 100644
47183 --- a/drivers/net/ethernet/altera/altera_tse_main.c
47184 +++ b/drivers/net/ethernet/altera/altera_tse_main.c
47185 @@ -1224,7 +1224,7 @@ static int tse_shutdown(struct net_device *dev)
47186 return 0;
47187 }
47188
47189 -static struct net_device_ops altera_tse_netdev_ops = {
47190 +static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
47191 .ndo_open = tse_open,
47192 .ndo_stop = tse_shutdown,
47193 .ndo_start_xmit = tse_start_xmit,
47194 @@ -1461,11 +1461,13 @@ static int altera_tse_probe(struct platform_device *pdev)
47195 ndev->netdev_ops = &altera_tse_netdev_ops;
47196 altera_tse_set_ethtool_ops(ndev);
47197
47198 + pax_open_kernel();
47199 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
47200
47201 if (priv->hash_filter)
47202 altera_tse_netdev_ops.ndo_set_rx_mode =
47203 tse_set_rx_mode_hashfilter;
47204 + pax_close_kernel();
47205
47206 /* Scatter/gather IO is not supported,
47207 * so it is turned off
47208 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-common.h b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47209 index caade30..3e257d9 100644
47210 --- a/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47211 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47212 @@ -1072,14 +1072,14 @@ do { \
47213 * operations, everything works on mask values.
47214 */
47215 #define XMDIO_READ(_pdata, _mmd, _reg) \
47216 - ((_pdata)->hw_if.read_mmd_regs((_pdata), 0, \
47217 + ((_pdata)->hw_if->read_mmd_regs((_pdata), 0, \
47218 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff)))
47219
47220 #define XMDIO_READ_BITS(_pdata, _mmd, _reg, _mask) \
47221 (XMDIO_READ((_pdata), _mmd, _reg) & _mask)
47222
47223 #define XMDIO_WRITE(_pdata, _mmd, _reg, _val) \
47224 - ((_pdata)->hw_if.write_mmd_regs((_pdata), 0, \
47225 + ((_pdata)->hw_if->write_mmd_regs((_pdata), 0, \
47226 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff), (_val)))
47227
47228 #define XMDIO_WRITE_BITS(_pdata, _mmd, _reg, _mask, _val) \
47229 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47230 index 8a50b01..39c1ad0 100644
47231 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47232 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47233 @@ -187,7 +187,7 @@ static int xgbe_dcb_ieee_setets(struct net_device *netdev,
47234
47235 memcpy(pdata->ets, ets, sizeof(*pdata->ets));
47236
47237 - pdata->hw_if.config_dcb_tc(pdata);
47238 + pdata->hw_if->config_dcb_tc(pdata);
47239
47240 return 0;
47241 }
47242 @@ -226,7 +226,7 @@ static int xgbe_dcb_ieee_setpfc(struct net_device *netdev,
47243
47244 memcpy(pdata->pfc, pfc, sizeof(*pdata->pfc));
47245
47246 - pdata->hw_if.config_dcb_pfc(pdata);
47247 + pdata->hw_if->config_dcb_pfc(pdata);
47248
47249 return 0;
47250 }
47251 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47252 index 6fc5da0..61ac2cb 100644
47253 --- a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47254 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47255 @@ -235,7 +235,7 @@ err_ring:
47256
47257 static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47258 {
47259 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47260 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47261 struct xgbe_channel *channel;
47262 struct xgbe_ring *ring;
47263 struct xgbe_ring_data *rdata;
47264 @@ -276,7 +276,7 @@ static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47265
47266 static void xgbe_wrapper_rx_descriptor_init(struct xgbe_prv_data *pdata)
47267 {
47268 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47269 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47270 struct xgbe_channel *channel;
47271 struct xgbe_ring *ring;
47272 struct xgbe_ring_desc *rdesc;
47273 @@ -505,7 +505,7 @@ err_out:
47274 static void xgbe_realloc_skb(struct xgbe_channel *channel)
47275 {
47276 struct xgbe_prv_data *pdata = channel->pdata;
47277 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47278 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47279 struct xgbe_ring *ring = channel->rx_ring;
47280 struct xgbe_ring_data *rdata;
47281 struct sk_buff *skb = NULL;
47282 @@ -546,17 +546,12 @@ static void xgbe_realloc_skb(struct xgbe_channel *channel)
47283 DBGPR("<--xgbe_realloc_skb\n");
47284 }
47285
47286 -void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *desc_if)
47287 -{
47288 - DBGPR("-->xgbe_init_function_ptrs_desc\n");
47289 -
47290 - desc_if->alloc_ring_resources = xgbe_alloc_ring_resources;
47291 - desc_if->free_ring_resources = xgbe_free_ring_resources;
47292 - desc_if->map_tx_skb = xgbe_map_tx_skb;
47293 - desc_if->realloc_skb = xgbe_realloc_skb;
47294 - desc_if->unmap_skb = xgbe_unmap_skb;
47295 - desc_if->wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init;
47296 - desc_if->wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init;
47297 -
47298 - DBGPR("<--xgbe_init_function_ptrs_desc\n");
47299 -}
47300 +const struct xgbe_desc_if default_xgbe_desc_if = {
47301 + .alloc_ring_resources = xgbe_alloc_ring_resources,
47302 + .free_ring_resources = xgbe_free_ring_resources,
47303 + .map_tx_skb = xgbe_map_tx_skb,
47304 + .realloc_skb = xgbe_realloc_skb,
47305 + .unmap_skb = xgbe_unmap_skb,
47306 + .wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init,
47307 + .wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init,
47308 +};
47309 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47310 index 9da3a03..022f15c 100644
47311 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47312 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47313 @@ -2462,7 +2462,7 @@ static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
47314
47315 static int xgbe_init(struct xgbe_prv_data *pdata)
47316 {
47317 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47318 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47319 int ret;
47320
47321 DBGPR("-->xgbe_init\n");
47322 @@ -2524,101 +2524,96 @@ static int xgbe_init(struct xgbe_prv_data *pdata)
47323 return 0;
47324 }
47325
47326 -void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
47327 -{
47328 - DBGPR("-->xgbe_init_function_ptrs\n");
47329 -
47330 - hw_if->tx_complete = xgbe_tx_complete;
47331 -
47332 - hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
47333 - hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
47334 - hw_if->add_mac_addresses = xgbe_add_mac_addresses;
47335 - hw_if->set_mac_address = xgbe_set_mac_address;
47336 -
47337 - hw_if->enable_rx_csum = xgbe_enable_rx_csum;
47338 - hw_if->disable_rx_csum = xgbe_disable_rx_csum;
47339 -
47340 - hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
47341 - hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
47342 - hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
47343 - hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
47344 - hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
47345 -
47346 - hw_if->read_mmd_regs = xgbe_read_mmd_regs;
47347 - hw_if->write_mmd_regs = xgbe_write_mmd_regs;
47348 -
47349 - hw_if->set_gmii_speed = xgbe_set_gmii_speed;
47350 - hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
47351 - hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
47352 -
47353 - hw_if->enable_tx = xgbe_enable_tx;
47354 - hw_if->disable_tx = xgbe_disable_tx;
47355 - hw_if->enable_rx = xgbe_enable_rx;
47356 - hw_if->disable_rx = xgbe_disable_rx;
47357 -
47358 - hw_if->powerup_tx = xgbe_powerup_tx;
47359 - hw_if->powerdown_tx = xgbe_powerdown_tx;
47360 - hw_if->powerup_rx = xgbe_powerup_rx;
47361 - hw_if->powerdown_rx = xgbe_powerdown_rx;
47362 -
47363 - hw_if->pre_xmit = xgbe_pre_xmit;
47364 - hw_if->dev_read = xgbe_dev_read;
47365 - hw_if->enable_int = xgbe_enable_int;
47366 - hw_if->disable_int = xgbe_disable_int;
47367 - hw_if->init = xgbe_init;
47368 - hw_if->exit = xgbe_exit;
47369 +const struct xgbe_hw_if default_xgbe_hw_if = {
47370 + .tx_complete = xgbe_tx_complete,
47371 +
47372 + .set_promiscuous_mode = xgbe_set_promiscuous_mode,
47373 + .set_all_multicast_mode = xgbe_set_all_multicast_mode,
47374 + .add_mac_addresses = xgbe_add_mac_addresses,
47375 + .set_mac_address = xgbe_set_mac_address,
47376 +
47377 + .enable_rx_csum = xgbe_enable_rx_csum,
47378 + .disable_rx_csum = xgbe_disable_rx_csum,
47379 +
47380 + .enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping,
47381 + .disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping,
47382 + .enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering,
47383 + .disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering,
47384 + .update_vlan_hash_table = xgbe_update_vlan_hash_table,
47385 +
47386 + .read_mmd_regs = xgbe_read_mmd_regs,
47387 + .write_mmd_regs = xgbe_write_mmd_regs,
47388 +
47389 + .set_gmii_speed = xgbe_set_gmii_speed,
47390 + .set_gmii_2500_speed = xgbe_set_gmii_2500_speed,
47391 + .set_xgmii_speed = xgbe_set_xgmii_speed,
47392 +
47393 + .enable_tx = xgbe_enable_tx,
47394 + .disable_tx = xgbe_disable_tx,
47395 + .enable_rx = xgbe_enable_rx,
47396 + .disable_rx = xgbe_disable_rx,
47397 +
47398 + .powerup_tx = xgbe_powerup_tx,
47399 + .powerdown_tx = xgbe_powerdown_tx,
47400 + .powerup_rx = xgbe_powerup_rx,
47401 + .powerdown_rx = xgbe_powerdown_rx,
47402 +
47403 + .pre_xmit = xgbe_pre_xmit,
47404 + .dev_read = xgbe_dev_read,
47405 + .enable_int = xgbe_enable_int,
47406 + .disable_int = xgbe_disable_int,
47407 + .init = xgbe_init,
47408 + .exit = xgbe_exit,
47409
47410 /* Descriptor related Sequences have to be initialized here */
47411 - hw_if->tx_desc_init = xgbe_tx_desc_init;
47412 - hw_if->rx_desc_init = xgbe_rx_desc_init;
47413 - hw_if->tx_desc_reset = xgbe_tx_desc_reset;
47414 - hw_if->rx_desc_reset = xgbe_rx_desc_reset;
47415 - hw_if->is_last_desc = xgbe_is_last_desc;
47416 - hw_if->is_context_desc = xgbe_is_context_desc;
47417 + .tx_desc_init = xgbe_tx_desc_init,
47418 + .rx_desc_init = xgbe_rx_desc_init,
47419 + .tx_desc_reset = xgbe_tx_desc_reset,
47420 + .rx_desc_reset = xgbe_rx_desc_reset,
47421 + .is_last_desc = xgbe_is_last_desc,
47422 + .is_context_desc = xgbe_is_context_desc,
47423
47424 /* For FLOW ctrl */
47425 - hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
47426 - hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
47427 + .config_tx_flow_control = xgbe_config_tx_flow_control,
47428 + .config_rx_flow_control = xgbe_config_rx_flow_control,
47429
47430 /* For RX coalescing */
47431 - hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
47432 - hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
47433 - hw_if->usec_to_riwt = xgbe_usec_to_riwt;
47434 - hw_if->riwt_to_usec = xgbe_riwt_to_usec;
47435 + .config_rx_coalesce = xgbe_config_rx_coalesce,
47436 + .config_tx_coalesce = xgbe_config_tx_coalesce,
47437 + .usec_to_riwt = xgbe_usec_to_riwt,
47438 + .riwt_to_usec = xgbe_riwt_to_usec,
47439
47440 /* For RX and TX threshold config */
47441 - hw_if->config_rx_threshold = xgbe_config_rx_threshold;
47442 - hw_if->config_tx_threshold = xgbe_config_tx_threshold;
47443 + .config_rx_threshold = xgbe_config_rx_threshold,
47444 + .config_tx_threshold = xgbe_config_tx_threshold,
47445
47446 /* For RX and TX Store and Forward Mode config */
47447 - hw_if->config_rsf_mode = xgbe_config_rsf_mode;
47448 - hw_if->config_tsf_mode = xgbe_config_tsf_mode;
47449 + .config_rsf_mode = xgbe_config_rsf_mode,
47450 + .config_tsf_mode = xgbe_config_tsf_mode,
47451
47452 /* For TX DMA Operating on Second Frame config */
47453 - hw_if->config_osp_mode = xgbe_config_osp_mode;
47454 + .config_osp_mode = xgbe_config_osp_mode,
47455
47456 /* For RX and TX PBL config */
47457 - hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
47458 - hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
47459 - hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
47460 - hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
47461 - hw_if->config_pblx8 = xgbe_config_pblx8;
47462 + .config_rx_pbl_val = xgbe_config_rx_pbl_val,
47463 + .get_rx_pbl_val = xgbe_get_rx_pbl_val,
47464 + .config_tx_pbl_val = xgbe_config_tx_pbl_val,
47465 + .get_tx_pbl_val = xgbe_get_tx_pbl_val,
47466 + .config_pblx8 = xgbe_config_pblx8,
47467
47468 /* For MMC statistics support */
47469 - hw_if->tx_mmc_int = xgbe_tx_mmc_int;
47470 - hw_if->rx_mmc_int = xgbe_rx_mmc_int;
47471 - hw_if->read_mmc_stats = xgbe_read_mmc_stats;
47472 + .tx_mmc_int = xgbe_tx_mmc_int,
47473 + .rx_mmc_int = xgbe_rx_mmc_int,
47474 + .read_mmc_stats = xgbe_read_mmc_stats,
47475
47476 /* For PTP config */
47477 - hw_if->config_tstamp = xgbe_config_tstamp;
47478 - hw_if->update_tstamp_addend = xgbe_update_tstamp_addend;
47479 - hw_if->set_tstamp_time = xgbe_set_tstamp_time;
47480 - hw_if->get_tstamp_time = xgbe_get_tstamp_time;
47481 - hw_if->get_tx_tstamp = xgbe_get_tx_tstamp;
47482 + .config_tstamp = xgbe_config_tstamp,
47483 + .update_tstamp_addend = xgbe_update_tstamp_addend,
47484 + .set_tstamp_time = xgbe_set_tstamp_time,
47485 + .get_tstamp_time = xgbe_get_tstamp_time,
47486 + .get_tx_tstamp = xgbe_get_tx_tstamp,
47487
47488 /* For Data Center Bridging config */
47489 - hw_if->config_dcb_tc = xgbe_config_dcb_tc;
47490 - hw_if->config_dcb_pfc = xgbe_config_dcb_pfc;
47491 -
47492 - DBGPR("<--xgbe_init_function_ptrs\n");
47493 -}
47494 + .config_dcb_tc = xgbe_config_dcb_tc,
47495 + .config_dcb_pfc = xgbe_config_dcb_pfc,
47496 +};
47497 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47498 index 2349ea9..a83a677 100644
47499 --- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47500 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47501 @@ -154,7 +154,7 @@ static int xgbe_calc_rx_buf_size(struct net_device *netdev, unsigned int mtu)
47502
47503 static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
47504 {
47505 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47506 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47507 struct xgbe_channel *channel;
47508 enum xgbe_int int_id;
47509 unsigned int i;
47510 @@ -176,7 +176,7 @@ static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
47511
47512 static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
47513 {
47514 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47515 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47516 struct xgbe_channel *channel;
47517 enum xgbe_int int_id;
47518 unsigned int i;
47519 @@ -199,7 +199,7 @@ static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
47520 static irqreturn_t xgbe_isr(int irq, void *data)
47521 {
47522 struct xgbe_prv_data *pdata = data;
47523 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47524 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47525 struct xgbe_channel *channel;
47526 unsigned int dma_isr, dma_ch_isr;
47527 unsigned int mac_isr, mac_tssr;
47528 @@ -446,7 +446,7 @@ static void xgbe_napi_disable(struct xgbe_prv_data *pdata, unsigned int del)
47529
47530 void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
47531 {
47532 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47533 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47534
47535 DBGPR("-->xgbe_init_tx_coalesce\n");
47536
47537 @@ -460,7 +460,7 @@ void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
47538
47539 void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
47540 {
47541 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47542 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47543
47544 DBGPR("-->xgbe_init_rx_coalesce\n");
47545
47546 @@ -474,7 +474,7 @@ void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
47547
47548 static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
47549 {
47550 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47551 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47552 struct xgbe_channel *channel;
47553 struct xgbe_ring *ring;
47554 struct xgbe_ring_data *rdata;
47555 @@ -499,7 +499,7 @@ static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
47556
47557 static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
47558 {
47559 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47560 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47561 struct xgbe_channel *channel;
47562 struct xgbe_ring *ring;
47563 struct xgbe_ring_data *rdata;
47564 @@ -525,7 +525,7 @@ static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
47565 static void xgbe_adjust_link(struct net_device *netdev)
47566 {
47567 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47568 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47569 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47570 struct phy_device *phydev = pdata->phydev;
47571 int new_state = 0;
47572
47573 @@ -633,7 +633,7 @@ static void xgbe_phy_exit(struct xgbe_prv_data *pdata)
47574 int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
47575 {
47576 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47577 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47578 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47579 unsigned long flags;
47580
47581 DBGPR("-->xgbe_powerdown\n");
47582 @@ -671,7 +671,7 @@ int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
47583 int xgbe_powerup(struct net_device *netdev, unsigned int caller)
47584 {
47585 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47586 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47587 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47588 unsigned long flags;
47589
47590 DBGPR("-->xgbe_powerup\n");
47591 @@ -708,7 +708,7 @@ int xgbe_powerup(struct net_device *netdev, unsigned int caller)
47592
47593 static int xgbe_start(struct xgbe_prv_data *pdata)
47594 {
47595 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47596 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47597 struct net_device *netdev = pdata->netdev;
47598
47599 DBGPR("-->xgbe_start\n");
47600 @@ -734,7 +734,7 @@ static int xgbe_start(struct xgbe_prv_data *pdata)
47601
47602 static void xgbe_stop(struct xgbe_prv_data *pdata)
47603 {
47604 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47605 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47606 struct net_device *netdev = pdata->netdev;
47607
47608 DBGPR("-->xgbe_stop\n");
47609 @@ -754,7 +754,7 @@ static void xgbe_stop(struct xgbe_prv_data *pdata)
47610
47611 static void xgbe_restart_dev(struct xgbe_prv_data *pdata, unsigned int reset)
47612 {
47613 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47614 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47615
47616 DBGPR("-->xgbe_restart_dev\n");
47617
47618 @@ -951,7 +951,7 @@ static int xgbe_set_hwtstamp_settings(struct xgbe_prv_data *pdata,
47619 return -ERANGE;
47620 }
47621
47622 - pdata->hw_if.config_tstamp(pdata, mac_tscr);
47623 + pdata->hw_if->config_tstamp(pdata, mac_tscr);
47624
47625 memcpy(&pdata->tstamp_config, &config, sizeof(config));
47626
47627 @@ -1089,8 +1089,8 @@ static void xgbe_packet_info(struct xgbe_prv_data *pdata,
47628 static int xgbe_open(struct net_device *netdev)
47629 {
47630 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47631 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47632 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47633 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47634 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47635 int ret;
47636
47637 DBGPR("-->xgbe_open\n");
47638 @@ -1170,8 +1170,8 @@ err_phy_init:
47639 static int xgbe_close(struct net_device *netdev)
47640 {
47641 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47642 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47643 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47644 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47645 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47646
47647 DBGPR("-->xgbe_close\n");
47648
47649 @@ -1205,8 +1205,8 @@ static int xgbe_close(struct net_device *netdev)
47650 static int xgbe_xmit(struct sk_buff *skb, struct net_device *netdev)
47651 {
47652 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47653 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47654 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47655 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47656 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47657 struct xgbe_channel *channel;
47658 struct xgbe_ring *ring;
47659 struct xgbe_packet_data *packet;
47660 @@ -1275,7 +1275,7 @@ tx_netdev_return:
47661 static void xgbe_set_rx_mode(struct net_device *netdev)
47662 {
47663 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47664 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47665 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47666 unsigned int pr_mode, am_mode;
47667
47668 DBGPR("-->xgbe_set_rx_mode\n");
47669 @@ -1294,7 +1294,7 @@ static void xgbe_set_rx_mode(struct net_device *netdev)
47670 static int xgbe_set_mac_address(struct net_device *netdev, void *addr)
47671 {
47672 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47673 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47674 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47675 struct sockaddr *saddr = addr;
47676
47677 DBGPR("-->xgbe_set_mac_address\n");
47678 @@ -1361,7 +1361,7 @@ static struct rtnl_link_stats64 *xgbe_get_stats64(struct net_device *netdev,
47679
47680 DBGPR("-->%s\n", __func__);
47681
47682 - pdata->hw_if.read_mmc_stats(pdata);
47683 + pdata->hw_if->read_mmc_stats(pdata);
47684
47685 s->rx_packets = pstats->rxframecount_gb;
47686 s->rx_bytes = pstats->rxoctetcount_gb;
47687 @@ -1388,7 +1388,7 @@ static int xgbe_vlan_rx_add_vid(struct net_device *netdev, __be16 proto,
47688 u16 vid)
47689 {
47690 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47691 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47692 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47693
47694 DBGPR("-->%s\n", __func__);
47695
47696 @@ -1404,7 +1404,7 @@ static int xgbe_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto,
47697 u16 vid)
47698 {
47699 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47700 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47701 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47702
47703 DBGPR("-->%s\n", __func__);
47704
47705 @@ -1464,7 +1464,7 @@ static int xgbe_set_features(struct net_device *netdev,
47706 netdev_features_t features)
47707 {
47708 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47709 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47710 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47711 netdev_features_t rxcsum, rxvlan, rxvlan_filter;
47712
47713 rxcsum = pdata->netdev_features & NETIF_F_RXCSUM;
47714 @@ -1520,7 +1520,7 @@ struct net_device_ops *xgbe_get_netdev_ops(void)
47715 static void xgbe_rx_refresh(struct xgbe_channel *channel)
47716 {
47717 struct xgbe_prv_data *pdata = channel->pdata;
47718 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47719 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47720 struct xgbe_ring *ring = channel->rx_ring;
47721 struct xgbe_ring_data *rdata;
47722
47723 @@ -1536,8 +1536,8 @@ static void xgbe_rx_refresh(struct xgbe_channel *channel)
47724 static int xgbe_tx_poll(struct xgbe_channel *channel)
47725 {
47726 struct xgbe_prv_data *pdata = channel->pdata;
47727 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47728 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47729 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47730 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47731 struct xgbe_ring *ring = channel->tx_ring;
47732 struct xgbe_ring_data *rdata;
47733 struct xgbe_ring_desc *rdesc;
47734 @@ -1589,7 +1589,7 @@ static int xgbe_tx_poll(struct xgbe_channel *channel)
47735 static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
47736 {
47737 struct xgbe_prv_data *pdata = channel->pdata;
47738 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47739 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47740 struct xgbe_ring *ring = channel->rx_ring;
47741 struct xgbe_ring_data *rdata;
47742 struct xgbe_packet_data *packet;
47743 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
47744 index 49508ec..2617cca 100644
47745 --- a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
47746 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
47747 @@ -203,7 +203,7 @@ static void xgbe_get_ethtool_stats(struct net_device *netdev,
47748
47749 DBGPR("-->%s\n", __func__);
47750
47751 - pdata->hw_if.read_mmc_stats(pdata);
47752 + pdata->hw_if->read_mmc_stats(pdata);
47753 for (i = 0; i < XGBE_STATS_COUNT; i++) {
47754 stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
47755 *data++ = *(u64 *)stat;
47756 @@ -378,7 +378,7 @@ static int xgbe_get_coalesce(struct net_device *netdev,
47757 struct ethtool_coalesce *ec)
47758 {
47759 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47760 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47761 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47762 unsigned int riwt;
47763
47764 DBGPR("-->xgbe_get_coalesce\n");
47765 @@ -401,7 +401,7 @@ static int xgbe_set_coalesce(struct net_device *netdev,
47766 struct ethtool_coalesce *ec)
47767 {
47768 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47769 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47770 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47771 unsigned int rx_frames, rx_riwt, rx_usecs;
47772 unsigned int tx_frames, tx_usecs;
47773
47774 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-main.c b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
47775 index f5a8fa0..0bb58ff 100644
47776 --- a/drivers/net/ethernet/amd/xgbe/xgbe-main.c
47777 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
47778 @@ -209,12 +209,6 @@ static void xgbe_default_config(struct xgbe_prv_data *pdata)
47779 DBGPR("<--xgbe_default_config\n");
47780 }
47781
47782 -static void xgbe_init_all_fptrs(struct xgbe_prv_data *pdata)
47783 -{
47784 - xgbe_init_function_ptrs_dev(&pdata->hw_if);
47785 - xgbe_init_function_ptrs_desc(&pdata->desc_if);
47786 -}
47787 -
47788 static int xgbe_probe(struct platform_device *pdev)
47789 {
47790 struct xgbe_prv_data *pdata;
47791 @@ -327,9 +321,8 @@ static int xgbe_probe(struct platform_device *pdev)
47792 netdev->base_addr = (unsigned long)pdata->xgmac_regs;
47793
47794 /* Set all the function pointers */
47795 - xgbe_init_all_fptrs(pdata);
47796 - hw_if = &pdata->hw_if;
47797 - desc_if = &pdata->desc_if;
47798 + hw_if = pdata->hw_if = &default_xgbe_hw_if;
47799 + desc_if = pdata->desc_if = &default_xgbe_desc_if;
47800
47801 /* Issue software reset to device */
47802 hw_if->exit(pdata);
47803 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
47804 index 363b210..b241389 100644
47805 --- a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
47806 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
47807 @@ -126,7 +126,7 @@
47808 static int xgbe_mdio_read(struct mii_bus *mii, int prtad, int mmd_reg)
47809 {
47810 struct xgbe_prv_data *pdata = mii->priv;
47811 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47812 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47813 int mmd_data;
47814
47815 DBGPR_MDIO("-->xgbe_mdio_read: prtad=%#x mmd_reg=%#x\n",
47816 @@ -143,7 +143,7 @@ static int xgbe_mdio_write(struct mii_bus *mii, int prtad, int mmd_reg,
47817 u16 mmd_val)
47818 {
47819 struct xgbe_prv_data *pdata = mii->priv;
47820 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47821 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47822 int mmd_data = mmd_val;
47823
47824 DBGPR_MDIO("-->xgbe_mdio_write: prtad=%#x mmd_reg=%#x mmd_data=%#x\n",
47825 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
47826 index a1bf9d1c..84adcab 100644
47827 --- a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
47828 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
47829 @@ -129,7 +129,7 @@ static cycle_t xgbe_cc_read(const struct cyclecounter *cc)
47830 tstamp_cc);
47831 u64 nsec;
47832
47833 - nsec = pdata->hw_if.get_tstamp_time(pdata);
47834 + nsec = pdata->hw_if->get_tstamp_time(pdata);
47835
47836 return nsec;
47837 }
47838 @@ -158,7 +158,7 @@ static int xgbe_adjfreq(struct ptp_clock_info *info, s32 delta)
47839
47840 spin_lock_irqsave(&pdata->tstamp_lock, flags);
47841
47842 - pdata->hw_if.update_tstamp_addend(pdata, addend);
47843 + pdata->hw_if->update_tstamp_addend(pdata, addend);
47844
47845 spin_unlock_irqrestore(&pdata->tstamp_lock, flags);
47846
47847 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe.h b/drivers/net/ethernet/amd/xgbe/xgbe.h
47848 index 789957d..d7d0245 100644
47849 --- a/drivers/net/ethernet/amd/xgbe/xgbe.h
47850 +++ b/drivers/net/ethernet/amd/xgbe/xgbe.h
47851 @@ -583,8 +583,8 @@ struct xgbe_prv_data {
47852
47853 int irq_number;
47854
47855 - struct xgbe_hw_if hw_if;
47856 - struct xgbe_desc_if desc_if;
47857 + const struct xgbe_hw_if *hw_if;
47858 + const struct xgbe_desc_if *desc_if;
47859
47860 /* AXI DMA settings */
47861 unsigned int axdomain;
47862 @@ -697,6 +697,9 @@ struct xgbe_prv_data {
47863 #endif
47864 };
47865
47866 +extern const struct xgbe_hw_if default_xgbe_hw_if;
47867 +extern const struct xgbe_desc_if default_xgbe_desc_if;
47868 +
47869 /* Function prototypes*/
47870
47871 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
47872 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
47873 index adcacda..fa6e0ae 100644
47874 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
47875 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
47876 @@ -1065,7 +1065,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
47877 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
47878 {
47879 /* RX_MODE controlling object */
47880 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
47881 + bnx2x_init_rx_mode_obj(bp);
47882
47883 /* multicast configuration controlling object */
47884 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
47885 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
47886 index 7bc2924..2112002 100644
47887 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
47888 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
47889 @@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
47890 return rc;
47891 }
47892
47893 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
47894 - struct bnx2x_rx_mode_obj *o)
47895 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
47896 {
47897 if (CHIP_IS_E1x(bp)) {
47898 - o->wait_comp = bnx2x_empty_rx_mode_wait;
47899 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
47900 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
47901 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
47902 } else {
47903 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
47904 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
47905 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
47906 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
47907 }
47908 }
47909
47910 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
47911 index e97275f..52e28bc 100644
47912 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
47913 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
47914 @@ -1409,8 +1409,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
47915
47916 /********************* RX MODE ****************/
47917
47918 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
47919 - struct bnx2x_rx_mode_obj *o);
47920 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
47921
47922 /**
47923 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
47924 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
47925 index 31c9f82..e65e986 100644
47926 --- a/drivers/net/ethernet/broadcom/tg3.h
47927 +++ b/drivers/net/ethernet/broadcom/tg3.h
47928 @@ -150,6 +150,7 @@
47929 #define CHIPREV_ID_5750_A0 0x4000
47930 #define CHIPREV_ID_5750_A1 0x4001
47931 #define CHIPREV_ID_5750_A3 0x4003
47932 +#define CHIPREV_ID_5750_C1 0x4201
47933 #define CHIPREV_ID_5750_C2 0x4202
47934 #define CHIPREV_ID_5752_A0_HW 0x5000
47935 #define CHIPREV_ID_5752_A0 0x6000
47936 diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
47937 index 903466e..b285864 100644
47938 --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
47939 +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
47940 @@ -1693,10 +1693,10 @@ bna_cb_ioceth_reset(void *arg)
47941 }
47942
47943 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
47944 - bna_cb_ioceth_enable,
47945 - bna_cb_ioceth_disable,
47946 - bna_cb_ioceth_hbfail,
47947 - bna_cb_ioceth_reset
47948 + .enable_cbfn = bna_cb_ioceth_enable,
47949 + .disable_cbfn = bna_cb_ioceth_disable,
47950 + .hbfail_cbfn = bna_cb_ioceth_hbfail,
47951 + .reset_cbfn = bna_cb_ioceth_reset
47952 };
47953
47954 static void bna_attr_init(struct bna_ioceth *ioceth)
47955 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
47956 index 8cffcdf..aadf043 100644
47957 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
47958 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
47959 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
47960 */
47961 struct l2t_skb_cb {
47962 arp_failure_handler_func arp_failure_handler;
47963 -};
47964 +} __no_const;
47965
47966 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
47967
47968 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
47969 index 279873c..11e1921 100644
47970 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
47971 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
47972 @@ -2365,7 +2365,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
47973
47974 int i;
47975 struct adapter *ap = netdev2adap(dev);
47976 - static const unsigned int *reg_ranges;
47977 + const unsigned int *reg_ranges;
47978 int arr_size = 0, buf_size = 0;
47979
47980 if (is_t4(ap->params.chip)) {
47981 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
47982 index cf8b6ff..274271e 100644
47983 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
47984 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
47985 @@ -5387,7 +5387,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
47986 for (i=0; i<ETH_ALEN; i++) {
47987 tmp.addr[i] = dev->dev_addr[i];
47988 }
47989 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
47990 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
47991 break;
47992
47993 case DE4X5_SET_HWADDR: /* Set the hardware address */
47994 @@ -5427,7 +5427,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
47995 spin_lock_irqsave(&lp->lock, flags);
47996 memcpy(&statbuf, &lp->pktStats, ioc->len);
47997 spin_unlock_irqrestore(&lp->lock, flags);
47998 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
47999 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
48000 return -EFAULT;
48001 break;
48002 }
48003 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
48004 index 597c463..5cc1a7f 100644
48005 --- a/drivers/net/ethernet/emulex/benet/be_main.c
48006 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
48007 @@ -537,7 +537,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
48008
48009 if (wrapped)
48010 newacc += 65536;
48011 - ACCESS_ONCE(*acc) = newacc;
48012 + ACCESS_ONCE_RW(*acc) = newacc;
48013 }
48014
48015 static void populate_erx_stats(struct be_adapter *adapter,
48016 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
48017 index c77fa4a..7fd42fc 100644
48018 --- a/drivers/net/ethernet/faraday/ftgmac100.c
48019 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
48020 @@ -30,6 +30,8 @@
48021 #include <linux/netdevice.h>
48022 #include <linux/phy.h>
48023 #include <linux/platform_device.h>
48024 +#include <linux/interrupt.h>
48025 +#include <linux/irqreturn.h>
48026 #include <net/ip.h>
48027
48028 #include "ftgmac100.h"
48029 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
48030 index 4ff1adc..0ea6bf4 100644
48031 --- a/drivers/net/ethernet/faraday/ftmac100.c
48032 +++ b/drivers/net/ethernet/faraday/ftmac100.c
48033 @@ -31,6 +31,8 @@
48034 #include <linux/module.h>
48035 #include <linux/netdevice.h>
48036 #include <linux/platform_device.h>
48037 +#include <linux/interrupt.h>
48038 +#include <linux/irqreturn.h>
48039
48040 #include "ftmac100.h"
48041
48042 diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48043 index 537b621..07f87ce 100644
48044 --- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48045 +++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48046 @@ -401,7 +401,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
48047 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
48048
48049 /* Update the base adjustement value. */
48050 - ACCESS_ONCE(pf->ptp_base_adj) = incval;
48051 + ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
48052 smp_mb(); /* Force the above update. */
48053 }
48054
48055 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48056 index 5fd4b52..87aa34b 100644
48057 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48058 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48059 @@ -794,7 +794,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
48060 }
48061
48062 /* update the base incval used to calculate frequency adjustment */
48063 - ACCESS_ONCE(adapter->base_incval) = incval;
48064 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
48065 smp_mb();
48066
48067 /* need lock to prevent incorrect read while modifying cyclecounter */
48068 diff --git a/drivers/net/ethernet/mellanox/mlx4/en_tx.c b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
48069 index 454d9fe..59f0f0b 100644
48070 --- a/drivers/net/ethernet/mellanox/mlx4/en_tx.c
48071 +++ b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
48072 @@ -458,8 +458,8 @@ static bool mlx4_en_process_tx_cq(struct net_device *dev,
48073 wmb();
48074
48075 /* we want to dirty this cache line once */
48076 - ACCESS_ONCE(ring->last_nr_txbb) = last_nr_txbb;
48077 - ACCESS_ONCE(ring->cons) = ring_cons + txbbs_skipped;
48078 + ACCESS_ONCE_RW(ring->last_nr_txbb) = last_nr_txbb;
48079 + ACCESS_ONCE_RW(ring->cons) = ring_cons + txbbs_skipped;
48080
48081 netdev_tx_completed_queue(ring->tx_queue, packets, bytes);
48082
48083 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48084 index 2bbd01f..e8baa64 100644
48085 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
48086 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48087 @@ -3457,7 +3457,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48088 struct __vxge_hw_fifo *fifo;
48089 struct vxge_hw_fifo_config *config;
48090 u32 txdl_size, txdl_per_memblock;
48091 - struct vxge_hw_mempool_cbs fifo_mp_callback;
48092 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
48093 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
48094 + };
48095 +
48096 struct __vxge_hw_virtualpath *vpath;
48097
48098 if ((vp == NULL) || (attr == NULL)) {
48099 @@ -3540,8 +3543,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48100 goto exit;
48101 }
48102
48103 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
48104 -
48105 fifo->mempool =
48106 __vxge_hw_mempool_create(vpath->hldev,
48107 fifo->config->memblock_size,
48108 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48109 index 2bb48d5..d1a865d 100644
48110 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48111 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48112 @@ -2324,7 +2324,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
48113 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
48114 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
48115 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
48116 - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48117 + pax_open_kernel();
48118 + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48119 + pax_close_kernel();
48120 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48121 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
48122 max_tx_rings = QLCNIC_MAX_TX_RINGS;
48123 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48124 index be7d7a6..a8983f8 100644
48125 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48126 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48127 @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
48128 case QLCNIC_NON_PRIV_FUNC:
48129 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
48130 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48131 - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48132 + pax_open_kernel();
48133 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48134 + pax_close_kernel();
48135 break;
48136 case QLCNIC_PRIV_FUNC:
48137 ahw->op_mode = QLCNIC_PRIV_FUNC;
48138 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
48139 - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48140 + pax_open_kernel();
48141 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48142 + pax_close_kernel();
48143 break;
48144 case QLCNIC_MGMT_FUNC:
48145 ahw->op_mode = QLCNIC_MGMT_FUNC;
48146 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48147 - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48148 + pax_open_kernel();
48149 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48150 + pax_close_kernel();
48151 break;
48152 default:
48153 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
48154 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48155 index c9f57fb..208bdc1 100644
48156 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48157 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48158 @@ -1285,7 +1285,7 @@ flash_temp:
48159 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
48160 {
48161 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
48162 - static const struct qlcnic_dump_operations *fw_dump_ops;
48163 + const struct qlcnic_dump_operations *fw_dump_ops;
48164 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
48165 u32 entry_offset, dump, no_entries, buf_offset = 0;
48166 int i, k, ops_cnt, ops_index, dump_size = 0;
48167 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
48168 index cf154f7..c948d1b 100644
48169 --- a/drivers/net/ethernet/realtek/r8169.c
48170 +++ b/drivers/net/ethernet/realtek/r8169.c
48171 @@ -788,22 +788,22 @@ struct rtl8169_private {
48172 struct mdio_ops {
48173 void (*write)(struct rtl8169_private *, int, int);
48174 int (*read)(struct rtl8169_private *, int);
48175 - } mdio_ops;
48176 + } __no_const mdio_ops;
48177
48178 struct pll_power_ops {
48179 void (*down)(struct rtl8169_private *);
48180 void (*up)(struct rtl8169_private *);
48181 - } pll_power_ops;
48182 + } __no_const pll_power_ops;
48183
48184 struct jumbo_ops {
48185 void (*enable)(struct rtl8169_private *);
48186 void (*disable)(struct rtl8169_private *);
48187 - } jumbo_ops;
48188 + } __no_const jumbo_ops;
48189
48190 struct csi_ops {
48191 void (*write)(struct rtl8169_private *, int, int);
48192 u32 (*read)(struct rtl8169_private *, int);
48193 - } csi_ops;
48194 + } __no_const csi_ops;
48195
48196 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
48197 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
48198 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
48199 index 6b861e3..204ac86 100644
48200 --- a/drivers/net/ethernet/sfc/ptp.c
48201 +++ b/drivers/net/ethernet/sfc/ptp.c
48202 @@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
48203 ptp->start.dma_addr);
48204
48205 /* Clear flag that signals MC ready */
48206 - ACCESS_ONCE(*start) = 0;
48207 + ACCESS_ONCE_RW(*start) = 0;
48208 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
48209 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
48210 EFX_BUG_ON_PARANOID(rc);
48211 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48212 index 08c483b..2c4a553 100644
48213 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48214 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48215 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
48216
48217 writel(value, ioaddr + MMC_CNTRL);
48218
48219 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48220 - MMC_CNTRL, value);
48221 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48222 +// MMC_CNTRL, value);
48223 }
48224
48225 /* To mask all all interrupts.*/
48226 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
48227 index 2f48f79..8ae1a1a 100644
48228 --- a/drivers/net/hyperv/hyperv_net.h
48229 +++ b/drivers/net/hyperv/hyperv_net.h
48230 @@ -171,7 +171,7 @@ struct rndis_device {
48231 enum rndis_device_state state;
48232 bool link_state;
48233 bool link_change;
48234 - atomic_t new_req_id;
48235 + atomic_unchecked_t new_req_id;
48236
48237 spinlock_t request_lock;
48238 struct list_head req_list;
48239 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
48240 index 2b86f0b..ecc996f 100644
48241 --- a/drivers/net/hyperv/rndis_filter.c
48242 +++ b/drivers/net/hyperv/rndis_filter.c
48243 @@ -102,7 +102,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
48244 * template
48245 */
48246 set = &rndis_msg->msg.set_req;
48247 - set->req_id = atomic_inc_return(&dev->new_req_id);
48248 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
48249
48250 /* Add to the request list */
48251 spin_lock_irqsave(&dev->request_lock, flags);
48252 @@ -911,7 +911,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
48253
48254 /* Setup the rndis set */
48255 halt = &request->request_msg.msg.halt_req;
48256 - halt->req_id = atomic_inc_return(&dev->new_req_id);
48257 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
48258
48259 /* Ignore return since this msg is optional. */
48260 rndis_filter_send_request(dev, request);
48261 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
48262 index 6cbc56a..5f7e6c8 100644
48263 --- a/drivers/net/ieee802154/fakehard.c
48264 +++ b/drivers/net/ieee802154/fakehard.c
48265 @@ -365,7 +365,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
48266 phy->transmit_power = 0xbf;
48267
48268 dev->netdev_ops = &fake_ops;
48269 - dev->ml_priv = &fake_mlme;
48270 + dev->ml_priv = (void *)&fake_mlme;
48271
48272 priv = netdev_priv(dev);
48273 priv->phy = phy;
48274 diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
48275 index 34f846b..4a0d5b1 100644
48276 --- a/drivers/net/ifb.c
48277 +++ b/drivers/net/ifb.c
48278 @@ -253,7 +253,7 @@ static int ifb_validate(struct nlattr *tb[], struct nlattr *data[])
48279 return 0;
48280 }
48281
48282 -static struct rtnl_link_ops ifb_link_ops __read_mostly = {
48283 +static struct rtnl_link_ops ifb_link_ops = {
48284 .kind = "ifb",
48285 .priv_size = sizeof(struct ifb_private),
48286 .setup = ifb_setup,
48287 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
48288 index bfb0b6e..5c396ce 100644
48289 --- a/drivers/net/macvlan.c
48290 +++ b/drivers/net/macvlan.c
48291 @@ -335,7 +335,7 @@ static void macvlan_broadcast_enqueue(struct macvlan_port *port,
48292 free_nskb:
48293 kfree_skb(nskb);
48294 err:
48295 - atomic_long_inc(&skb->dev->rx_dropped);
48296 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
48297 }
48298
48299 static void macvlan_flush_sources(struct macvlan_port *port,
48300 @@ -1454,13 +1454,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
48301 int macvlan_link_register(struct rtnl_link_ops *ops)
48302 {
48303 /* common fields */
48304 - ops->priv_size = sizeof(struct macvlan_dev);
48305 - ops->validate = macvlan_validate;
48306 - ops->maxtype = IFLA_MACVLAN_MAX;
48307 - ops->policy = macvlan_policy;
48308 - ops->changelink = macvlan_changelink;
48309 - ops->get_size = macvlan_get_size;
48310 - ops->fill_info = macvlan_fill_info;
48311 + pax_open_kernel();
48312 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
48313 + *(void **)&ops->validate = macvlan_validate;
48314 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
48315 + *(const void **)&ops->policy = macvlan_policy;
48316 + *(void **)&ops->changelink = macvlan_changelink;
48317 + *(void **)&ops->get_size = macvlan_get_size;
48318 + *(void **)&ops->fill_info = macvlan_fill_info;
48319 + pax_close_kernel();
48320
48321 return rtnl_link_register(ops);
48322 };
48323 @@ -1540,7 +1542,7 @@ static int macvlan_device_event(struct notifier_block *unused,
48324 return NOTIFY_DONE;
48325 }
48326
48327 -static struct notifier_block macvlan_notifier_block __read_mostly = {
48328 +static struct notifier_block macvlan_notifier_block = {
48329 .notifier_call = macvlan_device_event,
48330 };
48331
48332 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
48333 index 880cc09..6a68ba6 100644
48334 --- a/drivers/net/macvtap.c
48335 +++ b/drivers/net/macvtap.c
48336 @@ -422,7 +422,7 @@ static void macvtap_setup(struct net_device *dev)
48337 dev->tx_queue_len = TUN_READQ_SIZE;
48338 }
48339
48340 -static struct rtnl_link_ops macvtap_link_ops __read_mostly = {
48341 +static struct rtnl_link_ops macvtap_link_ops = {
48342 .kind = "macvtap",
48343 .setup = macvtap_setup,
48344 .newlink = macvtap_newlink,
48345 @@ -1020,7 +1020,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
48346 }
48347
48348 ret = 0;
48349 - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
48350 + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
48351 put_user(q->flags, &ifr->ifr_flags))
48352 ret = -EFAULT;
48353 macvtap_put_vlan(vlan);
48354 @@ -1190,7 +1190,7 @@ static int macvtap_device_event(struct notifier_block *unused,
48355 return NOTIFY_DONE;
48356 }
48357
48358 -static struct notifier_block macvtap_notifier_block __read_mostly = {
48359 +static struct notifier_block macvtap_notifier_block = {
48360 .notifier_call = macvtap_device_event,
48361 };
48362
48363 diff --git a/drivers/net/nlmon.c b/drivers/net/nlmon.c
48364 index 34924df..a747360 100644
48365 --- a/drivers/net/nlmon.c
48366 +++ b/drivers/net/nlmon.c
48367 @@ -154,7 +154,7 @@ static int nlmon_validate(struct nlattr *tb[], struct nlattr *data[])
48368 return 0;
48369 }
48370
48371 -static struct rtnl_link_ops nlmon_link_ops __read_mostly = {
48372 +static struct rtnl_link_ops nlmon_link_ops = {
48373 .kind = "nlmon",
48374 .priv_size = sizeof(struct nlmon),
48375 .setup = nlmon_setup,
48376 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
48377 index 794a473..9fd437b 100644
48378 --- a/drivers/net/ppp/ppp_generic.c
48379 +++ b/drivers/net/ppp/ppp_generic.c
48380 @@ -1020,7 +1020,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48381 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
48382 struct ppp_stats stats;
48383 struct ppp_comp_stats cstats;
48384 - char *vers;
48385
48386 switch (cmd) {
48387 case SIOCGPPPSTATS:
48388 @@ -1042,8 +1041,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48389 break;
48390
48391 case SIOCGPPPVER:
48392 - vers = PPP_VERSION;
48393 - if (copy_to_user(addr, vers, strlen(vers) + 1))
48394 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
48395 break;
48396 err = 0;
48397 break;
48398 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
48399 index 079f7ad..b2a2bfa7 100644
48400 --- a/drivers/net/slip/slhc.c
48401 +++ b/drivers/net/slip/slhc.c
48402 @@ -487,7 +487,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
48403 register struct tcphdr *thp;
48404 register struct iphdr *ip;
48405 register struct cstate *cs;
48406 - int len, hdrlen;
48407 + long len, hdrlen;
48408 unsigned char *cp = icp;
48409
48410 /* We've got a compressed packet; read the change byte */
48411 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
48412 index 2368395..bf6fe96 100644
48413 --- a/drivers/net/team/team.c
48414 +++ b/drivers/net/team/team.c
48415 @@ -2090,7 +2090,7 @@ static unsigned int team_get_num_rx_queues(void)
48416 return TEAM_DEFAULT_NUM_RX_QUEUES;
48417 }
48418
48419 -static struct rtnl_link_ops team_link_ops __read_mostly = {
48420 +static struct rtnl_link_ops team_link_ops = {
48421 .kind = DRV_NAME,
48422 .priv_size = sizeof(struct team),
48423 .setup = team_setup,
48424 @@ -2880,7 +2880,7 @@ static int team_device_event(struct notifier_block *unused,
48425 return NOTIFY_DONE;
48426 }
48427
48428 -static struct notifier_block team_notifier_block __read_mostly = {
48429 +static struct notifier_block team_notifier_block = {
48430 .notifier_call = team_device_event,
48431 };
48432
48433 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
48434 index 9dd3746..74f191e 100644
48435 --- a/drivers/net/tun.c
48436 +++ b/drivers/net/tun.c
48437 @@ -1426,7 +1426,7 @@ static int tun_validate(struct nlattr *tb[], struct nlattr *data[])
48438 return -EINVAL;
48439 }
48440
48441 -static struct rtnl_link_ops tun_link_ops __read_mostly = {
48442 +static struct rtnl_link_ops tun_link_ops = {
48443 .kind = DRV_NAME,
48444 .priv_size = sizeof(struct tun_struct),
48445 .setup = tun_setup,
48446 @@ -1868,7 +1868,7 @@ unlock:
48447 }
48448
48449 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
48450 - unsigned long arg, int ifreq_len)
48451 + unsigned long arg, size_t ifreq_len)
48452 {
48453 struct tun_file *tfile = file->private_data;
48454 struct tun_struct *tun;
48455 @@ -1881,6 +1881,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
48456 unsigned int ifindex;
48457 int ret;
48458
48459 + if (ifreq_len > sizeof ifr)
48460 + return -EFAULT;
48461 +
48462 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
48463 if (copy_from_user(&ifr, argp, ifreq_len))
48464 return -EFAULT;
48465 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
48466 index babda7d..e40c90a 100644
48467 --- a/drivers/net/usb/hso.c
48468 +++ b/drivers/net/usb/hso.c
48469 @@ -71,7 +71,7 @@
48470 #include <asm/byteorder.h>
48471 #include <linux/serial_core.h>
48472 #include <linux/serial.h>
48473 -
48474 +#include <asm/local.h>
48475
48476 #define MOD_AUTHOR "Option Wireless"
48477 #define MOD_DESCRIPTION "USB High Speed Option driver"
48478 @@ -1178,7 +1178,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
48479 struct urb *urb;
48480
48481 urb = serial->rx_urb[0];
48482 - if (serial->port.count > 0) {
48483 + if (atomic_read(&serial->port.count) > 0) {
48484 count = put_rxbuf_data(urb, serial);
48485 if (count == -1)
48486 return;
48487 @@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
48488 DUMP1(urb->transfer_buffer, urb->actual_length);
48489
48490 /* Anyone listening? */
48491 - if (serial->port.count == 0)
48492 + if (atomic_read(&serial->port.count) == 0)
48493 return;
48494
48495 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
48496 @@ -1278,8 +1278,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
48497 tty_port_tty_set(&serial->port, tty);
48498
48499 /* check for port already opened, if not set the termios */
48500 - serial->port.count++;
48501 - if (serial->port.count == 1) {
48502 + if (atomic_inc_return(&serial->port.count) == 1) {
48503 serial->rx_state = RX_IDLE;
48504 /* Force default termio settings */
48505 _hso_serial_set_termios(tty, NULL);
48506 @@ -1289,7 +1288,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
48507 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
48508 if (result) {
48509 hso_stop_serial_device(serial->parent);
48510 - serial->port.count--;
48511 + atomic_dec(&serial->port.count);
48512 kref_put(&serial->parent->ref, hso_serial_ref_free);
48513 }
48514 } else {
48515 @@ -1326,10 +1325,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
48516
48517 /* reset the rts and dtr */
48518 /* do the actual close */
48519 - serial->port.count--;
48520 + atomic_dec(&serial->port.count);
48521
48522 - if (serial->port.count <= 0) {
48523 - serial->port.count = 0;
48524 + if (atomic_read(&serial->port.count) <= 0) {
48525 + atomic_set(&serial->port.count, 0);
48526 tty_port_tty_set(&serial->port, NULL);
48527 if (!usb_gone)
48528 hso_stop_serial_device(serial->parent);
48529 @@ -1404,7 +1403,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
48530
48531 /* the actual setup */
48532 spin_lock_irqsave(&serial->serial_lock, flags);
48533 - if (serial->port.count)
48534 + if (atomic_read(&serial->port.count))
48535 _hso_serial_set_termios(tty, old);
48536 else
48537 tty->termios = *old;
48538 @@ -1873,7 +1872,7 @@ static void intr_callback(struct urb *urb)
48539 D1("Pending read interrupt on port %d\n", i);
48540 spin_lock(&serial->serial_lock);
48541 if (serial->rx_state == RX_IDLE &&
48542 - serial->port.count > 0) {
48543 + atomic_read(&serial->port.count) > 0) {
48544 /* Setup and send a ctrl req read on
48545 * port i */
48546 if (!serial->rx_urb_filled[0]) {
48547 @@ -3047,7 +3046,7 @@ static int hso_resume(struct usb_interface *iface)
48548 /* Start all serial ports */
48549 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
48550 if (serial_table[i] && (serial_table[i]->interface == iface)) {
48551 - if (dev2ser(serial_table[i])->port.count) {
48552 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
48553 result =
48554 hso_start_serial_device(serial_table[i], GFP_NOIO);
48555 hso_kick_transmit(dev2ser(serial_table[i]));
48556 diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
48557 index c6554c7..7e2ebd7 100644
48558 --- a/drivers/net/usb/r8152.c
48559 +++ b/drivers/net/usb/r8152.c
48560 @@ -577,7 +577,7 @@ struct r8152 {
48561 void (*unload)(struct r8152 *);
48562 int (*eee_get)(struct r8152 *, struct ethtool_eee *);
48563 int (*eee_set)(struct r8152 *, struct ethtool_eee *);
48564 - } rtl_ops;
48565 + } __no_const rtl_ops;
48566
48567 int intr_interval;
48568 u32 saved_wolopts;
48569 diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
48570 index a2515887..6d13233 100644
48571 --- a/drivers/net/usb/sierra_net.c
48572 +++ b/drivers/net/usb/sierra_net.c
48573 @@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
48574 /* atomic counter partially included in MAC address to make sure 2 devices
48575 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
48576 */
48577 -static atomic_t iface_counter = ATOMIC_INIT(0);
48578 +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
48579
48580 /*
48581 * SYNC Timer Delay definition used to set the expiry time
48582 @@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
48583 dev->net->netdev_ops = &sierra_net_device_ops;
48584
48585 /* change MAC addr to include, ifacenum, and to be unique */
48586 - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
48587 + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
48588 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
48589
48590 /* we will have to manufacture ethernet headers, prepare template */
48591 diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
48592 index b0bc8ea..3af931b5 100644
48593 --- a/drivers/net/virtio_net.c
48594 +++ b/drivers/net/virtio_net.c
48595 @@ -48,7 +48,7 @@ module_param(gso, bool, 0444);
48596 #define RECEIVE_AVG_WEIGHT 64
48597
48598 /* Minimum alignment for mergeable packet buffers. */
48599 -#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256)
48600 +#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256UL)
48601
48602 #define VIRTNET_DRIVER_VERSION "1.0.0"
48603
48604 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
48605 index 42b2d6a5..2a2cb41 100644
48606 --- a/drivers/net/vxlan.c
48607 +++ b/drivers/net/vxlan.c
48608 @@ -2695,7 +2695,7 @@ nla_put_failure:
48609 return -EMSGSIZE;
48610 }
48611
48612 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
48613 +static struct rtnl_link_ops vxlan_link_ops = {
48614 .kind = "vxlan",
48615 .maxtype = IFLA_VXLAN_MAX,
48616 .policy = vxlan_policy,
48617 @@ -2742,7 +2742,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
48618 return NOTIFY_DONE;
48619 }
48620
48621 -static struct notifier_block vxlan_notifier_block __read_mostly = {
48622 +static struct notifier_block vxlan_notifier_block = {
48623 .notifier_call = vxlan_lowerdev_event,
48624 };
48625
48626 diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
48627 index 5920c99..ff2e4a5 100644
48628 --- a/drivers/net/wan/lmc/lmc_media.c
48629 +++ b/drivers/net/wan/lmc/lmc_media.c
48630 @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
48631 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
48632
48633 lmc_media_t lmc_ds3_media = {
48634 - lmc_ds3_init, /* special media init stuff */
48635 - lmc_ds3_default, /* reset to default state */
48636 - lmc_ds3_set_status, /* reset status to state provided */
48637 - lmc_dummy_set_1, /* set clock source */
48638 - lmc_dummy_set2_1, /* set line speed */
48639 - lmc_ds3_set_100ft, /* set cable length */
48640 - lmc_ds3_set_scram, /* set scrambler */
48641 - lmc_ds3_get_link_status, /* get link status */
48642 - lmc_dummy_set_1, /* set link status */
48643 - lmc_ds3_set_crc_length, /* set CRC length */
48644 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
48645 - lmc_ds3_watchdog
48646 + .init = lmc_ds3_init, /* special media init stuff */
48647 + .defaults = lmc_ds3_default, /* reset to default state */
48648 + .set_status = lmc_ds3_set_status, /* reset status to state provided */
48649 + .set_clock_source = lmc_dummy_set_1, /* set clock source */
48650 + .set_speed = lmc_dummy_set2_1, /* set line speed */
48651 + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
48652 + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
48653 + .get_link_status = lmc_ds3_get_link_status, /* get link status */
48654 + .set_link_status = lmc_dummy_set_1, /* set link status */
48655 + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
48656 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
48657 + .watchdog = lmc_ds3_watchdog
48658 };
48659
48660 lmc_media_t lmc_hssi_media = {
48661 - lmc_hssi_init, /* special media init stuff */
48662 - lmc_hssi_default, /* reset to default state */
48663 - lmc_hssi_set_status, /* reset status to state provided */
48664 - lmc_hssi_set_clock, /* set clock source */
48665 - lmc_dummy_set2_1, /* set line speed */
48666 - lmc_dummy_set_1, /* set cable length */
48667 - lmc_dummy_set_1, /* set scrambler */
48668 - lmc_hssi_get_link_status, /* get link status */
48669 - lmc_hssi_set_link_status, /* set link status */
48670 - lmc_hssi_set_crc_length, /* set CRC length */
48671 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
48672 - lmc_hssi_watchdog
48673 + .init = lmc_hssi_init, /* special media init stuff */
48674 + .defaults = lmc_hssi_default, /* reset to default state */
48675 + .set_status = lmc_hssi_set_status, /* reset status to state provided */
48676 + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
48677 + .set_speed = lmc_dummy_set2_1, /* set line speed */
48678 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
48679 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
48680 + .get_link_status = lmc_hssi_get_link_status, /* get link status */
48681 + .set_link_status = lmc_hssi_set_link_status, /* set link status */
48682 + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
48683 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
48684 + .watchdog = lmc_hssi_watchdog
48685 };
48686
48687 -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
48688 - lmc_ssi_default, /* reset to default state */
48689 - lmc_ssi_set_status, /* reset status to state provided */
48690 - lmc_ssi_set_clock, /* set clock source */
48691 - lmc_ssi_set_speed, /* set line speed */
48692 - lmc_dummy_set_1, /* set cable length */
48693 - lmc_dummy_set_1, /* set scrambler */
48694 - lmc_ssi_get_link_status, /* get link status */
48695 - lmc_ssi_set_link_status, /* set link status */
48696 - lmc_ssi_set_crc_length, /* set CRC length */
48697 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
48698 - lmc_ssi_watchdog
48699 +lmc_media_t lmc_ssi_media = {
48700 + .init = lmc_ssi_init, /* special media init stuff */
48701 + .defaults = lmc_ssi_default, /* reset to default state */
48702 + .set_status = lmc_ssi_set_status, /* reset status to state provided */
48703 + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
48704 + .set_speed = lmc_ssi_set_speed, /* set line speed */
48705 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
48706 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
48707 + .get_link_status = lmc_ssi_get_link_status, /* get link status */
48708 + .set_link_status = lmc_ssi_set_link_status, /* set link status */
48709 + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
48710 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
48711 + .watchdog = lmc_ssi_watchdog
48712 };
48713
48714 lmc_media_t lmc_t1_media = {
48715 - lmc_t1_init, /* special media init stuff */
48716 - lmc_t1_default, /* reset to default state */
48717 - lmc_t1_set_status, /* reset status to state provided */
48718 - lmc_t1_set_clock, /* set clock source */
48719 - lmc_dummy_set2_1, /* set line speed */
48720 - lmc_dummy_set_1, /* set cable length */
48721 - lmc_dummy_set_1, /* set scrambler */
48722 - lmc_t1_get_link_status, /* get link status */
48723 - lmc_dummy_set_1, /* set link status */
48724 - lmc_t1_set_crc_length, /* set CRC length */
48725 - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
48726 - lmc_t1_watchdog
48727 + .init = lmc_t1_init, /* special media init stuff */
48728 + .defaults = lmc_t1_default, /* reset to default state */
48729 + .set_status = lmc_t1_set_status, /* reset status to state provided */
48730 + .set_clock_source = lmc_t1_set_clock, /* set clock source */
48731 + .set_speed = lmc_dummy_set2_1, /* set line speed */
48732 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
48733 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
48734 + .get_link_status = lmc_t1_get_link_status, /* get link status */
48735 + .set_link_status = lmc_dummy_set_1, /* set link status */
48736 + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
48737 + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
48738 + .watchdog = lmc_t1_watchdog
48739 };
48740
48741 static void
48742 diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
48743 index feacc3b..5bac0de 100644
48744 --- a/drivers/net/wan/z85230.c
48745 +++ b/drivers/net/wan/z85230.c
48746 @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
48747
48748 struct z8530_irqhandler z8530_sync =
48749 {
48750 - z8530_rx,
48751 - z8530_tx,
48752 - z8530_status
48753 + .rx = z8530_rx,
48754 + .tx = z8530_tx,
48755 + .status = z8530_status
48756 };
48757
48758 EXPORT_SYMBOL(z8530_sync);
48759 @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
48760 }
48761
48762 static struct z8530_irqhandler z8530_dma_sync = {
48763 - z8530_dma_rx,
48764 - z8530_dma_tx,
48765 - z8530_dma_status
48766 + .rx = z8530_dma_rx,
48767 + .tx = z8530_dma_tx,
48768 + .status = z8530_dma_status
48769 };
48770
48771 static struct z8530_irqhandler z8530_txdma_sync = {
48772 - z8530_rx,
48773 - z8530_dma_tx,
48774 - z8530_dma_status
48775 + .rx = z8530_rx,
48776 + .tx = z8530_dma_tx,
48777 + .status = z8530_dma_status
48778 };
48779
48780 /**
48781 @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
48782
48783 struct z8530_irqhandler z8530_nop=
48784 {
48785 - z8530_rx_clear,
48786 - z8530_tx_clear,
48787 - z8530_status_clear
48788 + .rx = z8530_rx_clear,
48789 + .tx = z8530_tx_clear,
48790 + .status = z8530_status_clear
48791 };
48792
48793
48794 diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
48795 index 0b60295..b8bfa5b 100644
48796 --- a/drivers/net/wimax/i2400m/rx.c
48797 +++ b/drivers/net/wimax/i2400m/rx.c
48798 @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
48799 if (i2400m->rx_roq == NULL)
48800 goto error_roq_alloc;
48801
48802 - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
48803 + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
48804 GFP_KERNEL);
48805 if (rd == NULL) {
48806 result = -ENOMEM;
48807 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
48808 index e71a2ce..2268d61 100644
48809 --- a/drivers/net/wireless/airo.c
48810 +++ b/drivers/net/wireless/airo.c
48811 @@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
48812 struct airo_info *ai = dev->ml_priv;
48813 int ridcode;
48814 int enabled;
48815 - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
48816 + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
48817 unsigned char *iobuf;
48818
48819 /* Only super-user can write RIDs */
48820 diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
48821 index da92bfa..5a9001a 100644
48822 --- a/drivers/net/wireless/at76c50x-usb.c
48823 +++ b/drivers/net/wireless/at76c50x-usb.c
48824 @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
48825 }
48826
48827 /* Convert timeout from the DFU status to jiffies */
48828 -static inline unsigned long at76_get_timeout(struct dfu_status *s)
48829 +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
48830 {
48831 return msecs_to_jiffies((s->poll_timeout[2] << 16)
48832 | (s->poll_timeout[1] << 8)
48833 diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
48834 index 676bd4e..0b807a3 100644
48835 --- a/drivers/net/wireless/ath/ath10k/htc.c
48836 +++ b/drivers/net/wireless/ath/ath10k/htc.c
48837 @@ -848,7 +848,10 @@ int ath10k_htc_start(struct ath10k_htc *htc)
48838 /* registered target arrival callback from the HIF layer */
48839 int ath10k_htc_init(struct ath10k *ar)
48840 {
48841 - struct ath10k_hif_cb htc_callbacks;
48842 + static struct ath10k_hif_cb htc_callbacks = {
48843 + .rx_completion = ath10k_htc_rx_completion_handler,
48844 + .tx_completion = ath10k_htc_tx_completion_handler,
48845 + };
48846 struct ath10k_htc_ep *ep = NULL;
48847 struct ath10k_htc *htc = &ar->htc;
48848
48849 @@ -857,8 +860,6 @@ int ath10k_htc_init(struct ath10k *ar)
48850 ath10k_htc_reset_endpoint_states(htc);
48851
48852 /* setup HIF layer callbacks */
48853 - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
48854 - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
48855 htc->ar = ar;
48856
48857 /* Get HIF default pipe for HTC message exchange */
48858 diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
48859 index 527179c..a890150 100644
48860 --- a/drivers/net/wireless/ath/ath10k/htc.h
48861 +++ b/drivers/net/wireless/ath/ath10k/htc.h
48862 @@ -270,13 +270,13 @@ enum ath10k_htc_ep_id {
48863
48864 struct ath10k_htc_ops {
48865 void (*target_send_suspend_complete)(struct ath10k *ar);
48866 -};
48867 +} __no_const;
48868
48869 struct ath10k_htc_ep_ops {
48870 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
48871 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
48872 void (*ep_tx_credits)(struct ath10k *);
48873 -};
48874 +} __no_const;
48875
48876 /* service connection information */
48877 struct ath10k_htc_svc_conn_req {
48878 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
48879 index 2a93519..7052786 100644
48880 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
48881 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
48882 @@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
48883 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
48884 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
48885
48886 - ACCESS_ONCE(ads->ds_link) = i->link;
48887 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
48888 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
48889 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
48890
48891 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
48892 ctl6 = SM(i->keytype, AR_EncrType);
48893 @@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
48894
48895 if ((i->is_first || i->is_last) &&
48896 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
48897 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
48898 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
48899 | set11nTries(i->rates, 1)
48900 | set11nTries(i->rates, 2)
48901 | set11nTries(i->rates, 3)
48902 | (i->dur_update ? AR_DurUpdateEna : 0)
48903 | SM(0, AR_BurstDur);
48904
48905 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
48906 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
48907 | set11nRate(i->rates, 1)
48908 | set11nRate(i->rates, 2)
48909 | set11nRate(i->rates, 3);
48910 } else {
48911 - ACCESS_ONCE(ads->ds_ctl2) = 0;
48912 - ACCESS_ONCE(ads->ds_ctl3) = 0;
48913 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
48914 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
48915 }
48916
48917 if (!i->is_first) {
48918 - ACCESS_ONCE(ads->ds_ctl0) = 0;
48919 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
48920 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
48921 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
48922 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
48923 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
48924 return;
48925 }
48926
48927 @@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
48928 break;
48929 }
48930
48931 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
48932 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
48933 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
48934 | SM(i->txpower, AR_XmitPower0)
48935 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
48936 @@ -289,27 +289,27 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
48937 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
48938 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
48939
48940 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
48941 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
48942 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
48943 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
48944
48945 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
48946 return;
48947
48948 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
48949 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
48950 | set11nPktDurRTSCTS(i->rates, 1);
48951
48952 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
48953 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
48954 | set11nPktDurRTSCTS(i->rates, 3);
48955
48956 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
48957 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
48958 | set11nRateFlags(i->rates, 1)
48959 | set11nRateFlags(i->rates, 2)
48960 | set11nRateFlags(i->rates, 3)
48961 | SM(i->rtscts_rate, AR_RTSCTSRate);
48962
48963 - ACCESS_ONCE(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
48964 - ACCESS_ONCE(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
48965 - ACCESS_ONCE(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
48966 + ACCESS_ONCE_RW(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
48967 + ACCESS_ONCE_RW(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
48968 + ACCESS_ONCE_RW(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
48969 }
48970
48971 static int ar9002_hw_proc_txdesc(struct ath_hw *ah, void *ds,
48972 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
48973 index 057b165..98ae88f 100644
48974 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
48975 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
48976 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
48977 (i->qcu << AR_TxQcuNum_S) | desc_len;
48978
48979 checksum += val;
48980 - ACCESS_ONCE(ads->info) = val;
48981 + ACCESS_ONCE_RW(ads->info) = val;
48982
48983 checksum += i->link;
48984 - ACCESS_ONCE(ads->link) = i->link;
48985 + ACCESS_ONCE_RW(ads->link) = i->link;
48986
48987 checksum += i->buf_addr[0];
48988 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
48989 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
48990 checksum += i->buf_addr[1];
48991 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
48992 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
48993 checksum += i->buf_addr[2];
48994 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
48995 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
48996 checksum += i->buf_addr[3];
48997 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
48998 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
48999
49000 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
49001 - ACCESS_ONCE(ads->ctl3) = val;
49002 + ACCESS_ONCE_RW(ads->ctl3) = val;
49003 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
49004 - ACCESS_ONCE(ads->ctl5) = val;
49005 + ACCESS_ONCE_RW(ads->ctl5) = val;
49006 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
49007 - ACCESS_ONCE(ads->ctl7) = val;
49008 + ACCESS_ONCE_RW(ads->ctl7) = val;
49009 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
49010 - ACCESS_ONCE(ads->ctl9) = val;
49011 + ACCESS_ONCE_RW(ads->ctl9) = val;
49012
49013 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
49014 - ACCESS_ONCE(ads->ctl10) = checksum;
49015 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
49016
49017 if (i->is_first || i->is_last) {
49018 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
49019 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
49020 | set11nTries(i->rates, 1)
49021 | set11nTries(i->rates, 2)
49022 | set11nTries(i->rates, 3)
49023 | (i->dur_update ? AR_DurUpdateEna : 0)
49024 | SM(0, AR_BurstDur);
49025
49026 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
49027 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
49028 | set11nRate(i->rates, 1)
49029 | set11nRate(i->rates, 2)
49030 | set11nRate(i->rates, 3);
49031 } else {
49032 - ACCESS_ONCE(ads->ctl13) = 0;
49033 - ACCESS_ONCE(ads->ctl14) = 0;
49034 + ACCESS_ONCE_RW(ads->ctl13) = 0;
49035 + ACCESS_ONCE_RW(ads->ctl14) = 0;
49036 }
49037
49038 ads->ctl20 = 0;
49039 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49040
49041 ctl17 = SM(i->keytype, AR_EncrType);
49042 if (!i->is_first) {
49043 - ACCESS_ONCE(ads->ctl11) = 0;
49044 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49045 - ACCESS_ONCE(ads->ctl15) = 0;
49046 - ACCESS_ONCE(ads->ctl16) = 0;
49047 - ACCESS_ONCE(ads->ctl17) = ctl17;
49048 - ACCESS_ONCE(ads->ctl18) = 0;
49049 - ACCESS_ONCE(ads->ctl19) = 0;
49050 + ACCESS_ONCE_RW(ads->ctl11) = 0;
49051 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49052 + ACCESS_ONCE_RW(ads->ctl15) = 0;
49053 + ACCESS_ONCE_RW(ads->ctl16) = 0;
49054 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49055 + ACCESS_ONCE_RW(ads->ctl18) = 0;
49056 + ACCESS_ONCE_RW(ads->ctl19) = 0;
49057 return;
49058 }
49059
49060 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49061 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49062 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
49063 | SM(i->txpower, AR_XmitPower0)
49064 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
49065 @@ -135,26 +135,26 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49066 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
49067 ctl12 |= SM(val, AR_PAPRDChainMask);
49068
49069 - ACCESS_ONCE(ads->ctl12) = ctl12;
49070 - ACCESS_ONCE(ads->ctl17) = ctl17;
49071 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
49072 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49073
49074 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49075 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49076 | set11nPktDurRTSCTS(i->rates, 1);
49077
49078 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49079 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49080 | set11nPktDurRTSCTS(i->rates, 3);
49081
49082 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
49083 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
49084 | set11nRateFlags(i->rates, 1)
49085 | set11nRateFlags(i->rates, 2)
49086 | set11nRateFlags(i->rates, 3)
49087 | SM(i->rtscts_rate, AR_RTSCTSRate);
49088
49089 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
49090 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
49091
49092 - ACCESS_ONCE(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49093 - ACCESS_ONCE(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49094 - ACCESS_ONCE(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49095 + ACCESS_ONCE_RW(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49096 + ACCESS_ONCE_RW(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49097 + ACCESS_ONCE_RW(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49098 }
49099
49100 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
49101 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
49102 index 975074f..e9440da 100644
49103 --- a/drivers/net/wireless/ath/ath9k/hw.h
49104 +++ b/drivers/net/wireless/ath/ath9k/hw.h
49105 @@ -630,7 +630,7 @@ struct ath_hw_private_ops {
49106
49107 /* ANI */
49108 void (*ani_cache_ini_regs)(struct ath_hw *ah);
49109 -};
49110 +} __no_const;
49111
49112 /**
49113 * struct ath_spec_scan - parameters for Atheros spectral scan
49114 @@ -708,7 +708,7 @@ struct ath_hw_ops {
49115 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
49116 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
49117 #endif
49118 -};
49119 +} __no_const;
49120
49121 struct ath_nf_limits {
49122 s16 max;
49123 diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
49124 index 4f18a6b..b07d92f 100644
49125 --- a/drivers/net/wireless/ath/ath9k/main.c
49126 +++ b/drivers/net/wireless/ath/ath9k/main.c
49127 @@ -2454,16 +2454,18 @@ void ath9k_fill_chanctx_ops(void)
49128 if (!ath9k_is_chanctx_enabled())
49129 return;
49130
49131 - ath9k_ops.hw_scan = ath9k_hw_scan;
49132 - ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49133 - ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49134 - ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49135 - ath9k_ops.add_chanctx = ath9k_add_chanctx;
49136 - ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49137 - ath9k_ops.change_chanctx = ath9k_change_chanctx;
49138 - ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49139 - ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49140 - ath9k_ops.mgd_prepare_tx = ath9k_mgd_prepare_tx;
49141 + pax_open_kernel();
49142 + *(void **)&ath9k_ops.hw_scan = ath9k_hw_scan;
49143 + *(void **)&ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49144 + *(void **)&ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49145 + *(void **)&ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49146 + *(void **)&ath9k_ops.add_chanctx = ath9k_add_chanctx;
49147 + *(void **)&ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49148 + *(void **)&ath9k_ops.change_chanctx = ath9k_change_chanctx;
49149 + *(void **)&ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49150 + *(void **)&ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49151 + *(void **)&ath9k_ops.mgd_prepare_tx = ath9k_mgd_prepare_tx;
49152 + pax_close_kernel();
49153 }
49154
49155 #endif
49156 diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
49157 index 058a9f2..d5cb1ba 100644
49158 --- a/drivers/net/wireless/b43/phy_lp.c
49159 +++ b/drivers/net/wireless/b43/phy_lp.c
49160 @@ -2502,7 +2502,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
49161 {
49162 struct ssb_bus *bus = dev->dev->sdev->bus;
49163
49164 - static const struct b206x_channel *chandata = NULL;
49165 + const struct b206x_channel *chandata = NULL;
49166 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
49167 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
49168 u16 old_comm15, scale;
49169 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
49170 index dc1d20c..f7a4f06 100644
49171 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
49172 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
49173 @@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
49174 */
49175 if (il3945_mod_params.disable_hw_scan) {
49176 D_INFO("Disabling hw_scan\n");
49177 - il3945_mac_ops.hw_scan = NULL;
49178 + pax_open_kernel();
49179 + *(void **)&il3945_mac_ops.hw_scan = NULL;
49180 + pax_close_kernel();
49181 }
49182
49183 D_INFO("*** LOAD DRIVER ***\n");
49184 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49185 index 0ffb6ff..c0b7f0e 100644
49186 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49187 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49188 @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
49189 {
49190 struct iwl_priv *priv = file->private_data;
49191 char buf[64];
49192 - int buf_size;
49193 + size_t buf_size;
49194 u32 offset, len;
49195
49196 memset(buf, 0, sizeof(buf));
49197 @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
49198 struct iwl_priv *priv = file->private_data;
49199
49200 char buf[8];
49201 - int buf_size;
49202 + size_t buf_size;
49203 u32 reset_flag;
49204
49205 memset(buf, 0, sizeof(buf));
49206 @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
49207 {
49208 struct iwl_priv *priv = file->private_data;
49209 char buf[8];
49210 - int buf_size;
49211 + size_t buf_size;
49212 int ht40;
49213
49214 memset(buf, 0, sizeof(buf));
49215 @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
49216 {
49217 struct iwl_priv *priv = file->private_data;
49218 char buf[8];
49219 - int buf_size;
49220 + size_t buf_size;
49221 int value;
49222
49223 memset(buf, 0, sizeof(buf));
49224 @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
49225 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
49226 DEBUGFS_READ_FILE_OPS(current_sleep_command);
49227
49228 -static const char *fmt_value = " %-30s %10u\n";
49229 -static const char *fmt_hex = " %-30s 0x%02X\n";
49230 -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
49231 -static const char *fmt_header =
49232 +static const char fmt_value[] = " %-30s %10u\n";
49233 +static const char fmt_hex[] = " %-30s 0x%02X\n";
49234 +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
49235 +static const char fmt_header[] =
49236 "%-32s current cumulative delta max\n";
49237
49238 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
49239 @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
49240 {
49241 struct iwl_priv *priv = file->private_data;
49242 char buf[8];
49243 - int buf_size;
49244 + size_t buf_size;
49245 int clear;
49246
49247 memset(buf, 0, sizeof(buf));
49248 @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
49249 {
49250 struct iwl_priv *priv = file->private_data;
49251 char buf[8];
49252 - int buf_size;
49253 + size_t buf_size;
49254 int trace;
49255
49256 memset(buf, 0, sizeof(buf));
49257 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
49258 {
49259 struct iwl_priv *priv = file->private_data;
49260 char buf[8];
49261 - int buf_size;
49262 + size_t buf_size;
49263 int missed;
49264
49265 memset(buf, 0, sizeof(buf));
49266 @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
49267
49268 struct iwl_priv *priv = file->private_data;
49269 char buf[8];
49270 - int buf_size;
49271 + size_t buf_size;
49272 int plcp;
49273
49274 memset(buf, 0, sizeof(buf));
49275 @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
49276
49277 struct iwl_priv *priv = file->private_data;
49278 char buf[8];
49279 - int buf_size;
49280 + size_t buf_size;
49281 int flush;
49282
49283 memset(buf, 0, sizeof(buf));
49284 @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
49285
49286 struct iwl_priv *priv = file->private_data;
49287 char buf[8];
49288 - int buf_size;
49289 + size_t buf_size;
49290 int rts;
49291
49292 if (!priv->cfg->ht_params)
49293 @@ -2204,7 +2204,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
49294 {
49295 struct iwl_priv *priv = file->private_data;
49296 char buf[8];
49297 - int buf_size;
49298 + size_t buf_size;
49299
49300 memset(buf, 0, sizeof(buf));
49301 buf_size = min(count, sizeof(buf) - 1);
49302 @@ -2238,7 +2238,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
49303 struct iwl_priv *priv = file->private_data;
49304 u32 event_log_flag;
49305 char buf[8];
49306 - int buf_size;
49307 + size_t buf_size;
49308
49309 /* check that the interface is up */
49310 if (!iwl_is_ready(priv))
49311 @@ -2292,7 +2292,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
49312 struct iwl_priv *priv = file->private_data;
49313 char buf[8];
49314 u32 calib_disabled;
49315 - int buf_size;
49316 + size_t buf_size;
49317
49318 memset(buf, 0, sizeof(buf));
49319 buf_size = min(count, sizeof(buf) - 1);
49320 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
49321 index dd2f3f8..fb1ae88 100644
49322 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
49323 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
49324 @@ -1689,7 +1689,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
49325 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
49326
49327 char buf[8];
49328 - int buf_size;
49329 + size_t buf_size;
49330 u32 reset_flag;
49331
49332 memset(buf, 0, sizeof(buf));
49333 @@ -1710,7 +1710,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
49334 {
49335 struct iwl_trans *trans = file->private_data;
49336 char buf[8];
49337 - int buf_size;
49338 + size_t buf_size;
49339 int csr;
49340
49341 memset(buf, 0, sizeof(buf));
49342 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
49343 index c9ad4cf..49a2fa0 100644
49344 --- a/drivers/net/wireless/mac80211_hwsim.c
49345 +++ b/drivers/net/wireless/mac80211_hwsim.c
49346 @@ -2577,20 +2577,20 @@ static int __init init_mac80211_hwsim(void)
49347 if (channels < 1)
49348 return -EINVAL;
49349
49350 - mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
49351 - mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
49352 - mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
49353 - mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
49354 - mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
49355 - mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
49356 - mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
49357 - mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
49358 - mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
49359 - mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
49360 - mac80211_hwsim_mchan_ops.assign_vif_chanctx =
49361 - mac80211_hwsim_assign_vif_chanctx;
49362 - mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
49363 - mac80211_hwsim_unassign_vif_chanctx;
49364 + pax_open_kernel();
49365 + memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
49366 + *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
49367 + *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
49368 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
49369 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
49370 + *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
49371 + *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
49372 + *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
49373 + *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
49374 + *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
49375 + *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
49376 + *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
49377 + pax_close_kernel();
49378
49379 spin_lock_init(&hwsim_radio_lock);
49380 INIT_LIST_HEAD(&hwsim_radios);
49381 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
49382 index 1a4facd..a2ecbbd 100644
49383 --- a/drivers/net/wireless/rndis_wlan.c
49384 +++ b/drivers/net/wireless/rndis_wlan.c
49385 @@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
49386
49387 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
49388
49389 - if (rts_threshold < 0 || rts_threshold > 2347)
49390 + if (rts_threshold > 2347)
49391 rts_threshold = 2347;
49392
49393 tmp = cpu_to_le32(rts_threshold);
49394 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
49395 index d13f25c..2573994 100644
49396 --- a/drivers/net/wireless/rt2x00/rt2x00.h
49397 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
49398 @@ -375,7 +375,7 @@ struct rt2x00_intf {
49399 * for hardware which doesn't support hardware
49400 * sequence counting.
49401 */
49402 - atomic_t seqno;
49403 + atomic_unchecked_t seqno;
49404 };
49405
49406 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
49407 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
49408 index 66ff364..3ce34f7 100644
49409 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
49410 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
49411 @@ -224,9 +224,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
49412 * sequence counter given by mac80211.
49413 */
49414 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
49415 - seqno = atomic_add_return(0x10, &intf->seqno);
49416 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
49417 else
49418 - seqno = atomic_read(&intf->seqno);
49419 + seqno = atomic_read_unchecked(&intf->seqno);
49420
49421 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
49422 hdr->seq_ctrl |= cpu_to_le16(seqno);
49423 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
49424 index b661f896..ddf7d2b 100644
49425 --- a/drivers/net/wireless/ti/wl1251/sdio.c
49426 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
49427 @@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
49428
49429 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
49430
49431 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
49432 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
49433 + pax_open_kernel();
49434 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
49435 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
49436 + pax_close_kernel();
49437
49438 wl1251_info("using dedicated interrupt line");
49439 } else {
49440 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
49441 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
49442 + pax_open_kernel();
49443 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
49444 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
49445 + pax_close_kernel();
49446
49447 wl1251_info("using SDIO interrupt");
49448 }
49449 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
49450 index 0bccf12..3d95068 100644
49451 --- a/drivers/net/wireless/ti/wl12xx/main.c
49452 +++ b/drivers/net/wireless/ti/wl12xx/main.c
49453 @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
49454 sizeof(wl->conf.mem));
49455
49456 /* read data preparation is only needed by wl127x */
49457 - wl->ops->prepare_read = wl127x_prepare_read;
49458 + pax_open_kernel();
49459 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
49460 + pax_close_kernel();
49461
49462 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
49463 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
49464 @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
49465 sizeof(wl->conf.mem));
49466
49467 /* read data preparation is only needed by wl127x */
49468 - wl->ops->prepare_read = wl127x_prepare_read;
49469 + pax_open_kernel();
49470 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
49471 + pax_close_kernel();
49472
49473 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
49474 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
49475 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
49476 index 7af1936..128bb35 100644
49477 --- a/drivers/net/wireless/ti/wl18xx/main.c
49478 +++ b/drivers/net/wireless/ti/wl18xx/main.c
49479 @@ -1916,8 +1916,10 @@ static int wl18xx_setup(struct wl1271 *wl)
49480 }
49481
49482 if (!checksum_param) {
49483 - wl18xx_ops.set_rx_csum = NULL;
49484 - wl18xx_ops.init_vif = NULL;
49485 + pax_open_kernel();
49486 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
49487 + *(void **)&wl18xx_ops.init_vif = NULL;
49488 + pax_close_kernel();
49489 }
49490
49491 /* Enable 11a Band only if we have 5G antennas */
49492 diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
49493 index a912dc0..a8225ba 100644
49494 --- a/drivers/net/wireless/zd1211rw/zd_usb.c
49495 +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
49496 @@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
49497 {
49498 struct zd_usb *usb = urb->context;
49499 struct zd_usb_interrupt *intr = &usb->intr;
49500 - int len;
49501 + unsigned int len;
49502 u16 int_num;
49503
49504 ZD_ASSERT(in_interrupt());
49505 diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
49506 index 683671a..4519fc2 100644
49507 --- a/drivers/nfc/nfcwilink.c
49508 +++ b/drivers/nfc/nfcwilink.c
49509 @@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
49510
49511 static int nfcwilink_probe(struct platform_device *pdev)
49512 {
49513 - static struct nfcwilink *drv;
49514 + struct nfcwilink *drv;
49515 int rc;
49516 __u32 protocols;
49517
49518 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
49519 index d93b2b6..ae50401 100644
49520 --- a/drivers/oprofile/buffer_sync.c
49521 +++ b/drivers/oprofile/buffer_sync.c
49522 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
49523 if (cookie == NO_COOKIE)
49524 offset = pc;
49525 if (cookie == INVALID_COOKIE) {
49526 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
49527 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
49528 offset = pc;
49529 }
49530 if (cookie != last_cookie) {
49531 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
49532 /* add userspace sample */
49533
49534 if (!mm) {
49535 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
49536 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
49537 return 0;
49538 }
49539
49540 cookie = lookup_dcookie(mm, s->eip, &offset);
49541
49542 if (cookie == INVALID_COOKIE) {
49543 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
49544 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
49545 return 0;
49546 }
49547
49548 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
49549 /* ignore backtraces if failed to add a sample */
49550 if (state == sb_bt_start) {
49551 state = sb_bt_ignore;
49552 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
49553 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
49554 }
49555 }
49556 release_mm(mm);
49557 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
49558 index c0cc4e7..44d4e54 100644
49559 --- a/drivers/oprofile/event_buffer.c
49560 +++ b/drivers/oprofile/event_buffer.c
49561 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
49562 }
49563
49564 if (buffer_pos == buffer_size) {
49565 - atomic_inc(&oprofile_stats.event_lost_overflow);
49566 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
49567 return;
49568 }
49569
49570 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
49571 index ed2c3ec..deda85a 100644
49572 --- a/drivers/oprofile/oprof.c
49573 +++ b/drivers/oprofile/oprof.c
49574 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
49575 if (oprofile_ops.switch_events())
49576 return;
49577
49578 - atomic_inc(&oprofile_stats.multiplex_counter);
49579 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
49580 start_switch_worker();
49581 }
49582
49583 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
49584 index ee2cfce..7f8f699 100644
49585 --- a/drivers/oprofile/oprofile_files.c
49586 +++ b/drivers/oprofile/oprofile_files.c
49587 @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
49588
49589 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
49590
49591 -static ssize_t timeout_read(struct file *file, char __user *buf,
49592 +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
49593 size_t count, loff_t *offset)
49594 {
49595 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
49596 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
49597 index 59659ce..6c860a0 100644
49598 --- a/drivers/oprofile/oprofile_stats.c
49599 +++ b/drivers/oprofile/oprofile_stats.c
49600 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
49601 cpu_buf->sample_invalid_eip = 0;
49602 }
49603
49604 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
49605 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
49606 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
49607 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
49608 - atomic_set(&oprofile_stats.multiplex_counter, 0);
49609 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
49610 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
49611 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
49612 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
49613 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
49614 }
49615
49616
49617 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
49618 index 1fc622b..8c48fc3 100644
49619 --- a/drivers/oprofile/oprofile_stats.h
49620 +++ b/drivers/oprofile/oprofile_stats.h
49621 @@ -13,11 +13,11 @@
49622 #include <linux/atomic.h>
49623
49624 struct oprofile_stat_struct {
49625 - atomic_t sample_lost_no_mm;
49626 - atomic_t sample_lost_no_mapping;
49627 - atomic_t bt_lost_no_mapping;
49628 - atomic_t event_lost_overflow;
49629 - atomic_t multiplex_counter;
49630 + atomic_unchecked_t sample_lost_no_mm;
49631 + atomic_unchecked_t sample_lost_no_mapping;
49632 + atomic_unchecked_t bt_lost_no_mapping;
49633 + atomic_unchecked_t event_lost_overflow;
49634 + atomic_unchecked_t multiplex_counter;
49635 };
49636
49637 extern struct oprofile_stat_struct oprofile_stats;
49638 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
49639 index 3f49345..c750d0b 100644
49640 --- a/drivers/oprofile/oprofilefs.c
49641 +++ b/drivers/oprofile/oprofilefs.c
49642 @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
49643
49644 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
49645 {
49646 - atomic_t *val = file->private_data;
49647 - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
49648 + atomic_unchecked_t *val = file->private_data;
49649 + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
49650 }
49651
49652
49653 @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
49654
49655
49656 int oprofilefs_create_ro_atomic(struct dentry *root,
49657 - char const *name, atomic_t *val)
49658 + char const *name, atomic_unchecked_t *val)
49659 {
49660 return __oprofilefs_create_file(root, name,
49661 &atomic_ro_fops, 0444, val);
49662 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
49663 index bdef916..88c7dee 100644
49664 --- a/drivers/oprofile/timer_int.c
49665 +++ b/drivers/oprofile/timer_int.c
49666 @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
49667 return NOTIFY_OK;
49668 }
49669
49670 -static struct notifier_block __refdata oprofile_cpu_notifier = {
49671 +static struct notifier_block oprofile_cpu_notifier = {
49672 .notifier_call = oprofile_cpu_notify,
49673 };
49674
49675 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
49676 index 3b47080..6cd05dd 100644
49677 --- a/drivers/parport/procfs.c
49678 +++ b/drivers/parport/procfs.c
49679 @@ -64,7 +64,7 @@ static int do_active_device(struct ctl_table *table, int write,
49680
49681 *ppos += len;
49682
49683 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
49684 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
49685 }
49686
49687 #ifdef CONFIG_PARPORT_1284
49688 @@ -106,7 +106,7 @@ static int do_autoprobe(struct ctl_table *table, int write,
49689
49690 *ppos += len;
49691
49692 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
49693 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
49694 }
49695 #endif /* IEEE1284.3 support. */
49696
49697 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
49698 index 6ca2399..68d866b 100644
49699 --- a/drivers/pci/hotplug/acpiphp_ibm.c
49700 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
49701 @@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
49702 goto init_cleanup;
49703 }
49704
49705 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
49706 + pax_open_kernel();
49707 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
49708 + pax_close_kernel();
49709 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
49710
49711 return retval;
49712 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
49713 index 66b7bbe..26bee78 100644
49714 --- a/drivers/pci/hotplug/cpcihp_generic.c
49715 +++ b/drivers/pci/hotplug/cpcihp_generic.c
49716 @@ -73,7 +73,6 @@ static u16 port;
49717 static unsigned int enum_bit;
49718 static u8 enum_mask;
49719
49720 -static struct cpci_hp_controller_ops generic_hpc_ops;
49721 static struct cpci_hp_controller generic_hpc;
49722
49723 static int __init validate_parameters(void)
49724 @@ -139,6 +138,10 @@ static int query_enum(void)
49725 return ((value & enum_mask) == enum_mask);
49726 }
49727
49728 +static struct cpci_hp_controller_ops generic_hpc_ops = {
49729 + .query_enum = query_enum,
49730 +};
49731 +
49732 static int __init cpcihp_generic_init(void)
49733 {
49734 int status;
49735 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
49736 pci_dev_put(dev);
49737
49738 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
49739 - generic_hpc_ops.query_enum = query_enum;
49740 generic_hpc.ops = &generic_hpc_ops;
49741
49742 status = cpci_hp_register_controller(&generic_hpc);
49743 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
49744 index 7ecf34e..effed62 100644
49745 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
49746 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
49747 @@ -59,7 +59,6 @@
49748 /* local variables */
49749 static bool debug;
49750 static bool poll;
49751 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
49752 static struct cpci_hp_controller zt5550_hpc;
49753
49754 /* Primary cPCI bus bridge device */
49755 @@ -204,6 +203,10 @@ static int zt5550_hc_disable_irq(void)
49756 return 0;
49757 }
49758
49759 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
49760 + .query_enum = zt5550_hc_query_enum,
49761 +};
49762 +
49763 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
49764 {
49765 int status;
49766 @@ -215,16 +218,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
49767 dbg("returned from zt5550_hc_config");
49768
49769 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
49770 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
49771 zt5550_hpc.ops = &zt5550_hpc_ops;
49772 if (!poll) {
49773 zt5550_hpc.irq = hc_dev->irq;
49774 zt5550_hpc.irq_flags = IRQF_SHARED;
49775 zt5550_hpc.dev_id = hc_dev;
49776
49777 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
49778 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
49779 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
49780 + pax_open_kernel();
49781 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
49782 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
49783 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
49784 + pax_open_kernel();
49785 } else {
49786 info("using ENUM# polling mode");
49787 }
49788 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
49789 index 1e08ff8c..3cd145f 100644
49790 --- a/drivers/pci/hotplug/cpqphp_nvram.c
49791 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
49792 @@ -425,8 +425,10 @@ static u32 store_HRT (void __iomem *rom_start)
49793
49794 void compaq_nvram_init (void __iomem *rom_start)
49795 {
49796 +#ifndef CONFIG_PAX_KERNEXEC
49797 if (rom_start)
49798 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
49799 +#endif
49800
49801 dbg("int15 entry = %p\n", compaq_int15_entry_point);
49802
49803 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
49804 index 56d8486..f26113f 100644
49805 --- a/drivers/pci/hotplug/pci_hotplug_core.c
49806 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
49807 @@ -436,8 +436,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
49808 return -EINVAL;
49809 }
49810
49811 - slot->ops->owner = owner;
49812 - slot->ops->mod_name = mod_name;
49813 + pax_open_kernel();
49814 + *(struct module **)&slot->ops->owner = owner;
49815 + *(const char **)&slot->ops->mod_name = mod_name;
49816 + pax_close_kernel();
49817
49818 mutex_lock(&pci_hp_mutex);
49819 /*
49820 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
49821 index 07aa722..84514b4 100644
49822 --- a/drivers/pci/hotplug/pciehp_core.c
49823 +++ b/drivers/pci/hotplug/pciehp_core.c
49824 @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
49825 struct slot *slot = ctrl->slot;
49826 struct hotplug_slot *hotplug = NULL;
49827 struct hotplug_slot_info *info = NULL;
49828 - struct hotplug_slot_ops *ops = NULL;
49829 + hotplug_slot_ops_no_const *ops = NULL;
49830 char name[SLOT_NAME_SIZE];
49831 int retval = -ENOMEM;
49832
49833 diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
49834 index 084587d..4a8f9df 100644
49835 --- a/drivers/pci/msi.c
49836 +++ b/drivers/pci/msi.c
49837 @@ -488,8 +488,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
49838 {
49839 struct attribute **msi_attrs;
49840 struct attribute *msi_attr;
49841 - struct device_attribute *msi_dev_attr;
49842 - struct attribute_group *msi_irq_group;
49843 + device_attribute_no_const *msi_dev_attr;
49844 + attribute_group_no_const *msi_irq_group;
49845 const struct attribute_group **msi_irq_groups;
49846 struct msi_desc *entry;
49847 int ret = -ENOMEM;
49848 @@ -549,7 +549,7 @@ error_attrs:
49849 count = 0;
49850 msi_attr = msi_attrs[count];
49851 while (msi_attr) {
49852 - msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
49853 + msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
49854 kfree(msi_attr->name);
49855 kfree(msi_dev_attr);
49856 ++count;
49857 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
49858 index 2c6643f..3a6d8e0 100644
49859 --- a/drivers/pci/pci-sysfs.c
49860 +++ b/drivers/pci/pci-sysfs.c
49861 @@ -1133,7 +1133,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
49862 {
49863 /* allocate attribute structure, piggyback attribute name */
49864 int name_len = write_combine ? 13 : 10;
49865 - struct bin_attribute *res_attr;
49866 + bin_attribute_no_const *res_attr;
49867 int retval;
49868
49869 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
49870 @@ -1310,7 +1310,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
49871 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
49872 {
49873 int retval;
49874 - struct bin_attribute *attr;
49875 + bin_attribute_no_const *attr;
49876
49877 /* If the device has VPD, try to expose it in sysfs. */
49878 if (dev->vpd) {
49879 @@ -1357,7 +1357,7 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev)
49880 {
49881 int retval;
49882 int rom_size = 0;
49883 - struct bin_attribute *attr;
49884 + bin_attribute_no_const *attr;
49885
49886 if (!sysfs_initialized)
49887 return -EACCES;
49888 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
49889 index 4a3902d..7f1fc42 100644
49890 --- a/drivers/pci/pci.h
49891 +++ b/drivers/pci/pci.h
49892 @@ -93,7 +93,7 @@ struct pci_vpd_ops {
49893 struct pci_vpd {
49894 unsigned int len;
49895 const struct pci_vpd_ops *ops;
49896 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
49897 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
49898 };
49899
49900 int pci_vpd_pci22_init(struct pci_dev *dev);
49901 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
49902 index e1e7026..d28dd33 100644
49903 --- a/drivers/pci/pcie/aspm.c
49904 +++ b/drivers/pci/pcie/aspm.c
49905 @@ -27,9 +27,9 @@
49906 #define MODULE_PARAM_PREFIX "pcie_aspm."
49907
49908 /* Note: those are not register definitions */
49909 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
49910 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
49911 -#define ASPM_STATE_L1 (4) /* L1 state */
49912 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
49913 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
49914 +#define ASPM_STATE_L1 (4U) /* L1 state */
49915 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
49916 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
49917
49918 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
49919 index c8ca98c..b1bc005 100644
49920 --- a/drivers/pci/probe.c
49921 +++ b/drivers/pci/probe.c
49922 @@ -177,7 +177,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
49923 struct pci_bus_region region, inverted_region;
49924 bool bar_too_big = false, bar_too_high = false, bar_invalid = false;
49925
49926 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
49927 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
49928
49929 /* No printks while decoding is disabled! */
49930 if (!dev->mmio_always_on) {
49931 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
49932 index 3f155e7..0f4b1f0 100644
49933 --- a/drivers/pci/proc.c
49934 +++ b/drivers/pci/proc.c
49935 @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
49936 static int __init pci_proc_init(void)
49937 {
49938 struct pci_dev *dev = NULL;
49939 +
49940 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49941 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49942 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
49943 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49944 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49945 +#endif
49946 +#else
49947 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
49948 +#endif
49949 proc_create("devices", 0, proc_bus_pci_dir,
49950 &proc_bus_pci_dev_operations);
49951 proc_initialized = 1;
49952 diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
49953 index d866db8..c827d1f 100644
49954 --- a/drivers/platform/chrome/chromeos_laptop.c
49955 +++ b/drivers/platform/chrome/chromeos_laptop.c
49956 @@ -479,7 +479,7 @@ static struct chromeos_laptop cr48 = {
49957 .callback = chromeos_laptop_dmi_matched, \
49958 .driver_data = (void *)&board_
49959
49960 -static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
49961 +static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
49962 {
49963 .ident = "Samsung Series 5 550",
49964 .matches = {
49965 diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
49966 index c5af23b..3d62d5e 100644
49967 --- a/drivers/platform/x86/alienware-wmi.c
49968 +++ b/drivers/platform/x86/alienware-wmi.c
49969 @@ -150,7 +150,7 @@ struct wmax_led_args {
49970 } __packed;
49971
49972 static struct platform_device *platform_device;
49973 -static struct device_attribute *zone_dev_attrs;
49974 +static device_attribute_no_const *zone_dev_attrs;
49975 static struct attribute **zone_attrs;
49976 static struct platform_zone *zone_data;
49977
49978 @@ -161,7 +161,7 @@ static struct platform_driver platform_driver = {
49979 }
49980 };
49981
49982 -static struct attribute_group zone_attribute_group = {
49983 +static attribute_group_no_const zone_attribute_group = {
49984 .name = "rgb_zones",
49985 };
49986
49987 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
49988 index 21fc932..ee9394a 100644
49989 --- a/drivers/platform/x86/asus-wmi.c
49990 +++ b/drivers/platform/x86/asus-wmi.c
49991 @@ -1590,6 +1590,10 @@ static int show_dsts(struct seq_file *m, void *data)
49992 int err;
49993 u32 retval = -1;
49994
49995 +#ifdef CONFIG_GRKERNSEC_KMEM
49996 + return -EPERM;
49997 +#endif
49998 +
49999 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
50000
50001 if (err < 0)
50002 @@ -1606,6 +1610,10 @@ static int show_devs(struct seq_file *m, void *data)
50003 int err;
50004 u32 retval = -1;
50005
50006 +#ifdef CONFIG_GRKERNSEC_KMEM
50007 + return -EPERM;
50008 +#endif
50009 +
50010 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
50011 &retval);
50012
50013 @@ -1630,6 +1638,10 @@ static int show_call(struct seq_file *m, void *data)
50014 union acpi_object *obj;
50015 acpi_status status;
50016
50017 +#ifdef CONFIG_GRKERNSEC_KMEM
50018 + return -EPERM;
50019 +#endif
50020 +
50021 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
50022 1, asus->debug.method_id,
50023 &input, &output);
50024 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
50025 index 62f8030..c7f2a45 100644
50026 --- a/drivers/platform/x86/msi-laptop.c
50027 +++ b/drivers/platform/x86/msi-laptop.c
50028 @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
50029
50030 if (!quirks->ec_read_only) {
50031 /* allow userland write sysfs file */
50032 - dev_attr_bluetooth.store = store_bluetooth;
50033 - dev_attr_wlan.store = store_wlan;
50034 - dev_attr_threeg.store = store_threeg;
50035 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
50036 - dev_attr_wlan.attr.mode |= S_IWUSR;
50037 - dev_attr_threeg.attr.mode |= S_IWUSR;
50038 + pax_open_kernel();
50039 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
50040 + *(void **)&dev_attr_wlan.store = store_wlan;
50041 + *(void **)&dev_attr_threeg.store = store_threeg;
50042 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
50043 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
50044 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
50045 + pax_close_kernel();
50046 }
50047
50048 /* disable hardware control by fn key */
50049 diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
50050 index 70222f2..8c8ce66 100644
50051 --- a/drivers/platform/x86/msi-wmi.c
50052 +++ b/drivers/platform/x86/msi-wmi.c
50053 @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
50054 static void msi_wmi_notify(u32 value, void *context)
50055 {
50056 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
50057 - static struct key_entry *key;
50058 + struct key_entry *key;
50059 union acpi_object *obj;
50060 acpi_status status;
50061
50062 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
50063 index 26ad9ff..7c52909 100644
50064 --- a/drivers/platform/x86/sony-laptop.c
50065 +++ b/drivers/platform/x86/sony-laptop.c
50066 @@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
50067 }
50068
50069 /* High speed charging function */
50070 -static struct device_attribute *hsc_handle;
50071 +static device_attribute_no_const *hsc_handle;
50072
50073 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
50074 struct device_attribute *attr,
50075 @@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
50076 }
50077
50078 /* low battery function */
50079 -static struct device_attribute *lowbatt_handle;
50080 +static device_attribute_no_const *lowbatt_handle;
50081
50082 static ssize_t sony_nc_lowbatt_store(struct device *dev,
50083 struct device_attribute *attr,
50084 @@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
50085 }
50086
50087 /* fan speed function */
50088 -static struct device_attribute *fan_handle, *hsf_handle;
50089 +static device_attribute_no_const *fan_handle, *hsf_handle;
50090
50091 static ssize_t sony_nc_hsfan_store(struct device *dev,
50092 struct device_attribute *attr,
50093 @@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
50094 }
50095
50096 /* USB charge function */
50097 -static struct device_attribute *uc_handle;
50098 +static device_attribute_no_const *uc_handle;
50099
50100 static ssize_t sony_nc_usb_charge_store(struct device *dev,
50101 struct device_attribute *attr,
50102 @@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
50103 }
50104
50105 /* Panel ID function */
50106 -static struct device_attribute *panel_handle;
50107 +static device_attribute_no_const *panel_handle;
50108
50109 static ssize_t sony_nc_panelid_show(struct device *dev,
50110 struct device_attribute *attr, char *buffer)
50111 @@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
50112 }
50113
50114 /* smart connect function */
50115 -static struct device_attribute *sc_handle;
50116 +static device_attribute_no_const *sc_handle;
50117
50118 static ssize_t sony_nc_smart_conn_store(struct device *dev,
50119 struct device_attribute *attr,
50120 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
50121 index cf0f893..5955997 100644
50122 --- a/drivers/platform/x86/thinkpad_acpi.c
50123 +++ b/drivers/platform/x86/thinkpad_acpi.c
50124 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
50125 return 0;
50126 }
50127
50128 -void static hotkey_mask_warn_incomplete_mask(void)
50129 +static void hotkey_mask_warn_incomplete_mask(void)
50130 {
50131 /* log only what the user can fix... */
50132 const u32 wantedmask = hotkey_driver_mask &
50133 @@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
50134 && !tp_features.bright_unkfw)
50135 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
50136 }
50137 +}
50138
50139 #undef TPACPI_COMPARE_KEY
50140 #undef TPACPI_MAY_SEND_KEY
50141 -}
50142
50143 /*
50144 * Polling driver
50145 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
50146 index 438d4c7..ca8a2fb 100644
50147 --- a/drivers/pnp/pnpbios/bioscalls.c
50148 +++ b/drivers/pnp/pnpbios/bioscalls.c
50149 @@ -59,7 +59,7 @@ do { \
50150 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
50151 } while(0)
50152
50153 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
50154 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
50155 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
50156
50157 /*
50158 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50159
50160 cpu = get_cpu();
50161 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
50162 +
50163 + pax_open_kernel();
50164 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
50165 + pax_close_kernel();
50166
50167 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
50168 spin_lock_irqsave(&pnp_bios_lock, flags);
50169 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50170 :"memory");
50171 spin_unlock_irqrestore(&pnp_bios_lock, flags);
50172
50173 + pax_open_kernel();
50174 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
50175 + pax_close_kernel();
50176 +
50177 put_cpu();
50178
50179 /* If we get here and this is set then the PnP BIOS faulted on us. */
50180 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
50181 return status;
50182 }
50183
50184 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
50185 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
50186 {
50187 int i;
50188
50189 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50190 pnp_bios_callpoint.offset = header->fields.pm16offset;
50191 pnp_bios_callpoint.segment = PNP_CS16;
50192
50193 + pax_open_kernel();
50194 +
50195 for_each_possible_cpu(i) {
50196 struct desc_struct *gdt = get_cpu_gdt_table(i);
50197 if (!gdt)
50198 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50199 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
50200 (unsigned long)__va(header->fields.pm16dseg));
50201 }
50202 +
50203 + pax_close_kernel();
50204 }
50205 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
50206 index 0c52e2a..3421ab7 100644
50207 --- a/drivers/power/pda_power.c
50208 +++ b/drivers/power/pda_power.c
50209 @@ -37,7 +37,11 @@ static int polling;
50210
50211 #if IS_ENABLED(CONFIG_USB_PHY)
50212 static struct usb_phy *transceiver;
50213 -static struct notifier_block otg_nb;
50214 +static int otg_handle_notification(struct notifier_block *nb,
50215 + unsigned long event, void *unused);
50216 +static struct notifier_block otg_nb = {
50217 + .notifier_call = otg_handle_notification
50218 +};
50219 #endif
50220
50221 static struct regulator *ac_draw;
50222 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
50223
50224 #if IS_ENABLED(CONFIG_USB_PHY)
50225 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
50226 - otg_nb.notifier_call = otg_handle_notification;
50227 ret = usb_register_notifier(transceiver, &otg_nb);
50228 if (ret) {
50229 dev_err(dev, "failure to register otg notifier\n");
50230 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
50231 index cc439fd..8fa30df 100644
50232 --- a/drivers/power/power_supply.h
50233 +++ b/drivers/power/power_supply.h
50234 @@ -16,12 +16,12 @@ struct power_supply;
50235
50236 #ifdef CONFIG_SYSFS
50237
50238 -extern void power_supply_init_attrs(struct device_type *dev_type);
50239 +extern void power_supply_init_attrs(void);
50240 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
50241
50242 #else
50243
50244 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
50245 +static inline void power_supply_init_attrs(void) {}
50246 #define power_supply_uevent NULL
50247
50248 #endif /* CONFIG_SYSFS */
50249 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
50250 index 694e8cd..9f03483 100644
50251 --- a/drivers/power/power_supply_core.c
50252 +++ b/drivers/power/power_supply_core.c
50253 @@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
50254 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
50255 EXPORT_SYMBOL_GPL(power_supply_notifier);
50256
50257 -static struct device_type power_supply_dev_type;
50258 +extern const struct attribute_group *power_supply_attr_groups[];
50259 +static struct device_type power_supply_dev_type = {
50260 + .groups = power_supply_attr_groups,
50261 +};
50262
50263 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
50264 struct power_supply *supply)
50265 @@ -637,7 +640,7 @@ static int __init power_supply_class_init(void)
50266 return PTR_ERR(power_supply_class);
50267
50268 power_supply_class->dev_uevent = power_supply_uevent;
50269 - power_supply_init_attrs(&power_supply_dev_type);
50270 + power_supply_init_attrs();
50271
50272 return 0;
50273 }
50274 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
50275 index 62653f5..d0bb485 100644
50276 --- a/drivers/power/power_supply_sysfs.c
50277 +++ b/drivers/power/power_supply_sysfs.c
50278 @@ -238,17 +238,15 @@ static struct attribute_group power_supply_attr_group = {
50279 .is_visible = power_supply_attr_is_visible,
50280 };
50281
50282 -static const struct attribute_group *power_supply_attr_groups[] = {
50283 +const struct attribute_group *power_supply_attr_groups[] = {
50284 &power_supply_attr_group,
50285 NULL,
50286 };
50287
50288 -void power_supply_init_attrs(struct device_type *dev_type)
50289 +void power_supply_init_attrs(void)
50290 {
50291 int i;
50292
50293 - dev_type->groups = power_supply_attr_groups;
50294 -
50295 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
50296 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
50297 }
50298 diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
50299 index 84419af..268ede8 100644
50300 --- a/drivers/powercap/powercap_sys.c
50301 +++ b/drivers/powercap/powercap_sys.c
50302 @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
50303 struct device_attribute name_attr;
50304 };
50305
50306 +static ssize_t show_constraint_name(struct device *dev,
50307 + struct device_attribute *dev_attr,
50308 + char *buf);
50309 +
50310 static struct powercap_constraint_attr
50311 - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
50312 + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
50313 + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
50314 + .power_limit_attr = {
50315 + .attr = {
50316 + .name = NULL,
50317 + .mode = S_IWUSR | S_IRUGO
50318 + },
50319 + .show = show_constraint_power_limit_uw,
50320 + .store = store_constraint_power_limit_uw
50321 + },
50322 +
50323 + .time_window_attr = {
50324 + .attr = {
50325 + .name = NULL,
50326 + .mode = S_IWUSR | S_IRUGO
50327 + },
50328 + .show = show_constraint_time_window_us,
50329 + .store = store_constraint_time_window_us
50330 + },
50331 +
50332 + .max_power_attr = {
50333 + .attr = {
50334 + .name = NULL,
50335 + .mode = S_IRUGO
50336 + },
50337 + .show = show_constraint_max_power_uw,
50338 + .store = NULL
50339 + },
50340 +
50341 + .min_power_attr = {
50342 + .attr = {
50343 + .name = NULL,
50344 + .mode = S_IRUGO
50345 + },
50346 + .show = show_constraint_min_power_uw,
50347 + .store = NULL
50348 + },
50349 +
50350 + .max_time_window_attr = {
50351 + .attr = {
50352 + .name = NULL,
50353 + .mode = S_IRUGO
50354 + },
50355 + .show = show_constraint_max_time_window_us,
50356 + .store = NULL
50357 + },
50358 +
50359 + .min_time_window_attr = {
50360 + .attr = {
50361 + .name = NULL,
50362 + .mode = S_IRUGO
50363 + },
50364 + .show = show_constraint_min_time_window_us,
50365 + .store = NULL
50366 + },
50367 +
50368 + .name_attr = {
50369 + .attr = {
50370 + .name = NULL,
50371 + .mode = S_IRUGO
50372 + },
50373 + .show = show_constraint_name,
50374 + .store = NULL
50375 + }
50376 + }
50377 +};
50378
50379 /* A list of powercap control_types */
50380 static LIST_HEAD(powercap_cntrl_list);
50381 @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
50382 }
50383
50384 static int create_constraint_attribute(int id, const char *name,
50385 - int mode,
50386 - struct device_attribute *dev_attr,
50387 - ssize_t (*show)(struct device *,
50388 - struct device_attribute *, char *),
50389 - ssize_t (*store)(struct device *,
50390 - struct device_attribute *,
50391 - const char *, size_t)
50392 - )
50393 + struct device_attribute *dev_attr)
50394 {
50395 + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
50396
50397 - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
50398 - id, name);
50399 - if (!dev_attr->attr.name)
50400 + if (!name)
50401 return -ENOMEM;
50402 - dev_attr->attr.mode = mode;
50403 - dev_attr->show = show;
50404 - dev_attr->store = store;
50405 +
50406 + pax_open_kernel();
50407 + *(const char **)&dev_attr->attr.name = name;
50408 + pax_close_kernel();
50409
50410 return 0;
50411 }
50412 @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
50413
50414 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
50415 ret = create_constraint_attribute(i, "power_limit_uw",
50416 - S_IWUSR | S_IRUGO,
50417 - &constraint_attrs[i].power_limit_attr,
50418 - show_constraint_power_limit_uw,
50419 - store_constraint_power_limit_uw);
50420 + &constraint_attrs[i].power_limit_attr);
50421 if (ret)
50422 goto err_alloc;
50423 ret = create_constraint_attribute(i, "time_window_us",
50424 - S_IWUSR | S_IRUGO,
50425 - &constraint_attrs[i].time_window_attr,
50426 - show_constraint_time_window_us,
50427 - store_constraint_time_window_us);
50428 + &constraint_attrs[i].time_window_attr);
50429 if (ret)
50430 goto err_alloc;
50431 - ret = create_constraint_attribute(i, "name", S_IRUGO,
50432 - &constraint_attrs[i].name_attr,
50433 - show_constraint_name,
50434 - NULL);
50435 + ret = create_constraint_attribute(i, "name",
50436 + &constraint_attrs[i].name_attr);
50437 if (ret)
50438 goto err_alloc;
50439 - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
50440 - &constraint_attrs[i].max_power_attr,
50441 - show_constraint_max_power_uw,
50442 - NULL);
50443 + ret = create_constraint_attribute(i, "max_power_uw",
50444 + &constraint_attrs[i].max_power_attr);
50445 if (ret)
50446 goto err_alloc;
50447 - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
50448 - &constraint_attrs[i].min_power_attr,
50449 - show_constraint_min_power_uw,
50450 - NULL);
50451 + ret = create_constraint_attribute(i, "min_power_uw",
50452 + &constraint_attrs[i].min_power_attr);
50453 if (ret)
50454 goto err_alloc;
50455 ret = create_constraint_attribute(i, "max_time_window_us",
50456 - S_IRUGO,
50457 - &constraint_attrs[i].max_time_window_attr,
50458 - show_constraint_max_time_window_us,
50459 - NULL);
50460 + &constraint_attrs[i].max_time_window_attr);
50461 if (ret)
50462 goto err_alloc;
50463 ret = create_constraint_attribute(i, "min_time_window_us",
50464 - S_IRUGO,
50465 - &constraint_attrs[i].min_time_window_attr,
50466 - show_constraint_min_time_window_us,
50467 - NULL);
50468 + &constraint_attrs[i].min_time_window_attr);
50469 if (ret)
50470 goto err_alloc;
50471
50472 @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
50473 power_zone->zone_dev_attrs[count++] =
50474 &dev_attr_max_energy_range_uj.attr;
50475 if (power_zone->ops->get_energy_uj) {
50476 + pax_open_kernel();
50477 if (power_zone->ops->reset_energy_uj)
50478 - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
50479 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
50480 else
50481 - dev_attr_energy_uj.attr.mode = S_IRUGO;
50482 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
50483 + pax_close_kernel();
50484 power_zone->zone_dev_attrs[count++] =
50485 &dev_attr_energy_uj.attr;
50486 }
50487 diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
50488 index 9c5d414..c7900ce 100644
50489 --- a/drivers/ptp/ptp_private.h
50490 +++ b/drivers/ptp/ptp_private.h
50491 @@ -51,7 +51,7 @@ struct ptp_clock {
50492 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
50493 wait_queue_head_t tsev_wq;
50494 int defunct; /* tells readers to go away when clock is being removed */
50495 - struct device_attribute *pin_dev_attr;
50496 + device_attribute_no_const *pin_dev_attr;
50497 struct attribute **pin_attr;
50498 struct attribute_group pin_attr_group;
50499 };
50500 diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
50501 index 302e626..12579af 100644
50502 --- a/drivers/ptp/ptp_sysfs.c
50503 +++ b/drivers/ptp/ptp_sysfs.c
50504 @@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
50505 goto no_pin_attr;
50506
50507 for (i = 0; i < n_pins; i++) {
50508 - struct device_attribute *da = &ptp->pin_dev_attr[i];
50509 + device_attribute_no_const *da = &ptp->pin_dev_attr[i];
50510 sysfs_attr_init(&da->attr);
50511 da->attr.name = info->pin_config[i].name;
50512 da->attr.mode = 0644;
50513 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
50514 index cd87c0c..715ecbe 100644
50515 --- a/drivers/regulator/core.c
50516 +++ b/drivers/regulator/core.c
50517 @@ -3567,7 +3567,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
50518 {
50519 const struct regulation_constraints *constraints = NULL;
50520 const struct regulator_init_data *init_data;
50521 - static atomic_t regulator_no = ATOMIC_INIT(0);
50522 + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
50523 struct regulator_dev *rdev;
50524 struct device *dev;
50525 int ret, i;
50526 @@ -3641,7 +3641,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
50527 rdev->dev.class = &regulator_class;
50528 rdev->dev.parent = dev;
50529 dev_set_name(&rdev->dev, "regulator.%d",
50530 - atomic_inc_return(&regulator_no) - 1);
50531 + atomic_inc_return_unchecked(&regulator_no) - 1);
50532 ret = device_register(&rdev->dev);
50533 if (ret != 0) {
50534 put_device(&rdev->dev);
50535 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
50536 index 7eee2ca..4024513 100644
50537 --- a/drivers/regulator/max8660.c
50538 +++ b/drivers/regulator/max8660.c
50539 @@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
50540 max8660->shadow_regs[MAX8660_OVER1] = 5;
50541 } else {
50542 /* Otherwise devices can be toggled via software */
50543 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
50544 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
50545 + pax_open_kernel();
50546 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
50547 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
50548 + pax_close_kernel();
50549 }
50550
50551 /*
50552 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
50553 index dbedf17..18ff6b7 100644
50554 --- a/drivers/regulator/max8973-regulator.c
50555 +++ b/drivers/regulator/max8973-regulator.c
50556 @@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
50557 if (!pdata || !pdata->enable_ext_control) {
50558 max->desc.enable_reg = MAX8973_VOUT;
50559 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
50560 - max->ops.enable = regulator_enable_regmap;
50561 - max->ops.disable = regulator_disable_regmap;
50562 - max->ops.is_enabled = regulator_is_enabled_regmap;
50563 + pax_open_kernel();
50564 + *(void **)&max->ops.enable = regulator_enable_regmap;
50565 + *(void **)&max->ops.disable = regulator_disable_regmap;
50566 + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
50567 + pax_close_kernel();
50568 }
50569
50570 if (pdata) {
50571 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
50572 index 793b662..85f74cd 100644
50573 --- a/drivers/regulator/mc13892-regulator.c
50574 +++ b/drivers/regulator/mc13892-regulator.c
50575 @@ -584,10 +584,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
50576 mc13xxx_unlock(mc13892);
50577
50578 /* update mc13892_vcam ops */
50579 + pax_open_kernel();
50580 memcpy(&mc13892_vcam_ops, mc13892_regulators[MC13892_VCAM].desc.ops,
50581 sizeof(struct regulator_ops));
50582 - mc13892_vcam_ops.set_mode = mc13892_vcam_set_mode,
50583 - mc13892_vcam_ops.get_mode = mc13892_vcam_get_mode,
50584 + *(void **)&mc13892_vcam_ops.set_mode = mc13892_vcam_set_mode,
50585 + *(void **)&mc13892_vcam_ops.get_mode = mc13892_vcam_get_mode,
50586 + pax_close_kernel();
50587 mc13892_regulators[MC13892_VCAM].desc.ops = &mc13892_vcam_ops;
50588
50589 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
50590 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
50591 index 5b2e761..c8c8a4a 100644
50592 --- a/drivers/rtc/rtc-cmos.c
50593 +++ b/drivers/rtc/rtc-cmos.c
50594 @@ -789,7 +789,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
50595 hpet_rtc_timer_init();
50596
50597 /* export at least the first block of NVRAM */
50598 - nvram.size = address_space - NVRAM_OFFSET;
50599 + pax_open_kernel();
50600 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
50601 + pax_close_kernel();
50602 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
50603 if (retval < 0) {
50604 dev_dbg(dev, "can't create nvram file? %d\n", retval);
50605 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
50606 index d049393..bb20be0 100644
50607 --- a/drivers/rtc/rtc-dev.c
50608 +++ b/drivers/rtc/rtc-dev.c
50609 @@ -16,6 +16,7 @@
50610 #include <linux/module.h>
50611 #include <linux/rtc.h>
50612 #include <linux/sched.h>
50613 +#include <linux/grsecurity.h>
50614 #include "rtc-core.h"
50615
50616 static dev_t rtc_devt;
50617 @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
50618 if (copy_from_user(&tm, uarg, sizeof(tm)))
50619 return -EFAULT;
50620
50621 + gr_log_timechange();
50622 +
50623 return rtc_set_time(rtc, &tm);
50624
50625 case RTC_PIE_ON:
50626 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
50627 index bb43cf7..ee4d274 100644
50628 --- a/drivers/rtc/rtc-ds1307.c
50629 +++ b/drivers/rtc/rtc-ds1307.c
50630 @@ -107,7 +107,7 @@ struct ds1307 {
50631 u8 offset; /* register's offset */
50632 u8 regs[11];
50633 u16 nvram_offset;
50634 - struct bin_attribute *nvram;
50635 + bin_attribute_no_const *nvram;
50636 enum ds_type type;
50637 unsigned long flags;
50638 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
50639 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
50640 index 11880c1..b823aa4 100644
50641 --- a/drivers/rtc/rtc-m48t59.c
50642 +++ b/drivers/rtc/rtc-m48t59.c
50643 @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
50644 if (IS_ERR(m48t59->rtc))
50645 return PTR_ERR(m48t59->rtc);
50646
50647 - m48t59_nvram_attr.size = pdata->offset;
50648 + pax_open_kernel();
50649 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
50650 + pax_close_kernel();
50651
50652 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
50653 if (ret)
50654 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
50655 index e693af6..2e525b6 100644
50656 --- a/drivers/scsi/bfa/bfa_fcpim.h
50657 +++ b/drivers/scsi/bfa/bfa_fcpim.h
50658 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
50659
50660 struct bfa_itn_s {
50661 bfa_isr_func_t isr;
50662 -};
50663 +} __no_const;
50664
50665 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
50666 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
50667 diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
50668 index 0f19455..ef7adb5 100644
50669 --- a/drivers/scsi/bfa/bfa_fcs.c
50670 +++ b/drivers/scsi/bfa/bfa_fcs.c
50671 @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
50672 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
50673
50674 static struct bfa_fcs_mod_s fcs_modules[] = {
50675 - { bfa_fcs_port_attach, NULL, NULL },
50676 - { bfa_fcs_uf_attach, NULL, NULL },
50677 - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
50678 - bfa_fcs_fabric_modexit },
50679 + {
50680 + .attach = bfa_fcs_port_attach,
50681 + .modinit = NULL,
50682 + .modexit = NULL
50683 + },
50684 + {
50685 + .attach = bfa_fcs_uf_attach,
50686 + .modinit = NULL,
50687 + .modexit = NULL
50688 + },
50689 + {
50690 + .attach = bfa_fcs_fabric_attach,
50691 + .modinit = bfa_fcs_fabric_modinit,
50692 + .modexit = bfa_fcs_fabric_modexit
50693 + },
50694 };
50695
50696 /*
50697 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
50698 index ff75ef8..2dfe00a 100644
50699 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
50700 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
50701 @@ -89,15 +89,26 @@ static struct {
50702 void (*offline) (struct bfa_fcs_lport_s *port);
50703 } __port_action[] = {
50704 {
50705 - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
50706 - bfa_fcs_lport_unknown_offline}, {
50707 - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
50708 - bfa_fcs_lport_fab_offline}, {
50709 - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
50710 - bfa_fcs_lport_n2n_offline}, {
50711 - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
50712 - bfa_fcs_lport_loop_offline},
50713 - };
50714 + .init = bfa_fcs_lport_unknown_init,
50715 + .online = bfa_fcs_lport_unknown_online,
50716 + .offline = bfa_fcs_lport_unknown_offline
50717 + },
50718 + {
50719 + .init = bfa_fcs_lport_fab_init,
50720 + .online = bfa_fcs_lport_fab_online,
50721 + .offline = bfa_fcs_lport_fab_offline
50722 + },
50723 + {
50724 + .init = bfa_fcs_lport_n2n_init,
50725 + .online = bfa_fcs_lport_n2n_online,
50726 + .offline = bfa_fcs_lport_n2n_offline
50727 + },
50728 + {
50729 + .init = bfa_fcs_lport_loop_init,
50730 + .online = bfa_fcs_lport_loop_online,
50731 + .offline = bfa_fcs_lport_loop_offline
50732 + },
50733 +};
50734
50735 /*
50736 * fcs_port_sm FCS logical port state machine
50737 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
50738 index a38aafa0..fe8f03b 100644
50739 --- a/drivers/scsi/bfa/bfa_ioc.h
50740 +++ b/drivers/scsi/bfa/bfa_ioc.h
50741 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
50742 bfa_ioc_disable_cbfn_t disable_cbfn;
50743 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
50744 bfa_ioc_reset_cbfn_t reset_cbfn;
50745 -};
50746 +} __no_const;
50747
50748 /*
50749 * IOC event notification mechanism.
50750 @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
50751 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
50752 enum bfi_ioc_state fwstate);
50753 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
50754 -};
50755 +} __no_const;
50756
50757 /*
50758 * Queue element to wait for room in request queue. FIFO order is
50759 diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
50760 index a14c784..6de6790 100644
50761 --- a/drivers/scsi/bfa/bfa_modules.h
50762 +++ b/drivers/scsi/bfa/bfa_modules.h
50763 @@ -78,12 +78,12 @@ enum {
50764 \
50765 extern struct bfa_module_s hal_mod_ ## __mod; \
50766 struct bfa_module_s hal_mod_ ## __mod = { \
50767 - bfa_ ## __mod ## _meminfo, \
50768 - bfa_ ## __mod ## _attach, \
50769 - bfa_ ## __mod ## _detach, \
50770 - bfa_ ## __mod ## _start, \
50771 - bfa_ ## __mod ## _stop, \
50772 - bfa_ ## __mod ## _iocdisable, \
50773 + .meminfo = bfa_ ## __mod ## _meminfo, \
50774 + .attach = bfa_ ## __mod ## _attach, \
50775 + .detach = bfa_ ## __mod ## _detach, \
50776 + .start = bfa_ ## __mod ## _start, \
50777 + .stop = bfa_ ## __mod ## _stop, \
50778 + .iocdisable = bfa_ ## __mod ## _iocdisable, \
50779 }
50780
50781 #define BFA_CACHELINE_SZ (256)
50782 diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
50783 index 045c4e1..13de803 100644
50784 --- a/drivers/scsi/fcoe/fcoe_sysfs.c
50785 +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
50786 @@ -33,8 +33,8 @@
50787 */
50788 #include "libfcoe.h"
50789
50790 -static atomic_t ctlr_num;
50791 -static atomic_t fcf_num;
50792 +static atomic_unchecked_t ctlr_num;
50793 +static atomic_unchecked_t fcf_num;
50794
50795 /*
50796 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
50797 @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
50798 if (!ctlr)
50799 goto out;
50800
50801 - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
50802 + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
50803 ctlr->f = f;
50804 ctlr->mode = FIP_CONN_TYPE_FABRIC;
50805 INIT_LIST_HEAD(&ctlr->fcfs);
50806 @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
50807 fcf->dev.parent = &ctlr->dev;
50808 fcf->dev.bus = &fcoe_bus_type;
50809 fcf->dev.type = &fcoe_fcf_device_type;
50810 - fcf->id = atomic_inc_return(&fcf_num) - 1;
50811 + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
50812 fcf->state = FCOE_FCF_STATE_UNKNOWN;
50813
50814 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
50815 @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
50816 {
50817 int error;
50818
50819 - atomic_set(&ctlr_num, 0);
50820 - atomic_set(&fcf_num, 0);
50821 + atomic_set_unchecked(&ctlr_num, 0);
50822 + atomic_set_unchecked(&fcf_num, 0);
50823
50824 error = bus_register(&fcoe_bus_type);
50825 if (error)
50826 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
50827 index 6de80e3..a11e0ac 100644
50828 --- a/drivers/scsi/hosts.c
50829 +++ b/drivers/scsi/hosts.c
50830 @@ -42,7 +42,7 @@
50831 #include "scsi_logging.h"
50832
50833
50834 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
50835 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
50836
50837
50838 static void scsi_host_cls_release(struct device *dev)
50839 @@ -392,7 +392,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
50840 * subtract one because we increment first then return, but we need to
50841 * know what the next host number was before increment
50842 */
50843 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
50844 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
50845 shost->dma_channel = 0xff;
50846
50847 /* These three are default values which can be overridden */
50848 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
50849 index cef5d49..01e280e 100644
50850 --- a/drivers/scsi/hpsa.c
50851 +++ b/drivers/scsi/hpsa.c
50852 @@ -701,10 +701,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
50853 unsigned long flags;
50854
50855 if (h->transMethod & CFGTBL_Trans_io_accel1)
50856 - return h->access.command_completed(h, q);
50857 + return h->access->command_completed(h, q);
50858
50859 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
50860 - return h->access.command_completed(h, q);
50861 + return h->access->command_completed(h, q);
50862
50863 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
50864 a = rq->head[rq->current_entry];
50865 @@ -5454,7 +5454,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
50866 while (!list_empty(&h->reqQ)) {
50867 c = list_entry(h->reqQ.next, struct CommandList, list);
50868 /* can't do anything if fifo is full */
50869 - if ((h->access.fifo_full(h))) {
50870 + if ((h->access->fifo_full(h))) {
50871 h->fifo_recently_full = 1;
50872 dev_warn(&h->pdev->dev, "fifo full\n");
50873 break;
50874 @@ -5476,7 +5476,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
50875
50876 /* Tell the controller execute command */
50877 spin_unlock_irqrestore(&h->lock, *flags);
50878 - h->access.submit_command(h, c);
50879 + h->access->submit_command(h, c);
50880 spin_lock_irqsave(&h->lock, *flags);
50881 }
50882 }
50883 @@ -5492,17 +5492,17 @@ static void lock_and_start_io(struct ctlr_info *h)
50884
50885 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
50886 {
50887 - return h->access.command_completed(h, q);
50888 + return h->access->command_completed(h, q);
50889 }
50890
50891 static inline bool interrupt_pending(struct ctlr_info *h)
50892 {
50893 - return h->access.intr_pending(h);
50894 + return h->access->intr_pending(h);
50895 }
50896
50897 static inline long interrupt_not_for_us(struct ctlr_info *h)
50898 {
50899 - return (h->access.intr_pending(h) == 0) ||
50900 + return (h->access->intr_pending(h) == 0) ||
50901 (h->interrupts_enabled == 0);
50902 }
50903
50904 @@ -6445,7 +6445,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
50905 if (prod_index < 0)
50906 return -ENODEV;
50907 h->product_name = products[prod_index].product_name;
50908 - h->access = *(products[prod_index].access);
50909 + h->access = products[prod_index].access;
50910
50911 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
50912 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
50913 @@ -6790,7 +6790,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
50914 unsigned long flags;
50915 u32 lockup_detected;
50916
50917 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
50918 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
50919 spin_lock_irqsave(&h->lock, flags);
50920 lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
50921 if (!lockup_detected) {
50922 @@ -7037,7 +7037,7 @@ reinit_after_soft_reset:
50923 }
50924
50925 /* make sure the board interrupts are off */
50926 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
50927 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
50928
50929 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
50930 goto clean2;
50931 @@ -7072,7 +7072,7 @@ reinit_after_soft_reset:
50932 * fake ones to scoop up any residual completions.
50933 */
50934 spin_lock_irqsave(&h->lock, flags);
50935 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
50936 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
50937 spin_unlock_irqrestore(&h->lock, flags);
50938 free_irqs(h);
50939 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
50940 @@ -7091,9 +7091,9 @@ reinit_after_soft_reset:
50941 dev_info(&h->pdev->dev, "Board READY.\n");
50942 dev_info(&h->pdev->dev,
50943 "Waiting for stale completions to drain.\n");
50944 - h->access.set_intr_mask(h, HPSA_INTR_ON);
50945 + h->access->set_intr_mask(h, HPSA_INTR_ON);
50946 msleep(10000);
50947 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
50948 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
50949
50950 rc = controller_reset_failed(h->cfgtable);
50951 if (rc)
50952 @@ -7119,7 +7119,7 @@ reinit_after_soft_reset:
50953 h->drv_req_rescan = 0;
50954
50955 /* Turn the interrupts on so we can service requests */
50956 - h->access.set_intr_mask(h, HPSA_INTR_ON);
50957 + h->access->set_intr_mask(h, HPSA_INTR_ON);
50958
50959 hpsa_hba_inquiry(h);
50960 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
50961 @@ -7184,7 +7184,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
50962 * To write all data in the battery backed cache to disks
50963 */
50964 hpsa_flush_cache(h);
50965 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
50966 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
50967 hpsa_free_irqs_and_disable_msix(h);
50968 }
50969
50970 @@ -7302,7 +7302,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
50971 CFGTBL_Trans_enable_directed_msix |
50972 (trans_support & (CFGTBL_Trans_io_accel1 |
50973 CFGTBL_Trans_io_accel2));
50974 - struct access_method access = SA5_performant_access;
50975 + struct access_method *access = &SA5_performant_access;
50976
50977 /* This is a bit complicated. There are 8 registers on
50978 * the controller which we write to to tell it 8 different
50979 @@ -7344,7 +7344,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
50980 * perform the superfluous readl() after each command submission.
50981 */
50982 if (trans_support & (CFGTBL_Trans_io_accel1 | CFGTBL_Trans_io_accel2))
50983 - access = SA5_performant_access_no_read;
50984 + access = &SA5_performant_access_no_read;
50985
50986 /* Controller spec: zero out this buffer. */
50987 for (i = 0; i < h->nreply_queues; i++)
50988 @@ -7374,12 +7374,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
50989 * enable outbound interrupt coalescing in accelerator mode;
50990 */
50991 if (trans_support & CFGTBL_Trans_io_accel1) {
50992 - access = SA5_ioaccel_mode1_access;
50993 + access = &SA5_ioaccel_mode1_access;
50994 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
50995 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
50996 } else {
50997 if (trans_support & CFGTBL_Trans_io_accel2) {
50998 - access = SA5_ioaccel_mode2_access;
50999 + access = &SA5_ioaccel_mode2_access;
51000 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
51001 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
51002 }
51003 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
51004 index 24472ce..8782caf 100644
51005 --- a/drivers/scsi/hpsa.h
51006 +++ b/drivers/scsi/hpsa.h
51007 @@ -127,7 +127,7 @@ struct ctlr_info {
51008 unsigned int msix_vector;
51009 unsigned int msi_vector;
51010 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
51011 - struct access_method access;
51012 + struct access_method *access;
51013 char hba_mode_enabled;
51014
51015 /* queue and queue Info */
51016 @@ -536,43 +536,43 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
51017 }
51018
51019 static struct access_method SA5_access = {
51020 - SA5_submit_command,
51021 - SA5_intr_mask,
51022 - SA5_fifo_full,
51023 - SA5_intr_pending,
51024 - SA5_completed,
51025 + .submit_command = SA5_submit_command,
51026 + .set_intr_mask = SA5_intr_mask,
51027 + .fifo_full = SA5_fifo_full,
51028 + .intr_pending = SA5_intr_pending,
51029 + .command_completed = SA5_completed,
51030 };
51031
51032 static struct access_method SA5_ioaccel_mode1_access = {
51033 - SA5_submit_command,
51034 - SA5_performant_intr_mask,
51035 - SA5_fifo_full,
51036 - SA5_ioaccel_mode1_intr_pending,
51037 - SA5_ioaccel_mode1_completed,
51038 + .submit_command = SA5_submit_command,
51039 + .set_intr_mask = SA5_performant_intr_mask,
51040 + .fifo_full = SA5_fifo_full,
51041 + .intr_pending = SA5_ioaccel_mode1_intr_pending,
51042 + .command_completed = SA5_ioaccel_mode1_completed,
51043 };
51044
51045 static struct access_method SA5_ioaccel_mode2_access = {
51046 - SA5_submit_command_ioaccel2,
51047 - SA5_performant_intr_mask,
51048 - SA5_fifo_full,
51049 - SA5_performant_intr_pending,
51050 - SA5_performant_completed,
51051 + .submit_command = SA5_submit_command_ioaccel2,
51052 + .set_intr_mask = SA5_performant_intr_mask,
51053 + .fifo_full = SA5_fifo_full,
51054 + .intr_pending = SA5_performant_intr_pending,
51055 + .command_completed = SA5_performant_completed,
51056 };
51057
51058 static struct access_method SA5_performant_access = {
51059 - SA5_submit_command,
51060 - SA5_performant_intr_mask,
51061 - SA5_fifo_full,
51062 - SA5_performant_intr_pending,
51063 - SA5_performant_completed,
51064 + .submit_command = SA5_submit_command,
51065 + .set_intr_mask = SA5_performant_intr_mask,
51066 + .fifo_full = SA5_fifo_full,
51067 + .intr_pending = SA5_performant_intr_pending,
51068 + .command_completed = SA5_performant_completed,
51069 };
51070
51071 static struct access_method SA5_performant_access_no_read = {
51072 - SA5_submit_command_no_read,
51073 - SA5_performant_intr_mask,
51074 - SA5_fifo_full,
51075 - SA5_performant_intr_pending,
51076 - SA5_performant_completed,
51077 + .submit_command = SA5_submit_command_no_read,
51078 + .set_intr_mask = SA5_performant_intr_mask,
51079 + .fifo_full = SA5_fifo_full,
51080 + .intr_pending = SA5_performant_intr_pending,
51081 + .command_completed = SA5_performant_completed,
51082 };
51083
51084 struct board_type {
51085 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
51086 index 1b3a094..068e683 100644
51087 --- a/drivers/scsi/libfc/fc_exch.c
51088 +++ b/drivers/scsi/libfc/fc_exch.c
51089 @@ -101,12 +101,12 @@ struct fc_exch_mgr {
51090 u16 pool_max_index;
51091
51092 struct {
51093 - atomic_t no_free_exch;
51094 - atomic_t no_free_exch_xid;
51095 - atomic_t xid_not_found;
51096 - atomic_t xid_busy;
51097 - atomic_t seq_not_found;
51098 - atomic_t non_bls_resp;
51099 + atomic_unchecked_t no_free_exch;
51100 + atomic_unchecked_t no_free_exch_xid;
51101 + atomic_unchecked_t xid_not_found;
51102 + atomic_unchecked_t xid_busy;
51103 + atomic_unchecked_t seq_not_found;
51104 + atomic_unchecked_t non_bls_resp;
51105 } stats;
51106 };
51107
51108 @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
51109 /* allocate memory for exchange */
51110 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
51111 if (!ep) {
51112 - atomic_inc(&mp->stats.no_free_exch);
51113 + atomic_inc_unchecked(&mp->stats.no_free_exch);
51114 goto out;
51115 }
51116 memset(ep, 0, sizeof(*ep));
51117 @@ -874,7 +874,7 @@ out:
51118 return ep;
51119 err:
51120 spin_unlock_bh(&pool->lock);
51121 - atomic_inc(&mp->stats.no_free_exch_xid);
51122 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
51123 mempool_free(ep, mp->ep_pool);
51124 return NULL;
51125 }
51126 @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51127 xid = ntohs(fh->fh_ox_id); /* we originated exch */
51128 ep = fc_exch_find(mp, xid);
51129 if (!ep) {
51130 - atomic_inc(&mp->stats.xid_not_found);
51131 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51132 reject = FC_RJT_OX_ID;
51133 goto out;
51134 }
51135 @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51136 ep = fc_exch_find(mp, xid);
51137 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
51138 if (ep) {
51139 - atomic_inc(&mp->stats.xid_busy);
51140 + atomic_inc_unchecked(&mp->stats.xid_busy);
51141 reject = FC_RJT_RX_ID;
51142 goto rel;
51143 }
51144 @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51145 }
51146 xid = ep->xid; /* get our XID */
51147 } else if (!ep) {
51148 - atomic_inc(&mp->stats.xid_not_found);
51149 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51150 reject = FC_RJT_RX_ID; /* XID not found */
51151 goto out;
51152 }
51153 @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51154 } else {
51155 sp = &ep->seq;
51156 if (sp->id != fh->fh_seq_id) {
51157 - atomic_inc(&mp->stats.seq_not_found);
51158 + atomic_inc_unchecked(&mp->stats.seq_not_found);
51159 if (f_ctl & FC_FC_END_SEQ) {
51160 /*
51161 * Update sequence_id based on incoming last
51162 @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51163
51164 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
51165 if (!ep) {
51166 - atomic_inc(&mp->stats.xid_not_found);
51167 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51168 goto out;
51169 }
51170 if (ep->esb_stat & ESB_ST_COMPLETE) {
51171 - atomic_inc(&mp->stats.xid_not_found);
51172 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51173 goto rel;
51174 }
51175 if (ep->rxid == FC_XID_UNKNOWN)
51176 ep->rxid = ntohs(fh->fh_rx_id);
51177 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
51178 - atomic_inc(&mp->stats.xid_not_found);
51179 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51180 goto rel;
51181 }
51182 if (ep->did != ntoh24(fh->fh_s_id) &&
51183 ep->did != FC_FID_FLOGI) {
51184 - atomic_inc(&mp->stats.xid_not_found);
51185 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51186 goto rel;
51187 }
51188 sof = fr_sof(fp);
51189 @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51190 sp->ssb_stat |= SSB_ST_RESP;
51191 sp->id = fh->fh_seq_id;
51192 } else if (sp->id != fh->fh_seq_id) {
51193 - atomic_inc(&mp->stats.seq_not_found);
51194 + atomic_inc_unchecked(&mp->stats.seq_not_found);
51195 goto rel;
51196 }
51197
51198 @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51199 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
51200
51201 if (!sp)
51202 - atomic_inc(&mp->stats.xid_not_found);
51203 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51204 else
51205 - atomic_inc(&mp->stats.non_bls_resp);
51206 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
51207
51208 fc_frame_free(fp);
51209 }
51210 @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
51211
51212 list_for_each_entry(ema, &lport->ema_list, ema_list) {
51213 mp = ema->mp;
51214 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
51215 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
51216 st->fc_no_free_exch_xid +=
51217 - atomic_read(&mp->stats.no_free_exch_xid);
51218 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
51219 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
51220 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
51221 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
51222 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
51223 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
51224 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
51225 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
51226 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
51227 }
51228 }
51229 EXPORT_SYMBOL(fc_exch_update_stats);
51230 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
51231 index 766098a..1c6c971 100644
51232 --- a/drivers/scsi/libsas/sas_ata.c
51233 +++ b/drivers/scsi/libsas/sas_ata.c
51234 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
51235 .postreset = ata_std_postreset,
51236 .error_handler = ata_std_error_handler,
51237 .post_internal_cmd = sas_ata_post_internal,
51238 - .qc_defer = ata_std_qc_defer,
51239 + .qc_defer = ata_std_qc_defer,
51240 .qc_prep = ata_noop_qc_prep,
51241 .qc_issue = sas_ata_qc_issue,
51242 .qc_fill_rtf = sas_ata_qc_fill_rtf,
51243 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
51244 index 434e903..5a4a79b 100644
51245 --- a/drivers/scsi/lpfc/lpfc.h
51246 +++ b/drivers/scsi/lpfc/lpfc.h
51247 @@ -430,7 +430,7 @@ struct lpfc_vport {
51248 struct dentry *debug_nodelist;
51249 struct dentry *vport_debugfs_root;
51250 struct lpfc_debugfs_trc *disc_trc;
51251 - atomic_t disc_trc_cnt;
51252 + atomic_unchecked_t disc_trc_cnt;
51253 #endif
51254 uint8_t stat_data_enabled;
51255 uint8_t stat_data_blocked;
51256 @@ -880,8 +880,8 @@ struct lpfc_hba {
51257 struct timer_list fabric_block_timer;
51258 unsigned long bit_flags;
51259 #define FABRIC_COMANDS_BLOCKED 0
51260 - atomic_t num_rsrc_err;
51261 - atomic_t num_cmd_success;
51262 + atomic_unchecked_t num_rsrc_err;
51263 + atomic_unchecked_t num_cmd_success;
51264 unsigned long last_rsrc_error_time;
51265 unsigned long last_ramp_down_time;
51266 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
51267 @@ -916,7 +916,7 @@ struct lpfc_hba {
51268
51269 struct dentry *debug_slow_ring_trc;
51270 struct lpfc_debugfs_trc *slow_ring_trc;
51271 - atomic_t slow_ring_trc_cnt;
51272 + atomic_unchecked_t slow_ring_trc_cnt;
51273 /* iDiag debugfs sub-directory */
51274 struct dentry *idiag_root;
51275 struct dentry *idiag_pci_cfg;
51276 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
51277 index 786a2af..562c6a2 100644
51278 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
51279 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
51280 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
51281
51282 #include <linux/debugfs.h>
51283
51284 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
51285 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
51286 static unsigned long lpfc_debugfs_start_time = 0L;
51287
51288 /* iDiag */
51289 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
51290 lpfc_debugfs_enable = 0;
51291
51292 len = 0;
51293 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
51294 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
51295 (lpfc_debugfs_max_disc_trc - 1);
51296 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
51297 dtp = vport->disc_trc + i;
51298 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
51299 lpfc_debugfs_enable = 0;
51300
51301 len = 0;
51302 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
51303 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
51304 (lpfc_debugfs_max_slow_ring_trc - 1);
51305 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
51306 dtp = phba->slow_ring_trc + i;
51307 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
51308 !vport || !vport->disc_trc)
51309 return;
51310
51311 - index = atomic_inc_return(&vport->disc_trc_cnt) &
51312 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
51313 (lpfc_debugfs_max_disc_trc - 1);
51314 dtp = vport->disc_trc + index;
51315 dtp->fmt = fmt;
51316 dtp->data1 = data1;
51317 dtp->data2 = data2;
51318 dtp->data3 = data3;
51319 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
51320 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
51321 dtp->jif = jiffies;
51322 #endif
51323 return;
51324 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
51325 !phba || !phba->slow_ring_trc)
51326 return;
51327
51328 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
51329 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
51330 (lpfc_debugfs_max_slow_ring_trc - 1);
51331 dtp = phba->slow_ring_trc + index;
51332 dtp->fmt = fmt;
51333 dtp->data1 = data1;
51334 dtp->data2 = data2;
51335 dtp->data3 = data3;
51336 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
51337 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
51338 dtp->jif = jiffies;
51339 #endif
51340 return;
51341 @@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
51342 "slow_ring buffer\n");
51343 goto debug_failed;
51344 }
51345 - atomic_set(&phba->slow_ring_trc_cnt, 0);
51346 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
51347 memset(phba->slow_ring_trc, 0,
51348 (sizeof(struct lpfc_debugfs_trc) *
51349 lpfc_debugfs_max_slow_ring_trc));
51350 @@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
51351 "buffer\n");
51352 goto debug_failed;
51353 }
51354 - atomic_set(&vport->disc_trc_cnt, 0);
51355 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
51356
51357 snprintf(name, sizeof(name), "discovery_trace");
51358 vport->debug_disc_trc =
51359 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
51360 index 0b2c53a..aec2b45 100644
51361 --- a/drivers/scsi/lpfc/lpfc_init.c
51362 +++ b/drivers/scsi/lpfc/lpfc_init.c
51363 @@ -11290,8 +11290,10 @@ lpfc_init(void)
51364 "misc_register returned with status %d", error);
51365
51366 if (lpfc_enable_npiv) {
51367 - lpfc_transport_functions.vport_create = lpfc_vport_create;
51368 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
51369 + pax_open_kernel();
51370 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
51371 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
51372 + pax_close_kernel();
51373 }
51374 lpfc_transport_template =
51375 fc_attach_transport(&lpfc_transport_functions);
51376 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
51377 index b99399f..d29dc75 100644
51378 --- a/drivers/scsi/lpfc/lpfc_scsi.c
51379 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
51380 @@ -383,7 +383,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
51381 unsigned long expires;
51382
51383 spin_lock_irqsave(&phba->hbalock, flags);
51384 - atomic_inc(&phba->num_rsrc_err);
51385 + atomic_inc_unchecked(&phba->num_rsrc_err);
51386 phba->last_rsrc_error_time = jiffies;
51387
51388 expires = phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL;
51389 @@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
51390 unsigned long num_rsrc_err, num_cmd_success;
51391 int i;
51392
51393 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
51394 - num_cmd_success = atomic_read(&phba->num_cmd_success);
51395 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
51396 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
51397
51398 /*
51399 * The error and success command counters are global per
51400 @@ -454,8 +454,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
51401 }
51402 }
51403 lpfc_destroy_vport_work_array(phba, vports);
51404 - atomic_set(&phba->num_rsrc_err, 0);
51405 - atomic_set(&phba->num_cmd_success, 0);
51406 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
51407 + atomic_set_unchecked(&phba->num_cmd_success, 0);
51408 }
51409
51410 /**
51411 diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51412 index c80ed04..e674f01 100644
51413 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51414 +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51415 @@ -1561,7 +1561,7 @@ _scsih_get_resync(struct device *dev)
51416 {
51417 struct scsi_device *sdev = to_scsi_device(dev);
51418 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
51419 - static struct _raid_device *raid_device;
51420 + struct _raid_device *raid_device;
51421 unsigned long flags;
51422 Mpi2RaidVolPage0_t vol_pg0;
51423 Mpi2ConfigReply_t mpi_reply;
51424 @@ -1613,7 +1613,7 @@ _scsih_get_state(struct device *dev)
51425 {
51426 struct scsi_device *sdev = to_scsi_device(dev);
51427 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
51428 - static struct _raid_device *raid_device;
51429 + struct _raid_device *raid_device;
51430 unsigned long flags;
51431 Mpi2RaidVolPage0_t vol_pg0;
51432 Mpi2ConfigReply_t mpi_reply;
51433 @@ -6663,7 +6663,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
51434 Mpi2EventDataIrOperationStatus_t *event_data =
51435 (Mpi2EventDataIrOperationStatus_t *)
51436 fw_event->event_data;
51437 - static struct _raid_device *raid_device;
51438 + struct _raid_device *raid_device;
51439 unsigned long flags;
51440 u16 handle;
51441
51442 @@ -7134,7 +7134,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
51443 u64 sas_address;
51444 struct _sas_device *sas_device;
51445 struct _sas_node *expander_device;
51446 - static struct _raid_device *raid_device;
51447 + struct _raid_device *raid_device;
51448 u8 retry_count;
51449 unsigned long flags;
51450
51451 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
51452 index bcb64eb..f08cf71 100644
51453 --- a/drivers/scsi/pmcraid.c
51454 +++ b/drivers/scsi/pmcraid.c
51455 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
51456 res->scsi_dev = scsi_dev;
51457 scsi_dev->hostdata = res;
51458 res->change_detected = 0;
51459 - atomic_set(&res->read_failures, 0);
51460 - atomic_set(&res->write_failures, 0);
51461 + atomic_set_unchecked(&res->read_failures, 0);
51462 + atomic_set_unchecked(&res->write_failures, 0);
51463 rc = 0;
51464 }
51465 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
51466 @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
51467
51468 /* If this was a SCSI read/write command keep count of errors */
51469 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
51470 - atomic_inc(&res->read_failures);
51471 + atomic_inc_unchecked(&res->read_failures);
51472 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
51473 - atomic_inc(&res->write_failures);
51474 + atomic_inc_unchecked(&res->write_failures);
51475
51476 if (!RES_IS_GSCSI(res->cfg_entry) &&
51477 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
51478 @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
51479 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
51480 * hrrq_id assigned here in queuecommand
51481 */
51482 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
51483 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
51484 pinstance->num_hrrq;
51485 cmd->cmd_done = pmcraid_io_done;
51486
51487 @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
51488 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
51489 * hrrq_id assigned here in queuecommand
51490 */
51491 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
51492 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
51493 pinstance->num_hrrq;
51494
51495 if (request_size) {
51496 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
51497
51498 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
51499 /* add resources only after host is added into system */
51500 - if (!atomic_read(&pinstance->expose_resources))
51501 + if (!atomic_read_unchecked(&pinstance->expose_resources))
51502 return;
51503
51504 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
51505 @@ -5312,8 +5312,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
51506 init_waitqueue_head(&pinstance->reset_wait_q);
51507
51508 atomic_set(&pinstance->outstanding_cmds, 0);
51509 - atomic_set(&pinstance->last_message_id, 0);
51510 - atomic_set(&pinstance->expose_resources, 0);
51511 + atomic_set_unchecked(&pinstance->last_message_id, 0);
51512 + atomic_set_unchecked(&pinstance->expose_resources, 0);
51513
51514 INIT_LIST_HEAD(&pinstance->free_res_q);
51515 INIT_LIST_HEAD(&pinstance->used_res_q);
51516 @@ -6026,7 +6026,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
51517 /* Schedule worker thread to handle CCN and take care of adding and
51518 * removing devices to OS
51519 */
51520 - atomic_set(&pinstance->expose_resources, 1);
51521 + atomic_set_unchecked(&pinstance->expose_resources, 1);
51522 schedule_work(&pinstance->worker_q);
51523 return rc;
51524
51525 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
51526 index e1d150f..6c6df44 100644
51527 --- a/drivers/scsi/pmcraid.h
51528 +++ b/drivers/scsi/pmcraid.h
51529 @@ -748,7 +748,7 @@ struct pmcraid_instance {
51530 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
51531
51532 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
51533 - atomic_t last_message_id;
51534 + atomic_unchecked_t last_message_id;
51535
51536 /* configuration table */
51537 struct pmcraid_config_table *cfg_table;
51538 @@ -777,7 +777,7 @@ struct pmcraid_instance {
51539 atomic_t outstanding_cmds;
51540
51541 /* should add/delete resources to mid-layer now ?*/
51542 - atomic_t expose_resources;
51543 + atomic_unchecked_t expose_resources;
51544
51545
51546
51547 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
51548 struct pmcraid_config_table_entry_ext cfg_entry_ext;
51549 };
51550 struct scsi_device *scsi_dev; /* Link scsi_device structure */
51551 - atomic_t read_failures; /* count of failed READ commands */
51552 - atomic_t write_failures; /* count of failed WRITE commands */
51553 + atomic_unchecked_t read_failures; /* count of failed READ commands */
51554 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
51555
51556 /* To indicate add/delete/modify during CCN */
51557 u8 change_detected;
51558 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
51559 index 82b92c4..3178171 100644
51560 --- a/drivers/scsi/qla2xxx/qla_attr.c
51561 +++ b/drivers/scsi/qla2xxx/qla_attr.c
51562 @@ -2192,7 +2192,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
51563 return 0;
51564 }
51565
51566 -struct fc_function_template qla2xxx_transport_functions = {
51567 +fc_function_template_no_const qla2xxx_transport_functions = {
51568
51569 .show_host_node_name = 1,
51570 .show_host_port_name = 1,
51571 @@ -2240,7 +2240,7 @@ struct fc_function_template qla2xxx_transport_functions = {
51572 .bsg_timeout = qla24xx_bsg_timeout,
51573 };
51574
51575 -struct fc_function_template qla2xxx_transport_vport_functions = {
51576 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
51577
51578 .show_host_node_name = 1,
51579 .show_host_port_name = 1,
51580 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
51581 index b1865a7..a7723d3 100644
51582 --- a/drivers/scsi/qla2xxx/qla_gbl.h
51583 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
51584 @@ -571,8 +571,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *, size_t);
51585 struct device_attribute;
51586 extern struct device_attribute *qla2x00_host_attrs[];
51587 struct fc_function_template;
51588 -extern struct fc_function_template qla2xxx_transport_functions;
51589 -extern struct fc_function_template qla2xxx_transport_vport_functions;
51590 +extern fc_function_template_no_const qla2xxx_transport_functions;
51591 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
51592 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
51593 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
51594 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
51595 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
51596 index db3dbd9..2492392 100644
51597 --- a/drivers/scsi/qla2xxx/qla_os.c
51598 +++ b/drivers/scsi/qla2xxx/qla_os.c
51599 @@ -1507,8 +1507,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
51600 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
51601 /* Ok, a 64bit DMA mask is applicable. */
51602 ha->flags.enable_64bit_addressing = 1;
51603 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
51604 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
51605 + pax_open_kernel();
51606 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
51607 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
51608 + pax_close_kernel();
51609 return;
51610 }
51611 }
51612 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
51613 index 8f6d0fb..1b21097 100644
51614 --- a/drivers/scsi/qla4xxx/ql4_def.h
51615 +++ b/drivers/scsi/qla4xxx/ql4_def.h
51616 @@ -305,7 +305,7 @@ struct ddb_entry {
51617 * (4000 only) */
51618 atomic_t relogin_timer; /* Max Time to wait for
51619 * relogin to complete */
51620 - atomic_t relogin_retry_count; /* Num of times relogin has been
51621 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
51622 * retried */
51623 uint32_t default_time2wait; /* Default Min time between
51624 * relogins (+aens) */
51625 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
51626 index 199fcf7..3c3a918 100644
51627 --- a/drivers/scsi/qla4xxx/ql4_os.c
51628 +++ b/drivers/scsi/qla4xxx/ql4_os.c
51629 @@ -4496,12 +4496,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
51630 */
51631 if (!iscsi_is_session_online(cls_sess)) {
51632 /* Reset retry relogin timer */
51633 - atomic_inc(&ddb_entry->relogin_retry_count);
51634 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
51635 DEBUG2(ql4_printk(KERN_INFO, ha,
51636 "%s: index[%d] relogin timed out-retrying"
51637 " relogin (%d), retry (%d)\n", __func__,
51638 ddb_entry->fw_ddb_index,
51639 - atomic_read(&ddb_entry->relogin_retry_count),
51640 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
51641 ddb_entry->default_time2wait + 4));
51642 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
51643 atomic_set(&ddb_entry->retry_relogin_timer,
51644 @@ -6609,7 +6609,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
51645
51646 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
51647 atomic_set(&ddb_entry->relogin_timer, 0);
51648 - atomic_set(&ddb_entry->relogin_retry_count, 0);
51649 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
51650 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
51651 ddb_entry->default_relogin_timeout =
51652 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
51653 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
51654 index 79c77b4..ef6ec0b 100644
51655 --- a/drivers/scsi/scsi.c
51656 +++ b/drivers/scsi/scsi.c
51657 @@ -645,7 +645,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
51658 struct Scsi_Host *host = cmd->device->host;
51659 int rtn = 0;
51660
51661 - atomic_inc(&cmd->device->iorequest_cnt);
51662 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
51663
51664 /* check if the device is still usable */
51665 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
51666 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
51667 index 50a6e1a..de5252e 100644
51668 --- a/drivers/scsi/scsi_lib.c
51669 +++ b/drivers/scsi/scsi_lib.c
51670 @@ -1583,7 +1583,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
51671 shost = sdev->host;
51672 scsi_init_cmd_errh(cmd);
51673 cmd->result = DID_NO_CONNECT << 16;
51674 - atomic_inc(&cmd->device->iorequest_cnt);
51675 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
51676
51677 /*
51678 * SCSI request completion path will do scsi_device_unbusy(),
51679 @@ -1606,9 +1606,9 @@ static void scsi_softirq_done(struct request *rq)
51680
51681 INIT_LIST_HEAD(&cmd->eh_entry);
51682
51683 - atomic_inc(&cmd->device->iodone_cnt);
51684 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
51685 if (cmd->result)
51686 - atomic_inc(&cmd->device->ioerr_cnt);
51687 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
51688
51689 disposition = scsi_decide_disposition(cmd);
51690 if (disposition != SUCCESS &&
51691 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
51692 index f4cb7b3..dfa79c4 100644
51693 --- a/drivers/scsi/scsi_sysfs.c
51694 +++ b/drivers/scsi/scsi_sysfs.c
51695 @@ -805,7 +805,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
51696 char *buf) \
51697 { \
51698 struct scsi_device *sdev = to_scsi_device(dev); \
51699 - unsigned long long count = atomic_read(&sdev->field); \
51700 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
51701 return snprintf(buf, 20, "0x%llx\n", count); \
51702 } \
51703 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
51704 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
51705 index 5d6f348..18778a6b 100644
51706 --- a/drivers/scsi/scsi_transport_fc.c
51707 +++ b/drivers/scsi/scsi_transport_fc.c
51708 @@ -501,7 +501,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
51709 * Netlink Infrastructure
51710 */
51711
51712 -static atomic_t fc_event_seq;
51713 +static atomic_unchecked_t fc_event_seq;
51714
51715 /**
51716 * fc_get_event_number - Obtain the next sequential FC event number
51717 @@ -514,7 +514,7 @@ static atomic_t fc_event_seq;
51718 u32
51719 fc_get_event_number(void)
51720 {
51721 - return atomic_add_return(1, &fc_event_seq);
51722 + return atomic_add_return_unchecked(1, &fc_event_seq);
51723 }
51724 EXPORT_SYMBOL(fc_get_event_number);
51725
51726 @@ -658,7 +658,7 @@ static __init int fc_transport_init(void)
51727 {
51728 int error;
51729
51730 - atomic_set(&fc_event_seq, 0);
51731 + atomic_set_unchecked(&fc_event_seq, 0);
51732
51733 error = transport_class_register(&fc_host_class);
51734 if (error)
51735 @@ -848,7 +848,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
51736 char *cp;
51737
51738 *val = simple_strtoul(buf, &cp, 0);
51739 - if ((*cp && (*cp != '\n')) || (*val < 0))
51740 + if (*cp && (*cp != '\n'))
51741 return -EINVAL;
51742 /*
51743 * Check for overflow; dev_loss_tmo is u32
51744 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
51745 index 67d43e3..8cee73c 100644
51746 --- a/drivers/scsi/scsi_transport_iscsi.c
51747 +++ b/drivers/scsi/scsi_transport_iscsi.c
51748 @@ -79,7 +79,7 @@ struct iscsi_internal {
51749 struct transport_container session_cont;
51750 };
51751
51752 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
51753 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
51754 static struct workqueue_struct *iscsi_eh_timer_workq;
51755
51756 static DEFINE_IDA(iscsi_sess_ida);
51757 @@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
51758 int err;
51759
51760 ihost = shost->shost_data;
51761 - session->sid = atomic_add_return(1, &iscsi_session_nr);
51762 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
51763
51764 if (target_id == ISCSI_MAX_TARGET) {
51765 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
51766 @@ -4515,7 +4515,7 @@ static __init int iscsi_transport_init(void)
51767 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
51768 ISCSI_TRANSPORT_VERSION);
51769
51770 - atomic_set(&iscsi_session_nr, 0);
51771 + atomic_set_unchecked(&iscsi_session_nr, 0);
51772
51773 err = class_register(&iscsi_transport_class);
51774 if (err)
51775 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
51776 index ae45bd9..c32a586 100644
51777 --- a/drivers/scsi/scsi_transport_srp.c
51778 +++ b/drivers/scsi/scsi_transport_srp.c
51779 @@ -35,7 +35,7 @@
51780 #include "scsi_priv.h"
51781
51782 struct srp_host_attrs {
51783 - atomic_t next_port_id;
51784 + atomic_unchecked_t next_port_id;
51785 };
51786 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
51787
51788 @@ -100,7 +100,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
51789 struct Scsi_Host *shost = dev_to_shost(dev);
51790 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
51791
51792 - atomic_set(&srp_host->next_port_id, 0);
51793 + atomic_set_unchecked(&srp_host->next_port_id, 0);
51794 return 0;
51795 }
51796
51797 @@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
51798 rport_fast_io_fail_timedout);
51799 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
51800
51801 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
51802 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
51803 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
51804
51805 transport_setup_device(&rport->dev);
51806 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
51807 index cfba74c..415f09b 100644
51808 --- a/drivers/scsi/sd.c
51809 +++ b/drivers/scsi/sd.c
51810 @@ -3022,7 +3022,7 @@ static int sd_probe(struct device *dev)
51811 sdkp->disk = gd;
51812 sdkp->index = index;
51813 atomic_set(&sdkp->openers, 0);
51814 - atomic_set(&sdkp->device->ioerr_cnt, 0);
51815 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
51816
51817 if (!sdp->request_queue->rq_timeout) {
51818 if (sdp->type != TYPE_MOD)
51819 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
51820 index 6035444..c82edd4 100644
51821 --- a/drivers/scsi/sg.c
51822 +++ b/drivers/scsi/sg.c
51823 @@ -1138,7 +1138,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
51824 sdp->disk->disk_name,
51825 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
51826 NULL,
51827 - (char *)arg);
51828 + (char __user *)arg);
51829 case BLKTRACESTART:
51830 return blk_trace_startstop(sdp->device->request_queue, 1);
51831 case BLKTRACESTOP:
51832 diff --git a/drivers/soc/tegra/fuse/fuse-tegra.c b/drivers/soc/tegra/fuse/fuse-tegra.c
51833 index 11a5043..e36f04c 100644
51834 --- a/drivers/soc/tegra/fuse/fuse-tegra.c
51835 +++ b/drivers/soc/tegra/fuse/fuse-tegra.c
51836 @@ -70,7 +70,7 @@ static ssize_t fuse_read(struct file *fd, struct kobject *kobj,
51837 return i;
51838 }
51839
51840 -static struct bin_attribute fuse_bin_attr = {
51841 +static bin_attribute_no_const fuse_bin_attr = {
51842 .attr = { .name = "fuse", .mode = S_IRUGO, },
51843 .read = fuse_read,
51844 };
51845 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
51846 index 50f20f2..6bd81e0 100644
51847 --- a/drivers/spi/spi.c
51848 +++ b/drivers/spi/spi.c
51849 @@ -2224,7 +2224,7 @@ int spi_bus_unlock(struct spi_master *master)
51850 EXPORT_SYMBOL_GPL(spi_bus_unlock);
51851
51852 /* portable code must never pass more than 32 bytes */
51853 -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
51854 +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
51855
51856 static u8 *buf;
51857
51858 diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
51859 index b41429f..2de5373 100644
51860 --- a/drivers/staging/android/timed_output.c
51861 +++ b/drivers/staging/android/timed_output.c
51862 @@ -25,7 +25,7 @@
51863 #include "timed_output.h"
51864
51865 static struct class *timed_output_class;
51866 -static atomic_t device_count;
51867 +static atomic_unchecked_t device_count;
51868
51869 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
51870 char *buf)
51871 @@ -65,7 +65,7 @@ static int create_timed_output_class(void)
51872 timed_output_class = class_create(THIS_MODULE, "timed_output");
51873 if (IS_ERR(timed_output_class))
51874 return PTR_ERR(timed_output_class);
51875 - atomic_set(&device_count, 0);
51876 + atomic_set_unchecked(&device_count, 0);
51877 timed_output_class->dev_groups = timed_output_groups;
51878 }
51879
51880 @@ -83,7 +83,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
51881 if (ret < 0)
51882 return ret;
51883
51884 - tdev->index = atomic_inc_return(&device_count);
51885 + tdev->index = atomic_inc_return_unchecked(&device_count);
51886 tdev->dev = device_create(timed_output_class, NULL,
51887 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
51888 if (IS_ERR(tdev->dev))
51889 diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
51890 index 001348c..cfaac8a 100644
51891 --- a/drivers/staging/gdm724x/gdm_tty.c
51892 +++ b/drivers/staging/gdm724x/gdm_tty.c
51893 @@ -44,7 +44,7 @@
51894 #define gdm_tty_send_control(n, r, v, d, l) (\
51895 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
51896
51897 -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
51898 +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
51899
51900 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
51901 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
51902 diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
51903 index 9cb222e..8766f26 100644
51904 --- a/drivers/staging/imx-drm/imx-drm-core.c
51905 +++ b/drivers/staging/imx-drm/imx-drm-core.c
51906 @@ -357,7 +357,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
51907 if (imxdrm->pipes >= MAX_CRTC)
51908 return -EINVAL;
51909
51910 - if (imxdrm->drm->open_count)
51911 + if (local_read(&imxdrm->drm->open_count))
51912 return -EBUSY;
51913
51914 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
51915 diff --git a/drivers/staging/line6/driver.c b/drivers/staging/line6/driver.c
51916 index 503b2d7..c918745 100644
51917 --- a/drivers/staging/line6/driver.c
51918 +++ b/drivers/staging/line6/driver.c
51919 @@ -463,7 +463,7 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
51920 {
51921 struct usb_device *usbdev = line6->usbdev;
51922 int ret;
51923 - unsigned char len;
51924 + unsigned char *plen;
51925
51926 /* query the serial number: */
51927 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
51928 @@ -476,27 +476,34 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
51929 return ret;
51930 }
51931
51932 + plen = kmalloc(1, GFP_KERNEL);
51933 + if (plen == NULL)
51934 + return -ENOMEM;
51935 +
51936 /* Wait for data length. We'll get 0xff until length arrives. */
51937 do {
51938 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
51939 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
51940 USB_DIR_IN,
51941 - 0x0012, 0x0000, &len, 1,
51942 + 0x0012, 0x0000, plen, 1,
51943 LINE6_TIMEOUT * HZ);
51944 if (ret < 0) {
51945 dev_err(line6->ifcdev,
51946 "receive length failed (error %d)\n", ret);
51947 + kfree(plen);
51948 return ret;
51949 }
51950 - } while (len == 0xff);
51951 + } while (*plen == 0xff);
51952
51953 - if (len != datalen) {
51954 + if (*plen != datalen) {
51955 /* should be equal or something went wrong */
51956 dev_err(line6->ifcdev,
51957 "length mismatch (expected %d, got %d)\n",
51958 - (int)datalen, (int)len);
51959 + (int)datalen, (int)*plen);
51960 + kfree(plen);
51961 return -EINVAL;
51962 }
51963 + kfree(plen);
51964
51965 /* receive the result: */
51966 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
51967 diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
51968 index a94f336..6a1924d 100644
51969 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
51970 +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
51971 @@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
51972 return 0;
51973 }
51974
51975 -sfw_test_client_ops_t brw_test_client;
51976 -void brw_init_test_client(void)
51977 -{
51978 - brw_test_client.tso_init = brw_client_init;
51979 - brw_test_client.tso_fini = brw_client_fini;
51980 - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
51981 - brw_test_client.tso_done_rpc = brw_client_done_rpc;
51982 +sfw_test_client_ops_t brw_test_client = {
51983 + .tso_init = brw_client_init,
51984 + .tso_fini = brw_client_fini,
51985 + .tso_prep_rpc = brw_client_prep_rpc,
51986 + .tso_done_rpc = brw_client_done_rpc,
51987 };
51988
51989 srpc_service_t brw_test_service;
51990 diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
51991 index df04ab7..1deb1ac 100644
51992 --- a/drivers/staging/lustre/lnet/selftest/framework.c
51993 +++ b/drivers/staging/lustre/lnet/selftest/framework.c
51994 @@ -1632,12 +1632,10 @@ static srpc_service_t sfw_services[] = {
51995
51996 extern sfw_test_client_ops_t ping_test_client;
51997 extern srpc_service_t ping_test_service;
51998 -extern void ping_init_test_client(void);
51999 extern void ping_init_test_service(void);
52000
52001 extern sfw_test_client_ops_t brw_test_client;
52002 extern srpc_service_t brw_test_service;
52003 -extern void brw_init_test_client(void);
52004 extern void brw_init_test_service(void);
52005
52006
52007 @@ -1681,12 +1679,10 @@ sfw_startup (void)
52008 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
52009 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
52010
52011 - brw_init_test_client();
52012 brw_init_test_service();
52013 rc = sfw_register_test(&brw_test_service, &brw_test_client);
52014 LASSERT (rc == 0);
52015
52016 - ping_init_test_client();
52017 ping_init_test_service();
52018 rc = sfw_register_test(&ping_test_service, &ping_test_client);
52019 LASSERT (rc == 0);
52020 diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
52021 index 750cac4..e4d751f 100644
52022 --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
52023 +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
52024 @@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
52025 return 0;
52026 }
52027
52028 -sfw_test_client_ops_t ping_test_client;
52029 -void ping_init_test_client(void)
52030 -{
52031 - ping_test_client.tso_init = ping_client_init;
52032 - ping_test_client.tso_fini = ping_client_fini;
52033 - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
52034 - ping_test_client.tso_done_rpc = ping_client_done_rpc;
52035 -}
52036 +sfw_test_client_ops_t ping_test_client = {
52037 + .tso_init = ping_client_init,
52038 + .tso_fini = ping_client_fini,
52039 + .tso_prep_rpc = ping_client_prep_rpc,
52040 + .tso_done_rpc = ping_client_done_rpc,
52041 +};
52042
52043 srpc_service_t ping_test_service;
52044 void ping_init_test_service(void)
52045 diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52046 index 14ac46f..eca2c16 100644
52047 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
52048 +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52049 @@ -1139,7 +1139,7 @@ struct ldlm_callback_suite {
52050 ldlm_completion_callback lcs_completion;
52051 ldlm_blocking_callback lcs_blocking;
52052 ldlm_glimpse_callback lcs_glimpse;
52053 -};
52054 +} __no_const;
52055
52056 /* ldlm_lockd.c */
52057 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
52058 diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
52059 index 2a88b80..62e7e5f 100644
52060 --- a/drivers/staging/lustre/lustre/include/obd.h
52061 +++ b/drivers/staging/lustre/lustre/include/obd.h
52062 @@ -1362,7 +1362,7 @@ struct md_ops {
52063 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
52064 * wrapper function in include/linux/obd_class.h.
52065 */
52066 -};
52067 +} __no_const;
52068
52069 struct lsm_operations {
52070 void (*lsm_free)(struct lov_stripe_md *);
52071 diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52072 index b798daa..b28ca8f 100644
52073 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52074 +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52075 @@ -258,7 +258,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
52076 int added = (mode == LCK_NL);
52077 int overlaps = 0;
52078 int splitted = 0;
52079 - const struct ldlm_callback_suite null_cbs = { NULL };
52080 + const struct ldlm_callback_suite null_cbs = { };
52081
52082 CDEBUG(D_DLMTRACE, "flags %#llx owner %llu pid %u mode %u start %llu end %llu\n",
52083 *flags, new->l_policy_data.l_flock.owner,
52084 diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52085 index bbe2c68..c6b4275 100644
52086 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52087 +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52088 @@ -236,7 +236,7 @@ int proc_console_max_delay_cs(struct ctl_table *table, int write,
52089 void __user *buffer, size_t *lenp, loff_t *ppos)
52090 {
52091 int rc, max_delay_cs;
52092 - struct ctl_table dummy = *table;
52093 + ctl_table_no_const dummy = *table;
52094 long d;
52095
52096 dummy.data = &max_delay_cs;
52097 @@ -268,7 +268,7 @@ int proc_console_min_delay_cs(struct ctl_table *table, int write,
52098 void __user *buffer, size_t *lenp, loff_t *ppos)
52099 {
52100 int rc, min_delay_cs;
52101 - struct ctl_table dummy = *table;
52102 + ctl_table_no_const dummy = *table;
52103 long d;
52104
52105 dummy.data = &min_delay_cs;
52106 @@ -300,7 +300,7 @@ int proc_console_backoff(struct ctl_table *table, int write,
52107 void __user *buffer, size_t *lenp, loff_t *ppos)
52108 {
52109 int rc, backoff;
52110 - struct ctl_table dummy = *table;
52111 + ctl_table_no_const dummy = *table;
52112
52113 dummy.data = &backoff;
52114 dummy.proc_handler = &proc_dointvec;
52115 diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
52116 index 2c4fc74..b04ca79 100644
52117 --- a/drivers/staging/lustre/lustre/libcfs/module.c
52118 +++ b/drivers/staging/lustre/lustre/libcfs/module.c
52119 @@ -315,11 +315,11 @@ out:
52120
52121
52122 struct cfs_psdev_ops libcfs_psdev_ops = {
52123 - libcfs_psdev_open,
52124 - libcfs_psdev_release,
52125 - NULL,
52126 - NULL,
52127 - libcfs_ioctl
52128 + .p_open = libcfs_psdev_open,
52129 + .p_close = libcfs_psdev_release,
52130 + .p_read = NULL,
52131 + .p_write = NULL,
52132 + .p_ioctl = libcfs_ioctl
52133 };
52134
52135 extern int insert_proc(void);
52136 diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
52137 index b0bb709..0117c96 100644
52138 --- a/drivers/staging/lustre/lustre/llite/dir.c
52139 +++ b/drivers/staging/lustre/lustre/llite/dir.c
52140 @@ -661,7 +661,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
52141 int mode;
52142 int err;
52143
52144 - mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
52145 + mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
52146 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
52147 strlen(filename), mode, LUSTRE_OPC_MKDIR,
52148 lump);
52149 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
52150 index b2b6c3c..302e4e4 100644
52151 --- a/drivers/staging/octeon/ethernet-rx.c
52152 +++ b/drivers/staging/octeon/ethernet-rx.c
52153 @@ -416,11 +416,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52154 /* Increment RX stats for virtual ports */
52155 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
52156 #ifdef CONFIG_64BIT
52157 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
52158 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
52159 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
52160 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
52161 #else
52162 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
52163 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
52164 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
52165 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
52166 #endif
52167 }
52168 netif_receive_skb(skb);
52169 @@ -431,9 +431,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52170 dev->name);
52171 */
52172 #ifdef CONFIG_64BIT
52173 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
52174 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52175 #else
52176 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
52177 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
52178 #endif
52179 dev_kfree_skb_irq(skb);
52180 }
52181 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
52182 index 8f9e3fb..d283fb9 100644
52183 --- a/drivers/staging/octeon/ethernet.c
52184 +++ b/drivers/staging/octeon/ethernet.c
52185 @@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
52186 * since the RX tasklet also increments it.
52187 */
52188 #ifdef CONFIG_64BIT
52189 - atomic64_add(rx_status.dropped_packets,
52190 - (atomic64_t *)&priv->stats.rx_dropped);
52191 + atomic64_add_unchecked(rx_status.dropped_packets,
52192 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52193 #else
52194 - atomic_add(rx_status.dropped_packets,
52195 - (atomic_t *)&priv->stats.rx_dropped);
52196 + atomic_add_unchecked(rx_status.dropped_packets,
52197 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
52198 #endif
52199 }
52200
52201 diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
52202 index 9191993..30e9817 100644
52203 --- a/drivers/staging/rtl8188eu/include/hal_intf.h
52204 +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
52205 @@ -225,7 +225,7 @@ struct hal_ops {
52206
52207 void (*hal_notch_filter)(struct adapter *adapter, bool enable);
52208 void (*hal_reset_security_engine)(struct adapter *adapter);
52209 -};
52210 +} __no_const;
52211
52212 enum rt_eeprom_type {
52213 EEPROM_93C46,
52214 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
52215 index 070cc03..6806e37 100644
52216 --- a/drivers/staging/rtl8712/rtl871x_io.h
52217 +++ b/drivers/staging/rtl8712/rtl871x_io.h
52218 @@ -108,7 +108,7 @@ struct _io_ops {
52219 u8 *pmem);
52220 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
52221 u8 *pmem);
52222 -};
52223 +} __no_const;
52224
52225 struct io_req {
52226 struct list_head list;
52227 diff --git a/drivers/staging/unisys/visorchipset/visorchipset.h b/drivers/staging/unisys/visorchipset/visorchipset.h
52228 index 2bf2e2f..84421c9 100644
52229 --- a/drivers/staging/unisys/visorchipset/visorchipset.h
52230 +++ b/drivers/staging/unisys/visorchipset/visorchipset.h
52231 @@ -228,7 +228,7 @@ typedef struct {
52232 void (*device_resume)(ulong busNo, ulong devNo);
52233 int (*get_channel_info)(uuid_le typeGuid, ulong *minSize,
52234 ulong *maxSize);
52235 -} VISORCHIPSET_BUSDEV_NOTIFIERS;
52236 +} __no_const VISORCHIPSET_BUSDEV_NOTIFIERS;
52237
52238 /* These functions live inside visorchipset, and will be called to indicate
52239 * responses to specific events (by code outside of visorchipset).
52240 @@ -243,7 +243,7 @@ typedef struct {
52241 void (*device_destroy)(ulong busNo, ulong devNo, int response);
52242 void (*device_pause)(ulong busNo, ulong devNo, int response);
52243 void (*device_resume)(ulong busNo, ulong devNo, int response);
52244 -} VISORCHIPSET_BUSDEV_RESPONDERS;
52245 +} __no_const VISORCHIPSET_BUSDEV_RESPONDERS;
52246
52247 /** Register functions (in the bus driver) to get called by visorchipset
52248 * whenever a bus or device appears for which this service partition is
52249 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
52250 index ae0dade..803d53a 100644
52251 --- a/drivers/staging/vt6655/hostap.c
52252 +++ b/drivers/staging/vt6655/hostap.c
52253 @@ -65,14 +65,13 @@
52254 *
52255 */
52256
52257 +static net_device_ops_no_const apdev_netdev_ops;
52258 +
52259 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
52260 {
52261 struct vnt_private *apdev_priv;
52262 struct net_device *dev = pDevice->dev;
52263 int ret;
52264 - const struct net_device_ops apdev_netdev_ops = {
52265 - .ndo_start_xmit = pDevice->tx_80211,
52266 - };
52267
52268 pr_debug("%s: Enabling hostapd mode\n", dev->name);
52269
52270 @@ -84,6 +83,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
52271 *apdev_priv = *pDevice;
52272 eth_hw_addr_inherit(pDevice->apdev, dev);
52273
52274 + /* only half broken now */
52275 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
52276 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
52277
52278 pDevice->apdev->type = ARPHRD_IEEE80211;
52279 diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
52280 index e7e9372..161f530 100644
52281 --- a/drivers/target/sbp/sbp_target.c
52282 +++ b/drivers/target/sbp/sbp_target.c
52283 @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
52284
52285 #define SESSION_MAINTENANCE_INTERVAL HZ
52286
52287 -static atomic_t login_id = ATOMIC_INIT(0);
52288 +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
52289
52290 static void session_maintenance_work(struct work_struct *);
52291 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
52292 @@ -444,7 +444,7 @@ static void sbp_management_request_login(
52293 login->lun = se_lun;
52294 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
52295 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
52296 - login->login_id = atomic_inc_return(&login_id);
52297 + login->login_id = atomic_inc_return_unchecked(&login_id);
52298
52299 login->tgt_agt = sbp_target_agent_register(login);
52300 if (IS_ERR(login->tgt_agt)) {
52301 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
52302 index c45f9e9..00e85f0 100644
52303 --- a/drivers/target/target_core_device.c
52304 +++ b/drivers/target/target_core_device.c
52305 @@ -1532,7 +1532,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
52306 spin_lock_init(&dev->se_tmr_lock);
52307 spin_lock_init(&dev->qf_cmd_lock);
52308 sema_init(&dev->caw_sem, 1);
52309 - atomic_set(&dev->dev_ordered_id, 0);
52310 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
52311 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
52312 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
52313 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
52314 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
52315 index be877bf..7be9cd4 100644
52316 --- a/drivers/target/target_core_transport.c
52317 +++ b/drivers/target/target_core_transport.c
52318 @@ -1168,7 +1168,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
52319 * Used to determine when ORDERED commands should go from
52320 * Dormant to Active status.
52321 */
52322 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
52323 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
52324 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
52325 cmd->se_ordered_id, cmd->sam_task_attr,
52326 dev->transport->name);
52327 diff --git a/drivers/thermal/int340x_thermal/int3400_thermal.c b/drivers/thermal/int340x_thermal/int3400_thermal.c
52328 index edc1cce..769e4cb 100644
52329 --- a/drivers/thermal/int340x_thermal/int3400_thermal.c
52330 +++ b/drivers/thermal/int340x_thermal/int3400_thermal.c
52331 @@ -209,8 +209,10 @@ static int int3400_thermal_probe(struct platform_device *pdev)
52332 platform_set_drvdata(pdev, priv);
52333
52334 if (priv->uuid_bitmap & 1 << INT3400_THERMAL_PASSIVE_1) {
52335 - int3400_thermal_ops.get_mode = int3400_thermal_get_mode;
52336 - int3400_thermal_ops.set_mode = int3400_thermal_set_mode;
52337 + pax_open_kernel();
52338 + *(void **)&int3400_thermal_ops.get_mode = int3400_thermal_get_mode;
52339 + *(void **)&int3400_thermal_ops.set_mode = int3400_thermal_set_mode;
52340 + pax_close_kernel();
52341 }
52342 priv->thermal = thermal_zone_device_register("INT3400 Thermal", 0, 0,
52343 priv, &int3400_thermal_ops,
52344 diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
52345 index 62143ba..ae21165 100644
52346 --- a/drivers/thermal/of-thermal.c
52347 +++ b/drivers/thermal/of-thermal.c
52348 @@ -30,6 +30,7 @@
52349 #include <linux/err.h>
52350 #include <linux/export.h>
52351 #include <linux/string.h>
52352 +#include <linux/mm.h>
52353
52354 #include "thermal_core.h"
52355
52356 @@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
52357 tz->get_trend = get_trend;
52358 tz->sensor_data = data;
52359
52360 - tzd->ops->get_temp = of_thermal_get_temp;
52361 - tzd->ops->get_trend = of_thermal_get_trend;
52362 + pax_open_kernel();
52363 + *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
52364 + *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
52365 + pax_close_kernel();
52366 mutex_unlock(&tzd->lock);
52367
52368 return tzd;
52369 @@ -473,8 +476,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
52370 return;
52371
52372 mutex_lock(&tzd->lock);
52373 - tzd->ops->get_temp = NULL;
52374 - tzd->ops->get_trend = NULL;
52375 + pax_open_kernel();
52376 + *(void **)&tzd->ops->get_temp = NULL;
52377 + *(void **)&tzd->ops->get_trend = NULL;
52378 + pax_close_kernel();
52379
52380 tz->get_temp = NULL;
52381 tz->get_trend = NULL;
52382 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
52383 index fd66f57..48e6376 100644
52384 --- a/drivers/tty/cyclades.c
52385 +++ b/drivers/tty/cyclades.c
52386 @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
52387 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
52388 info->port.count);
52389 #endif
52390 - info->port.count++;
52391 + atomic_inc(&info->port.count);
52392 #ifdef CY_DEBUG_COUNT
52393 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
52394 - current->pid, info->port.count);
52395 + current->pid, atomic_read(&info->port.count));
52396 #endif
52397
52398 /*
52399 @@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
52400 for (j = 0; j < cy_card[i].nports; j++) {
52401 info = &cy_card[i].ports[j];
52402
52403 - if (info->port.count) {
52404 + if (atomic_read(&info->port.count)) {
52405 /* XXX is the ldisc num worth this? */
52406 struct tty_struct *tty;
52407 struct tty_ldisc *ld;
52408 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
52409 index 4fcec1d..5a036f7 100644
52410 --- a/drivers/tty/hvc/hvc_console.c
52411 +++ b/drivers/tty/hvc/hvc_console.c
52412 @@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
52413
52414 spin_lock_irqsave(&hp->port.lock, flags);
52415 /* Check and then increment for fast path open. */
52416 - if (hp->port.count++ > 0) {
52417 + if (atomic_inc_return(&hp->port.count) > 1) {
52418 spin_unlock_irqrestore(&hp->port.lock, flags);
52419 hvc_kick();
52420 return 0;
52421 @@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
52422
52423 spin_lock_irqsave(&hp->port.lock, flags);
52424
52425 - if (--hp->port.count == 0) {
52426 + if (atomic_dec_return(&hp->port.count) == 0) {
52427 spin_unlock_irqrestore(&hp->port.lock, flags);
52428 /* We are done with the tty pointer now. */
52429 tty_port_tty_set(&hp->port, NULL);
52430 @@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
52431 */
52432 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
52433 } else {
52434 - if (hp->port.count < 0)
52435 + if (atomic_read(&hp->port.count) < 0)
52436 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
52437 - hp->vtermno, hp->port.count);
52438 + hp->vtermno, atomic_read(&hp->port.count));
52439 spin_unlock_irqrestore(&hp->port.lock, flags);
52440 }
52441 }
52442 @@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
52443 * open->hangup case this can be called after the final close so prevent
52444 * that from happening for now.
52445 */
52446 - if (hp->port.count <= 0) {
52447 + if (atomic_read(&hp->port.count) <= 0) {
52448 spin_unlock_irqrestore(&hp->port.lock, flags);
52449 return;
52450 }
52451
52452 - hp->port.count = 0;
52453 + atomic_set(&hp->port.count, 0);
52454 spin_unlock_irqrestore(&hp->port.lock, flags);
52455 tty_port_tty_set(&hp->port, NULL);
52456
52457 @@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
52458 return -EPIPE;
52459
52460 /* FIXME what's this (unprotected) check for? */
52461 - if (hp->port.count <= 0)
52462 + if (atomic_read(&hp->port.count) <= 0)
52463 return -EIO;
52464
52465 spin_lock_irqsave(&hp->lock, flags);
52466 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
52467 index 81e939e..95ead10 100644
52468 --- a/drivers/tty/hvc/hvcs.c
52469 +++ b/drivers/tty/hvc/hvcs.c
52470 @@ -83,6 +83,7 @@
52471 #include <asm/hvcserver.h>
52472 #include <asm/uaccess.h>
52473 #include <asm/vio.h>
52474 +#include <asm/local.h>
52475
52476 /*
52477 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
52478 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
52479
52480 spin_lock_irqsave(&hvcsd->lock, flags);
52481
52482 - if (hvcsd->port.count > 0) {
52483 + if (atomic_read(&hvcsd->port.count) > 0) {
52484 spin_unlock_irqrestore(&hvcsd->lock, flags);
52485 printk(KERN_INFO "HVCS: vterm state unchanged. "
52486 "The hvcs device node is still in use.\n");
52487 @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
52488 }
52489 }
52490
52491 - hvcsd->port.count = 0;
52492 + atomic_set(&hvcsd->port.count, 0);
52493 hvcsd->port.tty = tty;
52494 tty->driver_data = hvcsd;
52495
52496 @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
52497 unsigned long flags;
52498
52499 spin_lock_irqsave(&hvcsd->lock, flags);
52500 - hvcsd->port.count++;
52501 + atomic_inc(&hvcsd->port.count);
52502 hvcsd->todo_mask |= HVCS_SCHED_READ;
52503 spin_unlock_irqrestore(&hvcsd->lock, flags);
52504
52505 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
52506 hvcsd = tty->driver_data;
52507
52508 spin_lock_irqsave(&hvcsd->lock, flags);
52509 - if (--hvcsd->port.count == 0) {
52510 + if (atomic_dec_and_test(&hvcsd->port.count)) {
52511
52512 vio_disable_interrupts(hvcsd->vdev);
52513
52514 @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
52515
52516 free_irq(irq, hvcsd);
52517 return;
52518 - } else if (hvcsd->port.count < 0) {
52519 + } else if (atomic_read(&hvcsd->port.count) < 0) {
52520 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
52521 " is missmanaged.\n",
52522 - hvcsd->vdev->unit_address, hvcsd->port.count);
52523 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
52524 }
52525
52526 spin_unlock_irqrestore(&hvcsd->lock, flags);
52527 @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
52528
52529 spin_lock_irqsave(&hvcsd->lock, flags);
52530 /* Preserve this so that we know how many kref refs to put */
52531 - temp_open_count = hvcsd->port.count;
52532 + temp_open_count = atomic_read(&hvcsd->port.count);
52533
52534 /*
52535 * Don't kref put inside the spinlock because the destruction
52536 @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
52537 tty->driver_data = NULL;
52538 hvcsd->port.tty = NULL;
52539
52540 - hvcsd->port.count = 0;
52541 + atomic_set(&hvcsd->port.count, 0);
52542
52543 /* This will drop any buffered data on the floor which is OK in a hangup
52544 * scenario. */
52545 @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
52546 * the middle of a write operation? This is a crummy place to do this
52547 * but we want to keep it all in the spinlock.
52548 */
52549 - if (hvcsd->port.count <= 0) {
52550 + if (atomic_read(&hvcsd->port.count) <= 0) {
52551 spin_unlock_irqrestore(&hvcsd->lock, flags);
52552 return -ENODEV;
52553 }
52554 @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
52555 {
52556 struct hvcs_struct *hvcsd = tty->driver_data;
52557
52558 - if (!hvcsd || hvcsd->port.count <= 0)
52559 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
52560 return 0;
52561
52562 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
52563 diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
52564 index 4190199..06d5bfa 100644
52565 --- a/drivers/tty/hvc/hvsi.c
52566 +++ b/drivers/tty/hvc/hvsi.c
52567 @@ -85,7 +85,7 @@ struct hvsi_struct {
52568 int n_outbuf;
52569 uint32_t vtermno;
52570 uint32_t virq;
52571 - atomic_t seqno; /* HVSI packet sequence number */
52572 + atomic_unchecked_t seqno; /* HVSI packet sequence number */
52573 uint16_t mctrl;
52574 uint8_t state; /* HVSI protocol state */
52575 uint8_t flags;
52576 @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
52577
52578 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
52579 packet.hdr.len = sizeof(struct hvsi_query_response);
52580 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52581 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52582 packet.verb = VSV_SEND_VERSION_NUMBER;
52583 packet.u.version = HVSI_VERSION;
52584 packet.query_seqno = query_seqno+1;
52585 @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
52586
52587 packet.hdr.type = VS_QUERY_PACKET_HEADER;
52588 packet.hdr.len = sizeof(struct hvsi_query);
52589 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52590 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52591 packet.verb = verb;
52592
52593 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
52594 @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
52595 int wrote;
52596
52597 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
52598 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52599 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52600 packet.hdr.len = sizeof(struct hvsi_control);
52601 packet.verb = VSV_SET_MODEM_CTL;
52602 packet.mask = HVSI_TSDTR;
52603 @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
52604 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
52605
52606 packet.hdr.type = VS_DATA_PACKET_HEADER;
52607 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52608 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52609 packet.hdr.len = count + sizeof(struct hvsi_header);
52610 memcpy(&packet.data, buf, count);
52611
52612 @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
52613 struct hvsi_control packet __ALIGNED__;
52614
52615 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
52616 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52617 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52618 packet.hdr.len = 6;
52619 packet.verb = VSV_CLOSE_PROTOCOL;
52620
52621 @@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
52622
52623 tty_port_tty_set(&hp->port, tty);
52624 spin_lock_irqsave(&hp->lock, flags);
52625 - hp->port.count++;
52626 + atomic_inc(&hp->port.count);
52627 atomic_set(&hp->seqno, 0);
52628 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
52629 spin_unlock_irqrestore(&hp->lock, flags);
52630 @@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
52631
52632 spin_lock_irqsave(&hp->lock, flags);
52633
52634 - if (--hp->port.count == 0) {
52635 + if (atomic_dec_return(&hp->port.count) == 0) {
52636 tty_port_tty_set(&hp->port, NULL);
52637 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
52638
52639 @@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
52640
52641 spin_lock_irqsave(&hp->lock, flags);
52642 }
52643 - } else if (hp->port.count < 0)
52644 + } else if (atomic_read(&hp->port.count) < 0)
52645 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
52646 - hp - hvsi_ports, hp->port.count);
52647 + hp - hvsi_ports, atomic_read(&hp->port.count));
52648
52649 spin_unlock_irqrestore(&hp->lock, flags);
52650 }
52651 @@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
52652 tty_port_tty_set(&hp->port, NULL);
52653
52654 spin_lock_irqsave(&hp->lock, flags);
52655 - hp->port.count = 0;
52656 + atomic_set(&hp->port.count, 0);
52657 hp->n_outbuf = 0;
52658 spin_unlock_irqrestore(&hp->lock, flags);
52659 }
52660 diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
52661 index 7ae6c29..05c6dba 100644
52662 --- a/drivers/tty/hvc/hvsi_lib.c
52663 +++ b/drivers/tty/hvc/hvsi_lib.c
52664 @@ -8,7 +8,7 @@
52665
52666 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
52667 {
52668 - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
52669 + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
52670
52671 /* Assumes that always succeeds, works in practice */
52672 return pv->put_chars(pv->termno, (char *)packet, packet->len);
52673 @@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
52674
52675 /* Reset state */
52676 pv->established = 0;
52677 - atomic_set(&pv->seqno, 0);
52678 + atomic_set_unchecked(&pv->seqno, 0);
52679
52680 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
52681
52682 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
52683 index 345cebb..d5a1e9e 100644
52684 --- a/drivers/tty/ipwireless/tty.c
52685 +++ b/drivers/tty/ipwireless/tty.c
52686 @@ -28,6 +28,7 @@
52687 #include <linux/tty_driver.h>
52688 #include <linux/tty_flip.h>
52689 #include <linux/uaccess.h>
52690 +#include <asm/local.h>
52691
52692 #include "tty.h"
52693 #include "network.h"
52694 @@ -93,10 +94,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
52695 return -ENODEV;
52696
52697 mutex_lock(&tty->ipw_tty_mutex);
52698 - if (tty->port.count == 0)
52699 + if (atomic_read(&tty->port.count) == 0)
52700 tty->tx_bytes_queued = 0;
52701
52702 - tty->port.count++;
52703 + atomic_inc(&tty->port.count);
52704
52705 tty->port.tty = linux_tty;
52706 linux_tty->driver_data = tty;
52707 @@ -112,9 +113,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
52708
52709 static void do_ipw_close(struct ipw_tty *tty)
52710 {
52711 - tty->port.count--;
52712 -
52713 - if (tty->port.count == 0) {
52714 + if (atomic_dec_return(&tty->port.count) == 0) {
52715 struct tty_struct *linux_tty = tty->port.tty;
52716
52717 if (linux_tty != NULL) {
52718 @@ -135,7 +134,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
52719 return;
52720
52721 mutex_lock(&tty->ipw_tty_mutex);
52722 - if (tty->port.count == 0) {
52723 + if (atomic_read(&tty->port.count) == 0) {
52724 mutex_unlock(&tty->ipw_tty_mutex);
52725 return;
52726 }
52727 @@ -158,7 +157,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
52728
52729 mutex_lock(&tty->ipw_tty_mutex);
52730
52731 - if (!tty->port.count) {
52732 + if (!atomic_read(&tty->port.count)) {
52733 mutex_unlock(&tty->ipw_tty_mutex);
52734 return;
52735 }
52736 @@ -197,7 +196,7 @@ static int ipw_write(struct tty_struct *linux_tty,
52737 return -ENODEV;
52738
52739 mutex_lock(&tty->ipw_tty_mutex);
52740 - if (!tty->port.count) {
52741 + if (!atomic_read(&tty->port.count)) {
52742 mutex_unlock(&tty->ipw_tty_mutex);
52743 return -EINVAL;
52744 }
52745 @@ -237,7 +236,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
52746 if (!tty)
52747 return -ENODEV;
52748
52749 - if (!tty->port.count)
52750 + if (!atomic_read(&tty->port.count))
52751 return -EINVAL;
52752
52753 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
52754 @@ -279,7 +278,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
52755 if (!tty)
52756 return 0;
52757
52758 - if (!tty->port.count)
52759 + if (!atomic_read(&tty->port.count))
52760 return 0;
52761
52762 return tty->tx_bytes_queued;
52763 @@ -360,7 +359,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
52764 if (!tty)
52765 return -ENODEV;
52766
52767 - if (!tty->port.count)
52768 + if (!atomic_read(&tty->port.count))
52769 return -EINVAL;
52770
52771 return get_control_lines(tty);
52772 @@ -376,7 +375,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
52773 if (!tty)
52774 return -ENODEV;
52775
52776 - if (!tty->port.count)
52777 + if (!atomic_read(&tty->port.count))
52778 return -EINVAL;
52779
52780 return set_control_lines(tty, set, clear);
52781 @@ -390,7 +389,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
52782 if (!tty)
52783 return -ENODEV;
52784
52785 - if (!tty->port.count)
52786 + if (!atomic_read(&tty->port.count))
52787 return -EINVAL;
52788
52789 /* FIXME: Exactly how is the tty object locked here .. */
52790 @@ -546,7 +545,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
52791 * are gone */
52792 mutex_lock(&ttyj->ipw_tty_mutex);
52793 }
52794 - while (ttyj->port.count)
52795 + while (atomic_read(&ttyj->port.count))
52796 do_ipw_close(ttyj);
52797 ipwireless_disassociate_network_ttys(network,
52798 ttyj->channel_idx);
52799 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
52800 index 14c54e0..1efd4f2 100644
52801 --- a/drivers/tty/moxa.c
52802 +++ b/drivers/tty/moxa.c
52803 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
52804 }
52805
52806 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
52807 - ch->port.count++;
52808 + atomic_inc(&ch->port.count);
52809 tty->driver_data = ch;
52810 tty_port_tty_set(&ch->port, tty);
52811 mutex_lock(&ch->port.mutex);
52812 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
52813 index c434376..114ce13 100644
52814 --- a/drivers/tty/n_gsm.c
52815 +++ b/drivers/tty/n_gsm.c
52816 @@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
52817 spin_lock_init(&dlci->lock);
52818 mutex_init(&dlci->mutex);
52819 dlci->fifo = &dlci->_fifo;
52820 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
52821 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
52822 kfree(dlci);
52823 return NULL;
52824 }
52825 @@ -2958,7 +2958,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
52826 struct gsm_dlci *dlci = tty->driver_data;
52827 struct tty_port *port = &dlci->port;
52828
52829 - port->count++;
52830 + atomic_inc(&port->count);
52831 tty_port_tty_set(port, tty);
52832
52833 dlci->modem_rx = 0;
52834 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
52835 index 2e900a9..576d216 100644
52836 --- a/drivers/tty/n_tty.c
52837 +++ b/drivers/tty/n_tty.c
52838 @@ -115,7 +115,7 @@ struct n_tty_data {
52839 int minimum_to_wake;
52840
52841 /* consumer-published */
52842 - size_t read_tail;
52843 + size_t read_tail __intentional_overflow(-1);
52844 size_t line_start;
52845
52846 /* protected by output lock */
52847 @@ -2522,6 +2522,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
52848 {
52849 *ops = tty_ldisc_N_TTY;
52850 ops->owner = NULL;
52851 - ops->refcount = ops->flags = 0;
52852 + atomic_set(&ops->refcount, 0);
52853 + ops->flags = 0;
52854 }
52855 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
52856 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
52857 index 7c4447a..70fbc1e 100644
52858 --- a/drivers/tty/pty.c
52859 +++ b/drivers/tty/pty.c
52860 @@ -830,8 +830,10 @@ static void __init unix98_pty_init(void)
52861 panic("Couldn't register Unix98 pts driver");
52862
52863 /* Now create the /dev/ptmx special device */
52864 + pax_open_kernel();
52865 tty_default_fops(&ptmx_fops);
52866 - ptmx_fops.open = ptmx_open;
52867 + *(void **)&ptmx_fops.open = ptmx_open;
52868 + pax_close_kernel();
52869
52870 cdev_init(&ptmx_cdev, &ptmx_fops);
52871 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
52872 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
52873 index 383c4c7..d408e21 100644
52874 --- a/drivers/tty/rocket.c
52875 +++ b/drivers/tty/rocket.c
52876 @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
52877 tty->driver_data = info;
52878 tty_port_tty_set(port, tty);
52879
52880 - if (port->count++ == 0) {
52881 + if (atomic_inc_return(&port->count) == 1) {
52882 atomic_inc(&rp_num_ports_open);
52883
52884 #ifdef ROCKET_DEBUG_OPEN
52885 @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
52886 #endif
52887 }
52888 #ifdef ROCKET_DEBUG_OPEN
52889 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
52890 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
52891 #endif
52892
52893 /*
52894 @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
52895 spin_unlock_irqrestore(&info->port.lock, flags);
52896 return;
52897 }
52898 - if (info->port.count)
52899 + if (atomic_read(&info->port.count))
52900 atomic_dec(&rp_num_ports_open);
52901 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
52902 spin_unlock_irqrestore(&info->port.lock, flags);
52903 diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
52904 index aa28209..e08fb85 100644
52905 --- a/drivers/tty/serial/ioc4_serial.c
52906 +++ b/drivers/tty/serial/ioc4_serial.c
52907 @@ -437,7 +437,7 @@ struct ioc4_soft {
52908 } is_intr_info[MAX_IOC4_INTR_ENTS];
52909
52910 /* Number of entries active in the above array */
52911 - atomic_t is_num_intrs;
52912 + atomic_unchecked_t is_num_intrs;
52913 } is_intr_type[IOC4_NUM_INTR_TYPES];
52914
52915 /* is_ir_lock must be held while
52916 @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
52917 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
52918 || (type == IOC4_OTHER_INTR_TYPE)));
52919
52920 - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
52921 + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
52922 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
52923
52924 /* Save off the lower level interrupt handler */
52925 @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
52926
52927 soft = arg;
52928 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
52929 - num_intrs = (int)atomic_read(
52930 + num_intrs = (int)atomic_read_unchecked(
52931 &soft->is_intr_type[intr_type].is_num_intrs);
52932
52933 this_mir = this_ir = pending_intrs(soft, intr_type);
52934 diff --git a/drivers/tty/serial/kgdb_nmi.c b/drivers/tty/serial/kgdb_nmi.c
52935 index 129dc5b..1da5bb8 100644
52936 --- a/drivers/tty/serial/kgdb_nmi.c
52937 +++ b/drivers/tty/serial/kgdb_nmi.c
52938 @@ -53,7 +53,9 @@ static int kgdb_nmi_console_setup(struct console *co, char *options)
52939 * I/O utilities that messages sent to the console will automatically
52940 * be displayed on the dbg_io.
52941 */
52942 - dbg_io_ops->is_console = true;
52943 + pax_open_kernel();
52944 + *(int *)&dbg_io_ops->is_console = true;
52945 + pax_close_kernel();
52946
52947 return 0;
52948 }
52949 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
52950 index a260cde..6b2b5ce 100644
52951 --- a/drivers/tty/serial/kgdboc.c
52952 +++ b/drivers/tty/serial/kgdboc.c
52953 @@ -24,8 +24,9 @@
52954 #define MAX_CONFIG_LEN 40
52955
52956 static struct kgdb_io kgdboc_io_ops;
52957 +static struct kgdb_io kgdboc_io_ops_console;
52958
52959 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
52960 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
52961 static int configured = -1;
52962
52963 static char config[MAX_CONFIG_LEN];
52964 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
52965 kgdboc_unregister_kbd();
52966 if (configured == 1)
52967 kgdb_unregister_io_module(&kgdboc_io_ops);
52968 + else if (configured == 2)
52969 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
52970 }
52971
52972 static int configure_kgdboc(void)
52973 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
52974 int err;
52975 char *cptr = config;
52976 struct console *cons;
52977 + int is_console = 0;
52978
52979 err = kgdboc_option_setup(config);
52980 if (err || !strlen(config) || isspace(config[0]))
52981 goto noconfig;
52982
52983 err = -ENODEV;
52984 - kgdboc_io_ops.is_console = 0;
52985 kgdb_tty_driver = NULL;
52986
52987 kgdboc_use_kms = 0;
52988 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
52989 int idx;
52990 if (cons->device && cons->device(cons, &idx) == p &&
52991 idx == tty_line) {
52992 - kgdboc_io_ops.is_console = 1;
52993 + is_console = 1;
52994 break;
52995 }
52996 cons = cons->next;
52997 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
52998 kgdb_tty_line = tty_line;
52999
53000 do_register:
53001 - err = kgdb_register_io_module(&kgdboc_io_ops);
53002 + if (is_console) {
53003 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
53004 + configured = 2;
53005 + } else {
53006 + err = kgdb_register_io_module(&kgdboc_io_ops);
53007 + configured = 1;
53008 + }
53009 if (err)
53010 goto noconfig;
53011
53012 @@ -205,8 +214,6 @@ do_register:
53013 if (err)
53014 goto nmi_con_failed;
53015
53016 - configured = 1;
53017 -
53018 return 0;
53019
53020 nmi_con_failed:
53021 @@ -223,7 +230,7 @@ noconfig:
53022 static int __init init_kgdboc(void)
53023 {
53024 /* Already configured? */
53025 - if (configured == 1)
53026 + if (configured >= 1)
53027 return 0;
53028
53029 return configure_kgdboc();
53030 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
53031 if (config[len - 1] == '\n')
53032 config[len - 1] = '\0';
53033
53034 - if (configured == 1)
53035 + if (configured >= 1)
53036 cleanup_kgdboc();
53037
53038 /* Go and configure with the new params. */
53039 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
53040 .post_exception = kgdboc_post_exp_handler,
53041 };
53042
53043 +static struct kgdb_io kgdboc_io_ops_console = {
53044 + .name = "kgdboc",
53045 + .read_char = kgdboc_get_char,
53046 + .write_char = kgdboc_put_char,
53047 + .pre_exception = kgdboc_pre_exp_handler,
53048 + .post_exception = kgdboc_post_exp_handler,
53049 + .is_console = 1
53050 +};
53051 +
53052 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
53053 /* This is only available if kgdboc is a built in for early debugging */
53054 static int __init kgdboc_early_init(char *opt)
53055 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
53056 index 4b6c783..9a19db3 100644
53057 --- a/drivers/tty/serial/msm_serial.c
53058 +++ b/drivers/tty/serial/msm_serial.c
53059 @@ -1028,7 +1028,7 @@ static struct uart_driver msm_uart_driver = {
53060 .cons = MSM_CONSOLE,
53061 };
53062
53063 -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
53064 +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
53065
53066 static const struct of_device_id msm_uartdm_table[] = {
53067 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
53068 @@ -1047,7 +1047,7 @@ static int msm_serial_probe(struct platform_device *pdev)
53069 int irq;
53070
53071 if (pdev->id == -1)
53072 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
53073 + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
53074
53075 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
53076 return -ENXIO;
53077 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
53078 index c78f43a..22b1dab 100644
53079 --- a/drivers/tty/serial/samsung.c
53080 +++ b/drivers/tty/serial/samsung.c
53081 @@ -478,11 +478,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
53082 }
53083 }
53084
53085 +static int s3c64xx_serial_startup(struct uart_port *port);
53086 static int s3c24xx_serial_startup(struct uart_port *port)
53087 {
53088 struct s3c24xx_uart_port *ourport = to_ourport(port);
53089 int ret;
53090
53091 + /* Startup sequence is different for s3c64xx and higher SoC's */
53092 + if (s3c24xx_serial_has_interrupt_mask(port))
53093 + return s3c64xx_serial_startup(port);
53094 +
53095 dbg("s3c24xx_serial_startup: port=%p (%08llx,%p)\n",
53096 port, (unsigned long long)port->mapbase, port->membase);
53097
53098 @@ -1155,10 +1160,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
53099 /* setup info for port */
53100 port->dev = &platdev->dev;
53101
53102 - /* Startup sequence is different for s3c64xx and higher SoC's */
53103 - if (s3c24xx_serial_has_interrupt_mask(port))
53104 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
53105 -
53106 port->uartclk = 1;
53107
53108 if (cfg->uart_flags & UPF_CONS_FLOW) {
53109 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
53110 index eaeb9a0..2691250 100644
53111 --- a/drivers/tty/serial/serial_core.c
53112 +++ b/drivers/tty/serial/serial_core.c
53113 @@ -1339,7 +1339,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
53114
53115 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
53116
53117 - if (!port->count || tty_port_close_start(port, tty, filp) == 0)
53118 + if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
53119 return;
53120
53121 /*
53122 @@ -1466,7 +1466,7 @@ static void uart_hangup(struct tty_struct *tty)
53123 uart_flush_buffer(tty);
53124 uart_shutdown(tty, state);
53125 spin_lock_irqsave(&port->lock, flags);
53126 - port->count = 0;
53127 + atomic_set(&port->count, 0);
53128 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
53129 spin_unlock_irqrestore(&port->lock, flags);
53130 tty_port_tty_set(port, NULL);
53131 @@ -1564,7 +1564,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53132 goto end;
53133 }
53134
53135 - port->count++;
53136 + atomic_inc(&port->count);
53137 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
53138 retval = -ENXIO;
53139 goto err_dec_count;
53140 @@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53141 end:
53142 return retval;
53143 err_dec_count:
53144 - port->count--;
53145 + atomic_inc(&port->count);
53146 mutex_unlock(&port->mutex);
53147 goto end;
53148 }
53149 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
53150 index b799170..87dafd5 100644
53151 --- a/drivers/tty/synclink.c
53152 +++ b/drivers/tty/synclink.c
53153 @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53154
53155 if (debug_level >= DEBUG_LEVEL_INFO)
53156 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
53157 - __FILE__,__LINE__, info->device_name, info->port.count);
53158 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
53159
53160 if (tty_port_close_start(&info->port, tty, filp) == 0)
53161 goto cleanup;
53162 @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53163 cleanup:
53164 if (debug_level >= DEBUG_LEVEL_INFO)
53165 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
53166 - tty->driver->name, info->port.count);
53167 + tty->driver->name, atomic_read(&info->port.count));
53168
53169 } /* end of mgsl_close() */
53170
53171 @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
53172
53173 mgsl_flush_buffer(tty);
53174 shutdown(info);
53175 -
53176 - info->port.count = 0;
53177 +
53178 + atomic_set(&info->port.count, 0);
53179 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53180 info->port.tty = NULL;
53181
53182 @@ -3296,10 +3296,10 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53183
53184 if (debug_level >= DEBUG_LEVEL_INFO)
53185 printk("%s(%d):block_til_ready before block on %s count=%d\n",
53186 - __FILE__,__LINE__, tty->driver->name, port->count );
53187 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53188
53189 spin_lock_irqsave(&info->irq_spinlock, flags);
53190 - port->count--;
53191 + atomic_dec(&port->count);
53192 spin_unlock_irqrestore(&info->irq_spinlock, flags);
53193 port->blocked_open++;
53194
53195 @@ -3327,7 +3327,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53196
53197 if (debug_level >= DEBUG_LEVEL_INFO)
53198 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
53199 - __FILE__,__LINE__, tty->driver->name, port->count );
53200 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53201
53202 tty_unlock(tty);
53203 schedule();
53204 @@ -3339,12 +3339,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53205
53206 /* FIXME: Racy on hangup during close wait */
53207 if (!tty_hung_up_p(filp))
53208 - port->count++;
53209 + atomic_inc(&port->count);
53210 port->blocked_open--;
53211
53212 if (debug_level >= DEBUG_LEVEL_INFO)
53213 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
53214 - __FILE__,__LINE__, tty->driver->name, port->count );
53215 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53216
53217 if (!retval)
53218 port->flags |= ASYNC_NORMAL_ACTIVE;
53219 @@ -3396,7 +3396,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53220
53221 if (debug_level >= DEBUG_LEVEL_INFO)
53222 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
53223 - __FILE__,__LINE__,tty->driver->name, info->port.count);
53224 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
53225
53226 /* If port is closing, signal caller to try again */
53227 if (info->port.flags & ASYNC_CLOSING){
53228 @@ -3415,10 +3415,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53229 spin_unlock_irqrestore(&info->netlock, flags);
53230 goto cleanup;
53231 }
53232 - info->port.count++;
53233 + atomic_inc(&info->port.count);
53234 spin_unlock_irqrestore(&info->netlock, flags);
53235
53236 - if (info->port.count == 1) {
53237 + if (atomic_read(&info->port.count) == 1) {
53238 /* 1st open on this device, init hardware */
53239 retval = startup(info);
53240 if (retval < 0)
53241 @@ -3442,8 +3442,8 @@ cleanup:
53242 if (retval) {
53243 if (tty->count == 1)
53244 info->port.tty = NULL; /* tty layer will release tty struct */
53245 - if(info->port.count)
53246 - info->port.count--;
53247 + if (atomic_read(&info->port.count))
53248 + atomic_dec(&info->port.count);
53249 }
53250
53251 return retval;
53252 @@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53253 unsigned short new_crctype;
53254
53255 /* return error if TTY interface open */
53256 - if (info->port.count)
53257 + if (atomic_read(&info->port.count))
53258 return -EBUSY;
53259
53260 switch (encoding)
53261 @@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
53262
53263 /* arbitrate between network and tty opens */
53264 spin_lock_irqsave(&info->netlock, flags);
53265 - if (info->port.count != 0 || info->netcount != 0) {
53266 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53267 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
53268 spin_unlock_irqrestore(&info->netlock, flags);
53269 return -EBUSY;
53270 @@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53271 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
53272
53273 /* return error if TTY interface open */
53274 - if (info->port.count)
53275 + if (atomic_read(&info->port.count))
53276 return -EBUSY;
53277
53278 if (cmd != SIOCWANDEV)
53279 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
53280 index 0e8c39b..e0cb171 100644
53281 --- a/drivers/tty/synclink_gt.c
53282 +++ b/drivers/tty/synclink_gt.c
53283 @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
53284 tty->driver_data = info;
53285 info->port.tty = tty;
53286
53287 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
53288 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
53289
53290 /* If port is closing, signal caller to try again */
53291 if (info->port.flags & ASYNC_CLOSING){
53292 @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
53293 mutex_unlock(&info->port.mutex);
53294 goto cleanup;
53295 }
53296 - info->port.count++;
53297 + atomic_inc(&info->port.count);
53298 spin_unlock_irqrestore(&info->netlock, flags);
53299
53300 - if (info->port.count == 1) {
53301 + if (atomic_read(&info->port.count) == 1) {
53302 /* 1st open on this device, init hardware */
53303 retval = startup(info);
53304 if (retval < 0) {
53305 @@ -715,8 +715,8 @@ cleanup:
53306 if (retval) {
53307 if (tty->count == 1)
53308 info->port.tty = NULL; /* tty layer will release tty struct */
53309 - if(info->port.count)
53310 - info->port.count--;
53311 + if(atomic_read(&info->port.count))
53312 + atomic_dec(&info->port.count);
53313 }
53314
53315 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
53316 @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53317
53318 if (sanity_check(info, tty->name, "close"))
53319 return;
53320 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
53321 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
53322
53323 if (tty_port_close_start(&info->port, tty, filp) == 0)
53324 goto cleanup;
53325 @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53326 tty_port_close_end(&info->port, tty);
53327 info->port.tty = NULL;
53328 cleanup:
53329 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
53330 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
53331 }
53332
53333 static void hangup(struct tty_struct *tty)
53334 @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
53335 shutdown(info);
53336
53337 spin_lock_irqsave(&info->port.lock, flags);
53338 - info->port.count = 0;
53339 + atomic_set(&info->port.count, 0);
53340 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53341 info->port.tty = NULL;
53342 spin_unlock_irqrestore(&info->port.lock, flags);
53343 @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53344 unsigned short new_crctype;
53345
53346 /* return error if TTY interface open */
53347 - if (info->port.count)
53348 + if (atomic_read(&info->port.count))
53349 return -EBUSY;
53350
53351 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
53352 @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
53353
53354 /* arbitrate between network and tty opens */
53355 spin_lock_irqsave(&info->netlock, flags);
53356 - if (info->port.count != 0 || info->netcount != 0) {
53357 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53358 DBGINFO(("%s hdlc_open busy\n", dev->name));
53359 spin_unlock_irqrestore(&info->netlock, flags);
53360 return -EBUSY;
53361 @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53362 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
53363
53364 /* return error if TTY interface open */
53365 - if (info->port.count)
53366 + if (atomic_read(&info->port.count))
53367 return -EBUSY;
53368
53369 if (cmd != SIOCWANDEV)
53370 @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
53371 if (port == NULL)
53372 continue;
53373 spin_lock(&port->lock);
53374 - if ((port->port.count || port->netcount) &&
53375 + if ((atomic_read(&port->port.count) || port->netcount) &&
53376 port->pending_bh && !port->bh_running &&
53377 !port->bh_requested) {
53378 DBGISR(("%s bh queued\n", port->device_name));
53379 @@ -3299,7 +3299,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53380 add_wait_queue(&port->open_wait, &wait);
53381
53382 spin_lock_irqsave(&info->lock, flags);
53383 - port->count--;
53384 + atomic_dec(&port->count);
53385 spin_unlock_irqrestore(&info->lock, flags);
53386 port->blocked_open++;
53387
53388 @@ -3335,7 +3335,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53389 remove_wait_queue(&port->open_wait, &wait);
53390
53391 if (!tty_hung_up_p(filp))
53392 - port->count++;
53393 + atomic_inc(&port->count);
53394 port->blocked_open--;
53395
53396 if (!retval)
53397 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
53398 index c3f9091..abe4601 100644
53399 --- a/drivers/tty/synclinkmp.c
53400 +++ b/drivers/tty/synclinkmp.c
53401 @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
53402
53403 if (debug_level >= DEBUG_LEVEL_INFO)
53404 printk("%s(%d):%s open(), old ref count = %d\n",
53405 - __FILE__,__LINE__,tty->driver->name, info->port.count);
53406 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
53407
53408 /* If port is closing, signal caller to try again */
53409 if (info->port.flags & ASYNC_CLOSING){
53410 @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
53411 spin_unlock_irqrestore(&info->netlock, flags);
53412 goto cleanup;
53413 }
53414 - info->port.count++;
53415 + atomic_inc(&info->port.count);
53416 spin_unlock_irqrestore(&info->netlock, flags);
53417
53418 - if (info->port.count == 1) {
53419 + if (atomic_read(&info->port.count) == 1) {
53420 /* 1st open on this device, init hardware */
53421 retval = startup(info);
53422 if (retval < 0)
53423 @@ -796,8 +796,8 @@ cleanup:
53424 if (retval) {
53425 if (tty->count == 1)
53426 info->port.tty = NULL; /* tty layer will release tty struct */
53427 - if(info->port.count)
53428 - info->port.count--;
53429 + if(atomic_read(&info->port.count))
53430 + atomic_dec(&info->port.count);
53431 }
53432
53433 return retval;
53434 @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53435
53436 if (debug_level >= DEBUG_LEVEL_INFO)
53437 printk("%s(%d):%s close() entry, count=%d\n",
53438 - __FILE__,__LINE__, info->device_name, info->port.count);
53439 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
53440
53441 if (tty_port_close_start(&info->port, tty, filp) == 0)
53442 goto cleanup;
53443 @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53444 cleanup:
53445 if (debug_level >= DEBUG_LEVEL_INFO)
53446 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
53447 - tty->driver->name, info->port.count);
53448 + tty->driver->name, atomic_read(&info->port.count));
53449 }
53450
53451 /* Called by tty_hangup() when a hangup is signaled.
53452 @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
53453 shutdown(info);
53454
53455 spin_lock_irqsave(&info->port.lock, flags);
53456 - info->port.count = 0;
53457 + atomic_set(&info->port.count, 0);
53458 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53459 info->port.tty = NULL;
53460 spin_unlock_irqrestore(&info->port.lock, flags);
53461 @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53462 unsigned short new_crctype;
53463
53464 /* return error if TTY interface open */
53465 - if (info->port.count)
53466 + if (atomic_read(&info->port.count))
53467 return -EBUSY;
53468
53469 switch (encoding)
53470 @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
53471
53472 /* arbitrate between network and tty opens */
53473 spin_lock_irqsave(&info->netlock, flags);
53474 - if (info->port.count != 0 || info->netcount != 0) {
53475 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53476 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
53477 spin_unlock_irqrestore(&info->netlock, flags);
53478 return -EBUSY;
53479 @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53480 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
53481
53482 /* return error if TTY interface open */
53483 - if (info->port.count)
53484 + if (atomic_read(&info->port.count))
53485 return -EBUSY;
53486
53487 if (cmd != SIOCWANDEV)
53488 @@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
53489 * do not request bottom half processing if the
53490 * device is not open in a normal mode.
53491 */
53492 - if ( port && (port->port.count || port->netcount) &&
53493 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
53494 port->pending_bh && !port->bh_running &&
53495 !port->bh_requested ) {
53496 if ( debug_level >= DEBUG_LEVEL_ISR )
53497 @@ -3318,10 +3318,10 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53498
53499 if (debug_level >= DEBUG_LEVEL_INFO)
53500 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
53501 - __FILE__,__LINE__, tty->driver->name, port->count );
53502 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53503
53504 spin_lock_irqsave(&info->lock, flags);
53505 - port->count--;
53506 + atomic_dec(&port->count);
53507 spin_unlock_irqrestore(&info->lock, flags);
53508 port->blocked_open++;
53509
53510 @@ -3349,7 +3349,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53511
53512 if (debug_level >= DEBUG_LEVEL_INFO)
53513 printk("%s(%d):%s block_til_ready() count=%d\n",
53514 - __FILE__,__LINE__, tty->driver->name, port->count );
53515 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53516
53517 tty_unlock(tty);
53518 schedule();
53519 @@ -3359,12 +3359,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53520 set_current_state(TASK_RUNNING);
53521 remove_wait_queue(&port->open_wait, &wait);
53522 if (!tty_hung_up_p(filp))
53523 - port->count++;
53524 + atomic_inc(&port->count);
53525 port->blocked_open--;
53526
53527 if (debug_level >= DEBUG_LEVEL_INFO)
53528 printk("%s(%d):%s block_til_ready() after, count=%d\n",
53529 - __FILE__,__LINE__, tty->driver->name, port->count );
53530 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53531
53532 if (!retval)
53533 port->flags |= ASYNC_NORMAL_ACTIVE;
53534 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
53535 index 42bad18..447d7a2 100644
53536 --- a/drivers/tty/sysrq.c
53537 +++ b/drivers/tty/sysrq.c
53538 @@ -1084,7 +1084,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
53539 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
53540 size_t count, loff_t *ppos)
53541 {
53542 - if (count) {
53543 + if (count && capable(CAP_SYS_ADMIN)) {
53544 char c;
53545
53546 if (get_user(c, buf))
53547 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
53548 index 0508a1d..b610592 100644
53549 --- a/drivers/tty/tty_io.c
53550 +++ b/drivers/tty/tty_io.c
53551 @@ -3498,7 +3498,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
53552
53553 void tty_default_fops(struct file_operations *fops)
53554 {
53555 - *fops = tty_fops;
53556 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
53557 }
53558
53559 /*
53560 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
53561 index 2d822aa..a566234 100644
53562 --- a/drivers/tty/tty_ldisc.c
53563 +++ b/drivers/tty/tty_ldisc.c
53564 @@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
53565 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53566 tty_ldiscs[disc] = new_ldisc;
53567 new_ldisc->num = disc;
53568 - new_ldisc->refcount = 0;
53569 + atomic_set(&new_ldisc->refcount, 0);
53570 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
53571
53572 return ret;
53573 @@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
53574 return -EINVAL;
53575
53576 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53577 - if (tty_ldiscs[disc]->refcount)
53578 + if (atomic_read(&tty_ldiscs[disc]->refcount))
53579 ret = -EBUSY;
53580 else
53581 tty_ldiscs[disc] = NULL;
53582 @@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
53583 if (ldops) {
53584 ret = ERR_PTR(-EAGAIN);
53585 if (try_module_get(ldops->owner)) {
53586 - ldops->refcount++;
53587 + atomic_inc(&ldops->refcount);
53588 ret = ldops;
53589 }
53590 }
53591 @@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
53592 unsigned long flags;
53593
53594 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53595 - ldops->refcount--;
53596 + atomic_dec(&ldops->refcount);
53597 module_put(ldops->owner);
53598 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
53599 }
53600 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
53601 index 1b93357..ea9f82c 100644
53602 --- a/drivers/tty/tty_port.c
53603 +++ b/drivers/tty/tty_port.c
53604 @@ -237,7 +237,7 @@ void tty_port_hangup(struct tty_port *port)
53605 unsigned long flags;
53606
53607 spin_lock_irqsave(&port->lock, flags);
53608 - port->count = 0;
53609 + atomic_set(&port->count, 0);
53610 port->flags &= ~ASYNC_NORMAL_ACTIVE;
53611 tty = port->tty;
53612 if (tty)
53613 @@ -399,7 +399,7 @@ int tty_port_block_til_ready(struct tty_port *port,
53614
53615 /* The port lock protects the port counts */
53616 spin_lock_irqsave(&port->lock, flags);
53617 - port->count--;
53618 + atomic_dec(&port->count);
53619 port->blocked_open++;
53620 spin_unlock_irqrestore(&port->lock, flags);
53621
53622 @@ -441,7 +441,7 @@ int tty_port_block_til_ready(struct tty_port *port,
53623 we must not mess that up further */
53624 spin_lock_irqsave(&port->lock, flags);
53625 if (!tty_hung_up_p(filp))
53626 - port->count++;
53627 + atomic_inc(&port->count);
53628 port->blocked_open--;
53629 if (retval == 0)
53630 port->flags |= ASYNC_NORMAL_ACTIVE;
53631 @@ -479,19 +479,19 @@ int tty_port_close_start(struct tty_port *port,
53632 return 0;
53633 }
53634
53635 - if (tty->count == 1 && port->count != 1) {
53636 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
53637 printk(KERN_WARNING
53638 "tty_port_close_start: tty->count = 1 port count = %d.\n",
53639 - port->count);
53640 - port->count = 1;
53641 + atomic_read(&port->count));
53642 + atomic_set(&port->count, 1);
53643 }
53644 - if (--port->count < 0) {
53645 + if (atomic_dec_return(&port->count) < 0) {
53646 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
53647 - port->count);
53648 - port->count = 0;
53649 + atomic_read(&port->count));
53650 + atomic_set(&port->count, 0);
53651 }
53652
53653 - if (port->count) {
53654 + if (atomic_read(&port->count)) {
53655 spin_unlock_irqrestore(&port->lock, flags);
53656 return 0;
53657 }
53658 @@ -592,7 +592,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
53659 struct file *filp)
53660 {
53661 spin_lock_irq(&port->lock);
53662 - ++port->count;
53663 + atomic_inc(&port->count);
53664 spin_unlock_irq(&port->lock);
53665 tty_port_tty_set(port, tty);
53666
53667 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
53668 index c039cfe..0b463b0 100644
53669 --- a/drivers/tty/vt/keyboard.c
53670 +++ b/drivers/tty/vt/keyboard.c
53671 @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
53672 kbd->kbdmode == VC_OFF) &&
53673 value != KVAL(K_SAK))
53674 return; /* SAK is allowed even in raw mode */
53675 +
53676 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
53677 + {
53678 + void *func = fn_handler[value];
53679 + if (func == fn_show_state || func == fn_show_ptregs ||
53680 + func == fn_show_mem)
53681 + return;
53682 + }
53683 +#endif
53684 +
53685 fn_handler[value](vc);
53686 }
53687
53688 @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
53689 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
53690 return -EFAULT;
53691
53692 - if (!capable(CAP_SYS_TTY_CONFIG))
53693 - perm = 0;
53694 -
53695 switch (cmd) {
53696 case KDGKBENT:
53697 /* Ensure another thread doesn't free it under us */
53698 @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
53699 spin_unlock_irqrestore(&kbd_event_lock, flags);
53700 return put_user(val, &user_kbe->kb_value);
53701 case KDSKBENT:
53702 + if (!capable(CAP_SYS_TTY_CONFIG))
53703 + perm = 0;
53704 +
53705 if (!perm)
53706 return -EPERM;
53707 if (!i && v == K_NOSUCHMAP) {
53708 @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
53709 int i, j, k;
53710 int ret;
53711
53712 - if (!capable(CAP_SYS_TTY_CONFIG))
53713 - perm = 0;
53714 -
53715 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
53716 if (!kbs) {
53717 ret = -ENOMEM;
53718 @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
53719 kfree(kbs);
53720 return ((p && *p) ? -EOVERFLOW : 0);
53721 case KDSKBSENT:
53722 + if (!capable(CAP_SYS_TTY_CONFIG))
53723 + perm = 0;
53724 +
53725 if (!perm) {
53726 ret = -EPERM;
53727 goto reterr;
53728 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
53729 index 60fa627..7214965 100644
53730 --- a/drivers/uio/uio.c
53731 +++ b/drivers/uio/uio.c
53732 @@ -25,6 +25,7 @@
53733 #include <linux/kobject.h>
53734 #include <linux/cdev.h>
53735 #include <linux/uio_driver.h>
53736 +#include <asm/local.h>
53737
53738 #define UIO_MAX_DEVICES (1U << MINORBITS)
53739
53740 @@ -231,7 +232,7 @@ static ssize_t event_show(struct device *dev,
53741 struct device_attribute *attr, char *buf)
53742 {
53743 struct uio_device *idev = dev_get_drvdata(dev);
53744 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
53745 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
53746 }
53747 static DEVICE_ATTR_RO(event);
53748
53749 @@ -393,7 +394,7 @@ void uio_event_notify(struct uio_info *info)
53750 {
53751 struct uio_device *idev = info->uio_dev;
53752
53753 - atomic_inc(&idev->event);
53754 + atomic_inc_unchecked(&idev->event);
53755 wake_up_interruptible(&idev->wait);
53756 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
53757 }
53758 @@ -446,7 +447,7 @@ static int uio_open(struct inode *inode, struct file *filep)
53759 }
53760
53761 listener->dev = idev;
53762 - listener->event_count = atomic_read(&idev->event);
53763 + listener->event_count = atomic_read_unchecked(&idev->event);
53764 filep->private_data = listener;
53765
53766 if (idev->info->open) {
53767 @@ -497,7 +498,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
53768 return -EIO;
53769
53770 poll_wait(filep, &idev->wait, wait);
53771 - if (listener->event_count != atomic_read(&idev->event))
53772 + if (listener->event_count != atomic_read_unchecked(&idev->event))
53773 return POLLIN | POLLRDNORM;
53774 return 0;
53775 }
53776 @@ -522,7 +523,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
53777 do {
53778 set_current_state(TASK_INTERRUPTIBLE);
53779
53780 - event_count = atomic_read(&idev->event);
53781 + event_count = atomic_read_unchecked(&idev->event);
53782 if (event_count != listener->event_count) {
53783 if (copy_to_user(buf, &event_count, count))
53784 retval = -EFAULT;
53785 @@ -579,9 +580,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
53786 static int uio_find_mem_index(struct vm_area_struct *vma)
53787 {
53788 struct uio_device *idev = vma->vm_private_data;
53789 + unsigned long size;
53790
53791 if (vma->vm_pgoff < MAX_UIO_MAPS) {
53792 - if (idev->info->mem[vma->vm_pgoff].size == 0)
53793 + size = idev->info->mem[vma->vm_pgoff].size;
53794 + if (size == 0)
53795 + return -1;
53796 + if (vma->vm_end - vma->vm_start > size)
53797 return -1;
53798 return (int)vma->vm_pgoff;
53799 }
53800 @@ -813,7 +818,7 @@ int __uio_register_device(struct module *owner,
53801 idev->owner = owner;
53802 idev->info = info;
53803 init_waitqueue_head(&idev->wait);
53804 - atomic_set(&idev->event, 0);
53805 + atomic_set_unchecked(&idev->event, 0);
53806
53807 ret = uio_get_minor(idev);
53808 if (ret)
53809 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
53810 index 813d4d3..a71934f 100644
53811 --- a/drivers/usb/atm/cxacru.c
53812 +++ b/drivers/usb/atm/cxacru.c
53813 @@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
53814 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
53815 if (ret < 2)
53816 return -EINVAL;
53817 - if (index < 0 || index > 0x7f)
53818 + if (index > 0x7f)
53819 return -EINVAL;
53820 pos += tmp;
53821
53822 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
53823 index dada014..1d0d517 100644
53824 --- a/drivers/usb/atm/usbatm.c
53825 +++ b/drivers/usb/atm/usbatm.c
53826 @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
53827 if (printk_ratelimit())
53828 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
53829 __func__, vpi, vci);
53830 - atomic_inc(&vcc->stats->rx_err);
53831 + atomic_inc_unchecked(&vcc->stats->rx_err);
53832 return;
53833 }
53834
53835 @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
53836 if (length > ATM_MAX_AAL5_PDU) {
53837 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
53838 __func__, length, vcc);
53839 - atomic_inc(&vcc->stats->rx_err);
53840 + atomic_inc_unchecked(&vcc->stats->rx_err);
53841 goto out;
53842 }
53843
53844 @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
53845 if (sarb->len < pdu_length) {
53846 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
53847 __func__, pdu_length, sarb->len, vcc);
53848 - atomic_inc(&vcc->stats->rx_err);
53849 + atomic_inc_unchecked(&vcc->stats->rx_err);
53850 goto out;
53851 }
53852
53853 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
53854 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
53855 __func__, vcc);
53856 - atomic_inc(&vcc->stats->rx_err);
53857 + atomic_inc_unchecked(&vcc->stats->rx_err);
53858 goto out;
53859 }
53860
53861 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
53862 if (printk_ratelimit())
53863 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
53864 __func__, length);
53865 - atomic_inc(&vcc->stats->rx_drop);
53866 + atomic_inc_unchecked(&vcc->stats->rx_drop);
53867 goto out;
53868 }
53869
53870 @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
53871
53872 vcc->push(vcc, skb);
53873
53874 - atomic_inc(&vcc->stats->rx);
53875 + atomic_inc_unchecked(&vcc->stats->rx);
53876 out:
53877 skb_trim(sarb, 0);
53878 }
53879 @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
53880 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
53881
53882 usbatm_pop(vcc, skb);
53883 - atomic_inc(&vcc->stats->tx);
53884 + atomic_inc_unchecked(&vcc->stats->tx);
53885
53886 skb = skb_dequeue(&instance->sndqueue);
53887 }
53888 @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
53889 if (!left--)
53890 return sprintf(page,
53891 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
53892 - atomic_read(&atm_dev->stats.aal5.tx),
53893 - atomic_read(&atm_dev->stats.aal5.tx_err),
53894 - atomic_read(&atm_dev->stats.aal5.rx),
53895 - atomic_read(&atm_dev->stats.aal5.rx_err),
53896 - atomic_read(&atm_dev->stats.aal5.rx_drop));
53897 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
53898 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
53899 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
53900 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
53901 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
53902
53903 if (!left--) {
53904 if (instance->disconnected)
53905 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
53906 index 2a3bbdf..91d72cf 100644
53907 --- a/drivers/usb/core/devices.c
53908 +++ b/drivers/usb/core/devices.c
53909 @@ -126,7 +126,7 @@ static const char format_endpt[] =
53910 * time it gets called.
53911 */
53912 static struct device_connect_event {
53913 - atomic_t count;
53914 + atomic_unchecked_t count;
53915 wait_queue_head_t wait;
53916 } device_event = {
53917 .count = ATOMIC_INIT(1),
53918 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
53919
53920 void usbfs_conn_disc_event(void)
53921 {
53922 - atomic_add(2, &device_event.count);
53923 + atomic_add_unchecked(2, &device_event.count);
53924 wake_up(&device_event.wait);
53925 }
53926
53927 @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
53928
53929 poll_wait(file, &device_event.wait, wait);
53930
53931 - event_count = atomic_read(&device_event.count);
53932 + event_count = atomic_read_unchecked(&device_event.count);
53933 if (file->f_version != event_count) {
53934 file->f_version = event_count;
53935 return POLLIN | POLLRDNORM;
53936 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
53937 index 0b59731..46ee7d1 100644
53938 --- a/drivers/usb/core/devio.c
53939 +++ b/drivers/usb/core/devio.c
53940 @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
53941 struct usb_dev_state *ps = file->private_data;
53942 struct usb_device *dev = ps->dev;
53943 ssize_t ret = 0;
53944 - unsigned len;
53945 + size_t len;
53946 loff_t pos;
53947 int i;
53948
53949 @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
53950 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
53951 struct usb_config_descriptor *config =
53952 (struct usb_config_descriptor *)dev->rawdescriptors[i];
53953 - unsigned int length = le16_to_cpu(config->wTotalLength);
53954 + size_t length = le16_to_cpu(config->wTotalLength);
53955
53956 if (*ppos < pos + length) {
53957
53958 /* The descriptor may claim to be longer than it
53959 * really is. Here is the actual allocated length. */
53960 - unsigned alloclen =
53961 + size_t alloclen =
53962 le16_to_cpu(dev->config[i].desc.wTotalLength);
53963
53964 - len = length - (*ppos - pos);
53965 + len = length + pos - *ppos;
53966 if (len > nbytes)
53967 len = nbytes;
53968
53969 /* Simply don't write (skip over) unallocated parts */
53970 if (alloclen > (*ppos - pos)) {
53971 - alloclen -= (*ppos - pos);
53972 + alloclen = alloclen + pos - *ppos;
53973 if (copy_to_user(buf,
53974 dev->rawdescriptors[i] + (*ppos - pos),
53975 min(len, alloclen))) {
53976 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
53977 index a6efb41..6f72549b 100644
53978 --- a/drivers/usb/core/hcd.c
53979 +++ b/drivers/usb/core/hcd.c
53980 @@ -1551,7 +1551,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
53981 */
53982 usb_get_urb(urb);
53983 atomic_inc(&urb->use_count);
53984 - atomic_inc(&urb->dev->urbnum);
53985 + atomic_inc_unchecked(&urb->dev->urbnum);
53986 usbmon_urb_submit(&hcd->self, urb);
53987
53988 /* NOTE requirements on root-hub callers (usbfs and the hub
53989 @@ -1578,7 +1578,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
53990 urb->hcpriv = NULL;
53991 INIT_LIST_HEAD(&urb->urb_list);
53992 atomic_dec(&urb->use_count);
53993 - atomic_dec(&urb->dev->urbnum);
53994 + atomic_dec_unchecked(&urb->dev->urbnum);
53995 if (atomic_read(&urb->reject))
53996 wake_up(&usb_kill_urb_queue);
53997 usb_put_urb(urb);
53998 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
53999 index b649fef..c7107a0 100644
54000 --- a/drivers/usb/core/hub.c
54001 +++ b/drivers/usb/core/hub.c
54002 @@ -26,6 +26,7 @@
54003 #include <linux/mutex.h>
54004 #include <linux/random.h>
54005 #include <linux/pm_qos.h>
54006 +#include <linux/grsecurity.h>
54007
54008 #include <asm/uaccess.h>
54009 #include <asm/byteorder.h>
54010 @@ -4666,6 +4667,10 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
54011 goto done;
54012 return;
54013 }
54014 +
54015 + if (gr_handle_new_usb())
54016 + goto done;
54017 +
54018 if (hub_is_superspeed(hub->hdev))
54019 unit_load = 150;
54020 else
54021 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
54022 index f7b7713..23d07ec 100644
54023 --- a/drivers/usb/core/message.c
54024 +++ b/drivers/usb/core/message.c
54025 @@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
54026 * Return: If successful, the number of bytes transferred. Otherwise, a negative
54027 * error number.
54028 */
54029 -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54030 +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54031 __u8 requesttype, __u16 value, __u16 index, void *data,
54032 __u16 size, int timeout)
54033 {
54034 @@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
54035 * If successful, 0. Otherwise a negative error number. The number of actual
54036 * bytes transferred will be stored in the @actual_length parameter.
54037 */
54038 -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54039 +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54040 void *data, int len, int *actual_length, int timeout)
54041 {
54042 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
54043 @@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
54044 * bytes transferred will be stored in the @actual_length parameter.
54045 *
54046 */
54047 -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54048 +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54049 void *data, int len, int *actual_length, int timeout)
54050 {
54051 struct urb *urb;
54052 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
54053 index 1236c60..d47a51c 100644
54054 --- a/drivers/usb/core/sysfs.c
54055 +++ b/drivers/usb/core/sysfs.c
54056 @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
54057 struct usb_device *udev;
54058
54059 udev = to_usb_device(dev);
54060 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
54061 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
54062 }
54063 static DEVICE_ATTR_RO(urbnum);
54064
54065 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
54066 index 2dd2362..1135437 100644
54067 --- a/drivers/usb/core/usb.c
54068 +++ b/drivers/usb/core/usb.c
54069 @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
54070 set_dev_node(&dev->dev, dev_to_node(bus->controller));
54071 dev->state = USB_STATE_ATTACHED;
54072 dev->lpm_disable_count = 1;
54073 - atomic_set(&dev->urbnum, 0);
54074 + atomic_set_unchecked(&dev->urbnum, 0);
54075
54076 INIT_LIST_HEAD(&dev->ep0.urb_list);
54077 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
54078 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
54079 index 8cfc319..4868255 100644
54080 --- a/drivers/usb/early/ehci-dbgp.c
54081 +++ b/drivers/usb/early/ehci-dbgp.c
54082 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
54083
54084 #ifdef CONFIG_KGDB
54085 static struct kgdb_io kgdbdbgp_io_ops;
54086 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
54087 +static struct kgdb_io kgdbdbgp_io_ops_console;
54088 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
54089 #else
54090 #define dbgp_kgdb_mode (0)
54091 #endif
54092 @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
54093 .write_char = kgdbdbgp_write_char,
54094 };
54095
54096 +static struct kgdb_io kgdbdbgp_io_ops_console = {
54097 + .name = "kgdbdbgp",
54098 + .read_char = kgdbdbgp_read_char,
54099 + .write_char = kgdbdbgp_write_char,
54100 + .is_console = 1
54101 +};
54102 +
54103 static int kgdbdbgp_wait_time;
54104
54105 static int __init kgdbdbgp_parse_config(char *str)
54106 @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
54107 ptr++;
54108 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
54109 }
54110 - kgdb_register_io_module(&kgdbdbgp_io_ops);
54111 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
54112 + if (early_dbgp_console.index != -1)
54113 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
54114 + else
54115 + kgdb_register_io_module(&kgdbdbgp_io_ops);
54116
54117 return 0;
54118 }
54119 diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c
54120 index f7b2032..fbb340c 100644
54121 --- a/drivers/usb/gadget/function/f_uac1.c
54122 +++ b/drivers/usb/gadget/function/f_uac1.c
54123 @@ -14,6 +14,7 @@
54124 #include <linux/module.h>
54125 #include <linux/device.h>
54126 #include <linux/atomic.h>
54127 +#include <linux/module.h>
54128
54129 #include "u_uac1.h"
54130
54131 diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
54132 index 491082a..dfd7d17 100644
54133 --- a/drivers/usb/gadget/function/u_serial.c
54134 +++ b/drivers/usb/gadget/function/u_serial.c
54135 @@ -729,9 +729,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54136 spin_lock_irq(&port->port_lock);
54137
54138 /* already open? Great. */
54139 - if (port->port.count) {
54140 + if (atomic_read(&port->port.count)) {
54141 status = 0;
54142 - port->port.count++;
54143 + atomic_inc(&port->port.count);
54144
54145 /* currently opening/closing? wait ... */
54146 } else if (port->openclose) {
54147 @@ -790,7 +790,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54148 tty->driver_data = port;
54149 port->port.tty = tty;
54150
54151 - port->port.count = 1;
54152 + atomic_set(&port->port.count, 1);
54153 port->openclose = false;
54154
54155 /* if connected, start the I/O stream */
54156 @@ -832,11 +832,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54157
54158 spin_lock_irq(&port->port_lock);
54159
54160 - if (port->port.count != 1) {
54161 - if (port->port.count == 0)
54162 + if (atomic_read(&port->port.count) != 1) {
54163 + if (atomic_read(&port->port.count) == 0)
54164 WARN_ON(1);
54165 else
54166 - --port->port.count;
54167 + atomic_dec(&port->port.count);
54168 goto exit;
54169 }
54170
54171 @@ -846,7 +846,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54172 * and sleep if necessary
54173 */
54174 port->openclose = true;
54175 - port->port.count = 0;
54176 + atomic_set(&port->port.count, 0);
54177
54178 gser = port->port_usb;
54179 if (gser && gser->disconnect)
54180 @@ -1062,7 +1062,7 @@ static int gs_closed(struct gs_port *port)
54181 int cond;
54182
54183 spin_lock_irq(&port->port_lock);
54184 - cond = (port->port.count == 0) && !port->openclose;
54185 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
54186 spin_unlock_irq(&port->port_lock);
54187 return cond;
54188 }
54189 @@ -1205,7 +1205,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
54190 /* if it's already open, start I/O ... and notify the serial
54191 * protocol about open/close status (connect/disconnect).
54192 */
54193 - if (port->port.count) {
54194 + if (atomic_read(&port->port.count)) {
54195 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
54196 gs_start_io(port);
54197 if (gser->connect)
54198 @@ -1252,7 +1252,7 @@ void gserial_disconnect(struct gserial *gser)
54199
54200 port->port_usb = NULL;
54201 gser->ioport = NULL;
54202 - if (port->port.count > 0 || port->openclose) {
54203 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
54204 wake_up_interruptible(&port->drain_wait);
54205 if (port->port.tty)
54206 tty_hangup(port->port.tty);
54207 @@ -1268,7 +1268,7 @@ void gserial_disconnect(struct gserial *gser)
54208
54209 /* finally, free any unused/unusable I/O buffers */
54210 spin_lock_irqsave(&port->port_lock, flags);
54211 - if (port->port.count == 0 && !port->openclose)
54212 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
54213 gs_buf_free(&port->port_write_buf);
54214 gs_free_requests(gser->out, &port->read_pool, NULL);
54215 gs_free_requests(gser->out, &port->read_queue, NULL);
54216 diff --git a/drivers/usb/gadget/function/u_uac1.c b/drivers/usb/gadget/function/u_uac1.c
54217 index a44a07f..ecea924 100644
54218 --- a/drivers/usb/gadget/function/u_uac1.c
54219 +++ b/drivers/usb/gadget/function/u_uac1.c
54220 @@ -17,6 +17,7 @@
54221 #include <linux/ctype.h>
54222 #include <linux/random.h>
54223 #include <linux/syscalls.h>
54224 +#include <linux/module.h>
54225
54226 #include "u_uac1.h"
54227
54228 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
54229 index 5728829..fefc6bf 100644
54230 --- a/drivers/usb/host/ehci-hub.c
54231 +++ b/drivers/usb/host/ehci-hub.c
54232 @@ -771,7 +771,7 @@ static struct urb *request_single_step_set_feature_urb(
54233 urb->transfer_flags = URB_DIR_IN;
54234 usb_get_urb(urb);
54235 atomic_inc(&urb->use_count);
54236 - atomic_inc(&urb->dev->urbnum);
54237 + atomic_inc_unchecked(&urb->dev->urbnum);
54238 urb->setup_dma = dma_map_single(
54239 hcd->self.controller,
54240 urb->setup_packet,
54241 @@ -838,7 +838,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
54242 urb->status = -EINPROGRESS;
54243 usb_get_urb(urb);
54244 atomic_inc(&urb->use_count);
54245 - atomic_inc(&urb->dev->urbnum);
54246 + atomic_inc_unchecked(&urb->dev->urbnum);
54247 retval = submit_single_step_set_feature(hcd, urb, 0);
54248 if (!retval && !wait_for_completion_timeout(&done,
54249 msecs_to_jiffies(2000))) {
54250 diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
54251 index 1db0626..4948782 100644
54252 --- a/drivers/usb/host/hwa-hc.c
54253 +++ b/drivers/usb/host/hwa-hc.c
54254 @@ -337,7 +337,10 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
54255 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
54256 struct wahc *wa = &hwahc->wa;
54257 struct device *dev = &wa->usb_iface->dev;
54258 - u8 mas_le[UWB_NUM_MAS/8];
54259 + u8 *mas_le = kmalloc(UWB_NUM_MAS/8, GFP_KERNEL);
54260 +
54261 + if (mas_le == NULL)
54262 + return -ENOMEM;
54263
54264 /* Set the stream index */
54265 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
54266 @@ -356,10 +359,12 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
54267 WUSB_REQ_SET_WUSB_MAS,
54268 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
54269 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
54270 - mas_le, 32, USB_CTRL_SET_TIMEOUT);
54271 + mas_le, UWB_NUM_MAS/8, USB_CTRL_SET_TIMEOUT);
54272 if (result < 0)
54273 dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result);
54274 out:
54275 + kfree(mas_le);
54276 +
54277 return result;
54278 }
54279
54280 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
54281 index b3d245e..99549ed 100644
54282 --- a/drivers/usb/misc/appledisplay.c
54283 +++ b/drivers/usb/misc/appledisplay.c
54284 @@ -84,7 +84,7 @@ struct appledisplay {
54285 struct mutex sysfslock; /* concurrent read and write */
54286 };
54287
54288 -static atomic_t count_displays = ATOMIC_INIT(0);
54289 +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
54290 static struct workqueue_struct *wq;
54291
54292 static void appledisplay_complete(struct urb *urb)
54293 @@ -288,7 +288,7 @@ static int appledisplay_probe(struct usb_interface *iface,
54294
54295 /* Register backlight device */
54296 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
54297 - atomic_inc_return(&count_displays) - 1);
54298 + atomic_inc_return_unchecked(&count_displays) - 1);
54299 memset(&props, 0, sizeof(struct backlight_properties));
54300 props.type = BACKLIGHT_RAW;
54301 props.max_brightness = 0xff;
54302 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
54303 index 8d7fc48..01c4986 100644
54304 --- a/drivers/usb/serial/console.c
54305 +++ b/drivers/usb/serial/console.c
54306 @@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
54307
54308 info->port = port;
54309
54310 - ++port->port.count;
54311 + atomic_inc(&port->port.count);
54312 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
54313 if (serial->type->set_termios) {
54314 /*
54315 @@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
54316 }
54317 /* Now that any required fake tty operations are completed restore
54318 * the tty port count */
54319 - --port->port.count;
54320 + atomic_dec(&port->port.count);
54321 /* The console is special in terms of closing the device so
54322 * indicate this port is now acting as a system console. */
54323 port->port.console = 1;
54324 @@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
54325 free_tty:
54326 kfree(tty);
54327 reset_open_count:
54328 - port->port.count = 0;
54329 + atomic_set(&port->port.count, 0);
54330 usb_autopm_put_interface(serial->interface);
54331 error_get_interface:
54332 usb_serial_put(serial);
54333 @@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
54334 static void usb_console_write(struct console *co,
54335 const char *buf, unsigned count)
54336 {
54337 - static struct usbcons_info *info = &usbcons_info;
54338 + struct usbcons_info *info = &usbcons_info;
54339 struct usb_serial_port *port = info->port;
54340 struct usb_serial *serial;
54341 int retval = -ENODEV;
54342 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
54343 index 307e339..6aa97cb 100644
54344 --- a/drivers/usb/storage/usb.h
54345 +++ b/drivers/usb/storage/usb.h
54346 @@ -63,7 +63,7 @@ struct us_unusual_dev {
54347 __u8 useProtocol;
54348 __u8 useTransport;
54349 int (*initFunction)(struct us_data *);
54350 -};
54351 +} __do_const;
54352
54353
54354 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
54355 diff --git a/drivers/usb/usbip/vhci.h b/drivers/usb/usbip/vhci.h
54356 index a863a98..d272795 100644
54357 --- a/drivers/usb/usbip/vhci.h
54358 +++ b/drivers/usb/usbip/vhci.h
54359 @@ -83,7 +83,7 @@ struct vhci_hcd {
54360 unsigned resuming:1;
54361 unsigned long re_timeout;
54362
54363 - atomic_t seqnum;
54364 + atomic_unchecked_t seqnum;
54365
54366 /*
54367 * NOTE:
54368 diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
54369 index c02374b..32d47a9 100644
54370 --- a/drivers/usb/usbip/vhci_hcd.c
54371 +++ b/drivers/usb/usbip/vhci_hcd.c
54372 @@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
54373
54374 spin_lock(&vdev->priv_lock);
54375
54376 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
54377 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
54378 if (priv->seqnum == 0xffff)
54379 dev_info(&urb->dev->dev, "seqnum max\n");
54380
54381 @@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
54382 return -ENOMEM;
54383 }
54384
54385 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
54386 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
54387 if (unlink->seqnum == 0xffff)
54388 pr_info("seqnum max\n");
54389
54390 @@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
54391 vdev->rhport = rhport;
54392 }
54393
54394 - atomic_set(&vhci->seqnum, 0);
54395 + atomic_set_unchecked(&vhci->seqnum, 0);
54396 spin_lock_init(&vhci->lock);
54397
54398 hcd->power_budget = 0; /* no limit */
54399 diff --git a/drivers/usb/usbip/vhci_rx.c b/drivers/usb/usbip/vhci_rx.c
54400 index 00e4a54..d676f85 100644
54401 --- a/drivers/usb/usbip/vhci_rx.c
54402 +++ b/drivers/usb/usbip/vhci_rx.c
54403 @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
54404 if (!urb) {
54405 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
54406 pr_info("max seqnum %d\n",
54407 - atomic_read(&the_controller->seqnum));
54408 + atomic_read_unchecked(&the_controller->seqnum));
54409 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
54410 return;
54411 }
54412 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
54413 index edc7267..9f65ce2 100644
54414 --- a/drivers/usb/wusbcore/wa-hc.h
54415 +++ b/drivers/usb/wusbcore/wa-hc.h
54416 @@ -240,7 +240,7 @@ struct wahc {
54417 spinlock_t xfer_list_lock;
54418 struct work_struct xfer_enqueue_work;
54419 struct work_struct xfer_error_work;
54420 - atomic_t xfer_id_count;
54421 + atomic_unchecked_t xfer_id_count;
54422
54423 kernel_ulong_t quirks;
54424 };
54425 @@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
54426 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
54427 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
54428 wa->dto_in_use = 0;
54429 - atomic_set(&wa->xfer_id_count, 1);
54430 + atomic_set_unchecked(&wa->xfer_id_count, 1);
54431 /* init the buf in URBs */
54432 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
54433 usb_init_urb(&(wa->buf_in_urbs[index]));
54434 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
54435 index 69af4fd..da390d7 100644
54436 --- a/drivers/usb/wusbcore/wa-xfer.c
54437 +++ b/drivers/usb/wusbcore/wa-xfer.c
54438 @@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
54439 */
54440 static void wa_xfer_id_init(struct wa_xfer *xfer)
54441 {
54442 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
54443 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
54444 }
54445
54446 /* Return the xfer's ID. */
54447 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
54448 index f018d8d..ccab63f 100644
54449 --- a/drivers/vfio/vfio.c
54450 +++ b/drivers/vfio/vfio.c
54451 @@ -481,7 +481,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
54452 return 0;
54453
54454 /* TODO Prevent device auto probing */
54455 - WARN("Device %s added to live group %d!\n", dev_name(dev),
54456 + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
54457 iommu_group_id(group->iommu_group));
54458
54459 return 0;
54460 diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
54461 index 5174eba..451e6bc 100644
54462 --- a/drivers/vhost/vringh.c
54463 +++ b/drivers/vhost/vringh.c
54464 @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
54465 /* Userspace access helpers: in this case, addresses are really userspace. */
54466 static inline int getu16_user(u16 *val, const u16 *p)
54467 {
54468 - return get_user(*val, (__force u16 __user *)p);
54469 + return get_user(*val, (u16 __force_user *)p);
54470 }
54471
54472 static inline int putu16_user(u16 *p, u16 val)
54473 {
54474 - return put_user(val, (__force u16 __user *)p);
54475 + return put_user(val, (u16 __force_user *)p);
54476 }
54477
54478 static inline int copydesc_user(void *dst, const void *src, size_t len)
54479 {
54480 - return copy_from_user(dst, (__force void __user *)src, len) ?
54481 + return copy_from_user(dst, (void __force_user *)src, len) ?
54482 -EFAULT : 0;
54483 }
54484
54485 @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
54486 const struct vring_used_elem *src,
54487 unsigned int num)
54488 {
54489 - return copy_to_user((__force void __user *)dst, src,
54490 + return copy_to_user((void __force_user *)dst, src,
54491 sizeof(*dst) * num) ? -EFAULT : 0;
54492 }
54493
54494 static inline int xfer_from_user(void *src, void *dst, size_t len)
54495 {
54496 - return copy_from_user(dst, (__force void __user *)src, len) ?
54497 + return copy_from_user(dst, (void __force_user *)src, len) ?
54498 -EFAULT : 0;
54499 }
54500
54501 static inline int xfer_to_user(void *dst, void *src, size_t len)
54502 {
54503 - return copy_to_user((__force void __user *)dst, src, len) ?
54504 + return copy_to_user((void __force_user *)dst, src, len) ?
54505 -EFAULT : 0;
54506 }
54507
54508 @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
54509 vrh->last_used_idx = 0;
54510 vrh->vring.num = num;
54511 /* vring expects kernel addresses, but only used via accessors. */
54512 - vrh->vring.desc = (__force struct vring_desc *)desc;
54513 - vrh->vring.avail = (__force struct vring_avail *)avail;
54514 - vrh->vring.used = (__force struct vring_used *)used;
54515 + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
54516 + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
54517 + vrh->vring.used = (__force_kernel struct vring_used *)used;
54518 return 0;
54519 }
54520 EXPORT_SYMBOL(vringh_init_user);
54521 @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
54522
54523 static inline int putu16_kern(u16 *p, u16 val)
54524 {
54525 - ACCESS_ONCE(*p) = val;
54526 + ACCESS_ONCE_RW(*p) = val;
54527 return 0;
54528 }
54529
54530 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
54531 index 84a110a..96312c3 100644
54532 --- a/drivers/video/backlight/kb3886_bl.c
54533 +++ b/drivers/video/backlight/kb3886_bl.c
54534 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
54535 static unsigned long kb3886bl_flags;
54536 #define KB3886BL_SUSPENDED 0x01
54537
54538 -static struct dmi_system_id kb3886bl_device_table[] __initdata = {
54539 +static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
54540 {
54541 .ident = "Sahara Touch-iT",
54542 .matches = {
54543 diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
54544 index 1b0b233..6f34c2c 100644
54545 --- a/drivers/video/fbdev/arcfb.c
54546 +++ b/drivers/video/fbdev/arcfb.c
54547 @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
54548 return -ENOSPC;
54549
54550 err = 0;
54551 - if ((count + p) > fbmemlength) {
54552 + if (count > (fbmemlength - p)) {
54553 count = fbmemlength - p;
54554 err = -ENOSPC;
54555 }
54556 diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
54557 index aedf2fb..47c9aca 100644
54558 --- a/drivers/video/fbdev/aty/aty128fb.c
54559 +++ b/drivers/video/fbdev/aty/aty128fb.c
54560 @@ -149,7 +149,7 @@ enum {
54561 };
54562
54563 /* Must match above enum */
54564 -static char * const r128_family[] = {
54565 +static const char * const r128_family[] = {
54566 "AGP",
54567 "PCI",
54568 "PRO AGP",
54569 diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
54570 index 37ec09b..98f8862 100644
54571 --- a/drivers/video/fbdev/aty/atyfb_base.c
54572 +++ b/drivers/video/fbdev/aty/atyfb_base.c
54573 @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
54574 par->accel_flags = var->accel_flags; /* hack */
54575
54576 if (var->accel_flags) {
54577 - info->fbops->fb_sync = atyfb_sync;
54578 + pax_open_kernel();
54579 + *(void **)&info->fbops->fb_sync = atyfb_sync;
54580 + pax_close_kernel();
54581 info->flags &= ~FBINFO_HWACCEL_DISABLED;
54582 } else {
54583 - info->fbops->fb_sync = NULL;
54584 + pax_open_kernel();
54585 + *(void **)&info->fbops->fb_sync = NULL;
54586 + pax_close_kernel();
54587 info->flags |= FBINFO_HWACCEL_DISABLED;
54588 }
54589
54590 diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
54591 index 2fa0317..4983f2a 100644
54592 --- a/drivers/video/fbdev/aty/mach64_cursor.c
54593 +++ b/drivers/video/fbdev/aty/mach64_cursor.c
54594 @@ -8,6 +8,7 @@
54595 #include "../core/fb_draw.h"
54596
54597 #include <asm/io.h>
54598 +#include <asm/pgtable.h>
54599
54600 #ifdef __sparc__
54601 #include <asm/fbio.h>
54602 @@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
54603 info->sprite.buf_align = 16; /* and 64 lines tall. */
54604 info->sprite.flags = FB_PIXMAP_IO;
54605
54606 - info->fbops->fb_cursor = atyfb_cursor;
54607 + pax_open_kernel();
54608 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
54609 + pax_close_kernel();
54610
54611 return 0;
54612 }
54613 diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
54614 index 900aa4e..6d49418 100644
54615 --- a/drivers/video/fbdev/core/fb_defio.c
54616 +++ b/drivers/video/fbdev/core/fb_defio.c
54617 @@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
54618
54619 BUG_ON(!fbdefio);
54620 mutex_init(&fbdefio->lock);
54621 - info->fbops->fb_mmap = fb_deferred_io_mmap;
54622 + pax_open_kernel();
54623 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
54624 + pax_close_kernel();
54625 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
54626 INIT_LIST_HEAD(&fbdefio->pagelist);
54627 if (fbdefio->delay == 0) /* set a default of 1 s */
54628 @@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
54629 page->mapping = NULL;
54630 }
54631
54632 - info->fbops->fb_mmap = NULL;
54633 + *(void **)&info->fbops->fb_mmap = NULL;
54634 mutex_destroy(&fbdefio->lock);
54635 }
54636 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
54637 diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
54638 index 0705d88..d9429bf 100644
54639 --- a/drivers/video/fbdev/core/fbmem.c
54640 +++ b/drivers/video/fbdev/core/fbmem.c
54641 @@ -1301,7 +1301,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
54642 __u32 data;
54643 int err;
54644
54645 - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
54646 + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
54647
54648 data = (__u32) (unsigned long) fix->smem_start;
54649 err |= put_user(data, &fix32->smem_start);
54650 diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
54651 index 4254336..282567e 100644
54652 --- a/drivers/video/fbdev/hyperv_fb.c
54653 +++ b/drivers/video/fbdev/hyperv_fb.c
54654 @@ -240,7 +240,7 @@ static uint screen_fb_size;
54655 static inline int synthvid_send(struct hv_device *hdev,
54656 struct synthvid_msg *msg)
54657 {
54658 - static atomic64_t request_id = ATOMIC64_INIT(0);
54659 + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
54660 int ret;
54661
54662 msg->pipe_hdr.type = PIPE_MSG_DATA;
54663 @@ -248,7 +248,7 @@ static inline int synthvid_send(struct hv_device *hdev,
54664
54665 ret = vmbus_sendpacket(hdev->channel, msg,
54666 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
54667 - atomic64_inc_return(&request_id),
54668 + atomic64_inc_return_unchecked(&request_id),
54669 VM_PKT_DATA_INBAND, 0);
54670
54671 if (ret)
54672 diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
54673 index 7672d2e..b56437f 100644
54674 --- a/drivers/video/fbdev/i810/i810_accel.c
54675 +++ b/drivers/video/fbdev/i810/i810_accel.c
54676 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
54677 }
54678 }
54679 printk("ringbuffer lockup!!!\n");
54680 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
54681 i810_report_error(mmio);
54682 par->dev_flags |= LOCKUP;
54683 info->pixmap.scan_align = 1;
54684 diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
54685 index a01147f..5d896f8 100644
54686 --- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
54687 +++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
54688 @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
54689
54690 #ifdef CONFIG_FB_MATROX_MYSTIQUE
54691 struct matrox_switch matrox_mystique = {
54692 - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
54693 + .preinit = MGA1064_preinit,
54694 + .reset = MGA1064_reset,
54695 + .init = MGA1064_init,
54696 + .restore = MGA1064_restore,
54697 };
54698 EXPORT_SYMBOL(matrox_mystique);
54699 #endif
54700
54701 #ifdef CONFIG_FB_MATROX_G
54702 struct matrox_switch matrox_G100 = {
54703 - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
54704 + .preinit = MGAG100_preinit,
54705 + .reset = MGAG100_reset,
54706 + .init = MGAG100_init,
54707 + .restore = MGAG100_restore,
54708 };
54709 EXPORT_SYMBOL(matrox_G100);
54710 #endif
54711 diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
54712 index 195ad7c..09743fc 100644
54713 --- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
54714 +++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
54715 @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
54716 }
54717
54718 struct matrox_switch matrox_millennium = {
54719 - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
54720 + .preinit = Ti3026_preinit,
54721 + .reset = Ti3026_reset,
54722 + .init = Ti3026_init,
54723 + .restore = Ti3026_restore
54724 };
54725 EXPORT_SYMBOL(matrox_millennium);
54726 #endif
54727 diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
54728 index fe92eed..106e085 100644
54729 --- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
54730 +++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
54731 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
54732 struct mb862xxfb_par *par = info->par;
54733
54734 if (info->var.bits_per_pixel == 32) {
54735 - info->fbops->fb_fillrect = cfb_fillrect;
54736 - info->fbops->fb_copyarea = cfb_copyarea;
54737 - info->fbops->fb_imageblit = cfb_imageblit;
54738 + pax_open_kernel();
54739 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
54740 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
54741 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
54742 + pax_close_kernel();
54743 } else {
54744 outreg(disp, GC_L0EM, 3);
54745 - info->fbops->fb_fillrect = mb86290fb_fillrect;
54746 - info->fbops->fb_copyarea = mb86290fb_copyarea;
54747 - info->fbops->fb_imageblit = mb86290fb_imageblit;
54748 + pax_open_kernel();
54749 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
54750 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
54751 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
54752 + pax_close_kernel();
54753 }
54754 outreg(draw, GDC_REG_DRAW_BASE, 0);
54755 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
54756 diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
54757 index def0412..fed6529 100644
54758 --- a/drivers/video/fbdev/nvidia/nvidia.c
54759 +++ b/drivers/video/fbdev/nvidia/nvidia.c
54760 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
54761 info->fix.line_length = (info->var.xres_virtual *
54762 info->var.bits_per_pixel) >> 3;
54763 if (info->var.accel_flags) {
54764 - info->fbops->fb_imageblit = nvidiafb_imageblit;
54765 - info->fbops->fb_fillrect = nvidiafb_fillrect;
54766 - info->fbops->fb_copyarea = nvidiafb_copyarea;
54767 - info->fbops->fb_sync = nvidiafb_sync;
54768 + pax_open_kernel();
54769 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
54770 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
54771 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
54772 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
54773 + pax_close_kernel();
54774 info->pixmap.scan_align = 4;
54775 info->flags &= ~FBINFO_HWACCEL_DISABLED;
54776 info->flags |= FBINFO_READS_FAST;
54777 NVResetGraphics(info);
54778 } else {
54779 - info->fbops->fb_imageblit = cfb_imageblit;
54780 - info->fbops->fb_fillrect = cfb_fillrect;
54781 - info->fbops->fb_copyarea = cfb_copyarea;
54782 - info->fbops->fb_sync = NULL;
54783 + pax_open_kernel();
54784 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
54785 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
54786 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
54787 + *(void **)&info->fbops->fb_sync = NULL;
54788 + pax_close_kernel();
54789 info->pixmap.scan_align = 1;
54790 info->flags |= FBINFO_HWACCEL_DISABLED;
54791 info->flags &= ~FBINFO_READS_FAST;
54792 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
54793 info->pixmap.size = 8 * 1024;
54794 info->pixmap.flags = FB_PIXMAP_SYSTEM;
54795
54796 - if (!hwcur)
54797 - info->fbops->fb_cursor = NULL;
54798 + if (!hwcur) {
54799 + pax_open_kernel();
54800 + *(void **)&info->fbops->fb_cursor = NULL;
54801 + pax_close_kernel();
54802 + }
54803
54804 info->var.accel_flags = (!noaccel);
54805
54806 diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
54807 index 2412a0d..294215b 100644
54808 --- a/drivers/video/fbdev/omap2/dss/display.c
54809 +++ b/drivers/video/fbdev/omap2/dss/display.c
54810 @@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
54811 if (dssdev->name == NULL)
54812 dssdev->name = dssdev->alias;
54813
54814 + pax_open_kernel();
54815 if (drv && drv->get_resolution == NULL)
54816 - drv->get_resolution = omapdss_default_get_resolution;
54817 + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
54818 if (drv && drv->get_recommended_bpp == NULL)
54819 - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
54820 + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
54821 if (drv && drv->get_timings == NULL)
54822 - drv->get_timings = omapdss_default_get_timings;
54823 + *(void **)&drv->get_timings = omapdss_default_get_timings;
54824 + pax_close_kernel();
54825
54826 mutex_lock(&panel_list_mutex);
54827 list_add_tail(&dssdev->panel_list, &panel_list);
54828 diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
54829 index 83433cb..71e9b98 100644
54830 --- a/drivers/video/fbdev/s1d13xxxfb.c
54831 +++ b/drivers/video/fbdev/s1d13xxxfb.c
54832 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
54833
54834 switch(prod_id) {
54835 case S1D13506_PROD_ID: /* activate acceleration */
54836 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
54837 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
54838 + pax_open_kernel();
54839 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
54840 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
54841 + pax_close_kernel();
54842 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
54843 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
54844 break;
54845 diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
54846 index 2bcc84a..29dd1ea 100644
54847 --- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
54848 +++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
54849 @@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
54850 }
54851
54852 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
54853 - lcdc_sys_write_index,
54854 - lcdc_sys_write_data,
54855 - lcdc_sys_read_data,
54856 + .write_index = lcdc_sys_write_index,
54857 + .write_data = lcdc_sys_write_data,
54858 + .read_data = lcdc_sys_read_data,
54859 };
54860
54861 static int sh_mobile_lcdc_sginit(struct fb_info *info,
54862 diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
54863 index d513ed6..90b0de9 100644
54864 --- a/drivers/video/fbdev/smscufx.c
54865 +++ b/drivers/video/fbdev/smscufx.c
54866 @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
54867 fb_deferred_io_cleanup(info);
54868 kfree(info->fbdefio);
54869 info->fbdefio = NULL;
54870 - info->fbops->fb_mmap = ufx_ops_mmap;
54871 + pax_open_kernel();
54872 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
54873 + pax_close_kernel();
54874 }
54875
54876 pr_debug("released /dev/fb%d user=%d count=%d",
54877 diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
54878 index 046d51d..be564da 100644
54879 --- a/drivers/video/fbdev/udlfb.c
54880 +++ b/drivers/video/fbdev/udlfb.c
54881 @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
54882 dlfb_urb_completion(urb);
54883
54884 error:
54885 - atomic_add(bytes_sent, &dev->bytes_sent);
54886 - atomic_add(bytes_identical, &dev->bytes_identical);
54887 - atomic_add(width*height*2, &dev->bytes_rendered);
54888 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
54889 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
54890 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
54891 end_cycles = get_cycles();
54892 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
54893 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
54894 >> 10)), /* Kcycles */
54895 &dev->cpu_kcycles_used);
54896
54897 @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
54898 dlfb_urb_completion(urb);
54899
54900 error:
54901 - atomic_add(bytes_sent, &dev->bytes_sent);
54902 - atomic_add(bytes_identical, &dev->bytes_identical);
54903 - atomic_add(bytes_rendered, &dev->bytes_rendered);
54904 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
54905 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
54906 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
54907 end_cycles = get_cycles();
54908 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
54909 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
54910 >> 10)), /* Kcycles */
54911 &dev->cpu_kcycles_used);
54912 }
54913 @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
54914 fb_deferred_io_cleanup(info);
54915 kfree(info->fbdefio);
54916 info->fbdefio = NULL;
54917 - info->fbops->fb_mmap = dlfb_ops_mmap;
54918 + pax_open_kernel();
54919 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
54920 + pax_close_kernel();
54921 }
54922
54923 pr_warn("released /dev/fb%d user=%d count=%d\n",
54924 @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
54925 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54926 struct dlfb_data *dev = fb_info->par;
54927 return snprintf(buf, PAGE_SIZE, "%u\n",
54928 - atomic_read(&dev->bytes_rendered));
54929 + atomic_read_unchecked(&dev->bytes_rendered));
54930 }
54931
54932 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
54933 @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
54934 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54935 struct dlfb_data *dev = fb_info->par;
54936 return snprintf(buf, PAGE_SIZE, "%u\n",
54937 - atomic_read(&dev->bytes_identical));
54938 + atomic_read_unchecked(&dev->bytes_identical));
54939 }
54940
54941 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
54942 @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
54943 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54944 struct dlfb_data *dev = fb_info->par;
54945 return snprintf(buf, PAGE_SIZE, "%u\n",
54946 - atomic_read(&dev->bytes_sent));
54947 + atomic_read_unchecked(&dev->bytes_sent));
54948 }
54949
54950 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
54951 @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
54952 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54953 struct dlfb_data *dev = fb_info->par;
54954 return snprintf(buf, PAGE_SIZE, "%u\n",
54955 - atomic_read(&dev->cpu_kcycles_used));
54956 + atomic_read_unchecked(&dev->cpu_kcycles_used));
54957 }
54958
54959 static ssize_t edid_show(
54960 @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
54961 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54962 struct dlfb_data *dev = fb_info->par;
54963
54964 - atomic_set(&dev->bytes_rendered, 0);
54965 - atomic_set(&dev->bytes_identical, 0);
54966 - atomic_set(&dev->bytes_sent, 0);
54967 - atomic_set(&dev->cpu_kcycles_used, 0);
54968 + atomic_set_unchecked(&dev->bytes_rendered, 0);
54969 + atomic_set_unchecked(&dev->bytes_identical, 0);
54970 + atomic_set_unchecked(&dev->bytes_sent, 0);
54971 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
54972
54973 return count;
54974 }
54975 diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
54976 index 509d452..7c9d2de 100644
54977 --- a/drivers/video/fbdev/uvesafb.c
54978 +++ b/drivers/video/fbdev/uvesafb.c
54979 @@ -19,6 +19,7 @@
54980 #include <linux/io.h>
54981 #include <linux/mutex.h>
54982 #include <linux/slab.h>
54983 +#include <linux/moduleloader.h>
54984 #include <video/edid.h>
54985 #include <video/uvesafb.h>
54986 #ifdef CONFIG_X86
54987 @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
54988 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
54989 par->pmi_setpal = par->ypan = 0;
54990 } else {
54991 +
54992 +#ifdef CONFIG_PAX_KERNEXEC
54993 +#ifdef CONFIG_MODULES
54994 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
54995 +#endif
54996 + if (!par->pmi_code) {
54997 + par->pmi_setpal = par->ypan = 0;
54998 + return 0;
54999 + }
55000 +#endif
55001 +
55002 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
55003 + task->t.regs.edi);
55004 +
55005 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55006 + pax_open_kernel();
55007 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
55008 + pax_close_kernel();
55009 +
55010 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
55011 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
55012 +#else
55013 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
55014 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
55015 +#endif
55016 +
55017 printk(KERN_INFO "uvesafb: protected mode interface info at "
55018 "%04x:%04x\n",
55019 (u16)task->t.regs.es, (u16)task->t.regs.edi);
55020 @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
55021 par->ypan = ypan;
55022
55023 if (par->pmi_setpal || par->ypan) {
55024 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
55025 if (__supported_pte_mask & _PAGE_NX) {
55026 par->pmi_setpal = par->ypan = 0;
55027 printk(KERN_WARNING "uvesafb: NX protection is active, "
55028 "better not use the PMI.\n");
55029 - } else {
55030 + } else
55031 +#endif
55032 uvesafb_vbe_getpmi(task, par);
55033 - }
55034 }
55035 #else
55036 /* The protected mode interface is not available on non-x86. */
55037 @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55038 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
55039
55040 /* Disable blanking if the user requested so. */
55041 - if (!blank)
55042 - info->fbops->fb_blank = NULL;
55043 + if (!blank) {
55044 + pax_open_kernel();
55045 + *(void **)&info->fbops->fb_blank = NULL;
55046 + pax_close_kernel();
55047 + }
55048
55049 /*
55050 * Find out how much IO memory is required for the mode with
55051 @@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55052 info->flags = FBINFO_FLAG_DEFAULT |
55053 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
55054
55055 - if (!par->ypan)
55056 - info->fbops->fb_pan_display = NULL;
55057 + if (!par->ypan) {
55058 + pax_open_kernel();
55059 + *(void **)&info->fbops->fb_pan_display = NULL;
55060 + pax_close_kernel();
55061 + }
55062 }
55063
55064 static void uvesafb_init_mtrr(struct fb_info *info)
55065 @@ -1787,6 +1817,11 @@ out_mode:
55066 out:
55067 kfree(par->vbe_modes);
55068
55069 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55070 + if (par->pmi_code)
55071 + module_free_exec(NULL, par->pmi_code);
55072 +#endif
55073 +
55074 framebuffer_release(info);
55075 return err;
55076 }
55077 @@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
55078 kfree(par->vbe_state_orig);
55079 kfree(par->vbe_state_saved);
55080
55081 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55082 + if (par->pmi_code)
55083 + module_free_exec(NULL, par->pmi_code);
55084 +#endif
55085 +
55086 framebuffer_release(info);
55087 }
55088 return 0;
55089 diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
55090 index 6170e7f..dd63031 100644
55091 --- a/drivers/video/fbdev/vesafb.c
55092 +++ b/drivers/video/fbdev/vesafb.c
55093 @@ -9,6 +9,7 @@
55094 */
55095
55096 #include <linux/module.h>
55097 +#include <linux/moduleloader.h>
55098 #include <linux/kernel.h>
55099 #include <linux/errno.h>
55100 #include <linux/string.h>
55101 @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
55102 static int vram_total; /* Set total amount of memory */
55103 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
55104 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
55105 -static void (*pmi_start)(void) __read_mostly;
55106 -static void (*pmi_pal) (void) __read_mostly;
55107 +static void (*pmi_start)(void) __read_only;
55108 +static void (*pmi_pal) (void) __read_only;
55109 static int depth __read_mostly;
55110 static int vga_compat __read_mostly;
55111 /* --------------------------------------------------------------------- */
55112 @@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
55113 unsigned int size_remap;
55114 unsigned int size_total;
55115 char *option = NULL;
55116 + void *pmi_code = NULL;
55117
55118 /* ignore error return of fb_get_options */
55119 fb_get_options("vesafb", &option);
55120 @@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
55121 size_remap = size_total;
55122 vesafb_fix.smem_len = size_remap;
55123
55124 -#ifndef __i386__
55125 - screen_info.vesapm_seg = 0;
55126 -#endif
55127 -
55128 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
55129 printk(KERN_WARNING
55130 "vesafb: cannot reserve video memory at 0x%lx\n",
55131 @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
55132 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
55133 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
55134
55135 +#ifdef __i386__
55136 +
55137 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55138 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
55139 + if (!pmi_code)
55140 +#elif !defined(CONFIG_PAX_KERNEXEC)
55141 + if (0)
55142 +#endif
55143 +
55144 +#endif
55145 + screen_info.vesapm_seg = 0;
55146 +
55147 if (screen_info.vesapm_seg) {
55148 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
55149 - screen_info.vesapm_seg,screen_info.vesapm_off);
55150 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
55151 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
55152 }
55153
55154 if (screen_info.vesapm_seg < 0xc000)
55155 @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
55156
55157 if (ypan || pmi_setpal) {
55158 unsigned short *pmi_base;
55159 +
55160 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
55161 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
55162 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
55163 +
55164 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55165 + pax_open_kernel();
55166 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
55167 +#else
55168 + pmi_code = pmi_base;
55169 +#endif
55170 +
55171 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
55172 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
55173 +
55174 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55175 + pmi_start = ktva_ktla(pmi_start);
55176 + pmi_pal = ktva_ktla(pmi_pal);
55177 + pax_close_kernel();
55178 +#endif
55179 +
55180 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
55181 if (pmi_base[3]) {
55182 printk(KERN_INFO "vesafb: pmi: ports = ");
55183 @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
55184 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
55185 (ypan ? FBINFO_HWACCEL_YPAN : 0);
55186
55187 - if (!ypan)
55188 - info->fbops->fb_pan_display = NULL;
55189 + if (!ypan) {
55190 + pax_open_kernel();
55191 + *(void **)&info->fbops->fb_pan_display = NULL;
55192 + pax_close_kernel();
55193 + }
55194
55195 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
55196 err = -ENOMEM;
55197 @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
55198 fb_info(info, "%s frame buffer device\n", info->fix.id);
55199 return 0;
55200 err:
55201 +
55202 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55203 + module_free_exec(NULL, pmi_code);
55204 +#endif
55205 +
55206 if (info->screen_base)
55207 iounmap(info->screen_base);
55208 framebuffer_release(info);
55209 diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
55210 index 88714ae..16c2e11 100644
55211 --- a/drivers/video/fbdev/via/via_clock.h
55212 +++ b/drivers/video/fbdev/via/via_clock.h
55213 @@ -56,7 +56,7 @@ struct via_clock {
55214
55215 void (*set_engine_pll_state)(u8 state);
55216 void (*set_engine_pll)(struct via_pll_config config);
55217 -};
55218 +} __no_const;
55219
55220
55221 static inline u32 get_pll_internal_frequency(u32 ref_freq,
55222 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
55223 index 3c14e43..2630570 100644
55224 --- a/drivers/video/logo/logo_linux_clut224.ppm
55225 +++ b/drivers/video/logo/logo_linux_clut224.ppm
55226 @@ -2,1603 +2,1123 @@ P3
55227 # Standard 224-color Linux logo
55228 80 80
55229 255
55230 - 0 0 0 0 0 0 0 0 0 0 0 0
55231 - 0 0 0 0 0 0 0 0 0 0 0 0
55232 - 0 0 0 0 0 0 0 0 0 0 0 0
55233 - 0 0 0 0 0 0 0 0 0 0 0 0
55234 - 0 0 0 0 0 0 0 0 0 0 0 0
55235 - 0 0 0 0 0 0 0 0 0 0 0 0
55236 - 0 0 0 0 0 0 0 0 0 0 0 0
55237 - 0 0 0 0 0 0 0 0 0 0 0 0
55238 - 0 0 0 0 0 0 0 0 0 0 0 0
55239 - 6 6 6 6 6 6 10 10 10 10 10 10
55240 - 10 10 10 6 6 6 6 6 6 6 6 6
55241 - 0 0 0 0 0 0 0 0 0 0 0 0
55242 - 0 0 0 0 0 0 0 0 0 0 0 0
55243 - 0 0 0 0 0 0 0 0 0 0 0 0
55244 - 0 0 0 0 0 0 0 0 0 0 0 0
55245 - 0 0 0 0 0 0 0 0 0 0 0 0
55246 - 0 0 0 0 0 0 0 0 0 0 0 0
55247 - 0 0 0 0 0 0 0 0 0 0 0 0
55248 - 0 0 0 0 0 0 0 0 0 0 0 0
55249 - 0 0 0 0 0 0 0 0 0 0 0 0
55250 - 0 0 0 0 0 0 0 0 0 0 0 0
55251 - 0 0 0 0 0 0 0 0 0 0 0 0
55252 - 0 0 0 0 0 0 0 0 0 0 0 0
55253 - 0 0 0 0 0 0 0 0 0 0 0 0
55254 - 0 0 0 0 0 0 0 0 0 0 0 0
55255 - 0 0 0 0 0 0 0 0 0 0 0 0
55256 - 0 0 0 0 0 0 0 0 0 0 0 0
55257 - 0 0 0 0 0 0 0 0 0 0 0 0
55258 - 0 0 0 6 6 6 10 10 10 14 14 14
55259 - 22 22 22 26 26 26 30 30 30 34 34 34
55260 - 30 30 30 30 30 30 26 26 26 18 18 18
55261 - 14 14 14 10 10 10 6 6 6 0 0 0
55262 - 0 0 0 0 0 0 0 0 0 0 0 0
55263 - 0 0 0 0 0 0 0 0 0 0 0 0
55264 - 0 0 0 0 0 0 0 0 0 0 0 0
55265 - 0 0 0 0 0 0 0 0 0 0 0 0
55266 - 0 0 0 0 0 0 0 0 0 0 0 0
55267 - 0 0 0 0 0 0 0 0 0 0 0 0
55268 - 0 0 0 0 0 0 0 0 0 0 0 0
55269 - 0 0 0 0 0 0 0 0 0 0 0 0
55270 - 0 0 0 0 0 0 0 0 0 0 0 0
55271 - 0 0 0 0 0 1 0 0 1 0 0 0
55272 - 0 0 0 0 0 0 0 0 0 0 0 0
55273 - 0 0 0 0 0 0 0 0 0 0 0 0
55274 - 0 0 0 0 0 0 0 0 0 0 0 0
55275 - 0 0 0 0 0 0 0 0 0 0 0 0
55276 - 0 0 0 0 0 0 0 0 0 0 0 0
55277 - 0 0 0 0 0 0 0 0 0 0 0 0
55278 - 6 6 6 14 14 14 26 26 26 42 42 42
55279 - 54 54 54 66 66 66 78 78 78 78 78 78
55280 - 78 78 78 74 74 74 66 66 66 54 54 54
55281 - 42 42 42 26 26 26 18 18 18 10 10 10
55282 - 6 6 6 0 0 0 0 0 0 0 0 0
55283 - 0 0 0 0 0 0 0 0 0 0 0 0
55284 - 0 0 0 0 0 0 0 0 0 0 0 0
55285 - 0 0 0 0 0 0 0 0 0 0 0 0
55286 - 0 0 0 0 0 0 0 0 0 0 0 0
55287 - 0 0 0 0 0 0 0 0 0 0 0 0
55288 - 0 0 0 0 0 0 0 0 0 0 0 0
55289 - 0 0 0 0 0 0 0 0 0 0 0 0
55290 - 0 0 0 0 0 0 0 0 0 0 0 0
55291 - 0 0 1 0 0 0 0 0 0 0 0 0
55292 - 0 0 0 0 0 0 0 0 0 0 0 0
55293 - 0 0 0 0 0 0 0 0 0 0 0 0
55294 - 0 0 0 0 0 0 0 0 0 0 0 0
55295 - 0 0 0 0 0 0 0 0 0 0 0 0
55296 - 0 0 0 0 0 0 0 0 0 0 0 0
55297 - 0 0 0 0 0 0 0 0 0 10 10 10
55298 - 22 22 22 42 42 42 66 66 66 86 86 86
55299 - 66 66 66 38 38 38 38 38 38 22 22 22
55300 - 26 26 26 34 34 34 54 54 54 66 66 66
55301 - 86 86 86 70 70 70 46 46 46 26 26 26
55302 - 14 14 14 6 6 6 0 0 0 0 0 0
55303 - 0 0 0 0 0 0 0 0 0 0 0 0
55304 - 0 0 0 0 0 0 0 0 0 0 0 0
55305 - 0 0 0 0 0 0 0 0 0 0 0 0
55306 - 0 0 0 0 0 0 0 0 0 0 0 0
55307 - 0 0 0 0 0 0 0 0 0 0 0 0
55308 - 0 0 0 0 0 0 0 0 0 0 0 0
55309 - 0 0 0 0 0 0 0 0 0 0 0 0
55310 - 0 0 0 0 0 0 0 0 0 0 0 0
55311 - 0 0 1 0 0 1 0 0 1 0 0 0
55312 - 0 0 0 0 0 0 0 0 0 0 0 0
55313 - 0 0 0 0 0 0 0 0 0 0 0 0
55314 - 0 0 0 0 0 0 0 0 0 0 0 0
55315 - 0 0 0 0 0 0 0 0 0 0 0 0
55316 - 0 0 0 0 0 0 0 0 0 0 0 0
55317 - 0 0 0 0 0 0 10 10 10 26 26 26
55318 - 50 50 50 82 82 82 58 58 58 6 6 6
55319 - 2 2 6 2 2 6 2 2 6 2 2 6
55320 - 2 2 6 2 2 6 2 2 6 2 2 6
55321 - 6 6 6 54 54 54 86 86 86 66 66 66
55322 - 38 38 38 18 18 18 6 6 6 0 0 0
55323 - 0 0 0 0 0 0 0 0 0 0 0 0
55324 - 0 0 0 0 0 0 0 0 0 0 0 0
55325 - 0 0 0 0 0 0 0 0 0 0 0 0
55326 - 0 0 0 0 0 0 0 0 0 0 0 0
55327 - 0 0 0 0 0 0 0 0 0 0 0 0
55328 - 0 0 0 0 0 0 0 0 0 0 0 0
55329 - 0 0 0 0 0 0 0 0 0 0 0 0
55330 - 0 0 0 0 0 0 0 0 0 0 0 0
55331 - 0 0 0 0 0 0 0 0 0 0 0 0
55332 - 0 0 0 0 0 0 0 0 0 0 0 0
55333 - 0 0 0 0 0 0 0 0 0 0 0 0
55334 - 0 0 0 0 0 0 0 0 0 0 0 0
55335 - 0 0 0 0 0 0 0 0 0 0 0 0
55336 - 0 0 0 0 0 0 0 0 0 0 0 0
55337 - 0 0 0 6 6 6 22 22 22 50 50 50
55338 - 78 78 78 34 34 34 2 2 6 2 2 6
55339 - 2 2 6 2 2 6 2 2 6 2 2 6
55340 - 2 2 6 2 2 6 2 2 6 2 2 6
55341 - 2 2 6 2 2 6 6 6 6 70 70 70
55342 - 78 78 78 46 46 46 22 22 22 6 6 6
55343 - 0 0 0 0 0 0 0 0 0 0 0 0
55344 - 0 0 0 0 0 0 0 0 0 0 0 0
55345 - 0 0 0 0 0 0 0 0 0 0 0 0
55346 - 0 0 0 0 0 0 0 0 0 0 0 0
55347 - 0 0 0 0 0 0 0 0 0 0 0 0
55348 - 0 0 0 0 0 0 0 0 0 0 0 0
55349 - 0 0 0 0 0 0 0 0 0 0 0 0
55350 - 0 0 0 0 0 0 0 0 0 0 0 0
55351 - 0 0 1 0 0 1 0 0 1 0 0 0
55352 - 0 0 0 0 0 0 0 0 0 0 0 0
55353 - 0 0 0 0 0 0 0 0 0 0 0 0
55354 - 0 0 0 0 0 0 0 0 0 0 0 0
55355 - 0 0 0 0 0 0 0 0 0 0 0 0
55356 - 0 0 0 0 0 0 0 0 0 0 0 0
55357 - 6 6 6 18 18 18 42 42 42 82 82 82
55358 - 26 26 26 2 2 6 2 2 6 2 2 6
55359 - 2 2 6 2 2 6 2 2 6 2 2 6
55360 - 2 2 6 2 2 6 2 2 6 14 14 14
55361 - 46 46 46 34 34 34 6 6 6 2 2 6
55362 - 42 42 42 78 78 78 42 42 42 18 18 18
55363 - 6 6 6 0 0 0 0 0 0 0 0 0
55364 - 0 0 0 0 0 0 0 0 0 0 0 0
55365 - 0 0 0 0 0 0 0 0 0 0 0 0
55366 - 0 0 0 0 0 0 0 0 0 0 0 0
55367 - 0 0 0 0 0 0 0 0 0 0 0 0
55368 - 0 0 0 0 0 0 0 0 0 0 0 0
55369 - 0 0 0 0 0 0 0 0 0 0 0 0
55370 - 0 0 0 0 0 0 0 0 0 0 0 0
55371 - 0 0 1 0 0 0 0 0 1 0 0 0
55372 - 0 0 0 0 0 0 0 0 0 0 0 0
55373 - 0 0 0 0 0 0 0 0 0 0 0 0
55374 - 0 0 0 0 0 0 0 0 0 0 0 0
55375 - 0 0 0 0 0 0 0 0 0 0 0 0
55376 - 0 0 0 0 0 0 0 0 0 0 0 0
55377 - 10 10 10 30 30 30 66 66 66 58 58 58
55378 - 2 2 6 2 2 6 2 2 6 2 2 6
55379 - 2 2 6 2 2 6 2 2 6 2 2 6
55380 - 2 2 6 2 2 6 2 2 6 26 26 26
55381 - 86 86 86 101 101 101 46 46 46 10 10 10
55382 - 2 2 6 58 58 58 70 70 70 34 34 34
55383 - 10 10 10 0 0 0 0 0 0 0 0 0
55384 - 0 0 0 0 0 0 0 0 0 0 0 0
55385 - 0 0 0 0 0 0 0 0 0 0 0 0
55386 - 0 0 0 0 0 0 0 0 0 0 0 0
55387 - 0 0 0 0 0 0 0 0 0 0 0 0
55388 - 0 0 0 0 0 0 0 0 0 0 0 0
55389 - 0 0 0 0 0 0 0 0 0 0 0 0
55390 - 0 0 0 0 0 0 0 0 0 0 0 0
55391 - 0 0 1 0 0 1 0 0 1 0 0 0
55392 - 0 0 0 0 0 0 0 0 0 0 0 0
55393 - 0 0 0 0 0 0 0 0 0 0 0 0
55394 - 0 0 0 0 0 0 0 0 0 0 0 0
55395 - 0 0 0 0 0 0 0 0 0 0 0 0
55396 - 0 0 0 0 0 0 0 0 0 0 0 0
55397 - 14 14 14 42 42 42 86 86 86 10 10 10
55398 - 2 2 6 2 2 6 2 2 6 2 2 6
55399 - 2 2 6 2 2 6 2 2 6 2 2 6
55400 - 2 2 6 2 2 6 2 2 6 30 30 30
55401 - 94 94 94 94 94 94 58 58 58 26 26 26
55402 - 2 2 6 6 6 6 78 78 78 54 54 54
55403 - 22 22 22 6 6 6 0 0 0 0 0 0
55404 - 0 0 0 0 0 0 0 0 0 0 0 0
55405 - 0 0 0 0 0 0 0 0 0 0 0 0
55406 - 0 0 0 0 0 0 0 0 0 0 0 0
55407 - 0 0 0 0 0 0 0 0 0 0 0 0
55408 - 0 0 0 0 0 0 0 0 0 0 0 0
55409 - 0 0 0 0 0 0 0 0 0 0 0 0
55410 - 0 0 0 0 0 0 0 0 0 0 0 0
55411 - 0 0 0 0 0 0 0 0 0 0 0 0
55412 - 0 0 0 0 0 0 0 0 0 0 0 0
55413 - 0 0 0 0 0 0 0 0 0 0 0 0
55414 - 0 0 0 0 0 0 0 0 0 0 0 0
55415 - 0 0 0 0 0 0 0 0 0 0 0 0
55416 - 0 0 0 0 0 0 0 0 0 6 6 6
55417 - 22 22 22 62 62 62 62 62 62 2 2 6
55418 - 2 2 6 2 2 6 2 2 6 2 2 6
55419 - 2 2 6 2 2 6 2 2 6 2 2 6
55420 - 2 2 6 2 2 6 2 2 6 26 26 26
55421 - 54 54 54 38 38 38 18 18 18 10 10 10
55422 - 2 2 6 2 2 6 34 34 34 82 82 82
55423 - 38 38 38 14 14 14 0 0 0 0 0 0
55424 - 0 0 0 0 0 0 0 0 0 0 0 0
55425 - 0 0 0 0 0 0 0 0 0 0 0 0
55426 - 0 0 0 0 0 0 0 0 0 0 0 0
55427 - 0 0 0 0 0 0 0 0 0 0 0 0
55428 - 0 0 0 0 0 0 0 0 0 0 0 0
55429 - 0 0 0 0 0 0 0 0 0 0 0 0
55430 - 0 0 0 0 0 0 0 0 0 0 0 0
55431 - 0 0 0 0 0 1 0 0 1 0 0 0
55432 - 0 0 0 0 0 0 0 0 0 0 0 0
55433 - 0 0 0 0 0 0 0 0 0 0 0 0
55434 - 0 0 0 0 0 0 0 0 0 0 0 0
55435 - 0 0 0 0 0 0 0 0 0 0 0 0
55436 - 0 0 0 0 0 0 0 0 0 6 6 6
55437 - 30 30 30 78 78 78 30 30 30 2 2 6
55438 - 2 2 6 2 2 6 2 2 6 2 2 6
55439 - 2 2 6 2 2 6 2 2 6 2 2 6
55440 - 2 2 6 2 2 6 2 2 6 10 10 10
55441 - 10 10 10 2 2 6 2 2 6 2 2 6
55442 - 2 2 6 2 2 6 2 2 6 78 78 78
55443 - 50 50 50 18 18 18 6 6 6 0 0 0
55444 - 0 0 0 0 0 0 0 0 0 0 0 0
55445 - 0 0 0 0 0 0 0 0 0 0 0 0
55446 - 0 0 0 0 0 0 0 0 0 0 0 0
55447 - 0 0 0 0 0 0 0 0 0 0 0 0
55448 - 0 0 0 0 0 0 0 0 0 0 0 0
55449 - 0 0 0 0 0 0 0 0 0 0 0 0
55450 - 0 0 0 0 0 0 0 0 0 0 0 0
55451 - 0 0 1 0 0 0 0 0 0 0 0 0
55452 - 0 0 0 0 0 0 0 0 0 0 0 0
55453 - 0 0 0 0 0 0 0 0 0 0 0 0
55454 - 0 0 0 0 0 0 0 0 0 0 0 0
55455 - 0 0 0 0 0 0 0 0 0 0 0 0
55456 - 0 0 0 0 0 0 0 0 0 10 10 10
55457 - 38 38 38 86 86 86 14 14 14 2 2 6
55458 - 2 2 6 2 2 6 2 2 6 2 2 6
55459 - 2 2 6 2 2 6 2 2 6 2 2 6
55460 - 2 2 6 2 2 6 2 2 6 2 2 6
55461 - 2 2 6 2 2 6 2 2 6 2 2 6
55462 - 2 2 6 2 2 6 2 2 6 54 54 54
55463 - 66 66 66 26 26 26 6 6 6 0 0 0
55464 - 0 0 0 0 0 0 0 0 0 0 0 0
55465 - 0 0 0 0 0 0 0 0 0 0 0 0
55466 - 0 0 0 0 0 0 0 0 0 0 0 0
55467 - 0 0 0 0 0 0 0 0 0 0 0 0
55468 - 0 0 0 0 0 0 0 0 0 0 0 0
55469 - 0 0 0 0 0 0 0 0 0 0 0 0
55470 - 0 0 0 0 0 0 0 0 0 0 0 0
55471 - 0 0 0 0 0 1 0 0 1 0 0 0
55472 - 0 0 0 0 0 0 0 0 0 0 0 0
55473 - 0 0 0 0 0 0 0 0 0 0 0 0
55474 - 0 0 0 0 0 0 0 0 0 0 0 0
55475 - 0 0 0 0 0 0 0 0 0 0 0 0
55476 - 0 0 0 0 0 0 0 0 0 14 14 14
55477 - 42 42 42 82 82 82 2 2 6 2 2 6
55478 - 2 2 6 6 6 6 10 10 10 2 2 6
55479 - 2 2 6 2 2 6 2 2 6 2 2 6
55480 - 2 2 6 2 2 6 2 2 6 6 6 6
55481 - 14 14 14 10 10 10 2 2 6 2 2 6
55482 - 2 2 6 2 2 6 2 2 6 18 18 18
55483 - 82 82 82 34 34 34 10 10 10 0 0 0
55484 - 0 0 0 0 0 0 0 0 0 0 0 0
55485 - 0 0 0 0 0 0 0 0 0 0 0 0
55486 - 0 0 0 0 0 0 0 0 0 0 0 0
55487 - 0 0 0 0 0 0 0 0 0 0 0 0
55488 - 0 0 0 0 0 0 0 0 0 0 0 0
55489 - 0 0 0 0 0 0 0 0 0 0 0 0
55490 - 0 0 0 0 0 0 0 0 0 0 0 0
55491 - 0 0 1 0 0 0 0 0 0 0 0 0
55492 - 0 0 0 0 0 0 0 0 0 0 0 0
55493 - 0 0 0 0 0 0 0 0 0 0 0 0
55494 - 0 0 0 0 0 0 0 0 0 0 0 0
55495 - 0 0 0 0 0 0 0 0 0 0 0 0
55496 - 0 0 0 0 0 0 0 0 0 14 14 14
55497 - 46 46 46 86 86 86 2 2 6 2 2 6
55498 - 6 6 6 6 6 6 22 22 22 34 34 34
55499 - 6 6 6 2 2 6 2 2 6 2 2 6
55500 - 2 2 6 2 2 6 18 18 18 34 34 34
55501 - 10 10 10 50 50 50 22 22 22 2 2 6
55502 - 2 2 6 2 2 6 2 2 6 10 10 10
55503 - 86 86 86 42 42 42 14 14 14 0 0 0
55504 - 0 0 0 0 0 0 0 0 0 0 0 0
55505 - 0 0 0 0 0 0 0 0 0 0 0 0
55506 - 0 0 0 0 0 0 0 0 0 0 0 0
55507 - 0 0 0 0 0 0 0 0 0 0 0 0
55508 - 0 0 0 0 0 0 0 0 0 0 0 0
55509 - 0 0 0 0 0 0 0 0 0 0 0 0
55510 - 0 0 0 0 0 0 0 0 0 0 0 0
55511 - 0 0 1 0 0 1 0 0 1 0 0 0
55512 - 0 0 0 0 0 0 0 0 0 0 0 0
55513 - 0 0 0 0 0 0 0 0 0 0 0 0
55514 - 0 0 0 0 0 0 0 0 0 0 0 0
55515 - 0 0 0 0 0 0 0 0 0 0 0 0
55516 - 0 0 0 0 0 0 0 0 0 14 14 14
55517 - 46 46 46 86 86 86 2 2 6 2 2 6
55518 - 38 38 38 116 116 116 94 94 94 22 22 22
55519 - 22 22 22 2 2 6 2 2 6 2 2 6
55520 - 14 14 14 86 86 86 138 138 138 162 162 162
55521 -154 154 154 38 38 38 26 26 26 6 6 6
55522 - 2 2 6 2 2 6 2 2 6 2 2 6
55523 - 86 86 86 46 46 46 14 14 14 0 0 0
55524 - 0 0 0 0 0 0 0 0 0 0 0 0
55525 - 0 0 0 0 0 0 0 0 0 0 0 0
55526 - 0 0 0 0 0 0 0 0 0 0 0 0
55527 - 0 0 0 0 0 0 0 0 0 0 0 0
55528 - 0 0 0 0 0 0 0 0 0 0 0 0
55529 - 0 0 0 0 0 0 0 0 0 0 0 0
55530 - 0 0 0 0 0 0 0 0 0 0 0 0
55531 - 0 0 0 0 0 0 0 0 0 0 0 0
55532 - 0 0 0 0 0 0 0 0 0 0 0 0
55533 - 0 0 0 0 0 0 0 0 0 0 0 0
55534 - 0 0 0 0 0 0 0 0 0 0 0 0
55535 - 0 0 0 0 0 0 0 0 0 0 0 0
55536 - 0 0 0 0 0 0 0 0 0 14 14 14
55537 - 46 46 46 86 86 86 2 2 6 14 14 14
55538 -134 134 134 198 198 198 195 195 195 116 116 116
55539 - 10 10 10 2 2 6 2 2 6 6 6 6
55540 -101 98 89 187 187 187 210 210 210 218 218 218
55541 -214 214 214 134 134 134 14 14 14 6 6 6
55542 - 2 2 6 2 2 6 2 2 6 2 2 6
55543 - 86 86 86 50 50 50 18 18 18 6 6 6
55544 - 0 0 0 0 0 0 0 0 0 0 0 0
55545 - 0 0 0 0 0 0 0 0 0 0 0 0
55546 - 0 0 0 0 0 0 0 0 0 0 0 0
55547 - 0 0 0 0 0 0 0 0 0 0 0 0
55548 - 0 0 0 0 0 0 0 0 0 0 0 0
55549 - 0 0 0 0 0 0 0 0 0 0 0 0
55550 - 0 0 0 0 0 0 0 0 1 0 0 0
55551 - 0 0 1 0 0 1 0 0 1 0 0 0
55552 - 0 0 0 0 0 0 0 0 0 0 0 0
55553 - 0 0 0 0 0 0 0 0 0 0 0 0
55554 - 0 0 0 0 0 0 0 0 0 0 0 0
55555 - 0 0 0 0 0 0 0 0 0 0 0 0
55556 - 0 0 0 0 0 0 0 0 0 14 14 14
55557 - 46 46 46 86 86 86 2 2 6 54 54 54
55558 -218 218 218 195 195 195 226 226 226 246 246 246
55559 - 58 58 58 2 2 6 2 2 6 30 30 30
55560 -210 210 210 253 253 253 174 174 174 123 123 123
55561 -221 221 221 234 234 234 74 74 74 2 2 6
55562 - 2 2 6 2 2 6 2 2 6 2 2 6
55563 - 70 70 70 58 58 58 22 22 22 6 6 6
55564 - 0 0 0 0 0 0 0 0 0 0 0 0
55565 - 0 0 0 0 0 0 0 0 0 0 0 0
55566 - 0 0 0 0 0 0 0 0 0 0 0 0
55567 - 0 0 0 0 0 0 0 0 0 0 0 0
55568 - 0 0 0 0 0 0 0 0 0 0 0 0
55569 - 0 0 0 0 0 0 0 0 0 0 0 0
55570 - 0 0 0 0 0 0 0 0 0 0 0 0
55571 - 0 0 0 0 0 0 0 0 0 0 0 0
55572 - 0 0 0 0 0 0 0 0 0 0 0 0
55573 - 0 0 0 0 0 0 0 0 0 0 0 0
55574 - 0 0 0 0 0 0 0 0 0 0 0 0
55575 - 0 0 0 0 0 0 0 0 0 0 0 0
55576 - 0 0 0 0 0 0 0 0 0 14 14 14
55577 - 46 46 46 82 82 82 2 2 6 106 106 106
55578 -170 170 170 26 26 26 86 86 86 226 226 226
55579 -123 123 123 10 10 10 14 14 14 46 46 46
55580 -231 231 231 190 190 190 6 6 6 70 70 70
55581 - 90 90 90 238 238 238 158 158 158 2 2 6
55582 - 2 2 6 2 2 6 2 2 6 2 2 6
55583 - 70 70 70 58 58 58 22 22 22 6 6 6
55584 - 0 0 0 0 0 0 0 0 0 0 0 0
55585 - 0 0 0 0 0 0 0 0 0 0 0 0
55586 - 0 0 0 0 0 0 0 0 0 0 0 0
55587 - 0 0 0 0 0 0 0 0 0 0 0 0
55588 - 0 0 0 0 0 0 0 0 0 0 0 0
55589 - 0 0 0 0 0 0 0 0 0 0 0 0
55590 - 0 0 0 0 0 0 0 0 1 0 0 0
55591 - 0 0 1 0 0 1 0 0 1 0 0 0
55592 - 0 0 0 0 0 0 0 0 0 0 0 0
55593 - 0 0 0 0 0 0 0 0 0 0 0 0
55594 - 0 0 0 0 0 0 0 0 0 0 0 0
55595 - 0 0 0 0 0 0 0 0 0 0 0 0
55596 - 0 0 0 0 0 0 0 0 0 14 14 14
55597 - 42 42 42 86 86 86 6 6 6 116 116 116
55598 -106 106 106 6 6 6 70 70 70 149 149 149
55599 -128 128 128 18 18 18 38 38 38 54 54 54
55600 -221 221 221 106 106 106 2 2 6 14 14 14
55601 - 46 46 46 190 190 190 198 198 198 2 2 6
55602 - 2 2 6 2 2 6 2 2 6 2 2 6
55603 - 74 74 74 62 62 62 22 22 22 6 6 6
55604 - 0 0 0 0 0 0 0 0 0 0 0 0
55605 - 0 0 0 0 0 0 0 0 0 0 0 0
55606 - 0 0 0 0 0 0 0 0 0 0 0 0
55607 - 0 0 0 0 0 0 0 0 0 0 0 0
55608 - 0 0 0 0 0 0 0 0 0 0 0 0
55609 - 0 0 0 0 0 0 0 0 0 0 0 0
55610 - 0 0 0 0 0 0 0 0 1 0 0 0
55611 - 0 0 1 0 0 0 0 0 1 0 0 0
55612 - 0 0 0 0 0 0 0 0 0 0 0 0
55613 - 0 0 0 0 0 0 0 0 0 0 0 0
55614 - 0 0 0 0 0 0 0 0 0 0 0 0
55615 - 0 0 0 0 0 0 0 0 0 0 0 0
55616 - 0 0 0 0 0 0 0 0 0 14 14 14
55617 - 42 42 42 94 94 94 14 14 14 101 101 101
55618 -128 128 128 2 2 6 18 18 18 116 116 116
55619 -118 98 46 121 92 8 121 92 8 98 78 10
55620 -162 162 162 106 106 106 2 2 6 2 2 6
55621 - 2 2 6 195 195 195 195 195 195 6 6 6
55622 - 2 2 6 2 2 6 2 2 6 2 2 6
55623 - 74 74 74 62 62 62 22 22 22 6 6 6
55624 - 0 0 0 0 0 0 0 0 0 0 0 0
55625 - 0 0 0 0 0 0 0 0 0 0 0 0
55626 - 0 0 0 0 0 0 0 0 0 0 0 0
55627 - 0 0 0 0 0 0 0 0 0 0 0 0
55628 - 0 0 0 0 0 0 0 0 0 0 0 0
55629 - 0 0 0 0 0 0 0 0 0 0 0 0
55630 - 0 0 0 0 0 0 0 0 1 0 0 1
55631 - 0 0 1 0 0 0 0 0 1 0 0 0
55632 - 0 0 0 0 0 0 0 0 0 0 0 0
55633 - 0 0 0 0 0 0 0 0 0 0 0 0
55634 - 0 0 0 0 0 0 0 0 0 0 0 0
55635 - 0 0 0 0 0 0 0 0 0 0 0 0
55636 - 0 0 0 0 0 0 0 0 0 10 10 10
55637 - 38 38 38 90 90 90 14 14 14 58 58 58
55638 -210 210 210 26 26 26 54 38 6 154 114 10
55639 -226 170 11 236 186 11 225 175 15 184 144 12
55640 -215 174 15 175 146 61 37 26 9 2 2 6
55641 - 70 70 70 246 246 246 138 138 138 2 2 6
55642 - 2 2 6 2 2 6 2 2 6 2 2 6
55643 - 70 70 70 66 66 66 26 26 26 6 6 6
55644 - 0 0 0 0 0 0 0 0 0 0 0 0
55645 - 0 0 0 0 0 0 0 0 0 0 0 0
55646 - 0 0 0 0 0 0 0 0 0 0 0 0
55647 - 0 0 0 0 0 0 0 0 0 0 0 0
55648 - 0 0 0 0 0 0 0 0 0 0 0 0
55649 - 0 0 0 0 0 0 0 0 0 0 0 0
55650 - 0 0 0 0 0 0 0 0 0 0 0 0
55651 - 0 0 0 0 0 0 0 0 0 0 0 0
55652 - 0 0 0 0 0 0 0 0 0 0 0 0
55653 - 0 0 0 0 0 0 0 0 0 0 0 0
55654 - 0 0 0 0 0 0 0 0 0 0 0 0
55655 - 0 0 0 0 0 0 0 0 0 0 0 0
55656 - 0 0 0 0 0 0 0 0 0 10 10 10
55657 - 38 38 38 86 86 86 14 14 14 10 10 10
55658 -195 195 195 188 164 115 192 133 9 225 175 15
55659 -239 182 13 234 190 10 232 195 16 232 200 30
55660 -245 207 45 241 208 19 232 195 16 184 144 12
55661 -218 194 134 211 206 186 42 42 42 2 2 6
55662 - 2 2 6 2 2 6 2 2 6 2 2 6
55663 - 50 50 50 74 74 74 30 30 30 6 6 6
55664 - 0 0 0 0 0 0 0 0 0 0 0 0
55665 - 0 0 0 0 0 0 0 0 0 0 0 0
55666 - 0 0 0 0 0 0 0 0 0 0 0 0
55667 - 0 0 0 0 0 0 0 0 0 0 0 0
55668 - 0 0 0 0 0 0 0 0 0 0 0 0
55669 - 0 0 0 0 0 0 0 0 0 0 0 0
55670 - 0 0 0 0 0 0 0 0 0 0 0 0
55671 - 0 0 0 0 0 0 0 0 0 0 0 0
55672 - 0 0 0 0 0 0 0 0 0 0 0 0
55673 - 0 0 0 0 0 0 0 0 0 0 0 0
55674 - 0 0 0 0 0 0 0 0 0 0 0 0
55675 - 0 0 0 0 0 0 0 0 0 0 0 0
55676 - 0 0 0 0 0 0 0 0 0 10 10 10
55677 - 34 34 34 86 86 86 14 14 14 2 2 6
55678 -121 87 25 192 133 9 219 162 10 239 182 13
55679 -236 186 11 232 195 16 241 208 19 244 214 54
55680 -246 218 60 246 218 38 246 215 20 241 208 19
55681 -241 208 19 226 184 13 121 87 25 2 2 6
55682 - 2 2 6 2 2 6 2 2 6 2 2 6
55683 - 50 50 50 82 82 82 34 34 34 10 10 10
55684 - 0 0 0 0 0 0 0 0 0 0 0 0
55685 - 0 0 0 0 0 0 0 0 0 0 0 0
55686 - 0 0 0 0 0 0 0 0 0 0 0 0
55687 - 0 0 0 0 0 0 0 0 0 0 0 0
55688 - 0 0 0 0 0 0 0 0 0 0 0 0
55689 - 0 0 0 0 0 0 0 0 0 0 0 0
55690 - 0 0 0 0 0 0 0 0 0 0 0 0
55691 - 0 0 0 0 0 0 0 0 0 0 0 0
55692 - 0 0 0 0 0 0 0 0 0 0 0 0
55693 - 0 0 0 0 0 0 0 0 0 0 0 0
55694 - 0 0 0 0 0 0 0 0 0 0 0 0
55695 - 0 0 0 0 0 0 0 0 0 0 0 0
55696 - 0 0 0 0 0 0 0 0 0 10 10 10
55697 - 34 34 34 82 82 82 30 30 30 61 42 6
55698 -180 123 7 206 145 10 230 174 11 239 182 13
55699 -234 190 10 238 202 15 241 208 19 246 218 74
55700 -246 218 38 246 215 20 246 215 20 246 215 20
55701 -226 184 13 215 174 15 184 144 12 6 6 6
55702 - 2 2 6 2 2 6 2 2 6 2 2 6
55703 - 26 26 26 94 94 94 42 42 42 14 14 14
55704 - 0 0 0 0 0 0 0 0 0 0 0 0
55705 - 0 0 0 0 0 0 0 0 0 0 0 0
55706 - 0 0 0 0 0 0 0 0 0 0 0 0
55707 - 0 0 0 0 0 0 0 0 0 0 0 0
55708 - 0 0 0 0 0 0 0 0 0 0 0 0
55709 - 0 0 0 0 0 0 0 0 0 0 0 0
55710 - 0 0 0 0 0 0 0 0 0 0 0 0
55711 - 0 0 0 0 0 0 0 0 0 0 0 0
55712 - 0 0 0 0 0 0 0 0 0 0 0 0
55713 - 0 0 0 0 0 0 0 0 0 0 0 0
55714 - 0 0 0 0 0 0 0 0 0 0 0 0
55715 - 0 0 0 0 0 0 0 0 0 0 0 0
55716 - 0 0 0 0 0 0 0 0 0 10 10 10
55717 - 30 30 30 78 78 78 50 50 50 104 69 6
55718 -192 133 9 216 158 10 236 178 12 236 186 11
55719 -232 195 16 241 208 19 244 214 54 245 215 43
55720 -246 215 20 246 215 20 241 208 19 198 155 10
55721 -200 144 11 216 158 10 156 118 10 2 2 6
55722 - 2 2 6 2 2 6 2 2 6 2 2 6
55723 - 6 6 6 90 90 90 54 54 54 18 18 18
55724 - 6 6 6 0 0 0 0 0 0 0 0 0
55725 - 0 0 0 0 0 0 0 0 0 0 0 0
55726 - 0 0 0 0 0 0 0 0 0 0 0 0
55727 - 0 0 0 0 0 0 0 0 0 0 0 0
55728 - 0 0 0 0 0 0 0 0 0 0 0 0
55729 - 0 0 0 0 0 0 0 0 0 0 0 0
55730 - 0 0 0 0 0 0 0 0 0 0 0 0
55731 - 0 0 0 0 0 0 0 0 0 0 0 0
55732 - 0 0 0 0 0 0 0 0 0 0 0 0
55733 - 0 0 0 0 0 0 0 0 0 0 0 0
55734 - 0 0 0 0 0 0 0 0 0 0 0 0
55735 - 0 0 0 0 0 0 0 0 0 0 0 0
55736 - 0 0 0 0 0 0 0 0 0 10 10 10
55737 - 30 30 30 78 78 78 46 46 46 22 22 22
55738 -137 92 6 210 162 10 239 182 13 238 190 10
55739 -238 202 15 241 208 19 246 215 20 246 215 20
55740 -241 208 19 203 166 17 185 133 11 210 150 10
55741 -216 158 10 210 150 10 102 78 10 2 2 6
55742 - 6 6 6 54 54 54 14 14 14 2 2 6
55743 - 2 2 6 62 62 62 74 74 74 30 30 30
55744 - 10 10 10 0 0 0 0 0 0 0 0 0
55745 - 0 0 0 0 0 0 0 0 0 0 0 0
55746 - 0 0 0 0 0 0 0 0 0 0 0 0
55747 - 0 0 0 0 0 0 0 0 0 0 0 0
55748 - 0 0 0 0 0 0 0 0 0 0 0 0
55749 - 0 0 0 0 0 0 0 0 0 0 0 0
55750 - 0 0 0 0 0 0 0 0 0 0 0 0
55751 - 0 0 0 0 0 0 0 0 0 0 0 0
55752 - 0 0 0 0 0 0 0 0 0 0 0 0
55753 - 0 0 0 0 0 0 0 0 0 0 0 0
55754 - 0 0 0 0 0 0 0 0 0 0 0 0
55755 - 0 0 0 0 0 0 0 0 0 0 0 0
55756 - 0 0 0 0 0 0 0 0 0 10 10 10
55757 - 34 34 34 78 78 78 50 50 50 6 6 6
55758 - 94 70 30 139 102 15 190 146 13 226 184 13
55759 -232 200 30 232 195 16 215 174 15 190 146 13
55760 -168 122 10 192 133 9 210 150 10 213 154 11
55761 -202 150 34 182 157 106 101 98 89 2 2 6
55762 - 2 2 6 78 78 78 116 116 116 58 58 58
55763 - 2 2 6 22 22 22 90 90 90 46 46 46
55764 - 18 18 18 6 6 6 0 0 0 0 0 0
55765 - 0 0 0 0 0 0 0 0 0 0 0 0
55766 - 0 0 0 0 0 0 0 0 0 0 0 0
55767 - 0 0 0 0 0 0 0 0 0 0 0 0
55768 - 0 0 0 0 0 0 0 0 0 0 0 0
55769 - 0 0 0 0 0 0 0 0 0 0 0 0
55770 - 0 0 0 0 0 0 0 0 0 0 0 0
55771 - 0 0 0 0 0 0 0 0 0 0 0 0
55772 - 0 0 0 0 0 0 0 0 0 0 0 0
55773 - 0 0 0 0 0 0 0 0 0 0 0 0
55774 - 0 0 0 0 0 0 0 0 0 0 0 0
55775 - 0 0 0 0 0 0 0 0 0 0 0 0
55776 - 0 0 0 0 0 0 0 0 0 10 10 10
55777 - 38 38 38 86 86 86 50 50 50 6 6 6
55778 -128 128 128 174 154 114 156 107 11 168 122 10
55779 -198 155 10 184 144 12 197 138 11 200 144 11
55780 -206 145 10 206 145 10 197 138 11 188 164 115
55781 -195 195 195 198 198 198 174 174 174 14 14 14
55782 - 2 2 6 22 22 22 116 116 116 116 116 116
55783 - 22 22 22 2 2 6 74 74 74 70 70 70
55784 - 30 30 30 10 10 10 0 0 0 0 0 0
55785 - 0 0 0 0 0 0 0 0 0 0 0 0
55786 - 0 0 0 0 0 0 0 0 0 0 0 0
55787 - 0 0 0 0 0 0 0 0 0 0 0 0
55788 - 0 0 0 0 0 0 0 0 0 0 0 0
55789 - 0 0 0 0 0 0 0 0 0 0 0 0
55790 - 0 0 0 0 0 0 0 0 0 0 0 0
55791 - 0 0 0 0 0 0 0 0 0 0 0 0
55792 - 0 0 0 0 0 0 0 0 0 0 0 0
55793 - 0 0 0 0 0 0 0 0 0 0 0 0
55794 - 0 0 0 0 0 0 0 0 0 0 0 0
55795 - 0 0 0 0 0 0 0 0 0 0 0 0
55796 - 0 0 0 0 0 0 6 6 6 18 18 18
55797 - 50 50 50 101 101 101 26 26 26 10 10 10
55798 -138 138 138 190 190 190 174 154 114 156 107 11
55799 -197 138 11 200 144 11 197 138 11 192 133 9
55800 -180 123 7 190 142 34 190 178 144 187 187 187
55801 -202 202 202 221 221 221 214 214 214 66 66 66
55802 - 2 2 6 2 2 6 50 50 50 62 62 62
55803 - 6 6 6 2 2 6 10 10 10 90 90 90
55804 - 50 50 50 18 18 18 6 6 6 0 0 0
55805 - 0 0 0 0 0 0 0 0 0 0 0 0
55806 - 0 0 0 0 0 0 0 0 0 0 0 0
55807 - 0 0 0 0 0 0 0 0 0 0 0 0
55808 - 0 0 0 0 0 0 0 0 0 0 0 0
55809 - 0 0 0 0 0 0 0 0 0 0 0 0
55810 - 0 0 0 0 0 0 0 0 0 0 0 0
55811 - 0 0 0 0 0 0 0 0 0 0 0 0
55812 - 0 0 0 0 0 0 0 0 0 0 0 0
55813 - 0 0 0 0 0 0 0 0 0 0 0 0
55814 - 0 0 0 0 0 0 0 0 0 0 0 0
55815 - 0 0 0 0 0 0 0 0 0 0 0 0
55816 - 0 0 0 0 0 0 10 10 10 34 34 34
55817 - 74 74 74 74 74 74 2 2 6 6 6 6
55818 -144 144 144 198 198 198 190 190 190 178 166 146
55819 -154 121 60 156 107 11 156 107 11 168 124 44
55820 -174 154 114 187 187 187 190 190 190 210 210 210
55821 -246 246 246 253 253 253 253 253 253 182 182 182
55822 - 6 6 6 2 2 6 2 2 6 2 2 6
55823 - 2 2 6 2 2 6 2 2 6 62 62 62
55824 - 74 74 74 34 34 34 14 14 14 0 0 0
55825 - 0 0 0 0 0 0 0 0 0 0 0 0
55826 - 0 0 0 0 0 0 0 0 0 0 0 0
55827 - 0 0 0 0 0 0 0 0 0 0 0 0
55828 - 0 0 0 0 0 0 0 0 0 0 0 0
55829 - 0 0 0 0 0 0 0 0 0 0 0 0
55830 - 0 0 0 0 0 0 0 0 0 0 0 0
55831 - 0 0 0 0 0 0 0 0 0 0 0 0
55832 - 0 0 0 0 0 0 0 0 0 0 0 0
55833 - 0 0 0 0 0 0 0 0 0 0 0 0
55834 - 0 0 0 0 0 0 0 0 0 0 0 0
55835 - 0 0 0 0 0 0 0 0 0 0 0 0
55836 - 0 0 0 10 10 10 22 22 22 54 54 54
55837 - 94 94 94 18 18 18 2 2 6 46 46 46
55838 -234 234 234 221 221 221 190 190 190 190 190 190
55839 -190 190 190 187 187 187 187 187 187 190 190 190
55840 -190 190 190 195 195 195 214 214 214 242 242 242
55841 -253 253 253 253 253 253 253 253 253 253 253 253
55842 - 82 82 82 2 2 6 2 2 6 2 2 6
55843 - 2 2 6 2 2 6 2 2 6 14 14 14
55844 - 86 86 86 54 54 54 22 22 22 6 6 6
55845 - 0 0 0 0 0 0 0 0 0 0 0 0
55846 - 0 0 0 0 0 0 0 0 0 0 0 0
55847 - 0 0 0 0 0 0 0 0 0 0 0 0
55848 - 0 0 0 0 0 0 0 0 0 0 0 0
55849 - 0 0 0 0 0 0 0 0 0 0 0 0
55850 - 0 0 0 0 0 0 0 0 0 0 0 0
55851 - 0 0 0 0 0 0 0 0 0 0 0 0
55852 - 0 0 0 0 0 0 0 0 0 0 0 0
55853 - 0 0 0 0 0 0 0 0 0 0 0 0
55854 - 0 0 0 0 0 0 0 0 0 0 0 0
55855 - 0 0 0 0 0 0 0 0 0 0 0 0
55856 - 6 6 6 18 18 18 46 46 46 90 90 90
55857 - 46 46 46 18 18 18 6 6 6 182 182 182
55858 -253 253 253 246 246 246 206 206 206 190 190 190
55859 -190 190 190 190 190 190 190 190 190 190 190 190
55860 -206 206 206 231 231 231 250 250 250 253 253 253
55861 -253 253 253 253 253 253 253 253 253 253 253 253
55862 -202 202 202 14 14 14 2 2 6 2 2 6
55863 - 2 2 6 2 2 6 2 2 6 2 2 6
55864 - 42 42 42 86 86 86 42 42 42 18 18 18
55865 - 6 6 6 0 0 0 0 0 0 0 0 0
55866 - 0 0 0 0 0 0 0 0 0 0 0 0
55867 - 0 0 0 0 0 0 0 0 0 0 0 0
55868 - 0 0 0 0 0 0 0 0 0 0 0 0
55869 - 0 0 0 0 0 0 0 0 0 0 0 0
55870 - 0 0 0 0 0 0 0 0 0 0 0 0
55871 - 0 0 0 0 0 0 0 0 0 0 0 0
55872 - 0 0 0 0 0 0 0 0 0 0 0 0
55873 - 0 0 0 0 0 0 0 0 0 0 0 0
55874 - 0 0 0 0 0 0 0 0 0 0 0 0
55875 - 0 0 0 0 0 0 0 0 0 6 6 6
55876 - 14 14 14 38 38 38 74 74 74 66 66 66
55877 - 2 2 6 6 6 6 90 90 90 250 250 250
55878 -253 253 253 253 253 253 238 238 238 198 198 198
55879 -190 190 190 190 190 190 195 195 195 221 221 221
55880 -246 246 246 253 253 253 253 253 253 253 253 253
55881 -253 253 253 253 253 253 253 253 253 253 253 253
55882 -253 253 253 82 82 82 2 2 6 2 2 6
55883 - 2 2 6 2 2 6 2 2 6 2 2 6
55884 - 2 2 6 78 78 78 70 70 70 34 34 34
55885 - 14 14 14 6 6 6 0 0 0 0 0 0
55886 - 0 0 0 0 0 0 0 0 0 0 0 0
55887 - 0 0 0 0 0 0 0 0 0 0 0 0
55888 - 0 0 0 0 0 0 0 0 0 0 0 0
55889 - 0 0 0 0 0 0 0 0 0 0 0 0
55890 - 0 0 0 0 0 0 0 0 0 0 0 0
55891 - 0 0 0 0 0 0 0 0 0 0 0 0
55892 - 0 0 0 0 0 0 0 0 0 0 0 0
55893 - 0 0 0 0 0 0 0 0 0 0 0 0
55894 - 0 0 0 0 0 0 0 0 0 0 0 0
55895 - 0 0 0 0 0 0 0 0 0 14 14 14
55896 - 34 34 34 66 66 66 78 78 78 6 6 6
55897 - 2 2 6 18 18 18 218 218 218 253 253 253
55898 -253 253 253 253 253 253 253 253 253 246 246 246
55899 -226 226 226 231 231 231 246 246 246 253 253 253
55900 -253 253 253 253 253 253 253 253 253 253 253 253
55901 -253 253 253 253 253 253 253 253 253 253 253 253
55902 -253 253 253 178 178 178 2 2 6 2 2 6
55903 - 2 2 6 2 2 6 2 2 6 2 2 6
55904 - 2 2 6 18 18 18 90 90 90 62 62 62
55905 - 30 30 30 10 10 10 0 0 0 0 0 0
55906 - 0 0 0 0 0 0 0 0 0 0 0 0
55907 - 0 0 0 0 0 0 0 0 0 0 0 0
55908 - 0 0 0 0 0 0 0 0 0 0 0 0
55909 - 0 0 0 0 0 0 0 0 0 0 0 0
55910 - 0 0 0 0 0 0 0 0 0 0 0 0
55911 - 0 0 0 0 0 0 0 0 0 0 0 0
55912 - 0 0 0 0 0 0 0 0 0 0 0 0
55913 - 0 0 0 0 0 0 0 0 0 0 0 0
55914 - 0 0 0 0 0 0 0 0 0 0 0 0
55915 - 0 0 0 0 0 0 10 10 10 26 26 26
55916 - 58 58 58 90 90 90 18 18 18 2 2 6
55917 - 2 2 6 110 110 110 253 253 253 253 253 253
55918 -253 253 253 253 253 253 253 253 253 253 253 253
55919 -250 250 250 253 253 253 253 253 253 253 253 253
55920 -253 253 253 253 253 253 253 253 253 253 253 253
55921 -253 253 253 253 253 253 253 253 253 253 253 253
55922 -253 253 253 231 231 231 18 18 18 2 2 6
55923 - 2 2 6 2 2 6 2 2 6 2 2 6
55924 - 2 2 6 2 2 6 18 18 18 94 94 94
55925 - 54 54 54 26 26 26 10 10 10 0 0 0
55926 - 0 0 0 0 0 0 0 0 0 0 0 0
55927 - 0 0 0 0 0 0 0 0 0 0 0 0
55928 - 0 0 0 0 0 0 0 0 0 0 0 0
55929 - 0 0 0 0 0 0 0 0 0 0 0 0
55930 - 0 0 0 0 0 0 0 0 0 0 0 0
55931 - 0 0 0 0 0 0 0 0 0 0 0 0
55932 - 0 0 0 0 0 0 0 0 0 0 0 0
55933 - 0 0 0 0 0 0 0 0 0 0 0 0
55934 - 0 0 0 0 0 0 0 0 0 0 0 0
55935 - 0 0 0 6 6 6 22 22 22 50 50 50
55936 - 90 90 90 26 26 26 2 2 6 2 2 6
55937 - 14 14 14 195 195 195 250 250 250 253 253 253
55938 -253 253 253 253 253 253 253 253 253 253 253 253
55939 -253 253 253 253 253 253 253 253 253 253 253 253
55940 -253 253 253 253 253 253 253 253 253 253 253 253
55941 -253 253 253 253 253 253 253 253 253 253 253 253
55942 -250 250 250 242 242 242 54 54 54 2 2 6
55943 - 2 2 6 2 2 6 2 2 6 2 2 6
55944 - 2 2 6 2 2 6 2 2 6 38 38 38
55945 - 86 86 86 50 50 50 22 22 22 6 6 6
55946 - 0 0 0 0 0 0 0 0 0 0 0 0
55947 - 0 0 0 0 0 0 0 0 0 0 0 0
55948 - 0 0 0 0 0 0 0 0 0 0 0 0
55949 - 0 0 0 0 0 0 0 0 0 0 0 0
55950 - 0 0 0 0 0 0 0 0 0 0 0 0
55951 - 0 0 0 0 0 0 0 0 0 0 0 0
55952 - 0 0 0 0 0 0 0 0 0 0 0 0
55953 - 0 0 0 0 0 0 0 0 0 0 0 0
55954 - 0 0 0 0 0 0 0 0 0 0 0 0
55955 - 6 6 6 14 14 14 38 38 38 82 82 82
55956 - 34 34 34 2 2 6 2 2 6 2 2 6
55957 - 42 42 42 195 195 195 246 246 246 253 253 253
55958 -253 253 253 253 253 253 253 253 253 250 250 250
55959 -242 242 242 242 242 242 250 250 250 253 253 253
55960 -253 253 253 253 253 253 253 253 253 253 253 253
55961 -253 253 253 250 250 250 246 246 246 238 238 238
55962 -226 226 226 231 231 231 101 101 101 6 6 6
55963 - 2 2 6 2 2 6 2 2 6 2 2 6
55964 - 2 2 6 2 2 6 2 2 6 2 2 6
55965 - 38 38 38 82 82 82 42 42 42 14 14 14
55966 - 6 6 6 0 0 0 0 0 0 0 0 0
55967 - 0 0 0 0 0 0 0 0 0 0 0 0
55968 - 0 0 0 0 0 0 0 0 0 0 0 0
55969 - 0 0 0 0 0 0 0 0 0 0 0 0
55970 - 0 0 0 0 0 0 0 0 0 0 0 0
55971 - 0 0 0 0 0 0 0 0 0 0 0 0
55972 - 0 0 0 0 0 0 0 0 0 0 0 0
55973 - 0 0 0 0 0 0 0 0 0 0 0 0
55974 - 0 0 0 0 0 0 0 0 0 0 0 0
55975 - 10 10 10 26 26 26 62 62 62 66 66 66
55976 - 2 2 6 2 2 6 2 2 6 6 6 6
55977 - 70 70 70 170 170 170 206 206 206 234 234 234
55978 -246 246 246 250 250 250 250 250 250 238 238 238
55979 -226 226 226 231 231 231 238 238 238 250 250 250
55980 -250 250 250 250 250 250 246 246 246 231 231 231
55981 -214 214 214 206 206 206 202 202 202 202 202 202
55982 -198 198 198 202 202 202 182 182 182 18 18 18
55983 - 2 2 6 2 2 6 2 2 6 2 2 6
55984 - 2 2 6 2 2 6 2 2 6 2 2 6
55985 - 2 2 6 62 62 62 66 66 66 30 30 30
55986 - 10 10 10 0 0 0 0 0 0 0 0 0
55987 - 0 0 0 0 0 0 0 0 0 0 0 0
55988 - 0 0 0 0 0 0 0 0 0 0 0 0
55989 - 0 0 0 0 0 0 0 0 0 0 0 0
55990 - 0 0 0 0 0 0 0 0 0 0 0 0
55991 - 0 0 0 0 0 0 0 0 0 0 0 0
55992 - 0 0 0 0 0 0 0 0 0 0 0 0
55993 - 0 0 0 0 0 0 0 0 0 0 0 0
55994 - 0 0 0 0 0 0 0 0 0 0 0 0
55995 - 14 14 14 42 42 42 82 82 82 18 18 18
55996 - 2 2 6 2 2 6 2 2 6 10 10 10
55997 - 94 94 94 182 182 182 218 218 218 242 242 242
55998 -250 250 250 253 253 253 253 253 253 250 250 250
55999 -234 234 234 253 253 253 253 253 253 253 253 253
56000 -253 253 253 253 253 253 253 253 253 246 246 246
56001 -238 238 238 226 226 226 210 210 210 202 202 202
56002 -195 195 195 195 195 195 210 210 210 158 158 158
56003 - 6 6 6 14 14 14 50 50 50 14 14 14
56004 - 2 2 6 2 2 6 2 2 6 2 2 6
56005 - 2 2 6 6 6 6 86 86 86 46 46 46
56006 - 18 18 18 6 6 6 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 6 6 6
56015 - 22 22 22 54 54 54 70 70 70 2 2 6
56016 - 2 2 6 10 10 10 2 2 6 22 22 22
56017 -166 166 166 231 231 231 250 250 250 253 253 253
56018 -253 253 253 253 253 253 253 253 253 250 250 250
56019 -242 242 242 253 253 253 253 253 253 253 253 253
56020 -253 253 253 253 253 253 253 253 253 253 253 253
56021 -253 253 253 253 253 253 253 253 253 246 246 246
56022 -231 231 231 206 206 206 198 198 198 226 226 226
56023 - 94 94 94 2 2 6 6 6 6 38 38 38
56024 - 30 30 30 2 2 6 2 2 6 2 2 6
56025 - 2 2 6 2 2 6 62 62 62 66 66 66
56026 - 26 26 26 10 10 10 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 10 10 10
56035 - 30 30 30 74 74 74 50 50 50 2 2 6
56036 - 26 26 26 26 26 26 2 2 6 106 106 106
56037 -238 238 238 253 253 253 253 253 253 253 253 253
56038 -253 253 253 253 253 253 253 253 253 253 253 253
56039 -253 253 253 253 253 253 253 253 253 253 253 253
56040 -253 253 253 253 253 253 253 253 253 253 253 253
56041 -253 253 253 253 253 253 253 253 253 253 253 253
56042 -253 253 253 246 246 246 218 218 218 202 202 202
56043 -210 210 210 14 14 14 2 2 6 2 2 6
56044 - 30 30 30 22 22 22 2 2 6 2 2 6
56045 - 2 2 6 2 2 6 18 18 18 86 86 86
56046 - 42 42 42 14 14 14 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 14 14 14
56055 - 42 42 42 90 90 90 22 22 22 2 2 6
56056 - 42 42 42 2 2 6 18 18 18 218 218 218
56057 -253 253 253 253 253 253 253 253 253 253 253 253
56058 -253 253 253 253 253 253 253 253 253 253 253 253
56059 -253 253 253 253 253 253 253 253 253 253 253 253
56060 -253 253 253 253 253 253 253 253 253 253 253 253
56061 -253 253 253 253 253 253 253 253 253 253 253 253
56062 -253 253 253 253 253 253 250 250 250 221 221 221
56063 -218 218 218 101 101 101 2 2 6 14 14 14
56064 - 18 18 18 38 38 38 10 10 10 2 2 6
56065 - 2 2 6 2 2 6 2 2 6 78 78 78
56066 - 58 58 58 22 22 22 6 6 6 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 6 6 6 18 18 18
56075 - 54 54 54 82 82 82 2 2 6 26 26 26
56076 - 22 22 22 2 2 6 123 123 123 253 253 253
56077 -253 253 253 253 253 253 253 253 253 253 253 253
56078 -253 253 253 253 253 253 253 253 253 253 253 253
56079 -253 253 253 253 253 253 253 253 253 253 253 253
56080 -253 253 253 253 253 253 253 253 253 253 253 253
56081 -253 253 253 253 253 253 253 253 253 253 253 253
56082 -253 253 253 253 253 253 253 253 253 250 250 250
56083 -238 238 238 198 198 198 6 6 6 38 38 38
56084 - 58 58 58 26 26 26 38 38 38 2 2 6
56085 - 2 2 6 2 2 6 2 2 6 46 46 46
56086 - 78 78 78 30 30 30 10 10 10 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 10 10 10 30 30 30
56095 - 74 74 74 58 58 58 2 2 6 42 42 42
56096 - 2 2 6 22 22 22 231 231 231 253 253 253
56097 -253 253 253 253 253 253 253 253 253 253 253 253
56098 -253 253 253 253 253 253 253 253 253 250 250 250
56099 -253 253 253 253 253 253 253 253 253 253 253 253
56100 -253 253 253 253 253 253 253 253 253 253 253 253
56101 -253 253 253 253 253 253 253 253 253 253 253 253
56102 -253 253 253 253 253 253 253 253 253 253 253 253
56103 -253 253 253 246 246 246 46 46 46 38 38 38
56104 - 42 42 42 14 14 14 38 38 38 14 14 14
56105 - 2 2 6 2 2 6 2 2 6 6 6 6
56106 - 86 86 86 46 46 46 14 14 14 0 0 0
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 6 6 6 14 14 14 42 42 42
56115 - 90 90 90 18 18 18 18 18 18 26 26 26
56116 - 2 2 6 116 116 116 253 253 253 253 253 253
56117 -253 253 253 253 253 253 253 253 253 253 253 253
56118 -253 253 253 253 253 253 250 250 250 238 238 238
56119 -253 253 253 253 253 253 253 253 253 253 253 253
56120 -253 253 253 253 253 253 253 253 253 253 253 253
56121 -253 253 253 253 253 253 253 253 253 253 253 253
56122 -253 253 253 253 253 253 253 253 253 253 253 253
56123 -253 253 253 253 253 253 94 94 94 6 6 6
56124 - 2 2 6 2 2 6 10 10 10 34 34 34
56125 - 2 2 6 2 2 6 2 2 6 2 2 6
56126 - 74 74 74 58 58 58 22 22 22 6 6 6
56127 - 0 0 0 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 10 10 10 26 26 26 66 66 66
56135 - 82 82 82 2 2 6 38 38 38 6 6 6
56136 - 14 14 14 210 210 210 253 253 253 253 253 253
56137 -253 253 253 253 253 253 253 253 253 253 253 253
56138 -253 253 253 253 253 253 246 246 246 242 242 242
56139 -253 253 253 253 253 253 253 253 253 253 253 253
56140 -253 253 253 253 253 253 253 253 253 253 253 253
56141 -253 253 253 253 253 253 253 253 253 253 253 253
56142 -253 253 253 253 253 253 253 253 253 253 253 253
56143 -253 253 253 253 253 253 144 144 144 2 2 6
56144 - 2 2 6 2 2 6 2 2 6 46 46 46
56145 - 2 2 6 2 2 6 2 2 6 2 2 6
56146 - 42 42 42 74 74 74 30 30 30 10 10 10
56147 - 0 0 0 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 - 6 6 6 14 14 14 42 42 42 90 90 90
56155 - 26 26 26 6 6 6 42 42 42 2 2 6
56156 - 74 74 74 250 250 250 253 253 253 253 253 253
56157 -253 253 253 253 253 253 253 253 253 253 253 253
56158 -253 253 253 253 253 253 242 242 242 242 242 242
56159 -253 253 253 253 253 253 253 253 253 253 253 253
56160 -253 253 253 253 253 253 253 253 253 253 253 253
56161 -253 253 253 253 253 253 253 253 253 253 253 253
56162 -253 253 253 253 253 253 253 253 253 253 253 253
56163 -253 253 253 253 253 253 182 182 182 2 2 6
56164 - 2 2 6 2 2 6 2 2 6 46 46 46
56165 - 2 2 6 2 2 6 2 2 6 2 2 6
56166 - 10 10 10 86 86 86 38 38 38 10 10 10
56167 - 0 0 0 0 0 0 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 - 10 10 10 26 26 26 66 66 66 82 82 82
56175 - 2 2 6 22 22 22 18 18 18 2 2 6
56176 -149 149 149 253 253 253 253 253 253 253 253 253
56177 -253 253 253 253 253 253 253 253 253 253 253 253
56178 -253 253 253 253 253 253 234 234 234 242 242 242
56179 -253 253 253 253 253 253 253 253 253 253 253 253
56180 -253 253 253 253 253 253 253 253 253 253 253 253
56181 -253 253 253 253 253 253 253 253 253 253 253 253
56182 -253 253 253 253 253 253 253 253 253 253 253 253
56183 -253 253 253 253 253 253 206 206 206 2 2 6
56184 - 2 2 6 2 2 6 2 2 6 38 38 38
56185 - 2 2 6 2 2 6 2 2 6 2 2 6
56186 - 6 6 6 86 86 86 46 46 46 14 14 14
56187 - 0 0 0 0 0 0 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 6 6 6
56194 - 18 18 18 46 46 46 86 86 86 18 18 18
56195 - 2 2 6 34 34 34 10 10 10 6 6 6
56196 -210 210 210 253 253 253 253 253 253 253 253 253
56197 -253 253 253 253 253 253 253 253 253 253 253 253
56198 -253 253 253 253 253 253 234 234 234 242 242 242
56199 -253 253 253 253 253 253 253 253 253 253 253 253
56200 -253 253 253 253 253 253 253 253 253 253 253 253
56201 -253 253 253 253 253 253 253 253 253 253 253 253
56202 -253 253 253 253 253 253 253 253 253 253 253 253
56203 -253 253 253 253 253 253 221 221 221 6 6 6
56204 - 2 2 6 2 2 6 6 6 6 30 30 30
56205 - 2 2 6 2 2 6 2 2 6 2 2 6
56206 - 2 2 6 82 82 82 54 54 54 18 18 18
56207 - 6 6 6 0 0 0 0 0 0 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 10 10 10
56214 - 26 26 26 66 66 66 62 62 62 2 2 6
56215 - 2 2 6 38 38 38 10 10 10 26 26 26
56216 -238 238 238 253 253 253 253 253 253 253 253 253
56217 -253 253 253 253 253 253 253 253 253 253 253 253
56218 -253 253 253 253 253 253 231 231 231 238 238 238
56219 -253 253 253 253 253 253 253 253 253 253 253 253
56220 -253 253 253 253 253 253 253 253 253 253 253 253
56221 -253 253 253 253 253 253 253 253 253 253 253 253
56222 -253 253 253 253 253 253 253 253 253 253 253 253
56223 -253 253 253 253 253 253 231 231 231 6 6 6
56224 - 2 2 6 2 2 6 10 10 10 30 30 30
56225 - 2 2 6 2 2 6 2 2 6 2 2 6
56226 - 2 2 6 66 66 66 58 58 58 22 22 22
56227 - 6 6 6 0 0 0 0 0 0 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 10 10 10
56234 - 38 38 38 78 78 78 6 6 6 2 2 6
56235 - 2 2 6 46 46 46 14 14 14 42 42 42
56236 -246 246 246 253 253 253 253 253 253 253 253 253
56237 -253 253 253 253 253 253 253 253 253 253 253 253
56238 -253 253 253 253 253 253 231 231 231 242 242 242
56239 -253 253 253 253 253 253 253 253 253 253 253 253
56240 -253 253 253 253 253 253 253 253 253 253 253 253
56241 -253 253 253 253 253 253 253 253 253 253 253 253
56242 -253 253 253 253 253 253 253 253 253 253 253 253
56243 -253 253 253 253 253 253 234 234 234 10 10 10
56244 - 2 2 6 2 2 6 22 22 22 14 14 14
56245 - 2 2 6 2 2 6 2 2 6 2 2 6
56246 - 2 2 6 66 66 66 62 62 62 22 22 22
56247 - 6 6 6 0 0 0 0 0 0 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 6 6 6 18 18 18
56254 - 50 50 50 74 74 74 2 2 6 2 2 6
56255 - 14 14 14 70 70 70 34 34 34 62 62 62
56256 -250 250 250 253 253 253 253 253 253 253 253 253
56257 -253 253 253 253 253 253 253 253 253 253 253 253
56258 -253 253 253 253 253 253 231 231 231 246 246 246
56259 -253 253 253 253 253 253 253 253 253 253 253 253
56260 -253 253 253 253 253 253 253 253 253 253 253 253
56261 -253 253 253 253 253 253 253 253 253 253 253 253
56262 -253 253 253 253 253 253 253 253 253 253 253 253
56263 -253 253 253 253 253 253 234 234 234 14 14 14
56264 - 2 2 6 2 2 6 30 30 30 2 2 6
56265 - 2 2 6 2 2 6 2 2 6 2 2 6
56266 - 2 2 6 66 66 66 62 62 62 22 22 22
56267 - 6 6 6 0 0 0 0 0 0 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 6 6 6 18 18 18
56274 - 54 54 54 62 62 62 2 2 6 2 2 6
56275 - 2 2 6 30 30 30 46 46 46 70 70 70
56276 -250 250 250 253 253 253 253 253 253 253 253 253
56277 -253 253 253 253 253 253 253 253 253 253 253 253
56278 -253 253 253 253 253 253 231 231 231 246 246 246
56279 -253 253 253 253 253 253 253 253 253 253 253 253
56280 -253 253 253 253 253 253 253 253 253 253 253 253
56281 -253 253 253 253 253 253 253 253 253 253 253 253
56282 -253 253 253 253 253 253 253 253 253 253 253 253
56283 -253 253 253 253 253 253 226 226 226 10 10 10
56284 - 2 2 6 6 6 6 30 30 30 2 2 6
56285 - 2 2 6 2 2 6 2 2 6 2 2 6
56286 - 2 2 6 66 66 66 58 58 58 22 22 22
56287 - 6 6 6 0 0 0 0 0 0 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 6 6 6 22 22 22
56294 - 58 58 58 62 62 62 2 2 6 2 2 6
56295 - 2 2 6 2 2 6 30 30 30 78 78 78
56296 -250 250 250 253 253 253 253 253 253 253 253 253
56297 -253 253 253 253 253 253 253 253 253 253 253 253
56298 -253 253 253 253 253 253 231 231 231 246 246 246
56299 -253 253 253 253 253 253 253 253 253 253 253 253
56300 -253 253 253 253 253 253 253 253 253 253 253 253
56301 -253 253 253 253 253 253 253 253 253 253 253 253
56302 -253 253 253 253 253 253 253 253 253 253 253 253
56303 -253 253 253 253 253 253 206 206 206 2 2 6
56304 - 22 22 22 34 34 34 18 14 6 22 22 22
56305 - 26 26 26 18 18 18 6 6 6 2 2 6
56306 - 2 2 6 82 82 82 54 54 54 18 18 18
56307 - 6 6 6 0 0 0 0 0 0 0 0 0
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 6 6 6 26 26 26
56314 - 62 62 62 106 106 106 74 54 14 185 133 11
56315 -210 162 10 121 92 8 6 6 6 62 62 62
56316 -238 238 238 253 253 253 253 253 253 253 253 253
56317 -253 253 253 253 253 253 253 253 253 253 253 253
56318 -253 253 253 253 253 253 231 231 231 246 246 246
56319 -253 253 253 253 253 253 253 253 253 253 253 253
56320 -253 253 253 253 253 253 253 253 253 253 253 253
56321 -253 253 253 253 253 253 253 253 253 253 253 253
56322 -253 253 253 253 253 253 253 253 253 253 253 253
56323 -253 253 253 253 253 253 158 158 158 18 18 18
56324 - 14 14 14 2 2 6 2 2 6 2 2 6
56325 - 6 6 6 18 18 18 66 66 66 38 38 38
56326 - 6 6 6 94 94 94 50 50 50 18 18 18
56327 - 6 6 6 0 0 0 0 0 0 0 0 0
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 6 6 6
56333 - 10 10 10 10 10 10 18 18 18 38 38 38
56334 - 78 78 78 142 134 106 216 158 10 242 186 14
56335 -246 190 14 246 190 14 156 118 10 10 10 10
56336 - 90 90 90 238 238 238 253 253 253 253 253 253
56337 -253 253 253 253 253 253 253 253 253 253 253 253
56338 -253 253 253 253 253 253 231 231 231 250 250 250
56339 -253 253 253 253 253 253 253 253 253 253 253 253
56340 -253 253 253 253 253 253 253 253 253 253 253 253
56341 -253 253 253 253 253 253 253 253 253 253 253 253
56342 -253 253 253 253 253 253 253 253 253 246 230 190
56343 -238 204 91 238 204 91 181 142 44 37 26 9
56344 - 2 2 6 2 2 6 2 2 6 2 2 6
56345 - 2 2 6 2 2 6 38 38 38 46 46 46
56346 - 26 26 26 106 106 106 54 54 54 18 18 18
56347 - 6 6 6 0 0 0 0 0 0 0 0 0
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 6 6 6 14 14 14 22 22 22
56353 - 30 30 30 38 38 38 50 50 50 70 70 70
56354 -106 106 106 190 142 34 226 170 11 242 186 14
56355 -246 190 14 246 190 14 246 190 14 154 114 10
56356 - 6 6 6 74 74 74 226 226 226 253 253 253
56357 -253 253 253 253 253 253 253 253 253 253 253 253
56358 -253 253 253 253 253 253 231 231 231 250 250 250
56359 -253 253 253 253 253 253 253 253 253 253 253 253
56360 -253 253 253 253 253 253 253 253 253 253 253 253
56361 -253 253 253 253 253 253 253 253 253 253 253 253
56362 -253 253 253 253 253 253 253 253 253 228 184 62
56363 -241 196 14 241 208 19 232 195 16 38 30 10
56364 - 2 2 6 2 2 6 2 2 6 2 2 6
56365 - 2 2 6 6 6 6 30 30 30 26 26 26
56366 -203 166 17 154 142 90 66 66 66 26 26 26
56367 - 6 6 6 0 0 0 0 0 0 0 0 0
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 - 6 6 6 18 18 18 38 38 38 58 58 58
56373 - 78 78 78 86 86 86 101 101 101 123 123 123
56374 -175 146 61 210 150 10 234 174 13 246 186 14
56375 -246 190 14 246 190 14 246 190 14 238 190 10
56376 -102 78 10 2 2 6 46 46 46 198 198 198
56377 -253 253 253 253 253 253 253 253 253 253 253 253
56378 -253 253 253 253 253 253 234 234 234 242 242 242
56379 -253 253 253 253 253 253 253 253 253 253 253 253
56380 -253 253 253 253 253 253 253 253 253 253 253 253
56381 -253 253 253 253 253 253 253 253 253 253 253 253
56382 -253 253 253 253 253 253 253 253 253 224 178 62
56383 -242 186 14 241 196 14 210 166 10 22 18 6
56384 - 2 2 6 2 2 6 2 2 6 2 2 6
56385 - 2 2 6 2 2 6 6 6 6 121 92 8
56386 -238 202 15 232 195 16 82 82 82 34 34 34
56387 - 10 10 10 0 0 0 0 0 0 0 0 0
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 - 14 14 14 38 38 38 70 70 70 154 122 46
56393 -190 142 34 200 144 11 197 138 11 197 138 11
56394 -213 154 11 226 170 11 242 186 14 246 190 14
56395 -246 190 14 246 190 14 246 190 14 246 190 14
56396 -225 175 15 46 32 6 2 2 6 22 22 22
56397 -158 158 158 250 250 250 253 253 253 253 253 253
56398 -253 253 253 253 253 253 253 253 253 253 253 253
56399 -253 253 253 253 253 253 253 253 253 253 253 253
56400 -253 253 253 253 253 253 253 253 253 253 253 253
56401 -253 253 253 253 253 253 253 253 253 253 253 253
56402 -253 253 253 250 250 250 242 242 242 224 178 62
56403 -239 182 13 236 186 11 213 154 11 46 32 6
56404 - 2 2 6 2 2 6 2 2 6 2 2 6
56405 - 2 2 6 2 2 6 61 42 6 225 175 15
56406 -238 190 10 236 186 11 112 100 78 42 42 42
56407 - 14 14 14 0 0 0 0 0 0 0 0 0
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 6 6 6
56412 - 22 22 22 54 54 54 154 122 46 213 154 11
56413 -226 170 11 230 174 11 226 170 11 226 170 11
56414 -236 178 12 242 186 14 246 190 14 246 190 14
56415 -246 190 14 246 190 14 246 190 14 246 190 14
56416 -241 196 14 184 144 12 10 10 10 2 2 6
56417 - 6 6 6 116 116 116 242 242 242 253 253 253
56418 -253 253 253 253 253 253 253 253 253 253 253 253
56419 -253 253 253 253 253 253 253 253 253 253 253 253
56420 -253 253 253 253 253 253 253 253 253 253 253 253
56421 -253 253 253 253 253 253 253 253 253 253 253 253
56422 -253 253 253 231 231 231 198 198 198 214 170 54
56423 -236 178 12 236 178 12 210 150 10 137 92 6
56424 - 18 14 6 2 2 6 2 2 6 2 2 6
56425 - 6 6 6 70 47 6 200 144 11 236 178 12
56426 -239 182 13 239 182 13 124 112 88 58 58 58
56427 - 22 22 22 6 6 6 0 0 0 0 0 0
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 10 10 10
56432 - 30 30 30 70 70 70 180 133 36 226 170 11
56433 -239 182 13 242 186 14 242 186 14 246 186 14
56434 -246 190 14 246 190 14 246 190 14 246 190 14
56435 -246 190 14 246 190 14 246 190 14 246 190 14
56436 -246 190 14 232 195 16 98 70 6 2 2 6
56437 - 2 2 6 2 2 6 66 66 66 221 221 221
56438 -253 253 253 253 253 253 253 253 253 253 253 253
56439 -253 253 253 253 253 253 253 253 253 253 253 253
56440 -253 253 253 253 253 253 253 253 253 253 253 253
56441 -253 253 253 253 253 253 253 253 253 253 253 253
56442 -253 253 253 206 206 206 198 198 198 214 166 58
56443 -230 174 11 230 174 11 216 158 10 192 133 9
56444 -163 110 8 116 81 8 102 78 10 116 81 8
56445 -167 114 7 197 138 11 226 170 11 239 182 13
56446 -242 186 14 242 186 14 162 146 94 78 78 78
56447 - 34 34 34 14 14 14 6 6 6 0 0 0
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 6 6 6
56452 - 30 30 30 78 78 78 190 142 34 226 170 11
56453 -239 182 13 246 190 14 246 190 14 246 190 14
56454 -246 190 14 246 190 14 246 190 14 246 190 14
56455 -246 190 14 246 190 14 246 190 14 246 190 14
56456 -246 190 14 241 196 14 203 166 17 22 18 6
56457 - 2 2 6 2 2 6 2 2 6 38 38 38
56458 -218 218 218 253 253 253 253 253 253 253 253 253
56459 -253 253 253 253 253 253 253 253 253 253 253 253
56460 -253 253 253 253 253 253 253 253 253 253 253 253
56461 -253 253 253 253 253 253 253 253 253 253 253 253
56462 -250 250 250 206 206 206 198 198 198 202 162 69
56463 -226 170 11 236 178 12 224 166 10 210 150 10
56464 -200 144 11 197 138 11 192 133 9 197 138 11
56465 -210 150 10 226 170 11 242 186 14 246 190 14
56466 -246 190 14 246 186 14 225 175 15 124 112 88
56467 - 62 62 62 30 30 30 14 14 14 6 6 6
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 10 10 10
56472 - 30 30 30 78 78 78 174 135 50 224 166 10
56473 -239 182 13 246 190 14 246 190 14 246 190 14
56474 -246 190 14 246 190 14 246 190 14 246 190 14
56475 -246 190 14 246 190 14 246 190 14 246 190 14
56476 -246 190 14 246 190 14 241 196 14 139 102 15
56477 - 2 2 6 2 2 6 2 2 6 2 2 6
56478 - 78 78 78 250 250 250 253 253 253 253 253 253
56479 -253 253 253 253 253 253 253 253 253 253 253 253
56480 -253 253 253 253 253 253 253 253 253 253 253 253
56481 -253 253 253 253 253 253 253 253 253 253 253 253
56482 -250 250 250 214 214 214 198 198 198 190 150 46
56483 -219 162 10 236 178 12 234 174 13 224 166 10
56484 -216 158 10 213 154 11 213 154 11 216 158 10
56485 -226 170 11 239 182 13 246 190 14 246 190 14
56486 -246 190 14 246 190 14 242 186 14 206 162 42
56487 -101 101 101 58 58 58 30 30 30 14 14 14
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 10 10 10
56492 - 30 30 30 74 74 74 174 135 50 216 158 10
56493 -236 178 12 246 190 14 246 190 14 246 190 14
56494 -246 190 14 246 190 14 246 190 14 246 190 14
56495 -246 190 14 246 190 14 246 190 14 246 190 14
56496 -246 190 14 246 190 14 241 196 14 226 184 13
56497 - 61 42 6 2 2 6 2 2 6 2 2 6
56498 - 22 22 22 238 238 238 253 253 253 253 253 253
56499 -253 253 253 253 253 253 253 253 253 253 253 253
56500 -253 253 253 253 253 253 253 253 253 253 253 253
56501 -253 253 253 253 253 253 253 253 253 253 253 253
56502 -253 253 253 226 226 226 187 187 187 180 133 36
56503 -216 158 10 236 178 12 239 182 13 236 178 12
56504 -230 174 11 226 170 11 226 170 11 230 174 11
56505 -236 178 12 242 186 14 246 190 14 246 190 14
56506 -246 190 14 246 190 14 246 186 14 239 182 13
56507 -206 162 42 106 106 106 66 66 66 34 34 34
56508 - 14 14 14 6 6 6 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 6 6 6
56512 - 26 26 26 70 70 70 163 133 67 213 154 11
56513 -236 178 12 246 190 14 246 190 14 246 190 14
56514 -246 190 14 246 190 14 246 190 14 246 190 14
56515 -246 190 14 246 190 14 246 190 14 246 190 14
56516 -246 190 14 246 190 14 246 190 14 241 196 14
56517 -190 146 13 18 14 6 2 2 6 2 2 6
56518 - 46 46 46 246 246 246 253 253 253 253 253 253
56519 -253 253 253 253 253 253 253 253 253 253 253 253
56520 -253 253 253 253 253 253 253 253 253 253 253 253
56521 -253 253 253 253 253 253 253 253 253 253 253 253
56522 -253 253 253 221 221 221 86 86 86 156 107 11
56523 -216 158 10 236 178 12 242 186 14 246 186 14
56524 -242 186 14 239 182 13 239 182 13 242 186 14
56525 -242 186 14 246 186 14 246 190 14 246 190 14
56526 -246 190 14 246 190 14 246 190 14 246 190 14
56527 -242 186 14 225 175 15 142 122 72 66 66 66
56528 - 30 30 30 10 10 10 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 6 6 6
56532 - 26 26 26 70 70 70 163 133 67 210 150 10
56533 -236 178 12 246 190 14 246 190 14 246 190 14
56534 -246 190 14 246 190 14 246 190 14 246 190 14
56535 -246 190 14 246 190 14 246 190 14 246 190 14
56536 -246 190 14 246 190 14 246 190 14 246 190 14
56537 -232 195 16 121 92 8 34 34 34 106 106 106
56538 -221 221 221 253 253 253 253 253 253 253 253 253
56539 -253 253 253 253 253 253 253 253 253 253 253 253
56540 -253 253 253 253 253 253 253 253 253 253 253 253
56541 -253 253 253 253 253 253 253 253 253 253 253 253
56542 -242 242 242 82 82 82 18 14 6 163 110 8
56543 -216 158 10 236 178 12 242 186 14 246 190 14
56544 -246 190 14 246 190 14 246 190 14 246 190 14
56545 -246 190 14 246 190 14 246 190 14 246 190 14
56546 -246 190 14 246 190 14 246 190 14 246 190 14
56547 -246 190 14 246 190 14 242 186 14 163 133 67
56548 - 46 46 46 18 18 18 6 6 6 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 10 10 10
56552 - 30 30 30 78 78 78 163 133 67 210 150 10
56553 -236 178 12 246 186 14 246 190 14 246 190 14
56554 -246 190 14 246 190 14 246 190 14 246 190 14
56555 -246 190 14 246 190 14 246 190 14 246 190 14
56556 -246 190 14 246 190 14 246 190 14 246 190 14
56557 -241 196 14 215 174 15 190 178 144 253 253 253
56558 -253 253 253 253 253 253 253 253 253 253 253 253
56559 -253 253 253 253 253 253 253 253 253 253 253 253
56560 -253 253 253 253 253 253 253 253 253 253 253 253
56561 -253 253 253 253 253 253 253 253 253 218 218 218
56562 - 58 58 58 2 2 6 22 18 6 167 114 7
56563 -216 158 10 236 178 12 246 186 14 246 190 14
56564 -246 190 14 246 190 14 246 190 14 246 190 14
56565 -246 190 14 246 190 14 246 190 14 246 190 14
56566 -246 190 14 246 190 14 246 190 14 246 190 14
56567 -246 190 14 246 186 14 242 186 14 190 150 46
56568 - 54 54 54 22 22 22 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 14 14 14
56572 - 38 38 38 86 86 86 180 133 36 213 154 11
56573 -236 178 12 246 186 14 246 190 14 246 190 14
56574 -246 190 14 246 190 14 246 190 14 246 190 14
56575 -246 190 14 246 190 14 246 190 14 246 190 14
56576 -246 190 14 246 190 14 246 190 14 246 190 14
56577 -246 190 14 232 195 16 190 146 13 214 214 214
56578 -253 253 253 253 253 253 253 253 253 253 253 253
56579 -253 253 253 253 253 253 253 253 253 253 253 253
56580 -253 253 253 253 253 253 253 253 253 253 253 253
56581 -253 253 253 250 250 250 170 170 170 26 26 26
56582 - 2 2 6 2 2 6 37 26 9 163 110 8
56583 -219 162 10 239 182 13 246 186 14 246 190 14
56584 -246 190 14 246 190 14 246 190 14 246 190 14
56585 -246 190 14 246 190 14 246 190 14 246 190 14
56586 -246 190 14 246 190 14 246 190 14 246 190 14
56587 -246 186 14 236 178 12 224 166 10 142 122 72
56588 - 46 46 46 18 18 18 6 6 6 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 6 6 6 18 18 18
56592 - 50 50 50 109 106 95 192 133 9 224 166 10
56593 -242 186 14 246 190 14 246 190 14 246 190 14
56594 -246 190 14 246 190 14 246 190 14 246 190 14
56595 -246 190 14 246 190 14 246 190 14 246 190 14
56596 -246 190 14 246 190 14 246 190 14 246 190 14
56597 -242 186 14 226 184 13 210 162 10 142 110 46
56598 -226 226 226 253 253 253 253 253 253 253 253 253
56599 -253 253 253 253 253 253 253 253 253 253 253 253
56600 -253 253 253 253 253 253 253 253 253 253 253 253
56601 -198 198 198 66 66 66 2 2 6 2 2 6
56602 - 2 2 6 2 2 6 50 34 6 156 107 11
56603 -219 162 10 239 182 13 246 186 14 246 190 14
56604 -246 190 14 246 190 14 246 190 14 246 190 14
56605 -246 190 14 246 190 14 246 190 14 246 190 14
56606 -246 190 14 246 190 14 246 190 14 242 186 14
56607 -234 174 13 213 154 11 154 122 46 66 66 66
56608 - 30 30 30 10 10 10 0 0 0 0 0 0
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 6 6 6 22 22 22
56612 - 58 58 58 154 121 60 206 145 10 234 174 13
56613 -242 186 14 246 186 14 246 190 14 246 190 14
56614 -246 190 14 246 190 14 246 190 14 246 190 14
56615 -246 190 14 246 190 14 246 190 14 246 190 14
56616 -246 190 14 246 190 14 246 190 14 246 190 14
56617 -246 186 14 236 178 12 210 162 10 163 110 8
56618 - 61 42 6 138 138 138 218 218 218 250 250 250
56619 -253 253 253 253 253 253 253 253 253 250 250 250
56620 -242 242 242 210 210 210 144 144 144 66 66 66
56621 - 6 6 6 2 2 6 2 2 6 2 2 6
56622 - 2 2 6 2 2 6 61 42 6 163 110 8
56623 -216 158 10 236 178 12 246 190 14 246 190 14
56624 -246 190 14 246 190 14 246 190 14 246 190 14
56625 -246 190 14 246 190 14 246 190 14 246 190 14
56626 -246 190 14 239 182 13 230 174 11 216 158 10
56627 -190 142 34 124 112 88 70 70 70 38 38 38
56628 - 18 18 18 6 6 6 0 0 0 0 0 0
56629 - 0 0 0 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 6 6 6 22 22 22
56632 - 62 62 62 168 124 44 206 145 10 224 166 10
56633 -236 178 12 239 182 13 242 186 14 242 186 14
56634 -246 186 14 246 190 14 246 190 14 246 190 14
56635 -246 190 14 246 190 14 246 190 14 246 190 14
56636 -246 190 14 246 190 14 246 190 14 246 190 14
56637 -246 190 14 236 178 12 216 158 10 175 118 6
56638 - 80 54 7 2 2 6 6 6 6 30 30 30
56639 - 54 54 54 62 62 62 50 50 50 38 38 38
56640 - 14 14 14 2 2 6 2 2 6 2 2 6
56641 - 2 2 6 2 2 6 2 2 6 2 2 6
56642 - 2 2 6 6 6 6 80 54 7 167 114 7
56643 -213 154 11 236 178 12 246 190 14 246 190 14
56644 -246 190 14 246 190 14 246 190 14 246 190 14
56645 -246 190 14 242 186 14 239 182 13 239 182 13
56646 -230 174 11 210 150 10 174 135 50 124 112 88
56647 - 82 82 82 54 54 54 34 34 34 18 18 18
56648 - 6 6 6 0 0 0 0 0 0 0 0 0
56649 - 0 0 0 0 0 0 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 6 6 6 18 18 18
56652 - 50 50 50 158 118 36 192 133 9 200 144 11
56653 -216 158 10 219 162 10 224 166 10 226 170 11
56654 -230 174 11 236 178 12 239 182 13 239 182 13
56655 -242 186 14 246 186 14 246 190 14 246 190 14
56656 -246 190 14 246 190 14 246 190 14 246 190 14
56657 -246 186 14 230 174 11 210 150 10 163 110 8
56658 -104 69 6 10 10 10 2 2 6 2 2 6
56659 - 2 2 6 2 2 6 2 2 6 2 2 6
56660 - 2 2 6 2 2 6 2 2 6 2 2 6
56661 - 2 2 6 2 2 6 2 2 6 2 2 6
56662 - 2 2 6 6 6 6 91 60 6 167 114 7
56663 -206 145 10 230 174 11 242 186 14 246 190 14
56664 -246 190 14 246 190 14 246 186 14 242 186 14
56665 -239 182 13 230 174 11 224 166 10 213 154 11
56666 -180 133 36 124 112 88 86 86 86 58 58 58
56667 - 38 38 38 22 22 22 10 10 10 6 6 6
56668 - 0 0 0 0 0 0 0 0 0 0 0 0
56669 - 0 0 0 0 0 0 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 14 14 14
56672 - 34 34 34 70 70 70 138 110 50 158 118 36
56673 -167 114 7 180 123 7 192 133 9 197 138 11
56674 -200 144 11 206 145 10 213 154 11 219 162 10
56675 -224 166 10 230 174 11 239 182 13 242 186 14
56676 -246 186 14 246 186 14 246 186 14 246 186 14
56677 -239 182 13 216 158 10 185 133 11 152 99 6
56678 -104 69 6 18 14 6 2 2 6 2 2 6
56679 - 2 2 6 2 2 6 2 2 6 2 2 6
56680 - 2 2 6 2 2 6 2 2 6 2 2 6
56681 - 2 2 6 2 2 6 2 2 6 2 2 6
56682 - 2 2 6 6 6 6 80 54 7 152 99 6
56683 -192 133 9 219 162 10 236 178 12 239 182 13
56684 -246 186 14 242 186 14 239 182 13 236 178 12
56685 -224 166 10 206 145 10 192 133 9 154 121 60
56686 - 94 94 94 62 62 62 42 42 42 22 22 22
56687 - 14 14 14 6 6 6 0 0 0 0 0 0
56688 - 0 0 0 0 0 0 0 0 0 0 0 0
56689 - 0 0 0 0 0 0 0 0 0 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 6 6 6
56692 - 18 18 18 34 34 34 58 58 58 78 78 78
56693 -101 98 89 124 112 88 142 110 46 156 107 11
56694 -163 110 8 167 114 7 175 118 6 180 123 7
56695 -185 133 11 197 138 11 210 150 10 219 162 10
56696 -226 170 11 236 178 12 236 178 12 234 174 13
56697 -219 162 10 197 138 11 163 110 8 130 83 6
56698 - 91 60 6 10 10 10 2 2 6 2 2 6
56699 - 18 18 18 38 38 38 38 38 38 38 38 38
56700 - 38 38 38 38 38 38 38 38 38 38 38 38
56701 - 38 38 38 38 38 38 26 26 26 2 2 6
56702 - 2 2 6 6 6 6 70 47 6 137 92 6
56703 -175 118 6 200 144 11 219 162 10 230 174 11
56704 -234 174 13 230 174 11 219 162 10 210 150 10
56705 -192 133 9 163 110 8 124 112 88 82 82 82
56706 - 50 50 50 30 30 30 14 14 14 6 6 6
56707 - 0 0 0 0 0 0 0 0 0 0 0 0
56708 - 0 0 0 0 0 0 0 0 0 0 0 0
56709 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 6 6 6 14 14 14 22 22 22 34 34 34
56713 - 42 42 42 58 58 58 74 74 74 86 86 86
56714 -101 98 89 122 102 70 130 98 46 121 87 25
56715 -137 92 6 152 99 6 163 110 8 180 123 7
56716 -185 133 11 197 138 11 206 145 10 200 144 11
56717 -180 123 7 156 107 11 130 83 6 104 69 6
56718 - 50 34 6 54 54 54 110 110 110 101 98 89
56719 - 86 86 86 82 82 82 78 78 78 78 78 78
56720 - 78 78 78 78 78 78 78 78 78 78 78 78
56721 - 78 78 78 82 82 82 86 86 86 94 94 94
56722 -106 106 106 101 101 101 86 66 34 124 80 6
56723 -156 107 11 180 123 7 192 133 9 200 144 11
56724 -206 145 10 200 144 11 192 133 9 175 118 6
56725 -139 102 15 109 106 95 70 70 70 42 42 42
56726 - 22 22 22 10 10 10 0 0 0 0 0 0
56727 - 0 0 0 0 0 0 0 0 0 0 0 0
56728 - 0 0 0 0 0 0 0 0 0 0 0 0
56729 - 0 0 0 0 0 0 0 0 0 0 0 0
56730 - 0 0 0 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 6 6 6 10 10 10
56733 - 14 14 14 22 22 22 30 30 30 38 38 38
56734 - 50 50 50 62 62 62 74 74 74 90 90 90
56735 -101 98 89 112 100 78 121 87 25 124 80 6
56736 -137 92 6 152 99 6 152 99 6 152 99 6
56737 -138 86 6 124 80 6 98 70 6 86 66 30
56738 -101 98 89 82 82 82 58 58 58 46 46 46
56739 - 38 38 38 34 34 34 34 34 34 34 34 34
56740 - 34 34 34 34 34 34 34 34 34 34 34 34
56741 - 34 34 34 34 34 34 38 38 38 42 42 42
56742 - 54 54 54 82 82 82 94 86 76 91 60 6
56743 -134 86 6 156 107 11 167 114 7 175 118 6
56744 -175 118 6 167 114 7 152 99 6 121 87 25
56745 -101 98 89 62 62 62 34 34 34 18 18 18
56746 - 6 6 6 0 0 0 0 0 0 0 0 0
56747 - 0 0 0 0 0 0 0 0 0 0 0 0
56748 - 0 0 0 0 0 0 0 0 0 0 0 0
56749 - 0 0 0 0 0 0 0 0 0 0 0 0
56750 - 0 0 0 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 6 6 6 6 6 6 10 10 10
56754 - 18 18 18 22 22 22 30 30 30 42 42 42
56755 - 50 50 50 66 66 66 86 86 86 101 98 89
56756 -106 86 58 98 70 6 104 69 6 104 69 6
56757 -104 69 6 91 60 6 82 62 34 90 90 90
56758 - 62 62 62 38 38 38 22 22 22 14 14 14
56759 - 10 10 10 10 10 10 10 10 10 10 10 10
56760 - 10 10 10 10 10 10 6 6 6 10 10 10
56761 - 10 10 10 10 10 10 10 10 10 14 14 14
56762 - 22 22 22 42 42 42 70 70 70 89 81 66
56763 - 80 54 7 104 69 6 124 80 6 137 92 6
56764 -134 86 6 116 81 8 100 82 52 86 86 86
56765 - 58 58 58 30 30 30 14 14 14 6 6 6
56766 - 0 0 0 0 0 0 0 0 0 0 0 0
56767 - 0 0 0 0 0 0 0 0 0 0 0 0
56768 - 0 0 0 0 0 0 0 0 0 0 0 0
56769 - 0 0 0 0 0 0 0 0 0 0 0 0
56770 - 0 0 0 0 0 0 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 6 6 6 10 10 10 14 14 14
56775 - 18 18 18 26 26 26 38 38 38 54 54 54
56776 - 70 70 70 86 86 86 94 86 76 89 81 66
56777 - 89 81 66 86 86 86 74 74 74 50 50 50
56778 - 30 30 30 14 14 14 6 6 6 0 0 0
56779 - 0 0 0 0 0 0 0 0 0 0 0 0
56780 - 0 0 0 0 0 0 0 0 0 0 0 0
56781 - 0 0 0 0 0 0 0 0 0 0 0 0
56782 - 6 6 6 18 18 18 34 34 34 58 58 58
56783 - 82 82 82 89 81 66 89 81 66 89 81 66
56784 - 94 86 66 94 86 76 74 74 74 50 50 50
56785 - 26 26 26 14 14 14 6 6 6 0 0 0
56786 - 0 0 0 0 0 0 0 0 0 0 0 0
56787 - 0 0 0 0 0 0 0 0 0 0 0 0
56788 - 0 0 0 0 0 0 0 0 0 0 0 0
56789 - 0 0 0 0 0 0 0 0 0 0 0 0
56790 - 0 0 0 0 0 0 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 - 6 6 6 6 6 6 14 14 14 18 18 18
56796 - 30 30 30 38 38 38 46 46 46 54 54 54
56797 - 50 50 50 42 42 42 30 30 30 18 18 18
56798 - 10 10 10 0 0 0 0 0 0 0 0 0
56799 - 0 0 0 0 0 0 0 0 0 0 0 0
56800 - 0 0 0 0 0 0 0 0 0 0 0 0
56801 - 0 0 0 0 0 0 0 0 0 0 0 0
56802 - 0 0 0 6 6 6 14 14 14 26 26 26
56803 - 38 38 38 50 50 50 58 58 58 58 58 58
56804 - 54 54 54 42 42 42 30 30 30 18 18 18
56805 - 10 10 10 0 0 0 0 0 0 0 0 0
56806 - 0 0 0 0 0 0 0 0 0 0 0 0
56807 - 0 0 0 0 0 0 0 0 0 0 0 0
56808 - 0 0 0 0 0 0 0 0 0 0 0 0
56809 - 0 0 0 0 0 0 0 0 0 0 0 0
56810 - 0 0 0 0 0 0 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 6 6 6
56816 - 6 6 6 10 10 10 14 14 14 18 18 18
56817 - 18 18 18 14 14 14 10 10 10 6 6 6
56818 - 0 0 0 0 0 0 0 0 0 0 0 0
56819 - 0 0 0 0 0 0 0 0 0 0 0 0
56820 - 0 0 0 0 0 0 0 0 0 0 0 0
56821 - 0 0 0 0 0 0 0 0 0 0 0 0
56822 - 0 0 0 0 0 0 0 0 0 6 6 6
56823 - 14 14 14 18 18 18 22 22 22 22 22 22
56824 - 18 18 18 14 14 14 10 10 10 6 6 6
56825 - 0 0 0 0 0 0 0 0 0 0 0 0
56826 - 0 0 0 0 0 0 0 0 0 0 0 0
56827 - 0 0 0 0 0 0 0 0 0 0 0 0
56828 - 0 0 0 0 0 0 0 0 0 0 0 0
56829 - 0 0 0 0 0 0 0 0 0 0 0 0
56830 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56831 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56832 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56833 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56834 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56835 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56836 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56837 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56838 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56839 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56840 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56841 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56842 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56843 +4 4 4 4 4 4
56844 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56845 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56846 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56847 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56848 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56849 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56850 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56851 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56852 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56853 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56854 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56855 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56856 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56857 +4 4 4 4 4 4
56858 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56859 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56860 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56861 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56862 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56863 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56864 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56865 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56866 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56867 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56868 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56869 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56870 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56871 +4 4 4 4 4 4
56872 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56873 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56874 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56875 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56876 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56877 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56878 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56879 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56880 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56881 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56882 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56883 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56884 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56885 +4 4 4 4 4 4
56886 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56887 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56888 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56889 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56890 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56891 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56892 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56893 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56894 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56895 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56896 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56897 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56898 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56899 +4 4 4 4 4 4
56900 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56901 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56902 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56903 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56904 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56905 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56906 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56907 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56908 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56909 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56910 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56911 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56912 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56913 +4 4 4 4 4 4
56914 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56915 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56916 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56917 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56918 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
56919 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
56920 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56921 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56922 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56923 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
56924 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
56925 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
56926 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56927 +4 4 4 4 4 4
56928 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56929 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56930 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56931 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56932 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
56933 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
56934 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56935 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56936 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56937 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
56938 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
56939 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
56940 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56941 +4 4 4 4 4 4
56942 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56943 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56944 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56945 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56946 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
56947 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
56948 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
56949 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56950 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56951 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
56952 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
56953 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
56954 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
56955 +4 4 4 4 4 4
56956 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56957 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56958 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56959 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
56960 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
56961 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
56962 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
56963 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56964 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
56965 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
56966 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
56967 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
56968 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
56969 +4 4 4 4 4 4
56970 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56971 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56972 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56973 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
56974 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
56975 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
56976 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
56977 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
56978 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
56979 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
56980 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
56981 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
56982 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
56983 +4 4 4 4 4 4
56984 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56985 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56986 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
56987 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
56988 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
56989 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
56990 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
56991 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
56992 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
56993 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
56994 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
56995 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
56996 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
56997 +4 4 4 4 4 4
56998 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56999 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57000 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
57001 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
57002 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
57003 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
57004 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
57005 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
57006 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
57007 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
57008 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
57009 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
57010 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
57011 +4 4 4 4 4 4
57012 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57013 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57014 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
57015 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
57016 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
57017 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
57018 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
57019 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
57020 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
57021 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
57022 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
57023 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
57024 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
57025 +4 4 4 4 4 4
57026 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57027 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57028 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
57029 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
57030 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
57031 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
57032 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
57033 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
57034 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
57035 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
57036 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
57037 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
57038 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57039 +4 4 4 4 4 4
57040 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57041 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57042 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
57043 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
57044 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
57045 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
57046 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
57047 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
57048 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
57049 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
57050 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
57051 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
57052 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
57053 +4 4 4 4 4 4
57054 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57055 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
57056 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
57057 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
57058 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
57059 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
57060 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
57061 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
57062 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
57063 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
57064 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
57065 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
57066 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
57067 +4 4 4 4 4 4
57068 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57069 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
57070 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
57071 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
57072 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
57073 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
57074 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
57075 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
57076 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
57077 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
57078 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
57079 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
57080 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
57081 +0 0 0 4 4 4
57082 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
57083 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
57084 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
57085 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
57086 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
57087 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
57088 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
57089 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
57090 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
57091 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
57092 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
57093 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
57094 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
57095 +2 0 0 0 0 0
57096 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
57097 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
57098 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
57099 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
57100 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
57101 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
57102 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
57103 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
57104 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
57105 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
57106 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
57107 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
57108 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
57109 +37 38 37 0 0 0
57110 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57111 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
57112 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
57113 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
57114 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
57115 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
57116 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
57117 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
57118 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
57119 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
57120 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
57121 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
57122 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
57123 +85 115 134 4 0 0
57124 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
57125 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
57126 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
57127 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
57128 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
57129 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
57130 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
57131 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
57132 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
57133 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
57134 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
57135 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
57136 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
57137 +60 73 81 4 0 0
57138 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
57139 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
57140 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
57141 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
57142 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
57143 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
57144 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
57145 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
57146 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
57147 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
57148 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
57149 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
57150 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
57151 +16 19 21 4 0 0
57152 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
57153 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
57154 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
57155 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
57156 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
57157 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
57158 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
57159 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
57160 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
57161 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
57162 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
57163 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
57164 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
57165 +4 0 0 4 3 3
57166 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
57167 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
57168 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
57169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
57170 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
57171 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
57172 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
57173 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
57174 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
57175 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
57176 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
57177 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
57178 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
57179 +3 2 2 4 4 4
57180 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
57181 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
57182 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
57183 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57184 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
57185 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
57186 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
57187 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
57188 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
57189 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
57190 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
57191 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
57192 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
57193 +4 4 4 4 4 4
57194 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
57195 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
57196 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
57197 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
57198 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
57199 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
57200 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
57201 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
57202 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
57203 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
57204 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
57205 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
57206 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
57207 +4 4 4 4 4 4
57208 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
57209 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
57210 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
57211 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
57212 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
57213 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
57214 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
57215 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
57216 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
57217 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
57218 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
57219 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
57220 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
57221 +5 5 5 5 5 5
57222 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
57223 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
57224 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
57225 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
57226 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
57227 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57228 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
57229 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
57230 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
57231 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
57232 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
57233 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
57234 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
57235 +5 5 5 4 4 4
57236 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
57237 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
57238 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
57239 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
57240 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57241 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
57242 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
57243 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
57244 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
57245 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
57246 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
57247 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
57248 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57249 +4 4 4 4 4 4
57250 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
57251 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
57252 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
57253 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
57254 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
57255 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57256 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57257 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
57258 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
57259 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
57260 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
57261 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
57262 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57263 +4 4 4 4 4 4
57264 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
57265 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
57266 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
57267 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
57268 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57269 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
57270 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
57271 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
57272 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
57273 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
57274 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
57275 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57276 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57277 +4 4 4 4 4 4
57278 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
57279 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
57280 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
57281 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
57282 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57283 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57284 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57285 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
57286 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
57287 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
57288 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
57289 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57290 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57291 +4 4 4 4 4 4
57292 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
57293 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
57294 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
57295 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
57296 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57297 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
57298 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
57299 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
57300 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
57301 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
57302 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57303 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57304 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57305 +4 4 4 4 4 4
57306 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
57307 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
57308 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
57309 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
57310 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57311 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
57312 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
57313 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
57314 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
57315 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
57316 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
57317 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57318 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57319 +4 4 4 4 4 4
57320 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
57321 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
57322 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
57323 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
57324 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57325 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
57326 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
57327 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
57328 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
57329 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
57330 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
57331 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57332 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57333 +4 4 4 4 4 4
57334 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
57335 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
57336 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
57337 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
57338 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
57339 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
57340 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
57341 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
57342 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
57343 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
57344 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57345 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57346 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57347 +4 4 4 4 4 4
57348 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
57349 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
57350 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
57351 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
57352 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57353 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
57354 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
57355 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
57356 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
57357 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
57358 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57359 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57360 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57361 +4 4 4 4 4 4
57362 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
57363 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
57364 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
57365 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
57366 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57367 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
57368 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
57369 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
57370 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
57371 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
57372 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57373 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57374 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57375 +4 4 4 4 4 4
57376 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
57377 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
57378 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
57379 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
57380 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57381 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
57382 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
57383 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
57384 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
57385 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57386 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57387 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57388 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57389 +4 4 4 4 4 4
57390 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
57391 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
57392 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
57393 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
57394 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
57395 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
57396 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
57397 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
57398 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57399 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57400 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57401 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57402 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57403 +4 4 4 4 4 4
57404 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
57405 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
57406 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
57407 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
57408 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57409 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
57410 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
57411 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
57412 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57413 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57414 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57415 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57416 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57417 +4 4 4 4 4 4
57418 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
57419 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
57420 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
57421 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
57422 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
57423 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
57424 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
57425 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
57426 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57427 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57428 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57429 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57430 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57431 +4 4 4 4 4 4
57432 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
57433 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
57434 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57435 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
57436 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
57437 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
57438 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
57439 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
57440 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
57441 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57442 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57443 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57444 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57445 +4 4 4 4 4 4
57446 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
57447 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
57448 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
57449 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
57450 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
57451 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
57452 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
57453 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
57454 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57455 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57456 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57457 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57458 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57459 +4 4 4 4 4 4
57460 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
57461 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
57462 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57463 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
57464 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
57465 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
57466 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
57467 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
57468 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
57469 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57470 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57471 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57472 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57473 +4 4 4 4 4 4
57474 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
57475 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
57476 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
57477 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
57478 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
57479 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
57480 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
57481 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
57482 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57483 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57484 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57485 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57486 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57487 +4 4 4 4 4 4
57488 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57489 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
57490 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57491 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
57492 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
57493 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
57494 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
57495 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
57496 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57497 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57498 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57499 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57500 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57501 +4 4 4 4 4 4
57502 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
57503 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
57504 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
57505 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
57506 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
57507 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
57508 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57509 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
57510 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57511 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57512 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57513 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57514 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57515 +4 4 4 4 4 4
57516 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57517 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
57518 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
57519 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
57520 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
57521 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
57522 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57523 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
57524 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57525 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57526 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57527 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57528 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57529 +4 4 4 4 4 4
57530 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
57531 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
57532 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
57533 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
57534 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
57535 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
57536 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
57537 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
57538 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
57539 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57540 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57541 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57542 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57543 +4 4 4 4 4 4
57544 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57545 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
57546 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
57547 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
57548 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
57549 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
57550 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
57551 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
57552 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
57553 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57554 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57555 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57556 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57557 +4 4 4 4 4 4
57558 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
57559 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
57560 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
57561 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
57562 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
57563 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
57564 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
57565 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
57566 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
57567 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57568 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57569 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57570 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57571 +4 4 4 4 4 4
57572 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57573 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
57574 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
57575 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
57576 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
57577 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
57578 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
57579 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
57580 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
57581 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57582 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57583 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57584 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57585 +4 4 4 4 4 4
57586 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
57587 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
57588 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
57589 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
57590 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
57591 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
57592 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
57593 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
57594 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
57595 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
57596 +0 0 0 3 3 3 5 5 5 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
57600 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
57601 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
57602 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
57603 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
57604 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
57605 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
57606 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
57607 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
57608 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
57609 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
57610 +0 0 0 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
57614 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
57615 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
57616 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
57617 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
57618 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
57619 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
57620 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57621 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
57622 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
57623 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
57624 +4 3 3 5 5 5 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
57628 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
57629 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
57630 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
57631 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
57632 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
57633 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
57634 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
57635 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
57636 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
57637 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
57638 +5 5 5 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
57642 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
57643 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
57644 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
57645 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
57646 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
57647 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
57648 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
57649 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
57650 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
57651 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
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
57656 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
57657 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
57658 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
57659 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
57660 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
57661 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
57662 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
57663 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
57664 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
57665 +13 16 17 4 0 0 4 0 0 4 3 3 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
57670 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
57671 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
57672 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
57673 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
57674 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
57675 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
57676 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
57677 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
57678 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
57679 +4 0 0 4 0 0 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4
57683 +4 4 4 4 4 4
57684 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
57685 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
57686 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
57687 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
57688 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
57689 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
57690 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
57691 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
57692 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
57693 +4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57697 +4 4 4 4 4 4
57698 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
57699 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
57700 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
57701 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
57702 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
57703 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
57704 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
57705 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
57706 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
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 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57711 +4 4 4 4 4 4
57712 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
57713 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
57714 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
57715 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
57716 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
57717 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
57718 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
57719 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
57720 +4 0 0 4 0 0 4 0 0 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
57724 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57725 +4 4 4 4 4 4
57726 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
57727 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
57728 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
57729 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
57730 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
57731 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
57732 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
57733 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
57734 +4 0 0 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57738 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57739 +4 4 4 4 4 4
57740 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
57741 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
57742 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
57743 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
57744 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
57745 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
57746 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
57747 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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 4 4 4
57751 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57752 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57753 +4 4 4 4 4 4
57754 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
57755 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
57756 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
57757 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
57758 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
57759 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
57760 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
57761 +6 6 6 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4
57765 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57766 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57767 +4 4 4 4 4 4
57768 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
57769 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
57770 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
57771 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
57772 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
57773 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
57774 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
57775 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
57776 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57777 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57778 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57779 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57780 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57781 +4 4 4 4 4 4
57782 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57783 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
57784 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
57785 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
57786 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
57787 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
57788 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
57789 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
57790 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57791 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57792 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57793 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57794 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57795 +4 4 4 4 4 4
57796 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57797 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
57798 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
57799 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
57800 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
57801 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
57802 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
57803 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57804 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57805 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57806 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57807 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57808 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57809 +4 4 4 4 4 4
57810 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57811 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57812 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
57813 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
57814 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
57815 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
57816 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
57817 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57818 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57819 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57820 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57821 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57822 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57823 +4 4 4 4 4 4
57824 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57825 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57826 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
57827 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
57828 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
57829 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
57830 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
57831 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57832 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57833 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57834 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57835 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57836 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57837 +4 4 4 4 4 4
57838 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57839 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57840 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57841 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
57842 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
57843 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
57844 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
57845 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57846 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57847 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57848 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57849 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57850 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57851 +4 4 4 4 4 4
57852 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57853 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57854 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57855 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
57856 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
57857 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
57858 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
57859 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57860 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57861 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57862 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57863 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57864 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57865 +4 4 4 4 4 4
57866 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57867 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57868 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57869 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
57870 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
57871 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
57872 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
57873 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57874 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57875 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57876 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57877 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57878 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57879 +4 4 4 4 4 4
57880 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57881 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57882 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57883 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
57884 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
57885 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
57886 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57887 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57888 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57889 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57890 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57891 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57892 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57893 +4 4 4 4 4 4
57894 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57895 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57896 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57897 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57898 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
57899 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
57900 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
57901 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57902 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57903 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57904 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57905 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57906 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57907 +4 4 4 4 4 4
57908 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57909 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57910 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57911 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57912 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
57913 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
57914 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57915 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57916 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57917 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57918 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57919 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57920 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57921 +4 4 4 4 4 4
57922 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57923 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57924 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57925 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57926 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
57927 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
57928 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57929 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57930 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57931 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57932 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57933 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57934 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57935 +4 4 4 4 4 4
57936 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57937 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57938 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57939 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57940 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
57941 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
57942 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57943 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57944 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57945 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57946 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57947 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57948 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57949 +4 4 4 4 4 4
57950 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
57951 index fef20db..d28b1ab 100644
57952 --- a/drivers/xen/xenfs/xenstored.c
57953 +++ b/drivers/xen/xenfs/xenstored.c
57954 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
57955 static int xsd_kva_open(struct inode *inode, struct file *file)
57956 {
57957 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
57958 +#ifdef CONFIG_GRKERNSEC_HIDESYM
57959 + NULL);
57960 +#else
57961 xen_store_interface);
57962 +#endif
57963 +
57964 if (!file->private_data)
57965 return -ENOMEM;
57966 return 0;
57967 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
57968 index eb14e05..5156de7 100644
57969 --- a/fs/9p/vfs_addr.c
57970 +++ b/fs/9p/vfs_addr.c
57971 @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
57972
57973 retval = v9fs_file_write_internal(inode,
57974 v9inode->writeback_fid,
57975 - (__force const char __user *)buffer,
57976 + (const char __force_user *)buffer,
57977 len, &offset, 0);
57978 if (retval > 0)
57979 retval = 0;
57980 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
57981 index 296482f..183ddc3 100644
57982 --- a/fs/9p/vfs_inode.c
57983 +++ b/fs/9p/vfs_inode.c
57984 @@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
57985 void
57986 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
57987 {
57988 - char *s = nd_get_link(nd);
57989 + const char *s = nd_get_link(nd);
57990
57991 p9_debug(P9_DEBUG_VFS, " %pd %s\n",
57992 dentry, IS_ERR(s) ? "<error>" : s);
57993 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
57994 index 370b24c..ff0be7b 100644
57995 --- a/fs/Kconfig.binfmt
57996 +++ b/fs/Kconfig.binfmt
57997 @@ -103,7 +103,7 @@ config HAVE_AOUT
57998
57999 config BINFMT_AOUT
58000 tristate "Kernel support for a.out and ECOFF binaries"
58001 - depends on HAVE_AOUT
58002 + depends on HAVE_AOUT && BROKEN
58003 ---help---
58004 A.out (Assembler.OUTput) is a set of formats for libraries and
58005 executables used in the earliest versions of UNIX. Linux used
58006 diff --git a/fs/afs/inode.c b/fs/afs/inode.c
58007 index 2946712..f737435 100644
58008 --- a/fs/afs/inode.c
58009 +++ b/fs/afs/inode.c
58010 @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58011 struct afs_vnode *vnode;
58012 struct super_block *sb;
58013 struct inode *inode;
58014 - static atomic_t afs_autocell_ino;
58015 + static atomic_unchecked_t afs_autocell_ino;
58016
58017 _enter("{%x:%u},%*.*s,",
58018 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
58019 @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58020 data.fid.unique = 0;
58021 data.fid.vnode = 0;
58022
58023 - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
58024 + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
58025 afs_iget5_autocell_test, afs_iget5_set,
58026 &data);
58027 if (!inode) {
58028 diff --git a/fs/aio.c b/fs/aio.c
58029 index 14b9315..365980f 100644
58030 --- a/fs/aio.c
58031 +++ b/fs/aio.c
58032 @@ -388,7 +388,7 @@ static int aio_setup_ring(struct kioctx *ctx)
58033 size += sizeof(struct io_event) * nr_events;
58034
58035 nr_pages = PFN_UP(size);
58036 - if (nr_pages < 0)
58037 + if (nr_pages <= 0)
58038 return -EINVAL;
58039
58040 file = aio_private_file(ctx, nr_pages);
58041 diff --git a/fs/attr.c b/fs/attr.c
58042 index 6530ced..4a827e2 100644
58043 --- a/fs/attr.c
58044 +++ b/fs/attr.c
58045 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
58046 unsigned long limit;
58047
58048 limit = rlimit(RLIMIT_FSIZE);
58049 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
58050 if (limit != RLIM_INFINITY && offset > limit)
58051 goto out_sig;
58052 if (offset > inode->i_sb->s_maxbytes)
58053 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
58054 index 116fd38..c04182da 100644
58055 --- a/fs/autofs4/waitq.c
58056 +++ b/fs/autofs4/waitq.c
58057 @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
58058 {
58059 unsigned long sigpipe, flags;
58060 mm_segment_t fs;
58061 - const char *data = (const char *)addr;
58062 + const char __user *data = (const char __force_user *)addr;
58063 ssize_t wr = 0;
58064
58065 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
58066 @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
58067 return 1;
58068 }
58069
58070 +#ifdef CONFIG_GRKERNSEC_HIDESYM
58071 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
58072 +#endif
58073 +
58074 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58075 enum autofs_notify notify)
58076 {
58077 @@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58078
58079 /* If this is a direct mount request create a dummy name */
58080 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
58081 +#ifdef CONFIG_GRKERNSEC_HIDESYM
58082 + /* this name does get written to userland via autofs4_write() */
58083 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
58084 +#else
58085 qstr.len = sprintf(name, "%p", dentry);
58086 +#endif
58087 else {
58088 qstr.len = autofs4_getpath(sbi, dentry, &name);
58089 if (!qstr.len) {
58090 diff --git a/fs/befs/endian.h b/fs/befs/endian.h
58091 index 2722387..56059b5 100644
58092 --- a/fs/befs/endian.h
58093 +++ b/fs/befs/endian.h
58094 @@ -11,7 +11,7 @@
58095
58096 #include <asm/byteorder.h>
58097
58098 -static inline u64
58099 +static inline u64 __intentional_overflow(-1)
58100 fs64_to_cpu(const struct super_block *sb, fs64 n)
58101 {
58102 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58103 @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
58104 return (__force fs64)cpu_to_be64(n);
58105 }
58106
58107 -static inline u32
58108 +static inline u32 __intentional_overflow(-1)
58109 fs32_to_cpu(const struct super_block *sb, fs32 n)
58110 {
58111 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58112 @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
58113 return (__force fs32)cpu_to_be32(n);
58114 }
58115
58116 -static inline u16
58117 +static inline u16 __intentional_overflow(-1)
58118 fs16_to_cpu(const struct super_block *sb, fs16 n)
58119 {
58120 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58121 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
58122 index 929dec0..84bd914 100644
58123 --- a/fs/binfmt_aout.c
58124 +++ b/fs/binfmt_aout.c
58125 @@ -16,6 +16,7 @@
58126 #include <linux/string.h>
58127 #include <linux/fs.h>
58128 #include <linux/file.h>
58129 +#include <linux/security.h>
58130 #include <linux/stat.h>
58131 #include <linux/fcntl.h>
58132 #include <linux/ptrace.h>
58133 @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
58134 #endif
58135 # define START_STACK(u) ((void __user *)u.start_stack)
58136
58137 + memset(&dump, 0, sizeof(dump));
58138 +
58139 fs = get_fs();
58140 set_fs(KERNEL_DS);
58141 has_dumped = 1;
58142 @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
58143
58144 /* If the size of the dump file exceeds the rlimit, then see what would happen
58145 if we wrote the stack, but not the data area. */
58146 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
58147 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
58148 dump.u_dsize = 0;
58149
58150 /* Make sure we have enough room to write the stack and data areas. */
58151 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
58152 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
58153 dump.u_ssize = 0;
58154
58155 @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
58156 rlim = rlimit(RLIMIT_DATA);
58157 if (rlim >= RLIM_INFINITY)
58158 rlim = ~0;
58159 +
58160 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
58161 if (ex.a_data + ex.a_bss > rlim)
58162 return -ENOMEM;
58163
58164 @@ -261,6 +268,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
58165
58166 install_exec_creds(bprm);
58167
58168 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58169 + current->mm->pax_flags = 0UL;
58170 +#endif
58171 +
58172 +#ifdef CONFIG_PAX_PAGEEXEC
58173 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
58174 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
58175 +
58176 +#ifdef CONFIG_PAX_EMUTRAMP
58177 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
58178 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
58179 +#endif
58180 +
58181 +#ifdef CONFIG_PAX_MPROTECT
58182 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
58183 + current->mm->pax_flags |= MF_PAX_MPROTECT;
58184 +#endif
58185 +
58186 + }
58187 +#endif
58188 +
58189 if (N_MAGIC(ex) == OMAGIC) {
58190 unsigned long text_addr, map_size;
58191 loff_t pos;
58192 @@ -312,7 +340,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
58193 return error;
58194
58195 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
58196 - PROT_READ | PROT_WRITE | PROT_EXEC,
58197 + PROT_READ | PROT_WRITE,
58198 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
58199 fd_offset + ex.a_text);
58200 if (error != N_DATADDR(ex))
58201 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
58202 index d8fc060..cbd44d5 100644
58203 --- a/fs/binfmt_elf.c
58204 +++ b/fs/binfmt_elf.c
58205 @@ -34,6 +34,7 @@
58206 #include <linux/utsname.h>
58207 #include <linux/coredump.h>
58208 #include <linux/sched.h>
58209 +#include <linux/xattr.h>
58210 #include <asm/uaccess.h>
58211 #include <asm/param.h>
58212 #include <asm/page.h>
58213 @@ -47,7 +48,7 @@
58214
58215 static int load_elf_binary(struct linux_binprm *bprm);
58216 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
58217 - int, int, unsigned long);
58218 + int, int, unsigned long) __intentional_overflow(-1);
58219
58220 #ifdef CONFIG_USELIB
58221 static int load_elf_library(struct file *);
58222 @@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
58223 #define elf_core_dump NULL
58224 #endif
58225
58226 +#ifdef CONFIG_PAX_MPROTECT
58227 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
58228 +#endif
58229 +
58230 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58231 +static void elf_handle_mmap(struct file *file);
58232 +#endif
58233 +
58234 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
58235 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
58236 #else
58237 @@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
58238 .load_binary = load_elf_binary,
58239 .load_shlib = load_elf_library,
58240 .core_dump = elf_core_dump,
58241 +
58242 +#ifdef CONFIG_PAX_MPROTECT
58243 + .handle_mprotect= elf_handle_mprotect,
58244 +#endif
58245 +
58246 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58247 + .handle_mmap = elf_handle_mmap,
58248 +#endif
58249 +
58250 .min_coredump = ELF_EXEC_PAGESIZE,
58251 };
58252
58253 @@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
58254
58255 static int set_brk(unsigned long start, unsigned long end)
58256 {
58257 + unsigned long e = end;
58258 +
58259 start = ELF_PAGEALIGN(start);
58260 end = ELF_PAGEALIGN(end);
58261 if (end > start) {
58262 @@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
58263 if (BAD_ADDR(addr))
58264 return addr;
58265 }
58266 - current->mm->start_brk = current->mm->brk = end;
58267 + current->mm->start_brk = current->mm->brk = e;
58268 return 0;
58269 }
58270
58271 @@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58272 elf_addr_t __user *u_rand_bytes;
58273 const char *k_platform = ELF_PLATFORM;
58274 const char *k_base_platform = ELF_BASE_PLATFORM;
58275 - unsigned char k_rand_bytes[16];
58276 + u32 k_rand_bytes[4];
58277 int items;
58278 elf_addr_t *elf_info;
58279 int ei_index = 0;
58280 const struct cred *cred = current_cred();
58281 struct vm_area_struct *vma;
58282 + unsigned long saved_auxv[AT_VECTOR_SIZE];
58283
58284 /*
58285 * In some cases (e.g. Hyper-Threading), we want to avoid L1
58286 @@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58287 * Generate 16 random bytes for userspace PRNG seeding.
58288 */
58289 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
58290 - u_rand_bytes = (elf_addr_t __user *)
58291 - STACK_ALLOC(p, sizeof(k_rand_bytes));
58292 + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
58293 + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
58294 + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
58295 + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
58296 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
58297 + u_rand_bytes = (elf_addr_t __user *) p;
58298 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
58299 return -EFAULT;
58300
58301 @@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58302 return -EFAULT;
58303 current->mm->env_end = p;
58304
58305 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
58306 +
58307 /* Put the elf_info on the stack in the right place. */
58308 sp = (elf_addr_t __user *)envp + 1;
58309 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
58310 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
58311 return -EFAULT;
58312 return 0;
58313 }
58314 @@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
58315 an ELF header */
58316
58317 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58318 - struct file *interpreter, unsigned long *interp_map_addr,
58319 - unsigned long no_base)
58320 + struct file *interpreter, unsigned long no_base)
58321 {
58322 struct elf_phdr *elf_phdata;
58323 struct elf_phdr *eppnt;
58324 - unsigned long load_addr = 0;
58325 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
58326 int load_addr_set = 0;
58327 unsigned long last_bss = 0, elf_bss = 0;
58328 - unsigned long error = ~0UL;
58329 + unsigned long error = -EINVAL;
58330 unsigned long total_size;
58331 int retval, i, size;
58332
58333 @@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58334 goto out_close;
58335 }
58336
58337 +#ifdef CONFIG_PAX_SEGMEXEC
58338 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
58339 + pax_task_size = SEGMEXEC_TASK_SIZE;
58340 +#endif
58341 +
58342 eppnt = elf_phdata;
58343 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
58344 if (eppnt->p_type == PT_LOAD) {
58345 @@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58346 map_addr = elf_map(interpreter, load_addr + vaddr,
58347 eppnt, elf_prot, elf_type, total_size);
58348 total_size = 0;
58349 - if (!*interp_map_addr)
58350 - *interp_map_addr = map_addr;
58351 error = map_addr;
58352 if (BAD_ADDR(map_addr))
58353 goto out_close;
58354 @@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58355 k = load_addr + eppnt->p_vaddr;
58356 if (BAD_ADDR(k) ||
58357 eppnt->p_filesz > eppnt->p_memsz ||
58358 - eppnt->p_memsz > TASK_SIZE ||
58359 - TASK_SIZE - eppnt->p_memsz < k) {
58360 + eppnt->p_memsz > pax_task_size ||
58361 + pax_task_size - eppnt->p_memsz < k) {
58362 error = -ENOMEM;
58363 goto out_close;
58364 }
58365 @@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58366 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
58367
58368 /* Map the last of the bss segment */
58369 - error = vm_brk(elf_bss, last_bss - elf_bss);
58370 - if (BAD_ADDR(error))
58371 - goto out_close;
58372 + if (last_bss > elf_bss) {
58373 + error = vm_brk(elf_bss, last_bss - elf_bss);
58374 + if (BAD_ADDR(error))
58375 + goto out_close;
58376 + }
58377 }
58378
58379 error = load_addr;
58380 @@ -543,6 +574,336 @@ out:
58381 return error;
58382 }
58383
58384 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
58385 +#ifdef CONFIG_PAX_SOFTMODE
58386 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
58387 +{
58388 + unsigned long pax_flags = 0UL;
58389 +
58390 +#ifdef CONFIG_PAX_PAGEEXEC
58391 + if (elf_phdata->p_flags & PF_PAGEEXEC)
58392 + pax_flags |= MF_PAX_PAGEEXEC;
58393 +#endif
58394 +
58395 +#ifdef CONFIG_PAX_SEGMEXEC
58396 + if (elf_phdata->p_flags & PF_SEGMEXEC)
58397 + pax_flags |= MF_PAX_SEGMEXEC;
58398 +#endif
58399 +
58400 +#ifdef CONFIG_PAX_EMUTRAMP
58401 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
58402 + pax_flags |= MF_PAX_EMUTRAMP;
58403 +#endif
58404 +
58405 +#ifdef CONFIG_PAX_MPROTECT
58406 + if (elf_phdata->p_flags & PF_MPROTECT)
58407 + pax_flags |= MF_PAX_MPROTECT;
58408 +#endif
58409 +
58410 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58411 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
58412 + pax_flags |= MF_PAX_RANDMMAP;
58413 +#endif
58414 +
58415 + return pax_flags;
58416 +}
58417 +#endif
58418 +
58419 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
58420 +{
58421 + unsigned long pax_flags = 0UL;
58422 +
58423 +#ifdef CONFIG_PAX_PAGEEXEC
58424 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
58425 + pax_flags |= MF_PAX_PAGEEXEC;
58426 +#endif
58427 +
58428 +#ifdef CONFIG_PAX_SEGMEXEC
58429 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
58430 + pax_flags |= MF_PAX_SEGMEXEC;
58431 +#endif
58432 +
58433 +#ifdef CONFIG_PAX_EMUTRAMP
58434 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
58435 + pax_flags |= MF_PAX_EMUTRAMP;
58436 +#endif
58437 +
58438 +#ifdef CONFIG_PAX_MPROTECT
58439 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
58440 + pax_flags |= MF_PAX_MPROTECT;
58441 +#endif
58442 +
58443 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58444 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
58445 + pax_flags |= MF_PAX_RANDMMAP;
58446 +#endif
58447 +
58448 + return pax_flags;
58449 +}
58450 +#endif
58451 +
58452 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
58453 +#ifdef CONFIG_PAX_SOFTMODE
58454 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
58455 +{
58456 + unsigned long pax_flags = 0UL;
58457 +
58458 +#ifdef CONFIG_PAX_PAGEEXEC
58459 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
58460 + pax_flags |= MF_PAX_PAGEEXEC;
58461 +#endif
58462 +
58463 +#ifdef CONFIG_PAX_SEGMEXEC
58464 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
58465 + pax_flags |= MF_PAX_SEGMEXEC;
58466 +#endif
58467 +
58468 +#ifdef CONFIG_PAX_EMUTRAMP
58469 + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
58470 + pax_flags |= MF_PAX_EMUTRAMP;
58471 +#endif
58472 +
58473 +#ifdef CONFIG_PAX_MPROTECT
58474 + if (pax_flags_softmode & MF_PAX_MPROTECT)
58475 + pax_flags |= MF_PAX_MPROTECT;
58476 +#endif
58477 +
58478 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58479 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
58480 + pax_flags |= MF_PAX_RANDMMAP;
58481 +#endif
58482 +
58483 + return pax_flags;
58484 +}
58485 +#endif
58486 +
58487 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
58488 +{
58489 + unsigned long pax_flags = 0UL;
58490 +
58491 +#ifdef CONFIG_PAX_PAGEEXEC
58492 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
58493 + pax_flags |= MF_PAX_PAGEEXEC;
58494 +#endif
58495 +
58496 +#ifdef CONFIG_PAX_SEGMEXEC
58497 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
58498 + pax_flags |= MF_PAX_SEGMEXEC;
58499 +#endif
58500 +
58501 +#ifdef CONFIG_PAX_EMUTRAMP
58502 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
58503 + pax_flags |= MF_PAX_EMUTRAMP;
58504 +#endif
58505 +
58506 +#ifdef CONFIG_PAX_MPROTECT
58507 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
58508 + pax_flags |= MF_PAX_MPROTECT;
58509 +#endif
58510 +
58511 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58512 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
58513 + pax_flags |= MF_PAX_RANDMMAP;
58514 +#endif
58515 +
58516 + return pax_flags;
58517 +}
58518 +#endif
58519 +
58520 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58521 +static unsigned long pax_parse_defaults(void)
58522 +{
58523 + unsigned long pax_flags = 0UL;
58524 +
58525 +#ifdef CONFIG_PAX_SOFTMODE
58526 + if (pax_softmode)
58527 + return pax_flags;
58528 +#endif
58529 +
58530 +#ifdef CONFIG_PAX_PAGEEXEC
58531 + pax_flags |= MF_PAX_PAGEEXEC;
58532 +#endif
58533 +
58534 +#ifdef CONFIG_PAX_SEGMEXEC
58535 + pax_flags |= MF_PAX_SEGMEXEC;
58536 +#endif
58537 +
58538 +#ifdef CONFIG_PAX_MPROTECT
58539 + pax_flags |= MF_PAX_MPROTECT;
58540 +#endif
58541 +
58542 +#ifdef CONFIG_PAX_RANDMMAP
58543 + if (randomize_va_space)
58544 + pax_flags |= MF_PAX_RANDMMAP;
58545 +#endif
58546 +
58547 + return pax_flags;
58548 +}
58549 +
58550 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
58551 +{
58552 + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
58553 +
58554 +#ifdef CONFIG_PAX_EI_PAX
58555 +
58556 +#ifdef CONFIG_PAX_SOFTMODE
58557 + if (pax_softmode)
58558 + return pax_flags;
58559 +#endif
58560 +
58561 + pax_flags = 0UL;
58562 +
58563 +#ifdef CONFIG_PAX_PAGEEXEC
58564 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
58565 + pax_flags |= MF_PAX_PAGEEXEC;
58566 +#endif
58567 +
58568 +#ifdef CONFIG_PAX_SEGMEXEC
58569 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
58570 + pax_flags |= MF_PAX_SEGMEXEC;
58571 +#endif
58572 +
58573 +#ifdef CONFIG_PAX_EMUTRAMP
58574 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
58575 + pax_flags |= MF_PAX_EMUTRAMP;
58576 +#endif
58577 +
58578 +#ifdef CONFIG_PAX_MPROTECT
58579 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
58580 + pax_flags |= MF_PAX_MPROTECT;
58581 +#endif
58582 +
58583 +#ifdef CONFIG_PAX_ASLR
58584 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
58585 + pax_flags |= MF_PAX_RANDMMAP;
58586 +#endif
58587 +
58588 +#endif
58589 +
58590 + return pax_flags;
58591 +
58592 +}
58593 +
58594 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
58595 +{
58596 +
58597 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
58598 + unsigned long i;
58599 +
58600 + for (i = 0UL; i < elf_ex->e_phnum; i++)
58601 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
58602 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
58603 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
58604 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
58605 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
58606 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
58607 + return PAX_PARSE_FLAGS_FALLBACK;
58608 +
58609 +#ifdef CONFIG_PAX_SOFTMODE
58610 + if (pax_softmode)
58611 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
58612 + else
58613 +#endif
58614 +
58615 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
58616 + break;
58617 + }
58618 +#endif
58619 +
58620 + return PAX_PARSE_FLAGS_FALLBACK;
58621 +}
58622 +
58623 +static unsigned long pax_parse_xattr_pax(struct file * const file)
58624 +{
58625 +
58626 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
58627 + ssize_t xattr_size, i;
58628 + unsigned char xattr_value[sizeof("pemrs") - 1];
58629 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
58630 +
58631 + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
58632 + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
58633 + return PAX_PARSE_FLAGS_FALLBACK;
58634 +
58635 + for (i = 0; i < xattr_size; i++)
58636 + switch (xattr_value[i]) {
58637 + default:
58638 + return PAX_PARSE_FLAGS_FALLBACK;
58639 +
58640 +#define parse_flag(option1, option2, flag) \
58641 + case option1: \
58642 + if (pax_flags_hardmode & MF_PAX_##flag) \
58643 + return PAX_PARSE_FLAGS_FALLBACK;\
58644 + pax_flags_hardmode |= MF_PAX_##flag; \
58645 + break; \
58646 + case option2: \
58647 + if (pax_flags_softmode & MF_PAX_##flag) \
58648 + return PAX_PARSE_FLAGS_FALLBACK;\
58649 + pax_flags_softmode |= MF_PAX_##flag; \
58650 + break;
58651 +
58652 + parse_flag('p', 'P', PAGEEXEC);
58653 + parse_flag('e', 'E', EMUTRAMP);
58654 + parse_flag('m', 'M', MPROTECT);
58655 + parse_flag('r', 'R', RANDMMAP);
58656 + parse_flag('s', 'S', SEGMEXEC);
58657 +
58658 +#undef parse_flag
58659 + }
58660 +
58661 + if (pax_flags_hardmode & pax_flags_softmode)
58662 + return PAX_PARSE_FLAGS_FALLBACK;
58663 +
58664 +#ifdef CONFIG_PAX_SOFTMODE
58665 + if (pax_softmode)
58666 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
58667 + else
58668 +#endif
58669 +
58670 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
58671 +#else
58672 + return PAX_PARSE_FLAGS_FALLBACK;
58673 +#endif
58674 +
58675 +}
58676 +
58677 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
58678 +{
58679 + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
58680 +
58681 + pax_flags = pax_parse_defaults();
58682 + ei_pax_flags = pax_parse_ei_pax(elf_ex);
58683 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
58684 + xattr_pax_flags = pax_parse_xattr_pax(file);
58685 +
58686 + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
58687 + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
58688 + pt_pax_flags != xattr_pax_flags)
58689 + return -EINVAL;
58690 + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
58691 + pax_flags = xattr_pax_flags;
58692 + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
58693 + pax_flags = pt_pax_flags;
58694 + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
58695 + pax_flags = ei_pax_flags;
58696 +
58697 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
58698 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58699 + if ((__supported_pte_mask & _PAGE_NX))
58700 + pax_flags &= ~MF_PAX_SEGMEXEC;
58701 + else
58702 + pax_flags &= ~MF_PAX_PAGEEXEC;
58703 + }
58704 +#endif
58705 +
58706 + if (0 > pax_check_flags(&pax_flags))
58707 + return -EINVAL;
58708 +
58709 + current->mm->pax_flags = pax_flags;
58710 + return 0;
58711 +}
58712 +#endif
58713 +
58714 /*
58715 * These are the functions used to load ELF style executables and shared
58716 * libraries. There is no binary dependent code anywhere else.
58717 @@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
58718 {
58719 unsigned int random_variable = 0;
58720
58721 +#ifdef CONFIG_PAX_RANDUSTACK
58722 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
58723 + return stack_top - current->mm->delta_stack;
58724 +#endif
58725 +
58726 if ((current->flags & PF_RANDOMIZE) &&
58727 !(current->personality & ADDR_NO_RANDOMIZE)) {
58728 random_variable = get_random_int() & STACK_RND_MASK;
58729 @@ -574,7 +940,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
58730 unsigned long load_addr = 0, load_bias = 0;
58731 int load_addr_set = 0;
58732 char * elf_interpreter = NULL;
58733 - unsigned long error;
58734 + unsigned long error = 0;
58735 struct elf_phdr *elf_ppnt, *elf_phdata;
58736 unsigned long elf_bss, elf_brk;
58737 int retval, i;
58738 @@ -589,6 +955,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
58739 struct elfhdr elf_ex;
58740 struct elfhdr interp_elf_ex;
58741 } *loc;
58742 + unsigned long pax_task_size;
58743
58744 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
58745 if (!loc) {
58746 @@ -726,6 +1093,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
58747 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
58748 may depend on the personality. */
58749 SET_PERSONALITY(loc->elf_ex);
58750 +
58751 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58752 + current->mm->pax_flags = 0UL;
58753 +#endif
58754 +
58755 +#ifdef CONFIG_PAX_DLRESOLVE
58756 + current->mm->call_dl_resolve = 0UL;
58757 +#endif
58758 +
58759 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
58760 + current->mm->call_syscall = 0UL;
58761 +#endif
58762 +
58763 +#ifdef CONFIG_PAX_ASLR
58764 + current->mm->delta_mmap = 0UL;
58765 + current->mm->delta_stack = 0UL;
58766 +#endif
58767 +
58768 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58769 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
58770 + send_sig(SIGKILL, current, 0);
58771 + goto out_free_dentry;
58772 + }
58773 +#endif
58774 +
58775 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58776 + pax_set_initial_flags(bprm);
58777 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
58778 + if (pax_set_initial_flags_func)
58779 + (pax_set_initial_flags_func)(bprm);
58780 +#endif
58781 +
58782 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
58783 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
58784 + current->mm->context.user_cs_limit = PAGE_SIZE;
58785 + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
58786 + }
58787 +#endif
58788 +
58789 +#ifdef CONFIG_PAX_SEGMEXEC
58790 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
58791 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
58792 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
58793 + pax_task_size = SEGMEXEC_TASK_SIZE;
58794 + current->mm->def_flags |= VM_NOHUGEPAGE;
58795 + } else
58796 +#endif
58797 +
58798 + pax_task_size = TASK_SIZE;
58799 +
58800 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
58801 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58802 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
58803 + put_cpu();
58804 + }
58805 +#endif
58806 +
58807 +#ifdef CONFIG_PAX_ASLR
58808 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
58809 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
58810 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
58811 + }
58812 +#endif
58813 +
58814 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58815 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58816 + executable_stack = EXSTACK_DISABLE_X;
58817 + current->personality &= ~READ_IMPLIES_EXEC;
58818 + } else
58819 +#endif
58820 +
58821 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
58822 current->personality |= READ_IMPLIES_EXEC;
58823
58824 @@ -811,6 +1249,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
58825 #else
58826 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
58827 #endif
58828 +
58829 +#ifdef CONFIG_PAX_RANDMMAP
58830 + /* PaX: randomize base address at the default exe base if requested */
58831 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
58832 +#ifdef CONFIG_SPARC64
58833 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
58834 +#else
58835 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
58836 +#endif
58837 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
58838 + elf_flags |= MAP_FIXED;
58839 + }
58840 +#endif
58841 +
58842 }
58843
58844 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
58845 @@ -842,9 +1294,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
58846 * allowed task size. Note that p_filesz must always be
58847 * <= p_memsz so it is only necessary to check p_memsz.
58848 */
58849 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
58850 - elf_ppnt->p_memsz > TASK_SIZE ||
58851 - TASK_SIZE - elf_ppnt->p_memsz < k) {
58852 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
58853 + elf_ppnt->p_memsz > pax_task_size ||
58854 + pax_task_size - elf_ppnt->p_memsz < k) {
58855 /* set_brk can never work. Avoid overflows. */
58856 retval = -EINVAL;
58857 goto out_free_dentry;
58858 @@ -880,16 +1332,43 @@ static int load_elf_binary(struct linux_binprm *bprm)
58859 if (retval)
58860 goto out_free_dentry;
58861 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
58862 - retval = -EFAULT; /* Nobody gets to see this, but.. */
58863 - goto out_free_dentry;
58864 + /*
58865 + * This bss-zeroing can fail if the ELF
58866 + * file specifies odd protections. So
58867 + * we don't check the return value
58868 + */
58869 }
58870
58871 +#ifdef CONFIG_PAX_RANDMMAP
58872 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
58873 + unsigned long start, size, flags;
58874 + vm_flags_t vm_flags;
58875 +
58876 + start = ELF_PAGEALIGN(elf_brk);
58877 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
58878 + flags = MAP_FIXED | MAP_PRIVATE;
58879 + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
58880 +
58881 + down_write(&current->mm->mmap_sem);
58882 + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
58883 + retval = -ENOMEM;
58884 + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
58885 +// if (current->personality & ADDR_NO_RANDOMIZE)
58886 +// vm_flags |= VM_READ | VM_MAYREAD;
58887 + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
58888 + retval = IS_ERR_VALUE(start) ? start : 0;
58889 + }
58890 + up_write(&current->mm->mmap_sem);
58891 + if (retval == 0)
58892 + retval = set_brk(start + size, start + size + PAGE_SIZE);
58893 + if (retval < 0)
58894 + goto out_free_dentry;
58895 + }
58896 +#endif
58897 +
58898 if (elf_interpreter) {
58899 - unsigned long interp_map_addr = 0;
58900 -
58901 elf_entry = load_elf_interp(&loc->interp_elf_ex,
58902 interpreter,
58903 - &interp_map_addr,
58904 load_bias);
58905 if (!IS_ERR((void *)elf_entry)) {
58906 /*
58907 @@ -1115,7 +1594,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
58908 * Decide what to dump of a segment, part, all or none.
58909 */
58910 static unsigned long vma_dump_size(struct vm_area_struct *vma,
58911 - unsigned long mm_flags)
58912 + unsigned long mm_flags, long signr)
58913 {
58914 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
58915
58916 @@ -1153,7 +1632,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
58917 if (vma->vm_file == NULL)
58918 return 0;
58919
58920 - if (FILTER(MAPPED_PRIVATE))
58921 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
58922 goto whole;
58923
58924 /*
58925 @@ -1360,9 +1839,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
58926 {
58927 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
58928 int i = 0;
58929 - do
58930 + do {
58931 i += 2;
58932 - while (auxv[i - 2] != AT_NULL);
58933 + } while (auxv[i - 2] != AT_NULL);
58934 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
58935 }
58936
58937 @@ -1371,7 +1850,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
58938 {
58939 mm_segment_t old_fs = get_fs();
58940 set_fs(KERNEL_DS);
58941 - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
58942 + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
58943 set_fs(old_fs);
58944 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
58945 }
58946 @@ -1995,14 +2474,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
58947 }
58948
58949 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
58950 - unsigned long mm_flags)
58951 + struct coredump_params *cprm)
58952 {
58953 struct vm_area_struct *vma;
58954 size_t size = 0;
58955
58956 for (vma = first_vma(current, gate_vma); vma != NULL;
58957 vma = next_vma(vma, gate_vma))
58958 - size += vma_dump_size(vma, mm_flags);
58959 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
58960 return size;
58961 }
58962
58963 @@ -2093,7 +2572,7 @@ static int elf_core_dump(struct coredump_params *cprm)
58964
58965 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
58966
58967 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
58968 + offset += elf_core_vma_data_size(gate_vma, cprm);
58969 offset += elf_core_extra_data_size();
58970 e_shoff = offset;
58971
58972 @@ -2121,7 +2600,7 @@ static int elf_core_dump(struct coredump_params *cprm)
58973 phdr.p_offset = offset;
58974 phdr.p_vaddr = vma->vm_start;
58975 phdr.p_paddr = 0;
58976 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
58977 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
58978 phdr.p_memsz = vma->vm_end - vma->vm_start;
58979 offset += phdr.p_filesz;
58980 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
58981 @@ -2154,7 +2633,7 @@ static int elf_core_dump(struct coredump_params *cprm)
58982 unsigned long addr;
58983 unsigned long end;
58984
58985 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
58986 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
58987
58988 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
58989 struct page *page;
58990 @@ -2195,6 +2674,167 @@ out:
58991
58992 #endif /* CONFIG_ELF_CORE */
58993
58994 +#ifdef CONFIG_PAX_MPROTECT
58995 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
58996 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
58997 + * we'll remove VM_MAYWRITE for good on RELRO segments.
58998 + *
58999 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
59000 + * basis because we want to allow the common case and not the special ones.
59001 + */
59002 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
59003 +{
59004 + struct elfhdr elf_h;
59005 + struct elf_phdr elf_p;
59006 + unsigned long i;
59007 + unsigned long oldflags;
59008 + bool is_textrel_rw, is_textrel_rx, is_relro;
59009 +
59010 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
59011 + return;
59012 +
59013 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
59014 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
59015 +
59016 +#ifdef CONFIG_PAX_ELFRELOCS
59017 + /* possible TEXTREL */
59018 + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
59019 + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
59020 +#else
59021 + is_textrel_rw = false;
59022 + is_textrel_rx = false;
59023 +#endif
59024 +
59025 + /* possible RELRO */
59026 + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
59027 +
59028 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
59029 + return;
59030 +
59031 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59032 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59033 +
59034 +#ifdef CONFIG_PAX_ETEXECRELOCS
59035 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59036 +#else
59037 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
59038 +#endif
59039 +
59040 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59041 + !elf_check_arch(&elf_h) ||
59042 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59043 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59044 + return;
59045 +
59046 + for (i = 0UL; i < elf_h.e_phnum; i++) {
59047 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59048 + return;
59049 + switch (elf_p.p_type) {
59050 + case PT_DYNAMIC:
59051 + if (!is_textrel_rw && !is_textrel_rx)
59052 + continue;
59053 + i = 0UL;
59054 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
59055 + elf_dyn dyn;
59056 +
59057 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
59058 + break;
59059 + if (dyn.d_tag == DT_NULL)
59060 + break;
59061 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
59062 + gr_log_textrel(vma);
59063 + if (is_textrel_rw)
59064 + vma->vm_flags |= VM_MAYWRITE;
59065 + else
59066 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
59067 + vma->vm_flags &= ~VM_MAYWRITE;
59068 + break;
59069 + }
59070 + i++;
59071 + }
59072 + is_textrel_rw = false;
59073 + is_textrel_rx = false;
59074 + continue;
59075 +
59076 + case PT_GNU_RELRO:
59077 + if (!is_relro)
59078 + continue;
59079 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
59080 + vma->vm_flags &= ~VM_MAYWRITE;
59081 + is_relro = false;
59082 + continue;
59083 +
59084 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
59085 + case PT_PAX_FLAGS: {
59086 + const char *msg_mprotect = "", *msg_emutramp = "";
59087 + char *buffer_lib, *buffer_exe;
59088 +
59089 + if (elf_p.p_flags & PF_NOMPROTECT)
59090 + msg_mprotect = "MPROTECT disabled";
59091 +
59092 +#ifdef CONFIG_PAX_EMUTRAMP
59093 + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
59094 + msg_emutramp = "EMUTRAMP enabled";
59095 +#endif
59096 +
59097 + if (!msg_mprotect[0] && !msg_emutramp[0])
59098 + continue;
59099 +
59100 + if (!printk_ratelimit())
59101 + continue;
59102 +
59103 + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
59104 + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
59105 + if (buffer_lib && buffer_exe) {
59106 + char *path_lib, *path_exe;
59107 +
59108 + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
59109 + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
59110 +
59111 + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
59112 + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
59113 +
59114 + }
59115 + free_page((unsigned long)buffer_exe);
59116 + free_page((unsigned long)buffer_lib);
59117 + continue;
59118 + }
59119 +#endif
59120 +
59121 + }
59122 + }
59123 +}
59124 +#endif
59125 +
59126 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59127 +
59128 +extern int grsec_enable_log_rwxmaps;
59129 +
59130 +static void elf_handle_mmap(struct file *file)
59131 +{
59132 + struct elfhdr elf_h;
59133 + struct elf_phdr elf_p;
59134 + unsigned long i;
59135 +
59136 + if (!grsec_enable_log_rwxmaps)
59137 + return;
59138 +
59139 + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59140 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59141 + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
59142 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59143 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59144 + return;
59145 +
59146 + for (i = 0UL; i < elf_h.e_phnum; i++) {
59147 + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59148 + return;
59149 + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
59150 + gr_log_ptgnustack(file);
59151 + }
59152 +}
59153 +#endif
59154 +
59155 static int __init init_elf_binfmt(void)
59156 {
59157 register_binfmt(&elf_format);
59158 diff --git a/fs/block_dev.c b/fs/block_dev.c
59159 index 1d9c9f3..2905786 100644
59160 --- a/fs/block_dev.c
59161 +++ b/fs/block_dev.c
59162 @@ -697,7 +697,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
59163 else if (bdev->bd_contains == bdev)
59164 return true; /* is a whole device which isn't held */
59165
59166 - else if (whole->bd_holder == bd_may_claim)
59167 + else if (whole->bd_holder == (void *)bd_may_claim)
59168 return true; /* is a partition of a device that is being partitioned */
59169 else if (whole->bd_holder != NULL)
59170 return false; /* is a partition of a held device */
59171 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
59172 index 150822e..75bb326 100644
59173 --- a/fs/btrfs/ctree.c
59174 +++ b/fs/btrfs/ctree.c
59175 @@ -1173,9 +1173,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
59176 free_extent_buffer(buf);
59177 add_root_to_dirty_list(root);
59178 } else {
59179 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
59180 - parent_start = parent->start;
59181 - else
59182 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
59183 + if (parent)
59184 + parent_start = parent->start;
59185 + else
59186 + parent_start = 0;
59187 + } else
59188 parent_start = 0;
59189
59190 WARN_ON(trans->transid != btrfs_header_generation(parent));
59191 diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
59192 index 054577b..9b342cc 100644
59193 --- a/fs/btrfs/delayed-inode.c
59194 +++ b/fs/btrfs/delayed-inode.c
59195 @@ -462,7 +462,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
59196
59197 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
59198 {
59199 - int seq = atomic_inc_return(&delayed_root->items_seq);
59200 + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
59201 if ((atomic_dec_return(&delayed_root->items) <
59202 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
59203 waitqueue_active(&delayed_root->wait))
59204 @@ -1412,7 +1412,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
59205
59206 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
59207 {
59208 - int val = atomic_read(&delayed_root->items_seq);
59209 + int val = atomic_read_unchecked(&delayed_root->items_seq);
59210
59211 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
59212 return 1;
59213 @@ -1436,7 +1436,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
59214 int seq;
59215 int ret;
59216
59217 - seq = atomic_read(&delayed_root->items_seq);
59218 + seq = atomic_read_unchecked(&delayed_root->items_seq);
59219
59220 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
59221 if (ret)
59222 diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
59223 index f70119f..ab5894d 100644
59224 --- a/fs/btrfs/delayed-inode.h
59225 +++ b/fs/btrfs/delayed-inode.h
59226 @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
59227 */
59228 struct list_head prepare_list;
59229 atomic_t items; /* for delayed items */
59230 - atomic_t items_seq; /* for delayed items */
59231 + atomic_unchecked_t items_seq; /* for delayed items */
59232 int nodes; /* for delayed nodes */
59233 wait_queue_head_t wait;
59234 };
59235 @@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
59236 struct btrfs_delayed_root *delayed_root)
59237 {
59238 atomic_set(&delayed_root->items, 0);
59239 - atomic_set(&delayed_root->items_seq, 0);
59240 + atomic_set_unchecked(&delayed_root->items_seq, 0);
59241 delayed_root->nodes = 0;
59242 spin_lock_init(&delayed_root->lock);
59243 init_waitqueue_head(&delayed_root->wait);
59244 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
59245 index 4399f0c..a34d8b4 100644
59246 --- a/fs/btrfs/ioctl.c
59247 +++ b/fs/btrfs/ioctl.c
59248 @@ -3953,9 +3953,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
59249 for (i = 0; i < num_types; i++) {
59250 struct btrfs_space_info *tmp;
59251
59252 + /* Don't copy in more than we allocated */
59253 if (!slot_count)
59254 break;
59255
59256 + slot_count--;
59257 +
59258 info = NULL;
59259 rcu_read_lock();
59260 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
59261 @@ -3977,10 +3980,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
59262 memcpy(dest, &space, sizeof(space));
59263 dest++;
59264 space_args.total_spaces++;
59265 - slot_count--;
59266 }
59267 - if (!slot_count)
59268 - break;
59269 }
59270 up_read(&info->groups_sem);
59271 }
59272 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
59273 index 54bd91e..aefa810 100644
59274 --- a/fs/btrfs/super.c
59275 +++ b/fs/btrfs/super.c
59276 @@ -271,7 +271,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
59277 function, line, errstr);
59278 return;
59279 }
59280 - ACCESS_ONCE(trans->transaction->aborted) = errno;
59281 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
59282 /* Wake up anybody who may be waiting on this transaction */
59283 wake_up(&root->fs_info->transaction_wait);
59284 wake_up(&root->fs_info->transaction_blocked_wait);
59285 diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
59286 index b2e7bb4..3719201 100644
59287 --- a/fs/btrfs/sysfs.c
59288 +++ b/fs/btrfs/sysfs.c
59289 @@ -480,7 +480,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
59290 for (set = 0; set < FEAT_MAX; set++) {
59291 int i;
59292 struct attribute *attrs[2];
59293 - struct attribute_group agroup = {
59294 + attribute_group_no_const agroup = {
59295 .name = "features",
59296 .attrs = attrs,
59297 };
59298 diff --git a/fs/btrfs/tests/free-space-tests.c b/fs/btrfs/tests/free-space-tests.c
59299 index 2299bfd..4098e72 100644
59300 --- a/fs/btrfs/tests/free-space-tests.c
59301 +++ b/fs/btrfs/tests/free-space-tests.c
59302 @@ -463,7 +463,9 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache)
59303 * extent entry.
59304 */
59305 use_bitmap_op = cache->free_space_ctl->op->use_bitmap;
59306 - cache->free_space_ctl->op->use_bitmap = test_use_bitmap;
59307 + pax_open_kernel();
59308 + *(void **)&cache->free_space_ctl->op->use_bitmap = test_use_bitmap;
59309 + pax_close_kernel();
59310
59311 /*
59312 * Extent entry covering free space range [128Mb - 256Kb, 128Mb - 128Kb[
59313 @@ -870,7 +872,9 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache)
59314 if (ret)
59315 return ret;
59316
59317 - cache->free_space_ctl->op->use_bitmap = use_bitmap_op;
59318 + pax_open_kernel();
59319 + *(void **)&cache->free_space_ctl->op->use_bitmap = use_bitmap_op;
59320 + pax_close_kernel();
59321 __btrfs_remove_free_space_cache(cache->free_space_ctl);
59322
59323 return 0;
59324 diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h
59325 index 154990c..d0cf699 100644
59326 --- a/fs/btrfs/tree-log.h
59327 +++ b/fs/btrfs/tree-log.h
59328 @@ -43,7 +43,7 @@ static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx)
59329 static inline void btrfs_set_log_full_commit(struct btrfs_fs_info *fs_info,
59330 struct btrfs_trans_handle *trans)
59331 {
59332 - ACCESS_ONCE(fs_info->last_trans_log_full_commit) = trans->transid;
59333 + ACCESS_ONCE_RW(fs_info->last_trans_log_full_commit) = trans->transid;
59334 }
59335
59336 static inline int btrfs_need_log_full_commit(struct btrfs_fs_info *fs_info,
59337 diff --git a/fs/buffer.c b/fs/buffer.c
59338 index 20805db..2e8fc69 100644
59339 --- a/fs/buffer.c
59340 +++ b/fs/buffer.c
59341 @@ -3417,7 +3417,7 @@ void __init buffer_init(void)
59342 bh_cachep = kmem_cache_create("buffer_head",
59343 sizeof(struct buffer_head), 0,
59344 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
59345 - SLAB_MEM_SPREAD),
59346 + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
59347 NULL);
59348
59349 /*
59350 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
59351 index fbb08e9..0fda764 100644
59352 --- a/fs/cachefiles/bind.c
59353 +++ b/fs/cachefiles/bind.c
59354 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
59355 args);
59356
59357 /* start by checking things over */
59358 - ASSERT(cache->fstop_percent >= 0 &&
59359 - cache->fstop_percent < cache->fcull_percent &&
59360 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
59361 cache->fcull_percent < cache->frun_percent &&
59362 cache->frun_percent < 100);
59363
59364 - ASSERT(cache->bstop_percent >= 0 &&
59365 - cache->bstop_percent < cache->bcull_percent &&
59366 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
59367 cache->bcull_percent < cache->brun_percent &&
59368 cache->brun_percent < 100);
59369
59370 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
59371 index ce1b115..4a6852c 100644
59372 --- a/fs/cachefiles/daemon.c
59373 +++ b/fs/cachefiles/daemon.c
59374 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
59375 if (n > buflen)
59376 return -EMSGSIZE;
59377
59378 - if (copy_to_user(_buffer, buffer, n) != 0)
59379 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
59380 return -EFAULT;
59381
59382 return n;
59383 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
59384 if (test_bit(CACHEFILES_DEAD, &cache->flags))
59385 return -EIO;
59386
59387 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
59388 + if (datalen > PAGE_SIZE - 1)
59389 return -EOPNOTSUPP;
59390
59391 /* drag the command string into the kernel so we can parse it */
59392 @@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
59393 if (args[0] != '%' || args[1] != '\0')
59394 return -EINVAL;
59395
59396 - if (fstop < 0 || fstop >= cache->fcull_percent)
59397 + if (fstop >= cache->fcull_percent)
59398 return cachefiles_daemon_range_error(cache, args);
59399
59400 cache->fstop_percent = fstop;
59401 @@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
59402 if (args[0] != '%' || args[1] != '\0')
59403 return -EINVAL;
59404
59405 - if (bstop < 0 || bstop >= cache->bcull_percent)
59406 + if (bstop >= cache->bcull_percent)
59407 return cachefiles_daemon_range_error(cache, args);
59408
59409 cache->bstop_percent = bstop;
59410 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
59411 index 8c52472..c4e3a69 100644
59412 --- a/fs/cachefiles/internal.h
59413 +++ b/fs/cachefiles/internal.h
59414 @@ -66,7 +66,7 @@ struct cachefiles_cache {
59415 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
59416 struct rb_root active_nodes; /* active nodes (can't be culled) */
59417 rwlock_t active_lock; /* lock for active_nodes */
59418 - atomic_t gravecounter; /* graveyard uniquifier */
59419 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
59420 unsigned frun_percent; /* when to stop culling (% files) */
59421 unsigned fcull_percent; /* when to start culling (% files) */
59422 unsigned fstop_percent; /* when to stop allocating (% files) */
59423 @@ -178,19 +178,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
59424 * proc.c
59425 */
59426 #ifdef CONFIG_CACHEFILES_HISTOGRAM
59427 -extern atomic_t cachefiles_lookup_histogram[HZ];
59428 -extern atomic_t cachefiles_mkdir_histogram[HZ];
59429 -extern atomic_t cachefiles_create_histogram[HZ];
59430 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
59431 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
59432 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
59433
59434 extern int __init cachefiles_proc_init(void);
59435 extern void cachefiles_proc_cleanup(void);
59436 static inline
59437 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
59438 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
59439 {
59440 unsigned long jif = jiffies - start_jif;
59441 if (jif >= HZ)
59442 jif = HZ - 1;
59443 - atomic_inc(&histogram[jif]);
59444 + atomic_inc_unchecked(&histogram[jif]);
59445 }
59446
59447 #else
59448 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
59449 index e12f189..ed17244 100644
59450 --- a/fs/cachefiles/namei.c
59451 +++ b/fs/cachefiles/namei.c
59452 @@ -312,7 +312,7 @@ try_again:
59453 /* first step is to make up a grave dentry in the graveyard */
59454 sprintf(nbuffer, "%08x%08x",
59455 (uint32_t) get_seconds(),
59456 - (uint32_t) atomic_inc_return(&cache->gravecounter));
59457 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
59458
59459 /* do the multiway lock magic */
59460 trap = lock_rename(cache->graveyard, dir);
59461 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
59462 index eccd339..4c1d995 100644
59463 --- a/fs/cachefiles/proc.c
59464 +++ b/fs/cachefiles/proc.c
59465 @@ -14,9 +14,9 @@
59466 #include <linux/seq_file.h>
59467 #include "internal.h"
59468
59469 -atomic_t cachefiles_lookup_histogram[HZ];
59470 -atomic_t cachefiles_mkdir_histogram[HZ];
59471 -atomic_t cachefiles_create_histogram[HZ];
59472 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
59473 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
59474 +atomic_unchecked_t cachefiles_create_histogram[HZ];
59475
59476 /*
59477 * display the latency histogram
59478 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
59479 return 0;
59480 default:
59481 index = (unsigned long) v - 3;
59482 - x = atomic_read(&cachefiles_lookup_histogram[index]);
59483 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
59484 - z = atomic_read(&cachefiles_create_histogram[index]);
59485 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
59486 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
59487 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
59488 if (x == 0 && y == 0 && z == 0)
59489 return 0;
59490
59491 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
59492 index 695e788..f4a9d4d 100644
59493 --- a/fs/ceph/dir.c
59494 +++ b/fs/ceph/dir.c
59495 @@ -129,6 +129,8 @@ static int __dcache_readdir(struct file *file, struct dir_context *ctx,
59496 struct dentry *dentry, *last;
59497 struct ceph_dentry_info *di;
59498 int err = 0;
59499 + char d_name[DNAME_INLINE_LEN];
59500 + const unsigned char *name;
59501
59502 /* claim ref on last dentry we returned */
59503 last = fi->dentry;
59504 @@ -192,7 +194,12 @@ more:
59505
59506 dout(" %llu (%llu) dentry %p %.*s %p\n", di->offset, ctx->pos,
59507 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
59508 - if (!dir_emit(ctx, dentry->d_name.name,
59509 + name = dentry->d_name.name;
59510 + if (name == dentry->d_iname) {
59511 + memcpy(d_name, name, dentry->d_name.len);
59512 + name = d_name;
59513 + }
59514 + if (!dir_emit(ctx, name,
59515 dentry->d_name.len,
59516 ceph_translate_ino(dentry->d_sb, dentry->d_inode->i_ino),
59517 dentry->d_inode->i_mode >> 12)) {
59518 @@ -250,7 +257,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
59519 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
59520 struct ceph_mds_client *mdsc = fsc->mdsc;
59521 unsigned frag = fpos_frag(ctx->pos);
59522 - int off = fpos_off(ctx->pos);
59523 + unsigned int off = fpos_off(ctx->pos);
59524 int err;
59525 u32 ftype;
59526 struct ceph_mds_reply_info_parsed *rinfo;
59527 diff --git a/fs/ceph/super.c b/fs/ceph/super.c
59528 index f6e1237..796ffd1 100644
59529 --- a/fs/ceph/super.c
59530 +++ b/fs/ceph/super.c
59531 @@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
59532 /*
59533 * construct our own bdi so we can control readahead, etc.
59534 */
59535 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
59536 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
59537
59538 static int ceph_register_bdi(struct super_block *sb,
59539 struct ceph_fs_client *fsc)
59540 @@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
59541 default_backing_dev_info.ra_pages;
59542
59543 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
59544 - atomic_long_inc_return(&bdi_seq));
59545 + atomic_long_inc_return_unchecked(&bdi_seq));
59546 if (!err)
59547 sb->s_bdi = &fsc->backing_dev_info;
59548 return err;
59549 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
59550 index 44ec726..bcb06a3 100644
59551 --- a/fs/cifs/cifs_debug.c
59552 +++ b/fs/cifs/cifs_debug.c
59553 @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
59554
59555 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
59556 #ifdef CONFIG_CIFS_STATS2
59557 - atomic_set(&totBufAllocCount, 0);
59558 - atomic_set(&totSmBufAllocCount, 0);
59559 + atomic_set_unchecked(&totBufAllocCount, 0);
59560 + atomic_set_unchecked(&totSmBufAllocCount, 0);
59561 #endif /* CONFIG_CIFS_STATS2 */
59562 spin_lock(&cifs_tcp_ses_lock);
59563 list_for_each(tmp1, &cifs_tcp_ses_list) {
59564 @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
59565 tcon = list_entry(tmp3,
59566 struct cifs_tcon,
59567 tcon_list);
59568 - atomic_set(&tcon->num_smbs_sent, 0);
59569 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
59570 if (server->ops->clear_stats)
59571 server->ops->clear_stats(tcon);
59572 }
59573 @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
59574 smBufAllocCount.counter, cifs_min_small);
59575 #ifdef CONFIG_CIFS_STATS2
59576 seq_printf(m, "Total Large %d Small %d Allocations\n",
59577 - atomic_read(&totBufAllocCount),
59578 - atomic_read(&totSmBufAllocCount));
59579 + atomic_read_unchecked(&totBufAllocCount),
59580 + atomic_read_unchecked(&totSmBufAllocCount));
59581 #endif /* CONFIG_CIFS_STATS2 */
59582
59583 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
59584 @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
59585 if (tcon->need_reconnect)
59586 seq_puts(m, "\tDISCONNECTED ");
59587 seq_printf(m, "\nSMBs: %d",
59588 - atomic_read(&tcon->num_smbs_sent));
59589 + atomic_read_unchecked(&tcon->num_smbs_sent));
59590 if (server->ops->print_stats)
59591 server->ops->print_stats(m, tcon);
59592 }
59593 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
59594 index 9d7996e..35ad5cf4 100644
59595 --- a/fs/cifs/cifsfs.c
59596 +++ b/fs/cifs/cifsfs.c
59597 @@ -1093,7 +1093,7 @@ cifs_init_request_bufs(void)
59598 */
59599 cifs_req_cachep = kmem_cache_create("cifs_request",
59600 CIFSMaxBufSize + max_hdr_size, 0,
59601 - SLAB_HWCACHE_ALIGN, NULL);
59602 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
59603 if (cifs_req_cachep == NULL)
59604 return -ENOMEM;
59605
59606 @@ -1120,7 +1120,7 @@ cifs_init_request_bufs(void)
59607 efficient to alloc 1 per page off the slab compared to 17K (5page)
59608 alloc of large cifs buffers even when page debugging is on */
59609 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
59610 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
59611 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
59612 NULL);
59613 if (cifs_sm_req_cachep == NULL) {
59614 mempool_destroy(cifs_req_poolp);
59615 @@ -1205,8 +1205,8 @@ init_cifs(void)
59616 atomic_set(&bufAllocCount, 0);
59617 atomic_set(&smBufAllocCount, 0);
59618 #ifdef CONFIG_CIFS_STATS2
59619 - atomic_set(&totBufAllocCount, 0);
59620 - atomic_set(&totSmBufAllocCount, 0);
59621 + atomic_set_unchecked(&totBufAllocCount, 0);
59622 + atomic_set_unchecked(&totSmBufAllocCount, 0);
59623 #endif /* CONFIG_CIFS_STATS2 */
59624
59625 atomic_set(&midCount, 0);
59626 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
59627 index 02a33e5..3a28b5a 100644
59628 --- a/fs/cifs/cifsglob.h
59629 +++ b/fs/cifs/cifsglob.h
59630 @@ -823,35 +823,35 @@ struct cifs_tcon {
59631 __u16 Flags; /* optional support bits */
59632 enum statusEnum tidStatus;
59633 #ifdef CONFIG_CIFS_STATS
59634 - atomic_t num_smbs_sent;
59635 + atomic_unchecked_t num_smbs_sent;
59636 union {
59637 struct {
59638 - atomic_t num_writes;
59639 - atomic_t num_reads;
59640 - atomic_t num_flushes;
59641 - atomic_t num_oplock_brks;
59642 - atomic_t num_opens;
59643 - atomic_t num_closes;
59644 - atomic_t num_deletes;
59645 - atomic_t num_mkdirs;
59646 - atomic_t num_posixopens;
59647 - atomic_t num_posixmkdirs;
59648 - atomic_t num_rmdirs;
59649 - atomic_t num_renames;
59650 - atomic_t num_t2renames;
59651 - atomic_t num_ffirst;
59652 - atomic_t num_fnext;
59653 - atomic_t num_fclose;
59654 - atomic_t num_hardlinks;
59655 - atomic_t num_symlinks;
59656 - atomic_t num_locks;
59657 - atomic_t num_acl_get;
59658 - atomic_t num_acl_set;
59659 + atomic_unchecked_t num_writes;
59660 + atomic_unchecked_t num_reads;
59661 + atomic_unchecked_t num_flushes;
59662 + atomic_unchecked_t num_oplock_brks;
59663 + atomic_unchecked_t num_opens;
59664 + atomic_unchecked_t num_closes;
59665 + atomic_unchecked_t num_deletes;
59666 + atomic_unchecked_t num_mkdirs;
59667 + atomic_unchecked_t num_posixopens;
59668 + atomic_unchecked_t num_posixmkdirs;
59669 + atomic_unchecked_t num_rmdirs;
59670 + atomic_unchecked_t num_renames;
59671 + atomic_unchecked_t num_t2renames;
59672 + atomic_unchecked_t num_ffirst;
59673 + atomic_unchecked_t num_fnext;
59674 + atomic_unchecked_t num_fclose;
59675 + atomic_unchecked_t num_hardlinks;
59676 + atomic_unchecked_t num_symlinks;
59677 + atomic_unchecked_t num_locks;
59678 + atomic_unchecked_t num_acl_get;
59679 + atomic_unchecked_t num_acl_set;
59680 } cifs_stats;
59681 #ifdef CONFIG_CIFS_SMB2
59682 struct {
59683 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
59684 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
59685 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
59686 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
59687 } smb2_stats;
59688 #endif /* CONFIG_CIFS_SMB2 */
59689 } stats;
59690 @@ -1192,7 +1192,7 @@ convert_delimiter(char *path, char delim)
59691 }
59692
59693 #ifdef CONFIG_CIFS_STATS
59694 -#define cifs_stats_inc atomic_inc
59695 +#define cifs_stats_inc atomic_inc_unchecked
59696
59697 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
59698 unsigned int bytes)
59699 @@ -1559,8 +1559,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
59700 /* Various Debug counters */
59701 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
59702 #ifdef CONFIG_CIFS_STATS2
59703 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
59704 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
59705 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
59706 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
59707 #endif
59708 GLOBAL_EXTERN atomic_t smBufAllocCount;
59709 GLOBAL_EXTERN atomic_t midCount;
59710 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
59711 index 3e4d00a..38a122d 100644
59712 --- a/fs/cifs/file.c
59713 +++ b/fs/cifs/file.c
59714 @@ -2056,10 +2056,14 @@ static int cifs_writepages(struct address_space *mapping,
59715 index = mapping->writeback_index; /* Start from prev offset */
59716 end = -1;
59717 } else {
59718 - index = wbc->range_start >> PAGE_CACHE_SHIFT;
59719 - end = wbc->range_end >> PAGE_CACHE_SHIFT;
59720 - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
59721 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
59722 range_whole = true;
59723 + index = 0;
59724 + end = ULONG_MAX;
59725 + } else {
59726 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
59727 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
59728 + }
59729 scanned = true;
59730 }
59731 server = cifs_sb_master_tcon(cifs_sb)->ses->server;
59732 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
59733 index b7415d5..3984ec0 100644
59734 --- a/fs/cifs/misc.c
59735 +++ b/fs/cifs/misc.c
59736 @@ -170,7 +170,7 @@ cifs_buf_get(void)
59737 memset(ret_buf, 0, buf_size + 3);
59738 atomic_inc(&bufAllocCount);
59739 #ifdef CONFIG_CIFS_STATS2
59740 - atomic_inc(&totBufAllocCount);
59741 + atomic_inc_unchecked(&totBufAllocCount);
59742 #endif /* CONFIG_CIFS_STATS2 */
59743 }
59744
59745 @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
59746 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
59747 atomic_inc(&smBufAllocCount);
59748 #ifdef CONFIG_CIFS_STATS2
59749 - atomic_inc(&totSmBufAllocCount);
59750 + atomic_inc_unchecked(&totSmBufAllocCount);
59751 #endif /* CONFIG_CIFS_STATS2 */
59752
59753 }
59754 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
59755 index d297903..1cb7516 100644
59756 --- a/fs/cifs/smb1ops.c
59757 +++ b/fs/cifs/smb1ops.c
59758 @@ -622,27 +622,27 @@ static void
59759 cifs_clear_stats(struct cifs_tcon *tcon)
59760 {
59761 #ifdef CONFIG_CIFS_STATS
59762 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
59763 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
59764 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
59765 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
59766 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
59767 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
59768 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
59769 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
59770 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
59771 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
59772 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
59773 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
59774 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
59775 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
59776 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
59777 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
59778 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
59779 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
59780 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
59781 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
59782 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
59783 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
59784 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
59785 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
59786 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
59787 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
59788 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
59789 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
59790 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
59791 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
59792 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
59793 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
59794 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
59795 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
59796 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
59797 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
59798 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
59799 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
59800 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
59801 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
59802 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
59803 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
59804 #endif
59805 }
59806
59807 @@ -651,36 +651,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
59808 {
59809 #ifdef CONFIG_CIFS_STATS
59810 seq_printf(m, " Oplocks breaks: %d",
59811 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
59812 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
59813 seq_printf(m, "\nReads: %d Bytes: %llu",
59814 - atomic_read(&tcon->stats.cifs_stats.num_reads),
59815 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
59816 (long long)(tcon->bytes_read));
59817 seq_printf(m, "\nWrites: %d Bytes: %llu",
59818 - atomic_read(&tcon->stats.cifs_stats.num_writes),
59819 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
59820 (long long)(tcon->bytes_written));
59821 seq_printf(m, "\nFlushes: %d",
59822 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
59823 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
59824 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
59825 - atomic_read(&tcon->stats.cifs_stats.num_locks),
59826 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
59827 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
59828 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
59829 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
59830 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
59831 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
59832 - atomic_read(&tcon->stats.cifs_stats.num_opens),
59833 - atomic_read(&tcon->stats.cifs_stats.num_closes),
59834 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
59835 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
59836 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
59837 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
59838 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
59839 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
59840 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
59841 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
59842 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
59843 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
59844 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
59845 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
59846 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
59847 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
59848 seq_printf(m, "\nRenames: %d T2 Renames %d",
59849 - atomic_read(&tcon->stats.cifs_stats.num_renames),
59850 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
59851 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
59852 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
59853 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
59854 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
59855 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
59856 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
59857 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
59858 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
59859 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
59860 #endif
59861 }
59862
59863 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
59864 index c5f521b..1a40865 100644
59865 --- a/fs/cifs/smb2ops.c
59866 +++ b/fs/cifs/smb2ops.c
59867 @@ -417,8 +417,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
59868 #ifdef CONFIG_CIFS_STATS
59869 int i;
59870 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
59871 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
59872 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
59873 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
59874 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
59875 }
59876 #endif
59877 }
59878 @@ -458,65 +458,65 @@ static void
59879 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
59880 {
59881 #ifdef CONFIG_CIFS_STATS
59882 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
59883 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
59884 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
59885 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
59886 seq_printf(m, "\nNegotiates: %d sent %d failed",
59887 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
59888 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
59889 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
59890 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
59891 seq_printf(m, "\nSessionSetups: %d sent %d failed",
59892 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
59893 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
59894 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
59895 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
59896 seq_printf(m, "\nLogoffs: %d sent %d failed",
59897 - atomic_read(&sent[SMB2_LOGOFF_HE]),
59898 - atomic_read(&failed[SMB2_LOGOFF_HE]));
59899 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
59900 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
59901 seq_printf(m, "\nTreeConnects: %d sent %d failed",
59902 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
59903 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
59904 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
59905 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
59906 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
59907 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
59908 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
59909 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
59910 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
59911 seq_printf(m, "\nCreates: %d sent %d failed",
59912 - atomic_read(&sent[SMB2_CREATE_HE]),
59913 - atomic_read(&failed[SMB2_CREATE_HE]));
59914 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
59915 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
59916 seq_printf(m, "\nCloses: %d sent %d failed",
59917 - atomic_read(&sent[SMB2_CLOSE_HE]),
59918 - atomic_read(&failed[SMB2_CLOSE_HE]));
59919 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
59920 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
59921 seq_printf(m, "\nFlushes: %d sent %d failed",
59922 - atomic_read(&sent[SMB2_FLUSH_HE]),
59923 - atomic_read(&failed[SMB2_FLUSH_HE]));
59924 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
59925 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
59926 seq_printf(m, "\nReads: %d sent %d failed",
59927 - atomic_read(&sent[SMB2_READ_HE]),
59928 - atomic_read(&failed[SMB2_READ_HE]));
59929 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
59930 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
59931 seq_printf(m, "\nWrites: %d sent %d failed",
59932 - atomic_read(&sent[SMB2_WRITE_HE]),
59933 - atomic_read(&failed[SMB2_WRITE_HE]));
59934 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
59935 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
59936 seq_printf(m, "\nLocks: %d sent %d failed",
59937 - atomic_read(&sent[SMB2_LOCK_HE]),
59938 - atomic_read(&failed[SMB2_LOCK_HE]));
59939 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
59940 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
59941 seq_printf(m, "\nIOCTLs: %d sent %d failed",
59942 - atomic_read(&sent[SMB2_IOCTL_HE]),
59943 - atomic_read(&failed[SMB2_IOCTL_HE]));
59944 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
59945 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
59946 seq_printf(m, "\nCancels: %d sent %d failed",
59947 - atomic_read(&sent[SMB2_CANCEL_HE]),
59948 - atomic_read(&failed[SMB2_CANCEL_HE]));
59949 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
59950 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
59951 seq_printf(m, "\nEchos: %d sent %d failed",
59952 - atomic_read(&sent[SMB2_ECHO_HE]),
59953 - atomic_read(&failed[SMB2_ECHO_HE]));
59954 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
59955 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
59956 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
59957 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
59958 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
59959 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
59960 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
59961 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
59962 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
59963 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
59964 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
59965 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
59966 seq_printf(m, "\nQueryInfos: %d sent %d failed",
59967 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
59968 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
59969 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
59970 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
59971 seq_printf(m, "\nSetInfos: %d sent %d failed",
59972 - atomic_read(&sent[SMB2_SET_INFO_HE]),
59973 - atomic_read(&failed[SMB2_SET_INFO_HE]));
59974 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
59975 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
59976 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
59977 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
59978 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
59979 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
59980 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
59981 #endif
59982 }
59983
59984 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
59985 index 8f1672b..af339c07 100644
59986 --- a/fs/cifs/smb2pdu.c
59987 +++ b/fs/cifs/smb2pdu.c
59988 @@ -2145,8 +2145,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
59989 default:
59990 cifs_dbg(VFS, "info level %u isn't supported\n",
59991 srch_inf->info_level);
59992 - rc = -EINVAL;
59993 - goto qdir_exit;
59994 + return -EINVAL;
59995 }
59996
59997 req->FileIndex = cpu_to_le32(index);
59998 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
59999 index 46ee6f2..89a9e7f 100644
60000 --- a/fs/coda/cache.c
60001 +++ b/fs/coda/cache.c
60002 @@ -24,7 +24,7 @@
60003 #include "coda_linux.h"
60004 #include "coda_cache.h"
60005
60006 -static atomic_t permission_epoch = ATOMIC_INIT(0);
60007 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
60008
60009 /* replace or extend an acl cache hit */
60010 void coda_cache_enter(struct inode *inode, int mask)
60011 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
60012 struct coda_inode_info *cii = ITOC(inode);
60013
60014 spin_lock(&cii->c_lock);
60015 - cii->c_cached_epoch = atomic_read(&permission_epoch);
60016 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
60017 if (!uid_eq(cii->c_uid, current_fsuid())) {
60018 cii->c_uid = current_fsuid();
60019 cii->c_cached_perm = mask;
60020 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
60021 {
60022 struct coda_inode_info *cii = ITOC(inode);
60023 spin_lock(&cii->c_lock);
60024 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
60025 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
60026 spin_unlock(&cii->c_lock);
60027 }
60028
60029 /* remove all acl caches */
60030 void coda_cache_clear_all(struct super_block *sb)
60031 {
60032 - atomic_inc(&permission_epoch);
60033 + atomic_inc_unchecked(&permission_epoch);
60034 }
60035
60036
60037 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
60038 spin_lock(&cii->c_lock);
60039 hit = (mask & cii->c_cached_perm) == mask &&
60040 uid_eq(cii->c_uid, current_fsuid()) &&
60041 - cii->c_cached_epoch == atomic_read(&permission_epoch);
60042 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
60043 spin_unlock(&cii->c_lock);
60044
60045 return hit;
60046 diff --git a/fs/compat.c b/fs/compat.c
60047 index b13df99..6f6f4a3 100644
60048 --- a/fs/compat.c
60049 +++ b/fs/compat.c
60050 @@ -54,7 +54,7 @@
60051 #include <asm/ioctls.h>
60052 #include "internal.h"
60053
60054 -int compat_log = 1;
60055 +int compat_log = 0;
60056
60057 int compat_printk(const char *fmt, ...)
60058 {
60059 @@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
60060
60061 set_fs(KERNEL_DS);
60062 /* The __user pointer cast is valid because of the set_fs() */
60063 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
60064 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
60065 set_fs(oldfs);
60066 /* truncating is ok because it's a user address */
60067 if (!ret)
60068 @@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
60069 goto out;
60070
60071 ret = -EINVAL;
60072 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
60073 + if (nr_segs > UIO_MAXIOV)
60074 goto out;
60075 if (nr_segs > fast_segs) {
60076 ret = -ENOMEM;
60077 @@ -844,6 +844,7 @@ struct compat_old_linux_dirent {
60078 struct compat_readdir_callback {
60079 struct dir_context ctx;
60080 struct compat_old_linux_dirent __user *dirent;
60081 + struct file * file;
60082 int result;
60083 };
60084
60085 @@ -861,6 +862,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
60086 buf->result = -EOVERFLOW;
60087 return -EOVERFLOW;
60088 }
60089 +
60090 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60091 + return 0;
60092 +
60093 buf->result++;
60094 dirent = buf->dirent;
60095 if (!access_ok(VERIFY_WRITE, dirent,
60096 @@ -892,6 +897,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
60097 if (!f.file)
60098 return -EBADF;
60099
60100 + buf.file = f.file;
60101 error = iterate_dir(f.file, &buf.ctx);
60102 if (buf.result)
60103 error = buf.result;
60104 @@ -911,6 +917,7 @@ struct compat_getdents_callback {
60105 struct dir_context ctx;
60106 struct compat_linux_dirent __user *current_dir;
60107 struct compat_linux_dirent __user *previous;
60108 + struct file * file;
60109 int count;
60110 int error;
60111 };
60112 @@ -932,6 +939,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
60113 buf->error = -EOVERFLOW;
60114 return -EOVERFLOW;
60115 }
60116 +
60117 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60118 + return 0;
60119 +
60120 dirent = buf->previous;
60121 if (dirent) {
60122 if (__put_user(offset, &dirent->d_off))
60123 @@ -977,6 +988,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
60124 if (!f.file)
60125 return -EBADF;
60126
60127 + buf.file = f.file;
60128 error = iterate_dir(f.file, &buf.ctx);
60129 if (error >= 0)
60130 error = buf.error;
60131 @@ -997,6 +1009,7 @@ struct compat_getdents_callback64 {
60132 struct dir_context ctx;
60133 struct linux_dirent64 __user *current_dir;
60134 struct linux_dirent64 __user *previous;
60135 + struct file * file;
60136 int count;
60137 int error;
60138 };
60139 @@ -1013,6 +1026,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
60140 buf->error = -EINVAL; /* only used if we fail.. */
60141 if (reclen > buf->count)
60142 return -EINVAL;
60143 +
60144 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60145 + return 0;
60146 +
60147 dirent = buf->previous;
60148
60149 if (dirent) {
60150 @@ -1062,6 +1079,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
60151 if (!f.file)
60152 return -EBADF;
60153
60154 + buf.file = f.file;
60155 error = iterate_dir(f.file, &buf.ctx);
60156 if (error >= 0)
60157 error = buf.error;
60158 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
60159 index 4d24d17..4f8c09e 100644
60160 --- a/fs/compat_binfmt_elf.c
60161 +++ b/fs/compat_binfmt_elf.c
60162 @@ -30,11 +30,13 @@
60163 #undef elf_phdr
60164 #undef elf_shdr
60165 #undef elf_note
60166 +#undef elf_dyn
60167 #undef elf_addr_t
60168 #define elfhdr elf32_hdr
60169 #define elf_phdr elf32_phdr
60170 #define elf_shdr elf32_shdr
60171 #define elf_note elf32_note
60172 +#define elf_dyn Elf32_Dyn
60173 #define elf_addr_t Elf32_Addr
60174
60175 /*
60176 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
60177 index afec645..9c65620 100644
60178 --- a/fs/compat_ioctl.c
60179 +++ b/fs/compat_ioctl.c
60180 @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
60181 return -EFAULT;
60182 if (__get_user(udata, &ss32->iomem_base))
60183 return -EFAULT;
60184 - ss.iomem_base = compat_ptr(udata);
60185 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
60186 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
60187 __get_user(ss.port_high, &ss32->port_high))
60188 return -EFAULT;
60189 @@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
60190 for (i = 0; i < nmsgs; i++) {
60191 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
60192 return -EFAULT;
60193 - if (get_user(datap, &umsgs[i].buf) ||
60194 - put_user(compat_ptr(datap), &tmsgs[i].buf))
60195 + if (get_user(datap, (compat_caddr_t __user *)&umsgs[i].buf) ||
60196 + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
60197 return -EFAULT;
60198 }
60199 return sys_ioctl(fd, cmd, (unsigned long)tdata);
60200 @@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
60201 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
60202 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
60203 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
60204 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
60205 + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
60206 return -EFAULT;
60207
60208 return ioctl_preallocate(file, p);
60209 @@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
60210 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
60211 {
60212 unsigned int a, b;
60213 - a = *(unsigned int *)p;
60214 - b = *(unsigned int *)q;
60215 + a = *(const unsigned int *)p;
60216 + b = *(const unsigned int *)q;
60217 if (a > b)
60218 return 1;
60219 if (a < b)
60220 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
60221 index 668dcab..daebcd6 100644
60222 --- a/fs/configfs/dir.c
60223 +++ b/fs/configfs/dir.c
60224 @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
60225 }
60226 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
60227 struct configfs_dirent *next;
60228 - const char *name;
60229 + const unsigned char * name;
60230 + char d_name[sizeof(next->s_dentry->d_iname)];
60231 int len;
60232 struct inode *inode = NULL;
60233
60234 @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
60235 continue;
60236
60237 name = configfs_get_name(next);
60238 - len = strlen(name);
60239 + if (next->s_dentry && name == next->s_dentry->d_iname) {
60240 + len = next->s_dentry->d_name.len;
60241 + memcpy(d_name, name, len);
60242 + name = d_name;
60243 + } else
60244 + len = strlen(name);
60245
60246 /*
60247 * We'll have a dentry and an inode for
60248 diff --git a/fs/coredump.c b/fs/coredump.c
60249 index b5c86ff..0dac262 100644
60250 --- a/fs/coredump.c
60251 +++ b/fs/coredump.c
60252 @@ -450,8 +450,8 @@ static void wait_for_dump_helpers(struct file *file)
60253 struct pipe_inode_info *pipe = file->private_data;
60254
60255 pipe_lock(pipe);
60256 - pipe->readers++;
60257 - pipe->writers--;
60258 + atomic_inc(&pipe->readers);
60259 + atomic_dec(&pipe->writers);
60260 wake_up_interruptible_sync(&pipe->wait);
60261 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
60262 pipe_unlock(pipe);
60263 @@ -460,11 +460,11 @@ static void wait_for_dump_helpers(struct file *file)
60264 * We actually want wait_event_freezable() but then we need
60265 * to clear TIF_SIGPENDING and improve dump_interrupted().
60266 */
60267 - wait_event_interruptible(pipe->wait, pipe->readers == 1);
60268 + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
60269
60270 pipe_lock(pipe);
60271 - pipe->readers--;
60272 - pipe->writers++;
60273 + atomic_dec(&pipe->readers);
60274 + atomic_inc(&pipe->writers);
60275 pipe_unlock(pipe);
60276 }
60277
60278 @@ -511,7 +511,9 @@ void do_coredump(const siginfo_t *siginfo)
60279 struct files_struct *displaced;
60280 bool need_nonrelative = false;
60281 bool core_dumped = false;
60282 - static atomic_t core_dump_count = ATOMIC_INIT(0);
60283 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
60284 + long signr = siginfo->si_signo;
60285 + int dumpable;
60286 struct coredump_params cprm = {
60287 .siginfo = siginfo,
60288 .regs = signal_pt_regs(),
60289 @@ -524,12 +526,17 @@ void do_coredump(const siginfo_t *siginfo)
60290 .mm_flags = mm->flags,
60291 };
60292
60293 - audit_core_dumps(siginfo->si_signo);
60294 + audit_core_dumps(signr);
60295 +
60296 + dumpable = __get_dumpable(cprm.mm_flags);
60297 +
60298 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
60299 + gr_handle_brute_attach(dumpable);
60300
60301 binfmt = mm->binfmt;
60302 if (!binfmt || !binfmt->core_dump)
60303 goto fail;
60304 - if (!__get_dumpable(cprm.mm_flags))
60305 + if (!dumpable)
60306 goto fail;
60307
60308 cred = prepare_creds();
60309 @@ -548,7 +555,7 @@ void do_coredump(const siginfo_t *siginfo)
60310 need_nonrelative = true;
60311 }
60312
60313 - retval = coredump_wait(siginfo->si_signo, &core_state);
60314 + retval = coredump_wait(signr, &core_state);
60315 if (retval < 0)
60316 goto fail_creds;
60317
60318 @@ -591,7 +598,7 @@ void do_coredump(const siginfo_t *siginfo)
60319 }
60320 cprm.limit = RLIM_INFINITY;
60321
60322 - dump_count = atomic_inc_return(&core_dump_count);
60323 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
60324 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
60325 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
60326 task_tgid_vnr(current), current->comm);
60327 @@ -623,6 +630,8 @@ void do_coredump(const siginfo_t *siginfo)
60328 } else {
60329 struct inode *inode;
60330
60331 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
60332 +
60333 if (cprm.limit < binfmt->min_coredump)
60334 goto fail_unlock;
60335
60336 @@ -681,7 +690,7 @@ close_fail:
60337 filp_close(cprm.file, NULL);
60338 fail_dropcount:
60339 if (ispipe)
60340 - atomic_dec(&core_dump_count);
60341 + atomic_dec_unchecked(&core_dump_count);
60342 fail_unlock:
60343 kfree(cn.corename);
60344 coredump_finish(mm, core_dumped);
60345 @@ -702,6 +711,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
60346 struct file *file = cprm->file;
60347 loff_t pos = file->f_pos;
60348 ssize_t n;
60349 +
60350 + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
60351 if (cprm->written + nr > cprm->limit)
60352 return 0;
60353 while (nr) {
60354 diff --git a/fs/dcache.c b/fs/dcache.c
60355 index 71acf8d..815e743 100644
60356 --- a/fs/dcache.c
60357 +++ b/fs/dcache.c
60358 @@ -508,7 +508,7 @@ static void __dentry_kill(struct dentry *dentry)
60359 * dentry_iput drops the locks, at which point nobody (except
60360 * transient RCU lookups) can reach this dentry.
60361 */
60362 - BUG_ON((int)dentry->d_lockref.count > 0);
60363 + BUG_ON((int)__lockref_read(&dentry->d_lockref) > 0);
60364 this_cpu_dec(nr_dentry);
60365 if (dentry->d_op && dentry->d_op->d_release)
60366 dentry->d_op->d_release(dentry);
60367 @@ -561,7 +561,7 @@ static inline struct dentry *lock_parent(struct dentry *dentry)
60368 struct dentry *parent = dentry->d_parent;
60369 if (IS_ROOT(dentry))
60370 return NULL;
60371 - if (unlikely((int)dentry->d_lockref.count < 0))
60372 + if (unlikely((int)__lockref_read(&dentry->d_lockref) < 0))
60373 return NULL;
60374 if (likely(spin_trylock(&parent->d_lock)))
60375 return parent;
60376 @@ -638,7 +638,7 @@ repeat:
60377 dentry->d_flags |= DCACHE_REFERENCED;
60378 dentry_lru_add(dentry);
60379
60380 - dentry->d_lockref.count--;
60381 + __lockref_dec(&dentry->d_lockref);
60382 spin_unlock(&dentry->d_lock);
60383 return;
60384
60385 @@ -653,7 +653,7 @@ EXPORT_SYMBOL(dput);
60386 /* This must be called with d_lock held */
60387 static inline void __dget_dlock(struct dentry *dentry)
60388 {
60389 - dentry->d_lockref.count++;
60390 + __lockref_inc(&dentry->d_lockref);
60391 }
60392
60393 static inline void __dget(struct dentry *dentry)
60394 @@ -694,8 +694,8 @@ repeat:
60395 goto repeat;
60396 }
60397 rcu_read_unlock();
60398 - BUG_ON(!ret->d_lockref.count);
60399 - ret->d_lockref.count++;
60400 + BUG_ON(!__lockref_read(&ret->d_lockref));
60401 + __lockref_inc(&ret->d_lockref);
60402 spin_unlock(&ret->d_lock);
60403 return ret;
60404 }
60405 @@ -773,9 +773,9 @@ restart:
60406 spin_lock(&inode->i_lock);
60407 hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
60408 spin_lock(&dentry->d_lock);
60409 - if (!dentry->d_lockref.count) {
60410 + if (!__lockref_read(&dentry->d_lockref)) {
60411 struct dentry *parent = lock_parent(dentry);
60412 - if (likely(!dentry->d_lockref.count)) {
60413 + if (likely(!__lockref_read(&dentry->d_lockref))) {
60414 __dentry_kill(dentry);
60415 dput(parent);
60416 goto restart;
60417 @@ -810,7 +810,7 @@ static void shrink_dentry_list(struct list_head *list)
60418 * We found an inuse dentry which was not removed from
60419 * the LRU because of laziness during lookup. Do not free it.
60420 */
60421 - if ((int)dentry->d_lockref.count > 0) {
60422 + if ((int)__lockref_read(&dentry->d_lockref) > 0) {
60423 spin_unlock(&dentry->d_lock);
60424 if (parent)
60425 spin_unlock(&parent->d_lock);
60426 @@ -848,8 +848,8 @@ static void shrink_dentry_list(struct list_head *list)
60427 dentry = parent;
60428 while (dentry && !lockref_put_or_lock(&dentry->d_lockref)) {
60429 parent = lock_parent(dentry);
60430 - if (dentry->d_lockref.count != 1) {
60431 - dentry->d_lockref.count--;
60432 + if (__lockref_read(&dentry->d_lockref) != 1) {
60433 + __lockref_inc(&dentry->d_lockref);
60434 spin_unlock(&dentry->d_lock);
60435 if (parent)
60436 spin_unlock(&parent->d_lock);
60437 @@ -889,7 +889,7 @@ dentry_lru_isolate(struct list_head *item, spinlock_t *lru_lock, void *arg)
60438 * counts, just remove them from the LRU. Otherwise give them
60439 * another pass through the LRU.
60440 */
60441 - if (dentry->d_lockref.count) {
60442 + if (__lockref_read(&dentry->d_lockref) > 0) {
60443 d_lru_isolate(dentry);
60444 spin_unlock(&dentry->d_lock);
60445 return LRU_REMOVED;
60446 @@ -1225,7 +1225,7 @@ static enum d_walk_ret select_collect(void *_data, struct dentry *dentry)
60447 } else {
60448 if (dentry->d_flags & DCACHE_LRU_LIST)
60449 d_lru_del(dentry);
60450 - if (!dentry->d_lockref.count) {
60451 + if (!__lockref_read(&dentry->d_lockref)) {
60452 d_shrink_add(dentry, &data->dispose);
60453 data->found++;
60454 }
60455 @@ -1273,7 +1273,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
60456 return D_WALK_CONTINUE;
60457
60458 /* root with refcount 1 is fine */
60459 - if (dentry == _data && dentry->d_lockref.count == 1)
60460 + if (dentry == _data && __lockref_read(&dentry->d_lockref) == 1)
60461 return D_WALK_CONTINUE;
60462
60463 printk(KERN_ERR "BUG: Dentry %p{i=%lx,n=%pd} "
60464 @@ -1282,7 +1282,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
60465 dentry->d_inode ?
60466 dentry->d_inode->i_ino : 0UL,
60467 dentry,
60468 - dentry->d_lockref.count,
60469 + __lockref_read(&dentry->d_lockref),
60470 dentry->d_sb->s_type->name,
60471 dentry->d_sb->s_id);
60472 WARN_ON(1);
60473 @@ -1423,7 +1423,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
60474 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
60475 if (name->len > DNAME_INLINE_LEN-1) {
60476 size_t size = offsetof(struct external_name, name[1]);
60477 - struct external_name *p = kmalloc(size + name->len, GFP_KERNEL);
60478 + struct external_name *p = kmalloc(round_up(size + name->len, sizeof(unsigned long)), GFP_KERNEL);
60479 if (!p) {
60480 kmem_cache_free(dentry_cache, dentry);
60481 return NULL;
60482 @@ -1443,7 +1443,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
60483 smp_wmb();
60484 dentry->d_name.name = dname;
60485
60486 - dentry->d_lockref.count = 1;
60487 + __lockref_set(&dentry->d_lockref, 1);
60488 dentry->d_flags = 0;
60489 spin_lock_init(&dentry->d_lock);
60490 seqcount_init(&dentry->d_seq);
60491 @@ -2183,7 +2183,7 @@ struct dentry *__d_lookup(const struct dentry *parent, const struct qstr *name)
60492 goto next;
60493 }
60494
60495 - dentry->d_lockref.count++;
60496 + __lockref_inc(&dentry->d_lockref);
60497 found = dentry;
60498 spin_unlock(&dentry->d_lock);
60499 break;
60500 @@ -2282,7 +2282,7 @@ again:
60501 spin_lock(&dentry->d_lock);
60502 inode = dentry->d_inode;
60503 isdir = S_ISDIR(inode->i_mode);
60504 - if (dentry->d_lockref.count == 1) {
60505 + if (__lockref_read(&dentry->d_lockref) == 1) {
60506 if (!spin_trylock(&inode->i_lock)) {
60507 spin_unlock(&dentry->d_lock);
60508 cpu_relax();
60509 @@ -3306,7 +3306,7 @@ static enum d_walk_ret d_genocide_kill(void *data, struct dentry *dentry)
60510
60511 if (!(dentry->d_flags & DCACHE_GENOCIDE)) {
60512 dentry->d_flags |= DCACHE_GENOCIDE;
60513 - dentry->d_lockref.count--;
60514 + __lockref_dec(&dentry->d_lockref);
60515 }
60516 }
60517 return D_WALK_CONTINUE;
60518 @@ -3422,7 +3422,8 @@ void __init vfs_caches_init(unsigned long mempages)
60519 mempages -= reserve;
60520
60521 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
60522 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
60523 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
60524 + SLAB_NO_SANITIZE, NULL);
60525
60526 dcache_init();
60527 inode_init();
60528 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
60529 index 05f2960..b012481 100644
60530 --- a/fs/debugfs/inode.c
60531 +++ b/fs/debugfs/inode.c
60532 @@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
60533 */
60534 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
60535 {
60536 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
60537 + return __create_file(name, S_IFDIR | S_IRWXU,
60538 +#else
60539 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
60540 +#endif
60541 parent, NULL, NULL);
60542 }
60543 EXPORT_SYMBOL_GPL(debugfs_create_dir);
60544 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
60545 index 1686dc2..9611c50 100644
60546 --- a/fs/ecryptfs/inode.c
60547 +++ b/fs/ecryptfs/inode.c
60548 @@ -664,7 +664,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
60549 old_fs = get_fs();
60550 set_fs(get_ds());
60551 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
60552 - (char __user *)lower_buf,
60553 + (char __force_user *)lower_buf,
60554 PATH_MAX);
60555 set_fs(old_fs);
60556 if (rc < 0)
60557 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
60558 index e4141f2..d8263e8 100644
60559 --- a/fs/ecryptfs/miscdev.c
60560 +++ b/fs/ecryptfs/miscdev.c
60561 @@ -304,7 +304,7 @@ check_list:
60562 goto out_unlock_msg_ctx;
60563 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
60564 if (msg_ctx->msg) {
60565 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
60566 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
60567 goto out_unlock_msg_ctx;
60568 i += packet_length_size;
60569 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
60570 diff --git a/fs/exec.c b/fs/exec.c
60571 index 7302b75..7d61d19 100644
60572 --- a/fs/exec.c
60573 +++ b/fs/exec.c
60574 @@ -56,8 +56,20 @@
60575 #include <linux/pipe_fs_i.h>
60576 #include <linux/oom.h>
60577 #include <linux/compat.h>
60578 +#include <linux/random.h>
60579 +#include <linux/seq_file.h>
60580 +#include <linux/coredump.h>
60581 +#include <linux/mman.h>
60582 +
60583 +#ifdef CONFIG_PAX_REFCOUNT
60584 +#include <linux/kallsyms.h>
60585 +#include <linux/kdebug.h>
60586 +#endif
60587 +
60588 +#include <trace/events/fs.h>
60589
60590 #include <asm/uaccess.h>
60591 +#include <asm/sections.h>
60592 #include <asm/mmu_context.h>
60593 #include <asm/tlb.h>
60594
60595 @@ -66,19 +78,34 @@
60596
60597 #include <trace/events/sched.h>
60598
60599 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
60600 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
60601 +{
60602 + 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");
60603 +}
60604 +#endif
60605 +
60606 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
60607 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
60608 +EXPORT_SYMBOL(pax_set_initial_flags_func);
60609 +#endif
60610 +
60611 int suid_dumpable = 0;
60612
60613 static LIST_HEAD(formats);
60614 static DEFINE_RWLOCK(binfmt_lock);
60615
60616 +extern int gr_process_kernel_exec_ban(void);
60617 +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
60618 +
60619 void __register_binfmt(struct linux_binfmt * fmt, int insert)
60620 {
60621 BUG_ON(!fmt);
60622 if (WARN_ON(!fmt->load_binary))
60623 return;
60624 write_lock(&binfmt_lock);
60625 - insert ? list_add(&fmt->lh, &formats) :
60626 - list_add_tail(&fmt->lh, &formats);
60627 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
60628 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
60629 write_unlock(&binfmt_lock);
60630 }
60631
60632 @@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
60633 void unregister_binfmt(struct linux_binfmt * fmt)
60634 {
60635 write_lock(&binfmt_lock);
60636 - list_del(&fmt->lh);
60637 + pax_list_del((struct list_head *)&fmt->lh);
60638 write_unlock(&binfmt_lock);
60639 }
60640
60641 @@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
60642 int write)
60643 {
60644 struct page *page;
60645 - int ret;
60646
60647 -#ifdef CONFIG_STACK_GROWSUP
60648 - if (write) {
60649 - ret = expand_downwards(bprm->vma, pos);
60650 - if (ret < 0)
60651 - return NULL;
60652 - }
60653 -#endif
60654 - ret = get_user_pages(current, bprm->mm, pos,
60655 - 1, write, 1, &page, NULL);
60656 - if (ret <= 0)
60657 + if (0 > expand_downwards(bprm->vma, pos))
60658 + return NULL;
60659 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
60660 return NULL;
60661
60662 if (write) {
60663 @@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
60664 if (size <= ARG_MAX)
60665 return page;
60666
60667 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60668 + // only allow 512KB for argv+env on suid/sgid binaries
60669 + // to prevent easy ASLR exhaustion
60670 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
60671 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
60672 + (size > (512 * 1024))) {
60673 + put_page(page);
60674 + return NULL;
60675 + }
60676 +#endif
60677 +
60678 /*
60679 * Limit to 1/4-th the stack size for the argv+env strings.
60680 * This ensures that:
60681 @@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
60682 vma->vm_end = STACK_TOP_MAX;
60683 vma->vm_start = vma->vm_end - PAGE_SIZE;
60684 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
60685 +
60686 +#ifdef CONFIG_PAX_SEGMEXEC
60687 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
60688 +#endif
60689 +
60690 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
60691 INIT_LIST_HEAD(&vma->anon_vma_chain);
60692
60693 @@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
60694 mm->stack_vm = mm->total_vm = 1;
60695 up_write(&mm->mmap_sem);
60696 bprm->p = vma->vm_end - sizeof(void *);
60697 +
60698 +#ifdef CONFIG_PAX_RANDUSTACK
60699 + if (randomize_va_space)
60700 + bprm->p ^= prandom_u32() & ~PAGE_MASK;
60701 +#endif
60702 +
60703 return 0;
60704 err:
60705 up_write(&mm->mmap_sem);
60706 @@ -395,7 +436,7 @@ struct user_arg_ptr {
60707 } ptr;
60708 };
60709
60710 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
60711 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
60712 {
60713 const char __user *native;
60714
60715 @@ -404,14 +445,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
60716 compat_uptr_t compat;
60717
60718 if (get_user(compat, argv.ptr.compat + nr))
60719 - return ERR_PTR(-EFAULT);
60720 + return (const char __force_user *)ERR_PTR(-EFAULT);
60721
60722 return compat_ptr(compat);
60723 }
60724 #endif
60725
60726 if (get_user(native, argv.ptr.native + nr))
60727 - return ERR_PTR(-EFAULT);
60728 + return (const char __force_user *)ERR_PTR(-EFAULT);
60729
60730 return native;
60731 }
60732 @@ -430,7 +471,7 @@ static int count(struct user_arg_ptr argv, int max)
60733 if (!p)
60734 break;
60735
60736 - if (IS_ERR(p))
60737 + if (IS_ERR((const char __force_kernel *)p))
60738 return -EFAULT;
60739
60740 if (i >= max)
60741 @@ -465,7 +506,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
60742
60743 ret = -EFAULT;
60744 str = get_user_arg_ptr(argv, argc);
60745 - if (IS_ERR(str))
60746 + if (IS_ERR((const char __force_kernel *)str))
60747 goto out;
60748
60749 len = strnlen_user(str, MAX_ARG_STRLEN);
60750 @@ -547,7 +588,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
60751 int r;
60752 mm_segment_t oldfs = get_fs();
60753 struct user_arg_ptr argv = {
60754 - .ptr.native = (const char __user *const __user *)__argv,
60755 + .ptr.native = (const char __user * const __force_user *)__argv,
60756 };
60757
60758 set_fs(KERNEL_DS);
60759 @@ -582,7 +623,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
60760 unsigned long new_end = old_end - shift;
60761 struct mmu_gather tlb;
60762
60763 - BUG_ON(new_start > new_end);
60764 + if (new_start >= new_end || new_start < mmap_min_addr)
60765 + return -ENOMEM;
60766
60767 /*
60768 * ensure there are no vmas between where we want to go
60769 @@ -591,6 +633,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
60770 if (vma != find_vma(mm, new_start))
60771 return -EFAULT;
60772
60773 +#ifdef CONFIG_PAX_SEGMEXEC
60774 + BUG_ON(pax_find_mirror_vma(vma));
60775 +#endif
60776 +
60777 /*
60778 * cover the whole range: [new_start, old_end)
60779 */
60780 @@ -671,10 +717,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
60781 stack_top = arch_align_stack(stack_top);
60782 stack_top = PAGE_ALIGN(stack_top);
60783
60784 - if (unlikely(stack_top < mmap_min_addr) ||
60785 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
60786 - return -ENOMEM;
60787 -
60788 stack_shift = vma->vm_end - stack_top;
60789
60790 bprm->p -= stack_shift;
60791 @@ -686,8 +728,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
60792 bprm->exec -= stack_shift;
60793
60794 down_write(&mm->mmap_sem);
60795 +
60796 + /* Move stack pages down in memory. */
60797 + if (stack_shift) {
60798 + ret = shift_arg_pages(vma, stack_shift);
60799 + if (ret)
60800 + goto out_unlock;
60801 + }
60802 +
60803 vm_flags = VM_STACK_FLAGS;
60804
60805 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
60806 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
60807 + vm_flags &= ~VM_EXEC;
60808 +
60809 +#ifdef CONFIG_PAX_MPROTECT
60810 + if (mm->pax_flags & MF_PAX_MPROTECT)
60811 + vm_flags &= ~VM_MAYEXEC;
60812 +#endif
60813 +
60814 + }
60815 +#endif
60816 +
60817 /*
60818 * Adjust stack execute permissions; explicitly enable for
60819 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
60820 @@ -706,13 +768,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
60821 goto out_unlock;
60822 BUG_ON(prev != vma);
60823
60824 - /* Move stack pages down in memory. */
60825 - if (stack_shift) {
60826 - ret = shift_arg_pages(vma, stack_shift);
60827 - if (ret)
60828 - goto out_unlock;
60829 - }
60830 -
60831 /* mprotect_fixup is overkill to remove the temporary stack flags */
60832 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
60833
60834 @@ -736,6 +791,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
60835 #endif
60836 current->mm->start_stack = bprm->p;
60837 ret = expand_stack(vma, stack_base);
60838 +
60839 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
60840 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
60841 + unsigned long size;
60842 + vm_flags_t vm_flags;
60843 +
60844 + size = STACK_TOP - vma->vm_end;
60845 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
60846 +
60847 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
60848 +
60849 +#ifdef CONFIG_X86
60850 + if (!ret) {
60851 + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
60852 + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
60853 + }
60854 +#endif
60855 +
60856 + }
60857 +#endif
60858 +
60859 if (ret)
60860 ret = -EFAULT;
60861
60862 @@ -771,6 +847,8 @@ static struct file *do_open_exec(struct filename *name)
60863
60864 fsnotify_open(file);
60865
60866 + trace_open_exec(name->name);
60867 +
60868 err = deny_write_access(file);
60869 if (err)
60870 goto exit;
60871 @@ -800,7 +878,7 @@ int kernel_read(struct file *file, loff_t offset,
60872 old_fs = get_fs();
60873 set_fs(get_ds());
60874 /* The cast to a user pointer is valid due to the set_fs() */
60875 - result = vfs_read(file, (void __user *)addr, count, &pos);
60876 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
60877 set_fs(old_fs);
60878 return result;
60879 }
60880 @@ -845,6 +923,7 @@ static int exec_mmap(struct mm_struct *mm)
60881 tsk->mm = mm;
60882 tsk->active_mm = mm;
60883 activate_mm(active_mm, mm);
60884 + populate_stack();
60885 tsk->mm->vmacache_seqnum = 0;
60886 vmacache_flush(tsk);
60887 task_unlock(tsk);
60888 @@ -1243,7 +1322,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
60889 }
60890 rcu_read_unlock();
60891
60892 - if (p->fs->users > n_fs)
60893 + if (atomic_read(&p->fs->users) > n_fs)
60894 bprm->unsafe |= LSM_UNSAFE_SHARE;
60895 else
60896 p->fs->in_exec = 1;
60897 @@ -1424,6 +1503,31 @@ static int exec_binprm(struct linux_binprm *bprm)
60898 return ret;
60899 }
60900
60901 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60902 +static DEFINE_PER_CPU(u64, exec_counter);
60903 +static int __init init_exec_counters(void)
60904 +{
60905 + unsigned int cpu;
60906 +
60907 + for_each_possible_cpu(cpu) {
60908 + per_cpu(exec_counter, cpu) = (u64)cpu;
60909 + }
60910 +
60911 + return 0;
60912 +}
60913 +early_initcall(init_exec_counters);
60914 +static inline void increment_exec_counter(void)
60915 +{
60916 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
60917 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
60918 +}
60919 +#else
60920 +static inline void increment_exec_counter(void) {}
60921 +#endif
60922 +
60923 +extern void gr_handle_exec_args(struct linux_binprm *bprm,
60924 + struct user_arg_ptr argv);
60925 +
60926 /*
60927 * sys_execve() executes a new program.
60928 */
60929 @@ -1431,6 +1535,11 @@ static int do_execve_common(struct filename *filename,
60930 struct user_arg_ptr argv,
60931 struct user_arg_ptr envp)
60932 {
60933 +#ifdef CONFIG_GRKERNSEC
60934 + struct file *old_exec_file;
60935 + struct acl_subject_label *old_acl;
60936 + struct rlimit old_rlim[RLIM_NLIMITS];
60937 +#endif
60938 struct linux_binprm *bprm;
60939 struct file *file;
60940 struct files_struct *displaced;
60941 @@ -1439,6 +1548,8 @@ static int do_execve_common(struct filename *filename,
60942 if (IS_ERR(filename))
60943 return PTR_ERR(filename);
60944
60945 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
60946 +
60947 /*
60948 * We move the actual failure in case of RLIMIT_NPROC excess from
60949 * set*uid() to execve() because too many poorly written programs
60950 @@ -1476,11 +1587,21 @@ static int do_execve_common(struct filename *filename,
60951 if (IS_ERR(file))
60952 goto out_unmark;
60953
60954 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
60955 + retval = -EPERM;
60956 + goto out_unmark;
60957 + }
60958 +
60959 sched_exec();
60960
60961 bprm->file = file;
60962 bprm->filename = bprm->interp = filename->name;
60963
60964 + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
60965 + retval = -EACCES;
60966 + goto out_unmark;
60967 + }
60968 +
60969 retval = bprm_mm_init(bprm);
60970 if (retval)
60971 goto out_unmark;
60972 @@ -1497,24 +1618,70 @@ static int do_execve_common(struct filename *filename,
60973 if (retval < 0)
60974 goto out;
60975
60976 +#ifdef CONFIG_GRKERNSEC
60977 + old_acl = current->acl;
60978 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
60979 + old_exec_file = current->exec_file;
60980 + get_file(file);
60981 + current->exec_file = file;
60982 +#endif
60983 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60984 + /* limit suid stack to 8MB
60985 + * we saved the old limits above and will restore them if this exec fails
60986 + */
60987 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
60988 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
60989 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
60990 +#endif
60991 +
60992 + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
60993 + retval = -EPERM;
60994 + goto out_fail;
60995 + }
60996 +
60997 + if (!gr_tpe_allow(file)) {
60998 + retval = -EACCES;
60999 + goto out_fail;
61000 + }
61001 +
61002 + if (gr_check_crash_exec(file)) {
61003 + retval = -EACCES;
61004 + goto out_fail;
61005 + }
61006 +
61007 + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
61008 + bprm->unsafe);
61009 + if (retval < 0)
61010 + goto out_fail;
61011 +
61012 retval = copy_strings_kernel(1, &bprm->filename, bprm);
61013 if (retval < 0)
61014 - goto out;
61015 + goto out_fail;
61016
61017 bprm->exec = bprm->p;
61018 retval = copy_strings(bprm->envc, envp, bprm);
61019 if (retval < 0)
61020 - goto out;
61021 + goto out_fail;
61022
61023 retval = copy_strings(bprm->argc, argv, bprm);
61024 if (retval < 0)
61025 - goto out;
61026 + goto out_fail;
61027 +
61028 + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
61029 +
61030 + gr_handle_exec_args(bprm, argv);
61031
61032 retval = exec_binprm(bprm);
61033 if (retval < 0)
61034 - goto out;
61035 + goto out_fail;
61036 +#ifdef CONFIG_GRKERNSEC
61037 + if (old_exec_file)
61038 + fput(old_exec_file);
61039 +#endif
61040
61041 /* execve succeeded */
61042 +
61043 + increment_exec_counter();
61044 current->fs->in_exec = 0;
61045 current->in_execve = 0;
61046 acct_update_integrals(current);
61047 @@ -1525,6 +1692,14 @@ static int do_execve_common(struct filename *filename,
61048 put_files_struct(displaced);
61049 return retval;
61050
61051 +out_fail:
61052 +#ifdef CONFIG_GRKERNSEC
61053 + current->acl = old_acl;
61054 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
61055 + fput(current->exec_file);
61056 + current->exec_file = old_exec_file;
61057 +#endif
61058 +
61059 out:
61060 if (bprm->mm) {
61061 acct_arg_size(bprm, 0);
61062 @@ -1616,3 +1791,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
61063 return compat_do_execve(getname(filename), argv, envp);
61064 }
61065 #endif
61066 +
61067 +int pax_check_flags(unsigned long *flags)
61068 +{
61069 + int retval = 0;
61070 +
61071 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
61072 + if (*flags & MF_PAX_SEGMEXEC)
61073 + {
61074 + *flags &= ~MF_PAX_SEGMEXEC;
61075 + retval = -EINVAL;
61076 + }
61077 +#endif
61078 +
61079 + if ((*flags & MF_PAX_PAGEEXEC)
61080 +
61081 +#ifdef CONFIG_PAX_PAGEEXEC
61082 + && (*flags & MF_PAX_SEGMEXEC)
61083 +#endif
61084 +
61085 + )
61086 + {
61087 + *flags &= ~MF_PAX_PAGEEXEC;
61088 + retval = -EINVAL;
61089 + }
61090 +
61091 + if ((*flags & MF_PAX_MPROTECT)
61092 +
61093 +#ifdef CONFIG_PAX_MPROTECT
61094 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61095 +#endif
61096 +
61097 + )
61098 + {
61099 + *flags &= ~MF_PAX_MPROTECT;
61100 + retval = -EINVAL;
61101 + }
61102 +
61103 + if ((*flags & MF_PAX_EMUTRAMP)
61104 +
61105 +#ifdef CONFIG_PAX_EMUTRAMP
61106 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61107 +#endif
61108 +
61109 + )
61110 + {
61111 + *flags &= ~MF_PAX_EMUTRAMP;
61112 + retval = -EINVAL;
61113 + }
61114 +
61115 + return retval;
61116 +}
61117 +
61118 +EXPORT_SYMBOL(pax_check_flags);
61119 +
61120 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
61121 +char *pax_get_path(const struct path *path, char *buf, int buflen)
61122 +{
61123 + char *pathname = d_path(path, buf, buflen);
61124 +
61125 + if (IS_ERR(pathname))
61126 + goto toolong;
61127 +
61128 + pathname = mangle_path(buf, pathname, "\t\n\\");
61129 + if (!pathname)
61130 + goto toolong;
61131 +
61132 + *pathname = 0;
61133 + return buf;
61134 +
61135 +toolong:
61136 + return "<path too long>";
61137 +}
61138 +EXPORT_SYMBOL(pax_get_path);
61139 +
61140 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
61141 +{
61142 + struct task_struct *tsk = current;
61143 + struct mm_struct *mm = current->mm;
61144 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
61145 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
61146 + char *path_exec = NULL;
61147 + char *path_fault = NULL;
61148 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
61149 + siginfo_t info = { };
61150 +
61151 + if (buffer_exec && buffer_fault) {
61152 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
61153 +
61154 + down_read(&mm->mmap_sem);
61155 + vma = mm->mmap;
61156 + while (vma && (!vma_exec || !vma_fault)) {
61157 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
61158 + vma_exec = vma;
61159 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
61160 + vma_fault = vma;
61161 + vma = vma->vm_next;
61162 + }
61163 + if (vma_exec)
61164 + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
61165 + if (vma_fault) {
61166 + start = vma_fault->vm_start;
61167 + end = vma_fault->vm_end;
61168 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
61169 + if (vma_fault->vm_file)
61170 + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
61171 + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
61172 + path_fault = "<heap>";
61173 + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
61174 + path_fault = "<stack>";
61175 + else
61176 + path_fault = "<anonymous mapping>";
61177 + }
61178 + up_read(&mm->mmap_sem);
61179 + }
61180 + if (tsk->signal->curr_ip)
61181 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
61182 + else
61183 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
61184 + 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),
61185 + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
61186 + free_page((unsigned long)buffer_exec);
61187 + free_page((unsigned long)buffer_fault);
61188 + pax_report_insns(regs, pc, sp);
61189 + info.si_signo = SIGKILL;
61190 + info.si_errno = 0;
61191 + info.si_code = SI_KERNEL;
61192 + info.si_pid = 0;
61193 + info.si_uid = 0;
61194 + do_coredump(&info);
61195 +}
61196 +#endif
61197 +
61198 +#ifdef CONFIG_PAX_REFCOUNT
61199 +void pax_report_refcount_overflow(struct pt_regs *regs)
61200 +{
61201 + if (current->signal->curr_ip)
61202 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
61203 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
61204 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61205 + else
61206 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
61207 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61208 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
61209 + preempt_disable();
61210 + show_regs(regs);
61211 + preempt_enable();
61212 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
61213 +}
61214 +#endif
61215 +
61216 +#ifdef CONFIG_PAX_USERCOPY
61217 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
61218 +static noinline int check_stack_object(const void *obj, unsigned long len)
61219 +{
61220 + const void * const stack = task_stack_page(current);
61221 + const void * const stackend = stack + THREAD_SIZE;
61222 +
61223 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
61224 + const void *frame = NULL;
61225 + const void *oldframe;
61226 +#endif
61227 +
61228 + if (obj + len < obj)
61229 + return -1;
61230 +
61231 + if (obj + len <= stack || stackend <= obj)
61232 + return 0;
61233 +
61234 + if (obj < stack || stackend < obj + len)
61235 + return -1;
61236 +
61237 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
61238 + oldframe = __builtin_frame_address(1);
61239 + if (oldframe)
61240 + frame = __builtin_frame_address(2);
61241 + /*
61242 + low ----------------------------------------------> high
61243 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
61244 + ^----------------^
61245 + allow copies only within here
61246 + */
61247 + while (stack <= frame && frame < stackend) {
61248 + /* if obj + len extends past the last frame, this
61249 + check won't pass and the next frame will be 0,
61250 + causing us to bail out and correctly report
61251 + the copy as invalid
61252 + */
61253 + if (obj + len <= frame)
61254 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
61255 + oldframe = frame;
61256 + frame = *(const void * const *)frame;
61257 + }
61258 + return -1;
61259 +#else
61260 + return 1;
61261 +#endif
61262 +}
61263 +
61264 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
61265 +{
61266 + if (current->signal->curr_ip)
61267 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
61268 + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
61269 + else
61270 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
61271 + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
61272 + dump_stack();
61273 + gr_handle_kernel_exploit();
61274 + do_group_exit(SIGKILL);
61275 +}
61276 +#endif
61277 +
61278 +#ifdef CONFIG_PAX_USERCOPY
61279 +
61280 +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
61281 +{
61282 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
61283 + unsigned long textlow = ktla_ktva((unsigned long)_stext);
61284 +#ifdef CONFIG_MODULES
61285 + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
61286 +#else
61287 + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
61288 +#endif
61289 +
61290 +#else
61291 + unsigned long textlow = (unsigned long)_stext;
61292 + unsigned long texthigh = (unsigned long)_etext;
61293 +
61294 +#ifdef CONFIG_X86_64
61295 + /* check against linear mapping as well */
61296 + if (high > (unsigned long)__va(__pa(textlow)) &&
61297 + low < (unsigned long)__va(__pa(texthigh)))
61298 + return true;
61299 +#endif
61300 +
61301 +#endif
61302 +
61303 + if (high <= textlow || low >= texthigh)
61304 + return false;
61305 + else
61306 + return true;
61307 +}
61308 +#endif
61309 +
61310 +void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
61311 +{
61312 +#ifdef CONFIG_PAX_USERCOPY
61313 + const char *type;
61314 +#endif
61315 +
61316 +#ifndef CONFIG_STACK_GROWSUP
61317 + unsigned long stackstart = (unsigned long)task_stack_page(current);
61318 + unsigned long currentsp = (unsigned long)&stackstart;
61319 + if (unlikely((currentsp < stackstart + 512 ||
61320 + currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
61321 + BUG();
61322 +#endif
61323 +
61324 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
61325 + if (const_size)
61326 + return;
61327 +#endif
61328 +
61329 +#ifdef CONFIG_PAX_USERCOPY
61330 + if (!n)
61331 + return;
61332 +
61333 + type = check_heap_object(ptr, n);
61334 + if (!type) {
61335 + int ret = check_stack_object(ptr, n);
61336 + if (ret == 1 || ret == 2)
61337 + return;
61338 + if (ret == 0) {
61339 + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
61340 + type = "<kernel text>";
61341 + else
61342 + return;
61343 + } else
61344 + type = "<process stack>";
61345 + }
61346 +
61347 + pax_report_usercopy(ptr, n, to_user, type);
61348 +#endif
61349 +
61350 +}
61351 +EXPORT_SYMBOL(__check_object_size);
61352 +
61353 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
61354 +void pax_track_stack(void)
61355 +{
61356 + unsigned long sp = (unsigned long)&sp;
61357 + if (sp < current_thread_info()->lowest_stack &&
61358 + sp > (unsigned long)task_stack_page(current))
61359 + current_thread_info()->lowest_stack = sp;
61360 + if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
61361 + BUG();
61362 +}
61363 +EXPORT_SYMBOL(pax_track_stack);
61364 +#endif
61365 +
61366 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
61367 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
61368 +{
61369 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
61370 + dump_stack();
61371 + do_group_exit(SIGKILL);
61372 +}
61373 +EXPORT_SYMBOL(report_size_overflow);
61374 +#endif
61375 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
61376 index 9f9992b..8b59411 100644
61377 --- a/fs/ext2/balloc.c
61378 +++ b/fs/ext2/balloc.c
61379 @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
61380
61381 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
61382 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
61383 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
61384 + if (free_blocks < root_blocks + 1 &&
61385 !uid_eq(sbi->s_resuid, current_fsuid()) &&
61386 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
61387 - !in_group_p (sbi->s_resgid))) {
61388 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
61389 return 0;
61390 }
61391 return 1;
61392 diff --git a/fs/ext2/super.c b/fs/ext2/super.c
61393 index 170dc41..62f6b18 100644
61394 --- a/fs/ext2/super.c
61395 +++ b/fs/ext2/super.c
61396 @@ -264,10 +264,8 @@ static int ext2_show_options(struct seq_file *seq, struct dentry *root)
61397 #ifdef CONFIG_EXT2_FS_XATTR
61398 if (test_opt(sb, XATTR_USER))
61399 seq_puts(seq, ",user_xattr");
61400 - if (!test_opt(sb, XATTR_USER) &&
61401 - (def_mount_opts & EXT2_DEFM_XATTR_USER)) {
61402 + if (!test_opt(sb, XATTR_USER))
61403 seq_puts(seq, ",nouser_xattr");
61404 - }
61405 #endif
61406
61407 #ifdef CONFIG_EXT2_FS_POSIX_ACL
61408 @@ -841,8 +839,8 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
61409 if (def_mount_opts & EXT2_DEFM_UID16)
61410 set_opt(sbi->s_mount_opt, NO_UID32);
61411 #ifdef CONFIG_EXT2_FS_XATTR
61412 - if (def_mount_opts & EXT2_DEFM_XATTR_USER)
61413 - set_opt(sbi->s_mount_opt, XATTR_USER);
61414 + /* always enable user xattrs */
61415 + set_opt(sbi->s_mount_opt, XATTR_USER);
61416 #endif
61417 #ifdef CONFIG_EXT2_FS_POSIX_ACL
61418 if (def_mount_opts & EXT2_DEFM_ACL)
61419 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
61420 index 9142614..97484fa 100644
61421 --- a/fs/ext2/xattr.c
61422 +++ b/fs/ext2/xattr.c
61423 @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
61424 struct buffer_head *bh = NULL;
61425 struct ext2_xattr_entry *entry;
61426 char *end;
61427 - size_t rest = buffer_size;
61428 + size_t rest = buffer_size, total_size = 0;
61429 int error;
61430
61431 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
61432 @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
61433 buffer += size;
61434 }
61435 rest -= size;
61436 + total_size += size;
61437 }
61438 }
61439 - error = buffer_size - rest; /* total size */
61440 + error = total_size;
61441
61442 cleanup:
61443 brelse(bh);
61444 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
61445 index 158b5d4..2432610 100644
61446 --- a/fs/ext3/balloc.c
61447 +++ b/fs/ext3/balloc.c
61448 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
61449
61450 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
61451 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
61452 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
61453 + if (free_blocks < root_blocks + 1 &&
61454 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
61455 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
61456 - !in_group_p (sbi->s_resgid))) {
61457 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
61458 return 0;
61459 }
61460 return 1;
61461 diff --git a/fs/ext3/super.c b/fs/ext3/super.c
61462 index eb742d0..c19f705 100644
61463 --- a/fs/ext3/super.c
61464 +++ b/fs/ext3/super.c
61465 @@ -649,10 +649,8 @@ static int ext3_show_options(struct seq_file *seq, struct dentry *root)
61466 #ifdef CONFIG_EXT3_FS_XATTR
61467 if (test_opt(sb, XATTR_USER))
61468 seq_puts(seq, ",user_xattr");
61469 - if (!test_opt(sb, XATTR_USER) &&
61470 - (def_mount_opts & EXT3_DEFM_XATTR_USER)) {
61471 + if (!test_opt(sb, XATTR_USER))
61472 seq_puts(seq, ",nouser_xattr");
61473 - }
61474 #endif
61475 #ifdef CONFIG_EXT3_FS_POSIX_ACL
61476 if (test_opt(sb, POSIX_ACL))
61477 @@ -1749,8 +1747,8 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
61478 if (def_mount_opts & EXT3_DEFM_UID16)
61479 set_opt(sbi->s_mount_opt, NO_UID32);
61480 #ifdef CONFIG_EXT3_FS_XATTR
61481 - if (def_mount_opts & EXT3_DEFM_XATTR_USER)
61482 - set_opt(sbi->s_mount_opt, XATTR_USER);
61483 + /* always enable user xattrs */
61484 + set_opt(sbi->s_mount_opt, XATTR_USER);
61485 #endif
61486 #ifdef CONFIG_EXT3_FS_POSIX_ACL
61487 if (def_mount_opts & EXT3_DEFM_ACL)
61488 diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
61489 index c6874be..f8a6ae8 100644
61490 --- a/fs/ext3/xattr.c
61491 +++ b/fs/ext3/xattr.c
61492 @@ -330,7 +330,7 @@ static int
61493 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
61494 char *buffer, size_t buffer_size)
61495 {
61496 - size_t rest = buffer_size;
61497 + size_t rest = buffer_size, total_size = 0;
61498
61499 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
61500 const struct xattr_handler *handler =
61501 @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
61502 buffer += size;
61503 }
61504 rest -= size;
61505 + total_size += size;
61506 }
61507 }
61508 - return buffer_size - rest;
61509 + return total_size;
61510 }
61511
61512 static int
61513 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
61514 index 83a6f49..d4e4d03 100644
61515 --- a/fs/ext4/balloc.c
61516 +++ b/fs/ext4/balloc.c
61517 @@ -557,8 +557,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
61518 /* Hm, nope. Are (enough) root reserved clusters available? */
61519 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
61520 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
61521 - capable(CAP_SYS_RESOURCE) ||
61522 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
61523 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
61524 + capable_nolog(CAP_SYS_RESOURCE)) {
61525
61526 if (free_clusters >= (nclusters + dirty_clusters +
61527 resv_clusters))
61528 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
61529 index c55a1fa..9904ebb 100644
61530 --- a/fs/ext4/ext4.h
61531 +++ b/fs/ext4/ext4.h
61532 @@ -1279,19 +1279,19 @@ struct ext4_sb_info {
61533 unsigned long s_mb_last_start;
61534
61535 /* stats for buddy allocator */
61536 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
61537 - atomic_t s_bal_success; /* we found long enough chunks */
61538 - atomic_t s_bal_allocated; /* in blocks */
61539 - atomic_t s_bal_ex_scanned; /* total extents scanned */
61540 - atomic_t s_bal_goals; /* goal hits */
61541 - atomic_t s_bal_breaks; /* too long searches */
61542 - atomic_t s_bal_2orders; /* 2^order hits */
61543 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
61544 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
61545 + atomic_unchecked_t s_bal_allocated; /* in blocks */
61546 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
61547 + atomic_unchecked_t s_bal_goals; /* goal hits */
61548 + atomic_unchecked_t s_bal_breaks; /* too long searches */
61549 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
61550 spinlock_t s_bal_lock;
61551 unsigned long s_mb_buddies_generated;
61552 unsigned long long s_mb_generation_time;
61553 - atomic_t s_mb_lost_chunks;
61554 - atomic_t s_mb_preallocated;
61555 - atomic_t s_mb_discarded;
61556 + atomic_unchecked_t s_mb_lost_chunks;
61557 + atomic_unchecked_t s_mb_preallocated;
61558 + atomic_unchecked_t s_mb_discarded;
61559 atomic_t s_lock_busy;
61560
61561 /* locality groups */
61562 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
61563 index dbfe15c..9a6ee8d 100644
61564 --- a/fs/ext4/mballoc.c
61565 +++ b/fs/ext4/mballoc.c
61566 @@ -1901,7 +1901,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
61567 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
61568
61569 if (EXT4_SB(sb)->s_mb_stats)
61570 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
61571 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
61572
61573 break;
61574 }
61575 @@ -2211,7 +2211,7 @@ repeat:
61576 ac->ac_status = AC_STATUS_CONTINUE;
61577 ac->ac_flags |= EXT4_MB_HINT_FIRST;
61578 cr = 3;
61579 - atomic_inc(&sbi->s_mb_lost_chunks);
61580 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
61581 goto repeat;
61582 }
61583 }
61584 @@ -2717,25 +2717,25 @@ int ext4_mb_release(struct super_block *sb)
61585 if (sbi->s_mb_stats) {
61586 ext4_msg(sb, KERN_INFO,
61587 "mballoc: %u blocks %u reqs (%u success)",
61588 - atomic_read(&sbi->s_bal_allocated),
61589 - atomic_read(&sbi->s_bal_reqs),
61590 - atomic_read(&sbi->s_bal_success));
61591 + atomic_read_unchecked(&sbi->s_bal_allocated),
61592 + atomic_read_unchecked(&sbi->s_bal_reqs),
61593 + atomic_read_unchecked(&sbi->s_bal_success));
61594 ext4_msg(sb, KERN_INFO,
61595 "mballoc: %u extents scanned, %u goal hits, "
61596 "%u 2^N hits, %u breaks, %u lost",
61597 - atomic_read(&sbi->s_bal_ex_scanned),
61598 - atomic_read(&sbi->s_bal_goals),
61599 - atomic_read(&sbi->s_bal_2orders),
61600 - atomic_read(&sbi->s_bal_breaks),
61601 - atomic_read(&sbi->s_mb_lost_chunks));
61602 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
61603 + atomic_read_unchecked(&sbi->s_bal_goals),
61604 + atomic_read_unchecked(&sbi->s_bal_2orders),
61605 + atomic_read_unchecked(&sbi->s_bal_breaks),
61606 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
61607 ext4_msg(sb, KERN_INFO,
61608 "mballoc: %lu generated and it took %Lu",
61609 sbi->s_mb_buddies_generated,
61610 sbi->s_mb_generation_time);
61611 ext4_msg(sb, KERN_INFO,
61612 "mballoc: %u preallocated, %u discarded",
61613 - atomic_read(&sbi->s_mb_preallocated),
61614 - atomic_read(&sbi->s_mb_discarded));
61615 + atomic_read_unchecked(&sbi->s_mb_preallocated),
61616 + atomic_read_unchecked(&sbi->s_mb_discarded));
61617 }
61618
61619 free_percpu(sbi->s_locality_groups);
61620 @@ -3191,16 +3191,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
61621 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
61622
61623 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
61624 - atomic_inc(&sbi->s_bal_reqs);
61625 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
61626 + atomic_inc_unchecked(&sbi->s_bal_reqs);
61627 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
61628 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
61629 - atomic_inc(&sbi->s_bal_success);
61630 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
61631 + atomic_inc_unchecked(&sbi->s_bal_success);
61632 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
61633 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
61634 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
61635 - atomic_inc(&sbi->s_bal_goals);
61636 + atomic_inc_unchecked(&sbi->s_bal_goals);
61637 if (ac->ac_found > sbi->s_mb_max_to_scan)
61638 - atomic_inc(&sbi->s_bal_breaks);
61639 + atomic_inc_unchecked(&sbi->s_bal_breaks);
61640 }
61641
61642 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
61643 @@ -3627,7 +3627,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
61644 trace_ext4_mb_new_inode_pa(ac, pa);
61645
61646 ext4_mb_use_inode_pa(ac, pa);
61647 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
61648 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
61649
61650 ei = EXT4_I(ac->ac_inode);
61651 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
61652 @@ -3687,7 +3687,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
61653 trace_ext4_mb_new_group_pa(ac, pa);
61654
61655 ext4_mb_use_group_pa(ac, pa);
61656 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
61657 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
61658
61659 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
61660 lg = ac->ac_lg;
61661 @@ -3776,7 +3776,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
61662 * from the bitmap and continue.
61663 */
61664 }
61665 - atomic_add(free, &sbi->s_mb_discarded);
61666 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
61667
61668 return err;
61669 }
61670 @@ -3794,7 +3794,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
61671 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
61672 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
61673 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
61674 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
61675 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
61676 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
61677
61678 return 0;
61679 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
61680 index 8313ca3..8a37d08 100644
61681 --- a/fs/ext4/mmp.c
61682 +++ b/fs/ext4/mmp.c
61683 @@ -111,7 +111,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
61684 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
61685 const char *function, unsigned int line, const char *msg)
61686 {
61687 - __ext4_warning(sb, function, line, msg);
61688 + __ext4_warning(sb, function, line, "%s", msg);
61689 __ext4_warning(sb, function, line,
61690 "MMP failure info: last update time: %llu, last update "
61691 "node: %s, last update device: %s\n",
61692 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
61693 index 2c9e686..6a40edc 100644
61694 --- a/fs/ext4/super.c
61695 +++ b/fs/ext4/super.c
61696 @@ -1254,7 +1254,7 @@ static ext4_fsblk_t get_sb_block(void **data)
61697 }
61698
61699 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
61700 -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
61701 +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
61702 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
61703
61704 #ifdef CONFIG_QUOTA
61705 @@ -2434,7 +2434,7 @@ struct ext4_attr {
61706 int offset;
61707 int deprecated_val;
61708 } u;
61709 -};
61710 +} __do_const;
61711
61712 static int parse_strtoull(const char *buf,
61713 unsigned long long max, unsigned long long *value)
61714 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
61715 index 1e09fc7..0400dd4 100644
61716 --- a/fs/ext4/xattr.c
61717 +++ b/fs/ext4/xattr.c
61718 @@ -399,7 +399,7 @@ static int
61719 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
61720 char *buffer, size_t buffer_size)
61721 {
61722 - size_t rest = buffer_size;
61723 + size_t rest = buffer_size, total_size = 0;
61724
61725 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
61726 const struct xattr_handler *handler =
61727 @@ -416,9 +416,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
61728 buffer += size;
61729 }
61730 rest -= size;
61731 + total_size += size;
61732 }
61733 }
61734 - return buffer_size - rest;
61735 + return total_size;
61736 }
61737
61738 static int
61739 diff --git a/fs/fcntl.c b/fs/fcntl.c
61740 index 99d440a..eb979d1 100644
61741 --- a/fs/fcntl.c
61742 +++ b/fs/fcntl.c
61743 @@ -102,6 +102,10 @@ void __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
61744 int force)
61745 {
61746 security_file_set_fowner(filp);
61747 + if (gr_handle_chroot_fowner(pid, type))
61748 + return;
61749 + if (gr_check_protected_task_fowner(pid, type))
61750 + return;
61751 f_modown(filp, pid, type, force);
61752 }
61753 EXPORT_SYMBOL(__f_setown);
61754 diff --git a/fs/fhandle.c b/fs/fhandle.c
61755 index 999ff5c..ac037c9 100644
61756 --- a/fs/fhandle.c
61757 +++ b/fs/fhandle.c
61758 @@ -8,6 +8,7 @@
61759 #include <linux/fs_struct.h>
61760 #include <linux/fsnotify.h>
61761 #include <linux/personality.h>
61762 +#include <linux/grsecurity.h>
61763 #include <asm/uaccess.h>
61764 #include "internal.h"
61765 #include "mount.h"
61766 @@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
61767 } else
61768 retval = 0;
61769 /* copy the mount id */
61770 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
61771 - sizeof(*mnt_id)) ||
61772 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
61773 copy_to_user(ufh, handle,
61774 sizeof(struct file_handle) + handle_bytes))
61775 retval = -EFAULT;
61776 @@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
61777 * the directory. Ideally we would like CAP_DAC_SEARCH.
61778 * But we don't have that
61779 */
61780 - if (!capable(CAP_DAC_READ_SEARCH)) {
61781 + if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
61782 retval = -EPERM;
61783 goto out_err;
61784 }
61785 diff --git a/fs/file.c b/fs/file.c
61786 index ab3eb6a..8de2392 100644
61787 --- a/fs/file.c
61788 +++ b/fs/file.c
61789 @@ -16,6 +16,7 @@
61790 #include <linux/slab.h>
61791 #include <linux/vmalloc.h>
61792 #include <linux/file.h>
61793 +#include <linux/security.h>
61794 #include <linux/fdtable.h>
61795 #include <linux/bitops.h>
61796 #include <linux/interrupt.h>
61797 @@ -139,7 +140,7 @@ out:
61798 * Return <0 error code on error; 1 on successful completion.
61799 * The files->file_lock should be held on entry, and will be held on exit.
61800 */
61801 -static int expand_fdtable(struct files_struct *files, int nr)
61802 +static int expand_fdtable(struct files_struct *files, unsigned int nr)
61803 __releases(files->file_lock)
61804 __acquires(files->file_lock)
61805 {
61806 @@ -184,7 +185,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
61807 * expanded and execution may have blocked.
61808 * The files->file_lock should be held on entry, and will be held on exit.
61809 */
61810 -static int expand_files(struct files_struct *files, int nr)
61811 +static int expand_files(struct files_struct *files, unsigned int nr)
61812 {
61813 struct fdtable *fdt;
61814
61815 @@ -800,6 +801,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
61816 if (!file)
61817 return __close_fd(files, fd);
61818
61819 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
61820 if (fd >= rlimit(RLIMIT_NOFILE))
61821 return -EBADF;
61822
61823 @@ -826,6 +828,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
61824 if (unlikely(oldfd == newfd))
61825 return -EINVAL;
61826
61827 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
61828 if (newfd >= rlimit(RLIMIT_NOFILE))
61829 return -EBADF;
61830
61831 @@ -881,6 +884,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
61832 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
61833 {
61834 int err;
61835 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
61836 if (from >= rlimit(RLIMIT_NOFILE))
61837 return -EINVAL;
61838 err = alloc_fd(from, flags);
61839 diff --git a/fs/filesystems.c b/fs/filesystems.c
61840 index 5797d45..7d7d79a 100644
61841 --- a/fs/filesystems.c
61842 +++ b/fs/filesystems.c
61843 @@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
61844 int len = dot ? dot - name : strlen(name);
61845
61846 fs = __get_fs_type(name, len);
61847 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
61848 + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
61849 +#else
61850 if (!fs && (request_module("fs-%.*s", len, name) == 0))
61851 +#endif
61852 fs = __get_fs_type(name, len);
61853
61854 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
61855 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
61856 index 7dca743..543d620 100644
61857 --- a/fs/fs_struct.c
61858 +++ b/fs/fs_struct.c
61859 @@ -4,6 +4,7 @@
61860 #include <linux/path.h>
61861 #include <linux/slab.h>
61862 #include <linux/fs_struct.h>
61863 +#include <linux/grsecurity.h>
61864 #include "internal.h"
61865
61866 /*
61867 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
61868 write_seqcount_begin(&fs->seq);
61869 old_root = fs->root;
61870 fs->root = *path;
61871 + gr_set_chroot_entries(current, path);
61872 write_seqcount_end(&fs->seq);
61873 spin_unlock(&fs->lock);
61874 if (old_root.dentry)
61875 @@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
61876 int hits = 0;
61877 spin_lock(&fs->lock);
61878 write_seqcount_begin(&fs->seq);
61879 + /* this root replacement is only done by pivot_root,
61880 + leave grsec's chroot tagging alone for this task
61881 + so that a pivoted root isn't treated as a chroot
61882 + */
61883 hits += replace_path(&fs->root, old_root, new_root);
61884 hits += replace_path(&fs->pwd, old_root, new_root);
61885 write_seqcount_end(&fs->seq);
61886 @@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
61887 task_lock(tsk);
61888 spin_lock(&fs->lock);
61889 tsk->fs = NULL;
61890 - kill = !--fs->users;
61891 + gr_clear_chroot_entries(tsk);
61892 + kill = !atomic_dec_return(&fs->users);
61893 spin_unlock(&fs->lock);
61894 task_unlock(tsk);
61895 if (kill)
61896 @@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
61897 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
61898 /* We don't need to lock fs - think why ;-) */
61899 if (fs) {
61900 - fs->users = 1;
61901 + atomic_set(&fs->users, 1);
61902 fs->in_exec = 0;
61903 spin_lock_init(&fs->lock);
61904 seqcount_init(&fs->seq);
61905 @@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
61906 spin_lock(&old->lock);
61907 fs->root = old->root;
61908 path_get(&fs->root);
61909 + /* instead of calling gr_set_chroot_entries here,
61910 + we call it from every caller of this function
61911 + */
61912 fs->pwd = old->pwd;
61913 path_get(&fs->pwd);
61914 spin_unlock(&old->lock);
61915 @@ -139,8 +149,9 @@ int unshare_fs_struct(void)
61916
61917 task_lock(current);
61918 spin_lock(&fs->lock);
61919 - kill = !--fs->users;
61920 + kill = !atomic_dec_return(&fs->users);
61921 current->fs = new_fs;
61922 + gr_set_chroot_entries(current, &new_fs->root);
61923 spin_unlock(&fs->lock);
61924 task_unlock(current);
61925
61926 @@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
61927
61928 int current_umask(void)
61929 {
61930 - return current->fs->umask;
61931 + return current->fs->umask | gr_acl_umask();
61932 }
61933 EXPORT_SYMBOL(current_umask);
61934
61935 /* to be mentioned only in INIT_TASK */
61936 struct fs_struct init_fs = {
61937 - .users = 1,
61938 + .users = ATOMIC_INIT(1),
61939 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
61940 .seq = SEQCNT_ZERO(init_fs.seq),
61941 .umask = 0022,
61942 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
61943 index 89acec7..a575262 100644
61944 --- a/fs/fscache/cookie.c
61945 +++ b/fs/fscache/cookie.c
61946 @@ -19,7 +19,7 @@
61947
61948 struct kmem_cache *fscache_cookie_jar;
61949
61950 -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
61951 +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
61952
61953 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
61954 static int fscache_alloc_object(struct fscache_cache *cache,
61955 @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
61956 parent ? (char *) parent->def->name : "<no-parent>",
61957 def->name, netfs_data, enable);
61958
61959 - fscache_stat(&fscache_n_acquires);
61960 + fscache_stat_unchecked(&fscache_n_acquires);
61961
61962 /* if there's no parent cookie, then we don't create one here either */
61963 if (!parent) {
61964 - fscache_stat(&fscache_n_acquires_null);
61965 + fscache_stat_unchecked(&fscache_n_acquires_null);
61966 _leave(" [no parent]");
61967 return NULL;
61968 }
61969 @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
61970 /* allocate and initialise a cookie */
61971 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
61972 if (!cookie) {
61973 - fscache_stat(&fscache_n_acquires_oom);
61974 + fscache_stat_unchecked(&fscache_n_acquires_oom);
61975 _leave(" [ENOMEM]");
61976 return NULL;
61977 }
61978 @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
61979
61980 switch (cookie->def->type) {
61981 case FSCACHE_COOKIE_TYPE_INDEX:
61982 - fscache_stat(&fscache_n_cookie_index);
61983 + fscache_stat_unchecked(&fscache_n_cookie_index);
61984 break;
61985 case FSCACHE_COOKIE_TYPE_DATAFILE:
61986 - fscache_stat(&fscache_n_cookie_data);
61987 + fscache_stat_unchecked(&fscache_n_cookie_data);
61988 break;
61989 default:
61990 - fscache_stat(&fscache_n_cookie_special);
61991 + fscache_stat_unchecked(&fscache_n_cookie_special);
61992 break;
61993 }
61994
61995 @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
61996 } else {
61997 atomic_dec(&parent->n_children);
61998 __fscache_cookie_put(cookie);
61999 - fscache_stat(&fscache_n_acquires_nobufs);
62000 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
62001 _leave(" = NULL");
62002 return NULL;
62003 }
62004 @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62005 }
62006 }
62007
62008 - fscache_stat(&fscache_n_acquires_ok);
62009 + fscache_stat_unchecked(&fscache_n_acquires_ok);
62010 _leave(" = %p", cookie);
62011 return cookie;
62012 }
62013 @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
62014 cache = fscache_select_cache_for_object(cookie->parent);
62015 if (!cache) {
62016 up_read(&fscache_addremove_sem);
62017 - fscache_stat(&fscache_n_acquires_no_cache);
62018 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
62019 _leave(" = -ENOMEDIUM [no cache]");
62020 return -ENOMEDIUM;
62021 }
62022 @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
62023 object = cache->ops->alloc_object(cache, cookie);
62024 fscache_stat_d(&fscache_n_cop_alloc_object);
62025 if (IS_ERR(object)) {
62026 - fscache_stat(&fscache_n_object_no_alloc);
62027 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
62028 ret = PTR_ERR(object);
62029 goto error;
62030 }
62031
62032 - fscache_stat(&fscache_n_object_alloc);
62033 + fscache_stat_unchecked(&fscache_n_object_alloc);
62034
62035 - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
62036 + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
62037
62038 _debug("ALLOC OBJ%x: %s {%lx}",
62039 object->debug_id, cookie->def->name, object->events);
62040 @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
62041
62042 _enter("{%s}", cookie->def->name);
62043
62044 - fscache_stat(&fscache_n_invalidates);
62045 + fscache_stat_unchecked(&fscache_n_invalidates);
62046
62047 /* Only permit invalidation of data files. Invalidating an index will
62048 * require the caller to release all its attachments to the tree rooted
62049 @@ -476,10 +476,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
62050 {
62051 struct fscache_object *object;
62052
62053 - fscache_stat(&fscache_n_updates);
62054 + fscache_stat_unchecked(&fscache_n_updates);
62055
62056 if (!cookie) {
62057 - fscache_stat(&fscache_n_updates_null);
62058 + fscache_stat_unchecked(&fscache_n_updates_null);
62059 _leave(" [no cookie]");
62060 return;
62061 }
62062 @@ -580,12 +580,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
62063 */
62064 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
62065 {
62066 - fscache_stat(&fscache_n_relinquishes);
62067 + fscache_stat_unchecked(&fscache_n_relinquishes);
62068 if (retire)
62069 - fscache_stat(&fscache_n_relinquishes_retire);
62070 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
62071
62072 if (!cookie) {
62073 - fscache_stat(&fscache_n_relinquishes_null);
62074 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
62075 _leave(" [no cookie]");
62076 return;
62077 }
62078 @@ -686,7 +686,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
62079 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
62080 goto inconsistent;
62081
62082 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
62083 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62084
62085 __fscache_use_cookie(cookie);
62086 if (fscache_submit_op(object, op) < 0)
62087 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
62088 index 7872a62..d91b19f 100644
62089 --- a/fs/fscache/internal.h
62090 +++ b/fs/fscache/internal.h
62091 @@ -137,8 +137,8 @@ extern void fscache_operation_gc(struct work_struct *);
62092 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
62093 extern int fscache_wait_for_operation_activation(struct fscache_object *,
62094 struct fscache_operation *,
62095 - atomic_t *,
62096 - atomic_t *,
62097 + atomic_unchecked_t *,
62098 + atomic_unchecked_t *,
62099 void (*)(struct fscache_operation *));
62100 extern void fscache_invalidate_writes(struct fscache_cookie *);
62101
62102 @@ -157,101 +157,101 @@ extern void fscache_proc_cleanup(void);
62103 * stats.c
62104 */
62105 #ifdef CONFIG_FSCACHE_STATS
62106 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62107 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62108 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62109 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62110
62111 -extern atomic_t fscache_n_op_pend;
62112 -extern atomic_t fscache_n_op_run;
62113 -extern atomic_t fscache_n_op_enqueue;
62114 -extern atomic_t fscache_n_op_deferred_release;
62115 -extern atomic_t fscache_n_op_release;
62116 -extern atomic_t fscache_n_op_gc;
62117 -extern atomic_t fscache_n_op_cancelled;
62118 -extern atomic_t fscache_n_op_rejected;
62119 +extern atomic_unchecked_t fscache_n_op_pend;
62120 +extern atomic_unchecked_t fscache_n_op_run;
62121 +extern atomic_unchecked_t fscache_n_op_enqueue;
62122 +extern atomic_unchecked_t fscache_n_op_deferred_release;
62123 +extern atomic_unchecked_t fscache_n_op_release;
62124 +extern atomic_unchecked_t fscache_n_op_gc;
62125 +extern atomic_unchecked_t fscache_n_op_cancelled;
62126 +extern atomic_unchecked_t fscache_n_op_rejected;
62127
62128 -extern atomic_t fscache_n_attr_changed;
62129 -extern atomic_t fscache_n_attr_changed_ok;
62130 -extern atomic_t fscache_n_attr_changed_nobufs;
62131 -extern atomic_t fscache_n_attr_changed_nomem;
62132 -extern atomic_t fscache_n_attr_changed_calls;
62133 +extern atomic_unchecked_t fscache_n_attr_changed;
62134 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
62135 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
62136 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
62137 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
62138
62139 -extern atomic_t fscache_n_allocs;
62140 -extern atomic_t fscache_n_allocs_ok;
62141 -extern atomic_t fscache_n_allocs_wait;
62142 -extern atomic_t fscache_n_allocs_nobufs;
62143 -extern atomic_t fscache_n_allocs_intr;
62144 -extern atomic_t fscache_n_allocs_object_dead;
62145 -extern atomic_t fscache_n_alloc_ops;
62146 -extern atomic_t fscache_n_alloc_op_waits;
62147 +extern atomic_unchecked_t fscache_n_allocs;
62148 +extern atomic_unchecked_t fscache_n_allocs_ok;
62149 +extern atomic_unchecked_t fscache_n_allocs_wait;
62150 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
62151 +extern atomic_unchecked_t fscache_n_allocs_intr;
62152 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
62153 +extern atomic_unchecked_t fscache_n_alloc_ops;
62154 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
62155
62156 -extern atomic_t fscache_n_retrievals;
62157 -extern atomic_t fscache_n_retrievals_ok;
62158 -extern atomic_t fscache_n_retrievals_wait;
62159 -extern atomic_t fscache_n_retrievals_nodata;
62160 -extern atomic_t fscache_n_retrievals_nobufs;
62161 -extern atomic_t fscache_n_retrievals_intr;
62162 -extern atomic_t fscache_n_retrievals_nomem;
62163 -extern atomic_t fscache_n_retrievals_object_dead;
62164 -extern atomic_t fscache_n_retrieval_ops;
62165 -extern atomic_t fscache_n_retrieval_op_waits;
62166 +extern atomic_unchecked_t fscache_n_retrievals;
62167 +extern atomic_unchecked_t fscache_n_retrievals_ok;
62168 +extern atomic_unchecked_t fscache_n_retrievals_wait;
62169 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
62170 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
62171 +extern atomic_unchecked_t fscache_n_retrievals_intr;
62172 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
62173 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
62174 +extern atomic_unchecked_t fscache_n_retrieval_ops;
62175 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
62176
62177 -extern atomic_t fscache_n_stores;
62178 -extern atomic_t fscache_n_stores_ok;
62179 -extern atomic_t fscache_n_stores_again;
62180 -extern atomic_t fscache_n_stores_nobufs;
62181 -extern atomic_t fscache_n_stores_oom;
62182 -extern atomic_t fscache_n_store_ops;
62183 -extern atomic_t fscache_n_store_calls;
62184 -extern atomic_t fscache_n_store_pages;
62185 -extern atomic_t fscache_n_store_radix_deletes;
62186 -extern atomic_t fscache_n_store_pages_over_limit;
62187 +extern atomic_unchecked_t fscache_n_stores;
62188 +extern atomic_unchecked_t fscache_n_stores_ok;
62189 +extern atomic_unchecked_t fscache_n_stores_again;
62190 +extern atomic_unchecked_t fscache_n_stores_nobufs;
62191 +extern atomic_unchecked_t fscache_n_stores_oom;
62192 +extern atomic_unchecked_t fscache_n_store_ops;
62193 +extern atomic_unchecked_t fscache_n_store_calls;
62194 +extern atomic_unchecked_t fscache_n_store_pages;
62195 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
62196 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
62197
62198 -extern atomic_t fscache_n_store_vmscan_not_storing;
62199 -extern atomic_t fscache_n_store_vmscan_gone;
62200 -extern atomic_t fscache_n_store_vmscan_busy;
62201 -extern atomic_t fscache_n_store_vmscan_cancelled;
62202 -extern atomic_t fscache_n_store_vmscan_wait;
62203 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
62204 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
62205 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
62206 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
62207 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
62208
62209 -extern atomic_t fscache_n_marks;
62210 -extern atomic_t fscache_n_uncaches;
62211 +extern atomic_unchecked_t fscache_n_marks;
62212 +extern atomic_unchecked_t fscache_n_uncaches;
62213
62214 -extern atomic_t fscache_n_acquires;
62215 -extern atomic_t fscache_n_acquires_null;
62216 -extern atomic_t fscache_n_acquires_no_cache;
62217 -extern atomic_t fscache_n_acquires_ok;
62218 -extern atomic_t fscache_n_acquires_nobufs;
62219 -extern atomic_t fscache_n_acquires_oom;
62220 +extern atomic_unchecked_t fscache_n_acquires;
62221 +extern atomic_unchecked_t fscache_n_acquires_null;
62222 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
62223 +extern atomic_unchecked_t fscache_n_acquires_ok;
62224 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
62225 +extern atomic_unchecked_t fscache_n_acquires_oom;
62226
62227 -extern atomic_t fscache_n_invalidates;
62228 -extern atomic_t fscache_n_invalidates_run;
62229 +extern atomic_unchecked_t fscache_n_invalidates;
62230 +extern atomic_unchecked_t fscache_n_invalidates_run;
62231
62232 -extern atomic_t fscache_n_updates;
62233 -extern atomic_t fscache_n_updates_null;
62234 -extern atomic_t fscache_n_updates_run;
62235 +extern atomic_unchecked_t fscache_n_updates;
62236 +extern atomic_unchecked_t fscache_n_updates_null;
62237 +extern atomic_unchecked_t fscache_n_updates_run;
62238
62239 -extern atomic_t fscache_n_relinquishes;
62240 -extern atomic_t fscache_n_relinquishes_null;
62241 -extern atomic_t fscache_n_relinquishes_waitcrt;
62242 -extern atomic_t fscache_n_relinquishes_retire;
62243 +extern atomic_unchecked_t fscache_n_relinquishes;
62244 +extern atomic_unchecked_t fscache_n_relinquishes_null;
62245 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
62246 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
62247
62248 -extern atomic_t fscache_n_cookie_index;
62249 -extern atomic_t fscache_n_cookie_data;
62250 -extern atomic_t fscache_n_cookie_special;
62251 +extern atomic_unchecked_t fscache_n_cookie_index;
62252 +extern atomic_unchecked_t fscache_n_cookie_data;
62253 +extern atomic_unchecked_t fscache_n_cookie_special;
62254
62255 -extern atomic_t fscache_n_object_alloc;
62256 -extern atomic_t fscache_n_object_no_alloc;
62257 -extern atomic_t fscache_n_object_lookups;
62258 -extern atomic_t fscache_n_object_lookups_negative;
62259 -extern atomic_t fscache_n_object_lookups_positive;
62260 -extern atomic_t fscache_n_object_lookups_timed_out;
62261 -extern atomic_t fscache_n_object_created;
62262 -extern atomic_t fscache_n_object_avail;
62263 -extern atomic_t fscache_n_object_dead;
62264 +extern atomic_unchecked_t fscache_n_object_alloc;
62265 +extern atomic_unchecked_t fscache_n_object_no_alloc;
62266 +extern atomic_unchecked_t fscache_n_object_lookups;
62267 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
62268 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
62269 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
62270 +extern atomic_unchecked_t fscache_n_object_created;
62271 +extern atomic_unchecked_t fscache_n_object_avail;
62272 +extern atomic_unchecked_t fscache_n_object_dead;
62273
62274 -extern atomic_t fscache_n_checkaux_none;
62275 -extern atomic_t fscache_n_checkaux_okay;
62276 -extern atomic_t fscache_n_checkaux_update;
62277 -extern atomic_t fscache_n_checkaux_obsolete;
62278 +extern atomic_unchecked_t fscache_n_checkaux_none;
62279 +extern atomic_unchecked_t fscache_n_checkaux_okay;
62280 +extern atomic_unchecked_t fscache_n_checkaux_update;
62281 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
62282
62283 extern atomic_t fscache_n_cop_alloc_object;
62284 extern atomic_t fscache_n_cop_lookup_object;
62285 @@ -276,6 +276,11 @@ static inline void fscache_stat(atomic_t *stat)
62286 atomic_inc(stat);
62287 }
62288
62289 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
62290 +{
62291 + atomic_inc_unchecked(stat);
62292 +}
62293 +
62294 static inline void fscache_stat_d(atomic_t *stat)
62295 {
62296 atomic_dec(stat);
62297 @@ -288,6 +293,7 @@ extern const struct file_operations fscache_stats_fops;
62298
62299 #define __fscache_stat(stat) (NULL)
62300 #define fscache_stat(stat) do {} while (0)
62301 +#define fscache_stat_unchecked(stat) do {} while (0)
62302 #define fscache_stat_d(stat) do {} while (0)
62303 #endif
62304
62305 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
62306 index da032da..0076ce7 100644
62307 --- a/fs/fscache/object.c
62308 +++ b/fs/fscache/object.c
62309 @@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
62310 _debug("LOOKUP \"%s\" in \"%s\"",
62311 cookie->def->name, object->cache->tag->name);
62312
62313 - fscache_stat(&fscache_n_object_lookups);
62314 + fscache_stat_unchecked(&fscache_n_object_lookups);
62315 fscache_stat(&fscache_n_cop_lookup_object);
62316 ret = object->cache->ops->lookup_object(object);
62317 fscache_stat_d(&fscache_n_cop_lookup_object);
62318 @@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
62319 if (ret == -ETIMEDOUT) {
62320 /* probably stuck behind another object, so move this one to
62321 * the back of the queue */
62322 - fscache_stat(&fscache_n_object_lookups_timed_out);
62323 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
62324 _leave(" [timeout]");
62325 return NO_TRANSIT;
62326 }
62327 @@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
62328 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
62329
62330 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
62331 - fscache_stat(&fscache_n_object_lookups_negative);
62332 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
62333
62334 /* Allow write requests to begin stacking up and read requests to begin
62335 * returning ENODATA.
62336 @@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
62337 /* if we were still looking up, then we must have a positive lookup
62338 * result, in which case there may be data available */
62339 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
62340 - fscache_stat(&fscache_n_object_lookups_positive);
62341 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
62342
62343 /* We do (presumably) have data */
62344 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
62345 @@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
62346 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
62347 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
62348 } else {
62349 - fscache_stat(&fscache_n_object_created);
62350 + fscache_stat_unchecked(&fscache_n_object_created);
62351 }
62352
62353 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
62354 @@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
62355 fscache_stat_d(&fscache_n_cop_lookup_complete);
62356
62357 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
62358 - fscache_stat(&fscache_n_object_avail);
62359 + fscache_stat_unchecked(&fscache_n_object_avail);
62360
62361 _leave("");
62362 return transit_to(JUMPSTART_DEPS);
62363 @@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
62364
62365 /* this just shifts the object release to the work processor */
62366 fscache_put_object(object);
62367 - fscache_stat(&fscache_n_object_dead);
62368 + fscache_stat_unchecked(&fscache_n_object_dead);
62369
62370 _leave("");
62371 return transit_to(OBJECT_DEAD);
62372 @@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
62373 enum fscache_checkaux result;
62374
62375 if (!object->cookie->def->check_aux) {
62376 - fscache_stat(&fscache_n_checkaux_none);
62377 + fscache_stat_unchecked(&fscache_n_checkaux_none);
62378 return FSCACHE_CHECKAUX_OKAY;
62379 }
62380
62381 @@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
62382 switch (result) {
62383 /* entry okay as is */
62384 case FSCACHE_CHECKAUX_OKAY:
62385 - fscache_stat(&fscache_n_checkaux_okay);
62386 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
62387 break;
62388
62389 /* entry requires update */
62390 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
62391 - fscache_stat(&fscache_n_checkaux_update);
62392 + fscache_stat_unchecked(&fscache_n_checkaux_update);
62393 break;
62394
62395 /* entry requires deletion */
62396 case FSCACHE_CHECKAUX_OBSOLETE:
62397 - fscache_stat(&fscache_n_checkaux_obsolete);
62398 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
62399 break;
62400
62401 default:
62402 @@ -993,7 +993,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
62403 {
62404 const struct fscache_state *s;
62405
62406 - fscache_stat(&fscache_n_invalidates_run);
62407 + fscache_stat_unchecked(&fscache_n_invalidates_run);
62408 fscache_stat(&fscache_n_cop_invalidate_object);
62409 s = _fscache_invalidate_object(object, event);
62410 fscache_stat_d(&fscache_n_cop_invalidate_object);
62411 @@ -1008,7 +1008,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
62412 {
62413 _enter("{OBJ%x},%d", object->debug_id, event);
62414
62415 - fscache_stat(&fscache_n_updates_run);
62416 + fscache_stat_unchecked(&fscache_n_updates_run);
62417 fscache_stat(&fscache_n_cop_update_object);
62418 object->cache->ops->update_object(object);
62419 fscache_stat_d(&fscache_n_cop_update_object);
62420 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
62421 index e7b87a0..a85d47a 100644
62422 --- a/fs/fscache/operation.c
62423 +++ b/fs/fscache/operation.c
62424 @@ -17,7 +17,7 @@
62425 #include <linux/slab.h>
62426 #include "internal.h"
62427
62428 -atomic_t fscache_op_debug_id;
62429 +atomic_unchecked_t fscache_op_debug_id;
62430 EXPORT_SYMBOL(fscache_op_debug_id);
62431
62432 /**
62433 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
62434 ASSERTCMP(atomic_read(&op->usage), >, 0);
62435 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
62436
62437 - fscache_stat(&fscache_n_op_enqueue);
62438 + fscache_stat_unchecked(&fscache_n_op_enqueue);
62439 switch (op->flags & FSCACHE_OP_TYPE) {
62440 case FSCACHE_OP_ASYNC:
62441 _debug("queue async");
62442 @@ -72,7 +72,7 @@ static void fscache_run_op(struct fscache_object *object,
62443 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
62444 if (op->processor)
62445 fscache_enqueue_operation(op);
62446 - fscache_stat(&fscache_n_op_run);
62447 + fscache_stat_unchecked(&fscache_n_op_run);
62448 }
62449
62450 /*
62451 @@ -104,11 +104,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
62452 if (object->n_in_progress > 0) {
62453 atomic_inc(&op->usage);
62454 list_add_tail(&op->pend_link, &object->pending_ops);
62455 - fscache_stat(&fscache_n_op_pend);
62456 + fscache_stat_unchecked(&fscache_n_op_pend);
62457 } else if (!list_empty(&object->pending_ops)) {
62458 atomic_inc(&op->usage);
62459 list_add_tail(&op->pend_link, &object->pending_ops);
62460 - fscache_stat(&fscache_n_op_pend);
62461 + fscache_stat_unchecked(&fscache_n_op_pend);
62462 fscache_start_operations(object);
62463 } else {
62464 ASSERTCMP(object->n_in_progress, ==, 0);
62465 @@ -124,7 +124,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
62466 object->n_exclusive++; /* reads and writes must wait */
62467 atomic_inc(&op->usage);
62468 list_add_tail(&op->pend_link, &object->pending_ops);
62469 - fscache_stat(&fscache_n_op_pend);
62470 + fscache_stat_unchecked(&fscache_n_op_pend);
62471 ret = 0;
62472 } else {
62473 /* If we're in any other state, there must have been an I/O
62474 @@ -211,11 +211,11 @@ int fscache_submit_op(struct fscache_object *object,
62475 if (object->n_exclusive > 0) {
62476 atomic_inc(&op->usage);
62477 list_add_tail(&op->pend_link, &object->pending_ops);
62478 - fscache_stat(&fscache_n_op_pend);
62479 + fscache_stat_unchecked(&fscache_n_op_pend);
62480 } else if (!list_empty(&object->pending_ops)) {
62481 atomic_inc(&op->usage);
62482 list_add_tail(&op->pend_link, &object->pending_ops);
62483 - fscache_stat(&fscache_n_op_pend);
62484 + fscache_stat_unchecked(&fscache_n_op_pend);
62485 fscache_start_operations(object);
62486 } else {
62487 ASSERTCMP(object->n_exclusive, ==, 0);
62488 @@ -227,10 +227,10 @@ int fscache_submit_op(struct fscache_object *object,
62489 object->n_ops++;
62490 atomic_inc(&op->usage);
62491 list_add_tail(&op->pend_link, &object->pending_ops);
62492 - fscache_stat(&fscache_n_op_pend);
62493 + fscache_stat_unchecked(&fscache_n_op_pend);
62494 ret = 0;
62495 } else if (fscache_object_is_dying(object)) {
62496 - fscache_stat(&fscache_n_op_rejected);
62497 + fscache_stat_unchecked(&fscache_n_op_rejected);
62498 op->state = FSCACHE_OP_ST_CANCELLED;
62499 ret = -ENOBUFS;
62500 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
62501 @@ -309,7 +309,7 @@ int fscache_cancel_op(struct fscache_operation *op,
62502 ret = -EBUSY;
62503 if (op->state == FSCACHE_OP_ST_PENDING) {
62504 ASSERT(!list_empty(&op->pend_link));
62505 - fscache_stat(&fscache_n_op_cancelled);
62506 + fscache_stat_unchecked(&fscache_n_op_cancelled);
62507 list_del_init(&op->pend_link);
62508 if (do_cancel)
62509 do_cancel(op);
62510 @@ -341,7 +341,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
62511 while (!list_empty(&object->pending_ops)) {
62512 op = list_entry(object->pending_ops.next,
62513 struct fscache_operation, pend_link);
62514 - fscache_stat(&fscache_n_op_cancelled);
62515 + fscache_stat_unchecked(&fscache_n_op_cancelled);
62516 list_del_init(&op->pend_link);
62517
62518 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
62519 @@ -413,7 +413,7 @@ void fscache_put_operation(struct fscache_operation *op)
62520 op->state, ==, FSCACHE_OP_ST_CANCELLED);
62521 op->state = FSCACHE_OP_ST_DEAD;
62522
62523 - fscache_stat(&fscache_n_op_release);
62524 + fscache_stat_unchecked(&fscache_n_op_release);
62525
62526 if (op->release) {
62527 op->release(op);
62528 @@ -432,7 +432,7 @@ void fscache_put_operation(struct fscache_operation *op)
62529 * lock, and defer it otherwise */
62530 if (!spin_trylock(&object->lock)) {
62531 _debug("defer put");
62532 - fscache_stat(&fscache_n_op_deferred_release);
62533 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
62534
62535 cache = object->cache;
62536 spin_lock(&cache->op_gc_list_lock);
62537 @@ -485,7 +485,7 @@ void fscache_operation_gc(struct work_struct *work)
62538
62539 _debug("GC DEFERRED REL OBJ%x OP%x",
62540 object->debug_id, op->debug_id);
62541 - fscache_stat(&fscache_n_op_gc);
62542 + fscache_stat_unchecked(&fscache_n_op_gc);
62543
62544 ASSERTCMP(atomic_read(&op->usage), ==, 0);
62545 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
62546 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
62547 index de33b3f..8be4d29 100644
62548 --- a/fs/fscache/page.c
62549 +++ b/fs/fscache/page.c
62550 @@ -74,7 +74,7 @@ try_again:
62551 val = radix_tree_lookup(&cookie->stores, page->index);
62552 if (!val) {
62553 rcu_read_unlock();
62554 - fscache_stat(&fscache_n_store_vmscan_not_storing);
62555 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
62556 __fscache_uncache_page(cookie, page);
62557 return true;
62558 }
62559 @@ -104,11 +104,11 @@ try_again:
62560 spin_unlock(&cookie->stores_lock);
62561
62562 if (xpage) {
62563 - fscache_stat(&fscache_n_store_vmscan_cancelled);
62564 - fscache_stat(&fscache_n_store_radix_deletes);
62565 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
62566 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
62567 ASSERTCMP(xpage, ==, page);
62568 } else {
62569 - fscache_stat(&fscache_n_store_vmscan_gone);
62570 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
62571 }
62572
62573 wake_up_bit(&cookie->flags, 0);
62574 @@ -123,11 +123,11 @@ page_busy:
62575 * sleeping on memory allocation, so we may need to impose a timeout
62576 * too. */
62577 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
62578 - fscache_stat(&fscache_n_store_vmscan_busy);
62579 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
62580 return false;
62581 }
62582
62583 - fscache_stat(&fscache_n_store_vmscan_wait);
62584 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
62585 if (!release_page_wait_timeout(cookie, page))
62586 _debug("fscache writeout timeout page: %p{%lx}",
62587 page, page->index);
62588 @@ -156,7 +156,7 @@ static void fscache_end_page_write(struct fscache_object *object,
62589 FSCACHE_COOKIE_STORING_TAG);
62590 if (!radix_tree_tag_get(&cookie->stores, page->index,
62591 FSCACHE_COOKIE_PENDING_TAG)) {
62592 - fscache_stat(&fscache_n_store_radix_deletes);
62593 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
62594 xpage = radix_tree_delete(&cookie->stores, page->index);
62595 }
62596 spin_unlock(&cookie->stores_lock);
62597 @@ -177,7 +177,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
62598
62599 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
62600
62601 - fscache_stat(&fscache_n_attr_changed_calls);
62602 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
62603
62604 if (fscache_object_is_active(object)) {
62605 fscache_stat(&fscache_n_cop_attr_changed);
62606 @@ -204,11 +204,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
62607
62608 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
62609
62610 - fscache_stat(&fscache_n_attr_changed);
62611 + fscache_stat_unchecked(&fscache_n_attr_changed);
62612
62613 op = kzalloc(sizeof(*op), GFP_KERNEL);
62614 if (!op) {
62615 - fscache_stat(&fscache_n_attr_changed_nomem);
62616 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
62617 _leave(" = -ENOMEM");
62618 return -ENOMEM;
62619 }
62620 @@ -230,7 +230,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
62621 if (fscache_submit_exclusive_op(object, op) < 0)
62622 goto nobufs_dec;
62623 spin_unlock(&cookie->lock);
62624 - fscache_stat(&fscache_n_attr_changed_ok);
62625 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
62626 fscache_put_operation(op);
62627 _leave(" = 0");
62628 return 0;
62629 @@ -242,7 +242,7 @@ nobufs:
62630 kfree(op);
62631 if (wake_cookie)
62632 __fscache_wake_unused_cookie(cookie);
62633 - fscache_stat(&fscache_n_attr_changed_nobufs);
62634 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
62635 _leave(" = %d", -ENOBUFS);
62636 return -ENOBUFS;
62637 }
62638 @@ -281,7 +281,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
62639 /* allocate a retrieval operation and attempt to submit it */
62640 op = kzalloc(sizeof(*op), GFP_NOIO);
62641 if (!op) {
62642 - fscache_stat(&fscache_n_retrievals_nomem);
62643 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
62644 return NULL;
62645 }
62646
62647 @@ -311,12 +311,12 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
62648 return 0;
62649 }
62650
62651 - fscache_stat(&fscache_n_retrievals_wait);
62652 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
62653
62654 jif = jiffies;
62655 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
62656 TASK_INTERRUPTIBLE) != 0) {
62657 - fscache_stat(&fscache_n_retrievals_intr);
62658 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
62659 _leave(" = -ERESTARTSYS");
62660 return -ERESTARTSYS;
62661 }
62662 @@ -345,8 +345,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
62663 */
62664 int fscache_wait_for_operation_activation(struct fscache_object *object,
62665 struct fscache_operation *op,
62666 - atomic_t *stat_op_waits,
62667 - atomic_t *stat_object_dead,
62668 + atomic_unchecked_t *stat_op_waits,
62669 + atomic_unchecked_t *stat_object_dead,
62670 void (*do_cancel)(struct fscache_operation *))
62671 {
62672 int ret;
62673 @@ -356,7 +356,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
62674
62675 _debug(">>> WT");
62676 if (stat_op_waits)
62677 - fscache_stat(stat_op_waits);
62678 + fscache_stat_unchecked(stat_op_waits);
62679 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
62680 TASK_INTERRUPTIBLE) != 0) {
62681 ret = fscache_cancel_op(op, do_cancel);
62682 @@ -373,7 +373,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
62683 check_if_dead:
62684 if (op->state == FSCACHE_OP_ST_CANCELLED) {
62685 if (stat_object_dead)
62686 - fscache_stat(stat_object_dead);
62687 + fscache_stat_unchecked(stat_object_dead);
62688 _leave(" = -ENOBUFS [cancelled]");
62689 return -ENOBUFS;
62690 }
62691 @@ -381,7 +381,7 @@ check_if_dead:
62692 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
62693 fscache_cancel_op(op, do_cancel);
62694 if (stat_object_dead)
62695 - fscache_stat(stat_object_dead);
62696 + fscache_stat_unchecked(stat_object_dead);
62697 return -ENOBUFS;
62698 }
62699 return 0;
62700 @@ -409,7 +409,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
62701
62702 _enter("%p,%p,,,", cookie, page);
62703
62704 - fscache_stat(&fscache_n_retrievals);
62705 + fscache_stat_unchecked(&fscache_n_retrievals);
62706
62707 if (hlist_empty(&cookie->backing_objects))
62708 goto nobufs;
62709 @@ -451,7 +451,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
62710 goto nobufs_unlock_dec;
62711 spin_unlock(&cookie->lock);
62712
62713 - fscache_stat(&fscache_n_retrieval_ops);
62714 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
62715
62716 /* pin the netfs read context in case we need to do the actual netfs
62717 * read because we've encountered a cache read failure */
62718 @@ -482,15 +482,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
62719
62720 error:
62721 if (ret == -ENOMEM)
62722 - fscache_stat(&fscache_n_retrievals_nomem);
62723 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
62724 else if (ret == -ERESTARTSYS)
62725 - fscache_stat(&fscache_n_retrievals_intr);
62726 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
62727 else if (ret == -ENODATA)
62728 - fscache_stat(&fscache_n_retrievals_nodata);
62729 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
62730 else if (ret < 0)
62731 - fscache_stat(&fscache_n_retrievals_nobufs);
62732 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
62733 else
62734 - fscache_stat(&fscache_n_retrievals_ok);
62735 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
62736
62737 fscache_put_retrieval(op);
62738 _leave(" = %d", ret);
62739 @@ -505,7 +505,7 @@ nobufs_unlock:
62740 __fscache_wake_unused_cookie(cookie);
62741 kfree(op);
62742 nobufs:
62743 - fscache_stat(&fscache_n_retrievals_nobufs);
62744 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
62745 _leave(" = -ENOBUFS");
62746 return -ENOBUFS;
62747 }
62748 @@ -544,7 +544,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
62749
62750 _enter("%p,,%d,,,", cookie, *nr_pages);
62751
62752 - fscache_stat(&fscache_n_retrievals);
62753 + fscache_stat_unchecked(&fscache_n_retrievals);
62754
62755 if (hlist_empty(&cookie->backing_objects))
62756 goto nobufs;
62757 @@ -582,7 +582,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
62758 goto nobufs_unlock_dec;
62759 spin_unlock(&cookie->lock);
62760
62761 - fscache_stat(&fscache_n_retrieval_ops);
62762 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
62763
62764 /* pin the netfs read context in case we need to do the actual netfs
62765 * read because we've encountered a cache read failure */
62766 @@ -613,15 +613,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
62767
62768 error:
62769 if (ret == -ENOMEM)
62770 - fscache_stat(&fscache_n_retrievals_nomem);
62771 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
62772 else if (ret == -ERESTARTSYS)
62773 - fscache_stat(&fscache_n_retrievals_intr);
62774 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
62775 else if (ret == -ENODATA)
62776 - fscache_stat(&fscache_n_retrievals_nodata);
62777 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
62778 else if (ret < 0)
62779 - fscache_stat(&fscache_n_retrievals_nobufs);
62780 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
62781 else
62782 - fscache_stat(&fscache_n_retrievals_ok);
62783 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
62784
62785 fscache_put_retrieval(op);
62786 _leave(" = %d", ret);
62787 @@ -636,7 +636,7 @@ nobufs_unlock:
62788 if (wake_cookie)
62789 __fscache_wake_unused_cookie(cookie);
62790 nobufs:
62791 - fscache_stat(&fscache_n_retrievals_nobufs);
62792 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
62793 _leave(" = -ENOBUFS");
62794 return -ENOBUFS;
62795 }
62796 @@ -661,7 +661,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
62797
62798 _enter("%p,%p,,,", cookie, page);
62799
62800 - fscache_stat(&fscache_n_allocs);
62801 + fscache_stat_unchecked(&fscache_n_allocs);
62802
62803 if (hlist_empty(&cookie->backing_objects))
62804 goto nobufs;
62805 @@ -695,7 +695,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
62806 goto nobufs_unlock_dec;
62807 spin_unlock(&cookie->lock);
62808
62809 - fscache_stat(&fscache_n_alloc_ops);
62810 + fscache_stat_unchecked(&fscache_n_alloc_ops);
62811
62812 ret = fscache_wait_for_operation_activation(
62813 object, &op->op,
62814 @@ -712,11 +712,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
62815
62816 error:
62817 if (ret == -ERESTARTSYS)
62818 - fscache_stat(&fscache_n_allocs_intr);
62819 + fscache_stat_unchecked(&fscache_n_allocs_intr);
62820 else if (ret < 0)
62821 - fscache_stat(&fscache_n_allocs_nobufs);
62822 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
62823 else
62824 - fscache_stat(&fscache_n_allocs_ok);
62825 + fscache_stat_unchecked(&fscache_n_allocs_ok);
62826
62827 fscache_put_retrieval(op);
62828 _leave(" = %d", ret);
62829 @@ -730,7 +730,7 @@ nobufs_unlock:
62830 if (wake_cookie)
62831 __fscache_wake_unused_cookie(cookie);
62832 nobufs:
62833 - fscache_stat(&fscache_n_allocs_nobufs);
62834 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
62835 _leave(" = -ENOBUFS");
62836 return -ENOBUFS;
62837 }
62838 @@ -806,7 +806,7 @@ static void fscache_write_op(struct fscache_operation *_op)
62839
62840 spin_lock(&cookie->stores_lock);
62841
62842 - fscache_stat(&fscache_n_store_calls);
62843 + fscache_stat_unchecked(&fscache_n_store_calls);
62844
62845 /* find a page to store */
62846 page = NULL;
62847 @@ -817,7 +817,7 @@ static void fscache_write_op(struct fscache_operation *_op)
62848 page = results[0];
62849 _debug("gang %d [%lx]", n, page->index);
62850 if (page->index > op->store_limit) {
62851 - fscache_stat(&fscache_n_store_pages_over_limit);
62852 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
62853 goto superseded;
62854 }
62855
62856 @@ -829,7 +829,7 @@ static void fscache_write_op(struct fscache_operation *_op)
62857 spin_unlock(&cookie->stores_lock);
62858 spin_unlock(&object->lock);
62859
62860 - fscache_stat(&fscache_n_store_pages);
62861 + fscache_stat_unchecked(&fscache_n_store_pages);
62862 fscache_stat(&fscache_n_cop_write_page);
62863 ret = object->cache->ops->write_page(op, page);
62864 fscache_stat_d(&fscache_n_cop_write_page);
62865 @@ -933,7 +933,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
62866 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
62867 ASSERT(PageFsCache(page));
62868
62869 - fscache_stat(&fscache_n_stores);
62870 + fscache_stat_unchecked(&fscache_n_stores);
62871
62872 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
62873 _leave(" = -ENOBUFS [invalidating]");
62874 @@ -992,7 +992,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
62875 spin_unlock(&cookie->stores_lock);
62876 spin_unlock(&object->lock);
62877
62878 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
62879 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62880 op->store_limit = object->store_limit;
62881
62882 __fscache_use_cookie(cookie);
62883 @@ -1001,8 +1001,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
62884
62885 spin_unlock(&cookie->lock);
62886 radix_tree_preload_end();
62887 - fscache_stat(&fscache_n_store_ops);
62888 - fscache_stat(&fscache_n_stores_ok);
62889 + fscache_stat_unchecked(&fscache_n_store_ops);
62890 + fscache_stat_unchecked(&fscache_n_stores_ok);
62891
62892 /* the work queue now carries its own ref on the object */
62893 fscache_put_operation(&op->op);
62894 @@ -1010,14 +1010,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
62895 return 0;
62896
62897 already_queued:
62898 - fscache_stat(&fscache_n_stores_again);
62899 + fscache_stat_unchecked(&fscache_n_stores_again);
62900 already_pending:
62901 spin_unlock(&cookie->stores_lock);
62902 spin_unlock(&object->lock);
62903 spin_unlock(&cookie->lock);
62904 radix_tree_preload_end();
62905 kfree(op);
62906 - fscache_stat(&fscache_n_stores_ok);
62907 + fscache_stat_unchecked(&fscache_n_stores_ok);
62908 _leave(" = 0");
62909 return 0;
62910
62911 @@ -1039,14 +1039,14 @@ nobufs:
62912 kfree(op);
62913 if (wake_cookie)
62914 __fscache_wake_unused_cookie(cookie);
62915 - fscache_stat(&fscache_n_stores_nobufs);
62916 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
62917 _leave(" = -ENOBUFS");
62918 return -ENOBUFS;
62919
62920 nomem_free:
62921 kfree(op);
62922 nomem:
62923 - fscache_stat(&fscache_n_stores_oom);
62924 + fscache_stat_unchecked(&fscache_n_stores_oom);
62925 _leave(" = -ENOMEM");
62926 return -ENOMEM;
62927 }
62928 @@ -1064,7 +1064,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
62929 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
62930 ASSERTCMP(page, !=, NULL);
62931
62932 - fscache_stat(&fscache_n_uncaches);
62933 + fscache_stat_unchecked(&fscache_n_uncaches);
62934
62935 /* cache withdrawal may beat us to it */
62936 if (!PageFsCache(page))
62937 @@ -1115,7 +1115,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
62938 struct fscache_cookie *cookie = op->op.object->cookie;
62939
62940 #ifdef CONFIG_FSCACHE_STATS
62941 - atomic_inc(&fscache_n_marks);
62942 + atomic_inc_unchecked(&fscache_n_marks);
62943 #endif
62944
62945 _debug("- mark %p{%lx}", page, page->index);
62946 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
62947 index 40d13c7..ddf52b9 100644
62948 --- a/fs/fscache/stats.c
62949 +++ b/fs/fscache/stats.c
62950 @@ -18,99 +18,99 @@
62951 /*
62952 * operation counters
62953 */
62954 -atomic_t fscache_n_op_pend;
62955 -atomic_t fscache_n_op_run;
62956 -atomic_t fscache_n_op_enqueue;
62957 -atomic_t fscache_n_op_requeue;
62958 -atomic_t fscache_n_op_deferred_release;
62959 -atomic_t fscache_n_op_release;
62960 -atomic_t fscache_n_op_gc;
62961 -atomic_t fscache_n_op_cancelled;
62962 -atomic_t fscache_n_op_rejected;
62963 +atomic_unchecked_t fscache_n_op_pend;
62964 +atomic_unchecked_t fscache_n_op_run;
62965 +atomic_unchecked_t fscache_n_op_enqueue;
62966 +atomic_unchecked_t fscache_n_op_requeue;
62967 +atomic_unchecked_t fscache_n_op_deferred_release;
62968 +atomic_unchecked_t fscache_n_op_release;
62969 +atomic_unchecked_t fscache_n_op_gc;
62970 +atomic_unchecked_t fscache_n_op_cancelled;
62971 +atomic_unchecked_t fscache_n_op_rejected;
62972
62973 -atomic_t fscache_n_attr_changed;
62974 -atomic_t fscache_n_attr_changed_ok;
62975 -atomic_t fscache_n_attr_changed_nobufs;
62976 -atomic_t fscache_n_attr_changed_nomem;
62977 -atomic_t fscache_n_attr_changed_calls;
62978 +atomic_unchecked_t fscache_n_attr_changed;
62979 +atomic_unchecked_t fscache_n_attr_changed_ok;
62980 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
62981 +atomic_unchecked_t fscache_n_attr_changed_nomem;
62982 +atomic_unchecked_t fscache_n_attr_changed_calls;
62983
62984 -atomic_t fscache_n_allocs;
62985 -atomic_t fscache_n_allocs_ok;
62986 -atomic_t fscache_n_allocs_wait;
62987 -atomic_t fscache_n_allocs_nobufs;
62988 -atomic_t fscache_n_allocs_intr;
62989 -atomic_t fscache_n_allocs_object_dead;
62990 -atomic_t fscache_n_alloc_ops;
62991 -atomic_t fscache_n_alloc_op_waits;
62992 +atomic_unchecked_t fscache_n_allocs;
62993 +atomic_unchecked_t fscache_n_allocs_ok;
62994 +atomic_unchecked_t fscache_n_allocs_wait;
62995 +atomic_unchecked_t fscache_n_allocs_nobufs;
62996 +atomic_unchecked_t fscache_n_allocs_intr;
62997 +atomic_unchecked_t fscache_n_allocs_object_dead;
62998 +atomic_unchecked_t fscache_n_alloc_ops;
62999 +atomic_unchecked_t fscache_n_alloc_op_waits;
63000
63001 -atomic_t fscache_n_retrievals;
63002 -atomic_t fscache_n_retrievals_ok;
63003 -atomic_t fscache_n_retrievals_wait;
63004 -atomic_t fscache_n_retrievals_nodata;
63005 -atomic_t fscache_n_retrievals_nobufs;
63006 -atomic_t fscache_n_retrievals_intr;
63007 -atomic_t fscache_n_retrievals_nomem;
63008 -atomic_t fscache_n_retrievals_object_dead;
63009 -atomic_t fscache_n_retrieval_ops;
63010 -atomic_t fscache_n_retrieval_op_waits;
63011 +atomic_unchecked_t fscache_n_retrievals;
63012 +atomic_unchecked_t fscache_n_retrievals_ok;
63013 +atomic_unchecked_t fscache_n_retrievals_wait;
63014 +atomic_unchecked_t fscache_n_retrievals_nodata;
63015 +atomic_unchecked_t fscache_n_retrievals_nobufs;
63016 +atomic_unchecked_t fscache_n_retrievals_intr;
63017 +atomic_unchecked_t fscache_n_retrievals_nomem;
63018 +atomic_unchecked_t fscache_n_retrievals_object_dead;
63019 +atomic_unchecked_t fscache_n_retrieval_ops;
63020 +atomic_unchecked_t fscache_n_retrieval_op_waits;
63021
63022 -atomic_t fscache_n_stores;
63023 -atomic_t fscache_n_stores_ok;
63024 -atomic_t fscache_n_stores_again;
63025 -atomic_t fscache_n_stores_nobufs;
63026 -atomic_t fscache_n_stores_oom;
63027 -atomic_t fscache_n_store_ops;
63028 -atomic_t fscache_n_store_calls;
63029 -atomic_t fscache_n_store_pages;
63030 -atomic_t fscache_n_store_radix_deletes;
63031 -atomic_t fscache_n_store_pages_over_limit;
63032 +atomic_unchecked_t fscache_n_stores;
63033 +atomic_unchecked_t fscache_n_stores_ok;
63034 +atomic_unchecked_t fscache_n_stores_again;
63035 +atomic_unchecked_t fscache_n_stores_nobufs;
63036 +atomic_unchecked_t fscache_n_stores_oom;
63037 +atomic_unchecked_t fscache_n_store_ops;
63038 +atomic_unchecked_t fscache_n_store_calls;
63039 +atomic_unchecked_t fscache_n_store_pages;
63040 +atomic_unchecked_t fscache_n_store_radix_deletes;
63041 +atomic_unchecked_t fscache_n_store_pages_over_limit;
63042
63043 -atomic_t fscache_n_store_vmscan_not_storing;
63044 -atomic_t fscache_n_store_vmscan_gone;
63045 -atomic_t fscache_n_store_vmscan_busy;
63046 -atomic_t fscache_n_store_vmscan_cancelled;
63047 -atomic_t fscache_n_store_vmscan_wait;
63048 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
63049 +atomic_unchecked_t fscache_n_store_vmscan_gone;
63050 +atomic_unchecked_t fscache_n_store_vmscan_busy;
63051 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
63052 +atomic_unchecked_t fscache_n_store_vmscan_wait;
63053
63054 -atomic_t fscache_n_marks;
63055 -atomic_t fscache_n_uncaches;
63056 +atomic_unchecked_t fscache_n_marks;
63057 +atomic_unchecked_t fscache_n_uncaches;
63058
63059 -atomic_t fscache_n_acquires;
63060 -atomic_t fscache_n_acquires_null;
63061 -atomic_t fscache_n_acquires_no_cache;
63062 -atomic_t fscache_n_acquires_ok;
63063 -atomic_t fscache_n_acquires_nobufs;
63064 -atomic_t fscache_n_acquires_oom;
63065 +atomic_unchecked_t fscache_n_acquires;
63066 +atomic_unchecked_t fscache_n_acquires_null;
63067 +atomic_unchecked_t fscache_n_acquires_no_cache;
63068 +atomic_unchecked_t fscache_n_acquires_ok;
63069 +atomic_unchecked_t fscache_n_acquires_nobufs;
63070 +atomic_unchecked_t fscache_n_acquires_oom;
63071
63072 -atomic_t fscache_n_invalidates;
63073 -atomic_t fscache_n_invalidates_run;
63074 +atomic_unchecked_t fscache_n_invalidates;
63075 +atomic_unchecked_t fscache_n_invalidates_run;
63076
63077 -atomic_t fscache_n_updates;
63078 -atomic_t fscache_n_updates_null;
63079 -atomic_t fscache_n_updates_run;
63080 +atomic_unchecked_t fscache_n_updates;
63081 +atomic_unchecked_t fscache_n_updates_null;
63082 +atomic_unchecked_t fscache_n_updates_run;
63083
63084 -atomic_t fscache_n_relinquishes;
63085 -atomic_t fscache_n_relinquishes_null;
63086 -atomic_t fscache_n_relinquishes_waitcrt;
63087 -atomic_t fscache_n_relinquishes_retire;
63088 +atomic_unchecked_t fscache_n_relinquishes;
63089 +atomic_unchecked_t fscache_n_relinquishes_null;
63090 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
63091 +atomic_unchecked_t fscache_n_relinquishes_retire;
63092
63093 -atomic_t fscache_n_cookie_index;
63094 -atomic_t fscache_n_cookie_data;
63095 -atomic_t fscache_n_cookie_special;
63096 +atomic_unchecked_t fscache_n_cookie_index;
63097 +atomic_unchecked_t fscache_n_cookie_data;
63098 +atomic_unchecked_t fscache_n_cookie_special;
63099
63100 -atomic_t fscache_n_object_alloc;
63101 -atomic_t fscache_n_object_no_alloc;
63102 -atomic_t fscache_n_object_lookups;
63103 -atomic_t fscache_n_object_lookups_negative;
63104 -atomic_t fscache_n_object_lookups_positive;
63105 -atomic_t fscache_n_object_lookups_timed_out;
63106 -atomic_t fscache_n_object_created;
63107 -atomic_t fscache_n_object_avail;
63108 -atomic_t fscache_n_object_dead;
63109 +atomic_unchecked_t fscache_n_object_alloc;
63110 +atomic_unchecked_t fscache_n_object_no_alloc;
63111 +atomic_unchecked_t fscache_n_object_lookups;
63112 +atomic_unchecked_t fscache_n_object_lookups_negative;
63113 +atomic_unchecked_t fscache_n_object_lookups_positive;
63114 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
63115 +atomic_unchecked_t fscache_n_object_created;
63116 +atomic_unchecked_t fscache_n_object_avail;
63117 +atomic_unchecked_t fscache_n_object_dead;
63118
63119 -atomic_t fscache_n_checkaux_none;
63120 -atomic_t fscache_n_checkaux_okay;
63121 -atomic_t fscache_n_checkaux_update;
63122 -atomic_t fscache_n_checkaux_obsolete;
63123 +atomic_unchecked_t fscache_n_checkaux_none;
63124 +atomic_unchecked_t fscache_n_checkaux_okay;
63125 +atomic_unchecked_t fscache_n_checkaux_update;
63126 +atomic_unchecked_t fscache_n_checkaux_obsolete;
63127
63128 atomic_t fscache_n_cop_alloc_object;
63129 atomic_t fscache_n_cop_lookup_object;
63130 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
63131 seq_puts(m, "FS-Cache statistics\n");
63132
63133 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
63134 - atomic_read(&fscache_n_cookie_index),
63135 - atomic_read(&fscache_n_cookie_data),
63136 - atomic_read(&fscache_n_cookie_special));
63137 + atomic_read_unchecked(&fscache_n_cookie_index),
63138 + atomic_read_unchecked(&fscache_n_cookie_data),
63139 + atomic_read_unchecked(&fscache_n_cookie_special));
63140
63141 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
63142 - atomic_read(&fscache_n_object_alloc),
63143 - atomic_read(&fscache_n_object_no_alloc),
63144 - atomic_read(&fscache_n_object_avail),
63145 - atomic_read(&fscache_n_object_dead));
63146 + atomic_read_unchecked(&fscache_n_object_alloc),
63147 + atomic_read_unchecked(&fscache_n_object_no_alloc),
63148 + atomic_read_unchecked(&fscache_n_object_avail),
63149 + atomic_read_unchecked(&fscache_n_object_dead));
63150 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
63151 - atomic_read(&fscache_n_checkaux_none),
63152 - atomic_read(&fscache_n_checkaux_okay),
63153 - atomic_read(&fscache_n_checkaux_update),
63154 - atomic_read(&fscache_n_checkaux_obsolete));
63155 + atomic_read_unchecked(&fscache_n_checkaux_none),
63156 + atomic_read_unchecked(&fscache_n_checkaux_okay),
63157 + atomic_read_unchecked(&fscache_n_checkaux_update),
63158 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
63159
63160 seq_printf(m, "Pages : mrk=%u unc=%u\n",
63161 - atomic_read(&fscache_n_marks),
63162 - atomic_read(&fscache_n_uncaches));
63163 + atomic_read_unchecked(&fscache_n_marks),
63164 + atomic_read_unchecked(&fscache_n_uncaches));
63165
63166 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
63167 " oom=%u\n",
63168 - atomic_read(&fscache_n_acquires),
63169 - atomic_read(&fscache_n_acquires_null),
63170 - atomic_read(&fscache_n_acquires_no_cache),
63171 - atomic_read(&fscache_n_acquires_ok),
63172 - atomic_read(&fscache_n_acquires_nobufs),
63173 - atomic_read(&fscache_n_acquires_oom));
63174 + atomic_read_unchecked(&fscache_n_acquires),
63175 + atomic_read_unchecked(&fscache_n_acquires_null),
63176 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
63177 + atomic_read_unchecked(&fscache_n_acquires_ok),
63178 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
63179 + atomic_read_unchecked(&fscache_n_acquires_oom));
63180
63181 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
63182 - atomic_read(&fscache_n_object_lookups),
63183 - atomic_read(&fscache_n_object_lookups_negative),
63184 - atomic_read(&fscache_n_object_lookups_positive),
63185 - atomic_read(&fscache_n_object_created),
63186 - atomic_read(&fscache_n_object_lookups_timed_out));
63187 + atomic_read_unchecked(&fscache_n_object_lookups),
63188 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
63189 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
63190 + atomic_read_unchecked(&fscache_n_object_created),
63191 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
63192
63193 seq_printf(m, "Invals : n=%u run=%u\n",
63194 - atomic_read(&fscache_n_invalidates),
63195 - atomic_read(&fscache_n_invalidates_run));
63196 + atomic_read_unchecked(&fscache_n_invalidates),
63197 + atomic_read_unchecked(&fscache_n_invalidates_run));
63198
63199 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
63200 - atomic_read(&fscache_n_updates),
63201 - atomic_read(&fscache_n_updates_null),
63202 - atomic_read(&fscache_n_updates_run));
63203 + atomic_read_unchecked(&fscache_n_updates),
63204 + atomic_read_unchecked(&fscache_n_updates_null),
63205 + atomic_read_unchecked(&fscache_n_updates_run));
63206
63207 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
63208 - atomic_read(&fscache_n_relinquishes),
63209 - atomic_read(&fscache_n_relinquishes_null),
63210 - atomic_read(&fscache_n_relinquishes_waitcrt),
63211 - atomic_read(&fscache_n_relinquishes_retire));
63212 + atomic_read_unchecked(&fscache_n_relinquishes),
63213 + atomic_read_unchecked(&fscache_n_relinquishes_null),
63214 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
63215 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
63216
63217 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
63218 - atomic_read(&fscache_n_attr_changed),
63219 - atomic_read(&fscache_n_attr_changed_ok),
63220 - atomic_read(&fscache_n_attr_changed_nobufs),
63221 - atomic_read(&fscache_n_attr_changed_nomem),
63222 - atomic_read(&fscache_n_attr_changed_calls));
63223 + atomic_read_unchecked(&fscache_n_attr_changed),
63224 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
63225 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
63226 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
63227 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
63228
63229 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
63230 - atomic_read(&fscache_n_allocs),
63231 - atomic_read(&fscache_n_allocs_ok),
63232 - atomic_read(&fscache_n_allocs_wait),
63233 - atomic_read(&fscache_n_allocs_nobufs),
63234 - atomic_read(&fscache_n_allocs_intr));
63235 + atomic_read_unchecked(&fscache_n_allocs),
63236 + atomic_read_unchecked(&fscache_n_allocs_ok),
63237 + atomic_read_unchecked(&fscache_n_allocs_wait),
63238 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
63239 + atomic_read_unchecked(&fscache_n_allocs_intr));
63240 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
63241 - atomic_read(&fscache_n_alloc_ops),
63242 - atomic_read(&fscache_n_alloc_op_waits),
63243 - atomic_read(&fscache_n_allocs_object_dead));
63244 + atomic_read_unchecked(&fscache_n_alloc_ops),
63245 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
63246 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
63247
63248 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
63249 " int=%u oom=%u\n",
63250 - atomic_read(&fscache_n_retrievals),
63251 - atomic_read(&fscache_n_retrievals_ok),
63252 - atomic_read(&fscache_n_retrievals_wait),
63253 - atomic_read(&fscache_n_retrievals_nodata),
63254 - atomic_read(&fscache_n_retrievals_nobufs),
63255 - atomic_read(&fscache_n_retrievals_intr),
63256 - atomic_read(&fscache_n_retrievals_nomem));
63257 + atomic_read_unchecked(&fscache_n_retrievals),
63258 + atomic_read_unchecked(&fscache_n_retrievals_ok),
63259 + atomic_read_unchecked(&fscache_n_retrievals_wait),
63260 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
63261 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
63262 + atomic_read_unchecked(&fscache_n_retrievals_intr),
63263 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
63264 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
63265 - atomic_read(&fscache_n_retrieval_ops),
63266 - atomic_read(&fscache_n_retrieval_op_waits),
63267 - atomic_read(&fscache_n_retrievals_object_dead));
63268 + atomic_read_unchecked(&fscache_n_retrieval_ops),
63269 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
63270 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
63271
63272 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
63273 - atomic_read(&fscache_n_stores),
63274 - atomic_read(&fscache_n_stores_ok),
63275 - atomic_read(&fscache_n_stores_again),
63276 - atomic_read(&fscache_n_stores_nobufs),
63277 - atomic_read(&fscache_n_stores_oom));
63278 + atomic_read_unchecked(&fscache_n_stores),
63279 + atomic_read_unchecked(&fscache_n_stores_ok),
63280 + atomic_read_unchecked(&fscache_n_stores_again),
63281 + atomic_read_unchecked(&fscache_n_stores_nobufs),
63282 + atomic_read_unchecked(&fscache_n_stores_oom));
63283 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
63284 - atomic_read(&fscache_n_store_ops),
63285 - atomic_read(&fscache_n_store_calls),
63286 - atomic_read(&fscache_n_store_pages),
63287 - atomic_read(&fscache_n_store_radix_deletes),
63288 - atomic_read(&fscache_n_store_pages_over_limit));
63289 + atomic_read_unchecked(&fscache_n_store_ops),
63290 + atomic_read_unchecked(&fscache_n_store_calls),
63291 + atomic_read_unchecked(&fscache_n_store_pages),
63292 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
63293 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
63294
63295 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
63296 - atomic_read(&fscache_n_store_vmscan_not_storing),
63297 - atomic_read(&fscache_n_store_vmscan_gone),
63298 - atomic_read(&fscache_n_store_vmscan_busy),
63299 - atomic_read(&fscache_n_store_vmscan_cancelled),
63300 - atomic_read(&fscache_n_store_vmscan_wait));
63301 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
63302 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
63303 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
63304 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
63305 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
63306
63307 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
63308 - atomic_read(&fscache_n_op_pend),
63309 - atomic_read(&fscache_n_op_run),
63310 - atomic_read(&fscache_n_op_enqueue),
63311 - atomic_read(&fscache_n_op_cancelled),
63312 - atomic_read(&fscache_n_op_rejected));
63313 + atomic_read_unchecked(&fscache_n_op_pend),
63314 + atomic_read_unchecked(&fscache_n_op_run),
63315 + atomic_read_unchecked(&fscache_n_op_enqueue),
63316 + atomic_read_unchecked(&fscache_n_op_cancelled),
63317 + atomic_read_unchecked(&fscache_n_op_rejected));
63318 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
63319 - atomic_read(&fscache_n_op_deferred_release),
63320 - atomic_read(&fscache_n_op_release),
63321 - atomic_read(&fscache_n_op_gc));
63322 + atomic_read_unchecked(&fscache_n_op_deferred_release),
63323 + atomic_read_unchecked(&fscache_n_op_release),
63324 + atomic_read_unchecked(&fscache_n_op_gc));
63325
63326 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
63327 atomic_read(&fscache_n_cop_alloc_object),
63328 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
63329 index 966ace8..030a03a 100644
63330 --- a/fs/fuse/cuse.c
63331 +++ b/fs/fuse/cuse.c
63332 @@ -611,10 +611,12 @@ static int __init cuse_init(void)
63333 INIT_LIST_HEAD(&cuse_conntbl[i]);
63334
63335 /* inherit and extend fuse_dev_operations */
63336 - cuse_channel_fops = fuse_dev_operations;
63337 - cuse_channel_fops.owner = THIS_MODULE;
63338 - cuse_channel_fops.open = cuse_channel_open;
63339 - cuse_channel_fops.release = cuse_channel_release;
63340 + pax_open_kernel();
63341 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
63342 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
63343 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
63344 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
63345 + pax_close_kernel();
63346
63347 cuse_class = class_create(THIS_MODULE, "cuse");
63348 if (IS_ERR(cuse_class))
63349 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
63350 index ca88731..8e9c55d 100644
63351 --- a/fs/fuse/dev.c
63352 +++ b/fs/fuse/dev.c
63353 @@ -1318,7 +1318,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
63354 ret = 0;
63355 pipe_lock(pipe);
63356
63357 - if (!pipe->readers) {
63358 + if (!atomic_read(&pipe->readers)) {
63359 send_sig(SIGPIPE, current, 0);
63360 if (!ret)
63361 ret = -EPIPE;
63362 @@ -1347,7 +1347,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
63363 page_nr++;
63364 ret += buf->len;
63365
63366 - if (pipe->files)
63367 + if (atomic_read(&pipe->files))
63368 do_wakeup = 1;
63369 }
63370
63371 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
63372 index dbab798..fefa22b 100644
63373 --- a/fs/fuse/dir.c
63374 +++ b/fs/fuse/dir.c
63375 @@ -1474,7 +1474,7 @@ static char *read_link(struct dentry *dentry)
63376 return link;
63377 }
63378
63379 -static void free_link(char *link)
63380 +static void free_link(const char *link)
63381 {
63382 if (!IS_ERR(link))
63383 free_page((unsigned long) link);
63384 diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
63385 index fd62cae..3494dfa 100644
63386 --- a/fs/hostfs/hostfs_kern.c
63387 +++ b/fs/hostfs/hostfs_kern.c
63388 @@ -908,7 +908,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
63389
63390 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
63391 {
63392 - char *s = nd_get_link(nd);
63393 + const char *s = nd_get_link(nd);
63394 if (!IS_ERR(s))
63395 __putname(s);
63396 }
63397 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
63398 index 1e2872b..7aea000 100644
63399 --- a/fs/hugetlbfs/inode.c
63400 +++ b/fs/hugetlbfs/inode.c
63401 @@ -154,6 +154,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
63402 struct mm_struct *mm = current->mm;
63403 struct vm_area_struct *vma;
63404 struct hstate *h = hstate_file(file);
63405 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
63406 struct vm_unmapped_area_info info;
63407
63408 if (len & ~huge_page_mask(h))
63409 @@ -167,17 +168,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
63410 return addr;
63411 }
63412
63413 +#ifdef CONFIG_PAX_RANDMMAP
63414 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
63415 +#endif
63416 +
63417 if (addr) {
63418 addr = ALIGN(addr, huge_page_size(h));
63419 vma = find_vma(mm, addr);
63420 - if (TASK_SIZE - len >= addr &&
63421 - (!vma || addr + len <= vma->vm_start))
63422 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
63423 return addr;
63424 }
63425
63426 info.flags = 0;
63427 info.length = len;
63428 info.low_limit = TASK_UNMAPPED_BASE;
63429 +
63430 +#ifdef CONFIG_PAX_RANDMMAP
63431 + if (mm->pax_flags & MF_PAX_RANDMMAP)
63432 + info.low_limit += mm->delta_mmap;
63433 +#endif
63434 +
63435 info.high_limit = TASK_SIZE;
63436 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
63437 info.align_offset = 0;
63438 @@ -919,7 +929,7 @@ static struct file_system_type hugetlbfs_fs_type = {
63439 };
63440 MODULE_ALIAS_FS("hugetlbfs");
63441
63442 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
63443 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
63444
63445 static int can_do_hugetlb_shm(void)
63446 {
63447 diff --git a/fs/inode.c b/fs/inode.c
63448 index 26753ba..d19eb34 100644
63449 --- a/fs/inode.c
63450 +++ b/fs/inode.c
63451 @@ -840,16 +840,20 @@ unsigned int get_next_ino(void)
63452 unsigned int *p = &get_cpu_var(last_ino);
63453 unsigned int res = *p;
63454
63455 +start:
63456 +
63457 #ifdef CONFIG_SMP
63458 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
63459 - static atomic_t shared_last_ino;
63460 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
63461 + static atomic_unchecked_t shared_last_ino;
63462 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
63463
63464 res = next - LAST_INO_BATCH;
63465 }
63466 #endif
63467
63468 - *p = ++res;
63469 + if (unlikely(!++res))
63470 + goto start; /* never zero */
63471 + *p = res;
63472 put_cpu_var(last_ino);
63473 return res;
63474 }
63475 diff --git a/fs/isofs/rock.c b/fs/isofs/rock.c
63476 index f488bba..bb63254 100644
63477 --- a/fs/isofs/rock.c
63478 +++ b/fs/isofs/rock.c
63479 @@ -30,6 +30,7 @@ struct rock_state {
63480 int cont_size;
63481 int cont_extent;
63482 int cont_offset;
63483 + int cont_loops;
63484 struct inode *inode;
63485 };
63486
63487 @@ -73,6 +74,9 @@ static void init_rock_state(struct rock_state *rs, struct inode *inode)
63488 rs->inode = inode;
63489 }
63490
63491 +/* Maximum number of Rock Ridge continuation entries */
63492 +#define RR_MAX_CE_ENTRIES 32
63493 +
63494 /*
63495 * Returns 0 if the caller should continue scanning, 1 if the scan must end
63496 * and -ve on error.
63497 @@ -105,6 +109,8 @@ static int rock_continue(struct rock_state *rs)
63498 goto out;
63499 }
63500 ret = -EIO;
63501 + if (++rs->cont_loops >= RR_MAX_CE_ENTRIES)
63502 + goto out;
63503 bh = sb_bread(rs->inode->i_sb, rs->cont_extent);
63504 if (bh) {
63505 memcpy(rs->buffer, bh->b_data + rs->cont_offset,
63506 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
63507 index 4a6cf28..d3a29d3 100644
63508 --- a/fs/jffs2/erase.c
63509 +++ b/fs/jffs2/erase.c
63510 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
63511 struct jffs2_unknown_node marker = {
63512 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
63513 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
63514 - .totlen = cpu_to_je32(c->cleanmarker_size)
63515 + .totlen = cpu_to_je32(c->cleanmarker_size),
63516 + .hdr_crc = cpu_to_je32(0)
63517 };
63518
63519 jffs2_prealloc_raw_node_refs(c, jeb, 1);
63520 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
63521 index 09ed551..45684f8 100644
63522 --- a/fs/jffs2/wbuf.c
63523 +++ b/fs/jffs2/wbuf.c
63524 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
63525 {
63526 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
63527 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
63528 - .totlen = constant_cpu_to_je32(8)
63529 + .totlen = constant_cpu_to_je32(8),
63530 + .hdr_crc = constant_cpu_to_je32(0)
63531 };
63532
63533 /*
63534 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
63535 index 93e897e..a863de4 100644
63536 --- a/fs/jfs/super.c
63537 +++ b/fs/jfs/super.c
63538 @@ -893,7 +893,7 @@ static int __init init_jfs_fs(void)
63539
63540 jfs_inode_cachep =
63541 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
63542 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
63543 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
63544 init_once);
63545 if (jfs_inode_cachep == NULL)
63546 return -ENOMEM;
63547 diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
63548 index 1c77193..a50091d 100644
63549 --- a/fs/kernfs/dir.c
63550 +++ b/fs/kernfs/dir.c
63551 @@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
63552 *
63553 * Returns 31 bit hash of ns + name (so it fits in an off_t )
63554 */
63555 -static unsigned int kernfs_name_hash(const char *name, const void *ns)
63556 +static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
63557 {
63558 unsigned long hash = init_name_hash();
63559 unsigned int len = strlen(name);
63560 diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
63561 index 4429d6d..9831f52 100644
63562 --- a/fs/kernfs/file.c
63563 +++ b/fs/kernfs/file.c
63564 @@ -34,7 +34,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
63565
63566 struct kernfs_open_node {
63567 atomic_t refcnt;
63568 - atomic_t event;
63569 + atomic_unchecked_t event;
63570 wait_queue_head_t poll;
63571 struct list_head files; /* goes through kernfs_open_file.list */
63572 };
63573 @@ -163,7 +163,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
63574 {
63575 struct kernfs_open_file *of = sf->private;
63576
63577 - of->event = atomic_read(&of->kn->attr.open->event);
63578 + of->event = atomic_read_unchecked(&of->kn->attr.open->event);
63579
63580 return of->kn->attr.ops->seq_show(sf, v);
63581 }
63582 @@ -375,12 +375,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
63583 return ret;
63584 }
63585
63586 -static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
63587 - void *buf, int len, int write)
63588 +static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
63589 + void *buf, size_t len, int write)
63590 {
63591 struct file *file = vma->vm_file;
63592 struct kernfs_open_file *of = kernfs_of(file);
63593 - int ret;
63594 + ssize_t ret;
63595
63596 if (!of->vm_ops)
63597 return -EINVAL;
63598 @@ -581,7 +581,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
63599 return -ENOMEM;
63600
63601 atomic_set(&new_on->refcnt, 0);
63602 - atomic_set(&new_on->event, 1);
63603 + atomic_set_unchecked(&new_on->event, 1);
63604 init_waitqueue_head(&new_on->poll);
63605 INIT_LIST_HEAD(&new_on->files);
63606 goto retry;
63607 @@ -787,7 +787,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
63608
63609 kernfs_put_active(kn);
63610
63611 - if (of->event != atomic_read(&on->event))
63612 + if (of->event != atomic_read_unchecked(&on->event))
63613 goto trigger;
63614
63615 return DEFAULT_POLLMASK;
63616 @@ -818,7 +818,7 @@ repeat:
63617
63618 on = kn->attr.open;
63619 if (on) {
63620 - atomic_inc(&on->event);
63621 + atomic_inc_unchecked(&on->event);
63622 wake_up_interruptible(&on->poll);
63623 }
63624
63625 diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
63626 index 8a19889..4c3069a 100644
63627 --- a/fs/kernfs/symlink.c
63628 +++ b/fs/kernfs/symlink.c
63629 @@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
63630 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
63631 void *cookie)
63632 {
63633 - char *page = nd_get_link(nd);
63634 + const char *page = nd_get_link(nd);
63635 if (!IS_ERR(page))
63636 free_page((unsigned long)page);
63637 }
63638 diff --git a/fs/libfs.c b/fs/libfs.c
63639 index 005843c..06c4191 100644
63640 --- a/fs/libfs.c
63641 +++ b/fs/libfs.c
63642 @@ -160,6 +160,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
63643
63644 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
63645 struct dentry *next = list_entry(p, struct dentry, d_child);
63646 + char d_name[sizeof(next->d_iname)];
63647 + const unsigned char *name;
63648 +
63649 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
63650 if (!simple_positive(next)) {
63651 spin_unlock(&next->d_lock);
63652 @@ -168,7 +171,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
63653
63654 spin_unlock(&next->d_lock);
63655 spin_unlock(&dentry->d_lock);
63656 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
63657 + name = next->d_name.name;
63658 + if (name == next->d_iname) {
63659 + memcpy(d_name, name, next->d_name.len);
63660 + name = d_name;
63661 + }
63662 + if (!dir_emit(ctx, name, next->d_name.len,
63663 next->d_inode->i_ino, dt_type(next->d_inode)))
63664 return 0;
63665 spin_lock(&dentry->d_lock);
63666 @@ -1027,7 +1035,7 @@ EXPORT_SYMBOL(noop_fsync);
63667 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
63668 void *cookie)
63669 {
63670 - char *s = nd_get_link(nd);
63671 + const char *s = nd_get_link(nd);
63672 if (!IS_ERR(s))
63673 kfree(s);
63674 }
63675 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
63676 index acd3947..1f896e2 100644
63677 --- a/fs/lockd/clntproc.c
63678 +++ b/fs/lockd/clntproc.c
63679 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
63680 /*
63681 * Cookie counter for NLM requests
63682 */
63683 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
63684 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
63685
63686 void nlmclnt_next_cookie(struct nlm_cookie *c)
63687 {
63688 - u32 cookie = atomic_inc_return(&nlm_cookie);
63689 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
63690
63691 memcpy(c->data, &cookie, 4);
63692 c->len=4;
63693 diff --git a/fs/locks.c b/fs/locks.c
63694 index 735b8d3..dfc44a2 100644
63695 --- a/fs/locks.c
63696 +++ b/fs/locks.c
63697 @@ -2374,7 +2374,7 @@ void locks_remove_file(struct file *filp)
63698 locks_remove_posix(filp, filp);
63699
63700 if (filp->f_op->flock) {
63701 - struct file_lock fl = {
63702 + struct file_lock flock = {
63703 .fl_owner = filp,
63704 .fl_pid = current->tgid,
63705 .fl_file = filp,
63706 @@ -2382,9 +2382,9 @@ void locks_remove_file(struct file *filp)
63707 .fl_type = F_UNLCK,
63708 .fl_end = OFFSET_MAX,
63709 };
63710 - filp->f_op->flock(filp, F_SETLKW, &fl);
63711 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
63712 - fl.fl_ops->fl_release_private(&fl);
63713 + filp->f_op->flock(filp, F_SETLKW, &flock);
63714 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
63715 + flock.fl_ops->fl_release_private(&flock);
63716 }
63717
63718 spin_lock(&inode->i_lock);
63719 diff --git a/fs/mount.h b/fs/mount.h
63720 index f82c628..9492b99 100644
63721 --- a/fs/mount.h
63722 +++ b/fs/mount.h
63723 @@ -11,7 +11,7 @@ struct mnt_namespace {
63724 u64 seq; /* Sequence number to prevent loops */
63725 wait_queue_head_t poll;
63726 u64 event;
63727 -};
63728 +} __randomize_layout;
63729
63730 struct mnt_pcp {
63731 int mnt_count;
63732 @@ -62,7 +62,7 @@ struct mount {
63733 int mnt_expiry_mark; /* true if marked for expiry */
63734 struct hlist_head mnt_pins;
63735 struct path mnt_ex_mountpoint;
63736 -};
63737 +} __randomize_layout;
63738
63739 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
63740
63741 diff --git a/fs/namei.c b/fs/namei.c
63742 index db5fe86..d3dcc14 100644
63743 --- a/fs/namei.c
63744 +++ b/fs/namei.c
63745 @@ -331,17 +331,32 @@ int generic_permission(struct inode *inode, int mask)
63746 if (ret != -EACCES)
63747 return ret;
63748
63749 +#ifdef CONFIG_GRKERNSEC
63750 + /* we'll block if we have to log due to a denied capability use */
63751 + if (mask & MAY_NOT_BLOCK)
63752 + return -ECHILD;
63753 +#endif
63754 +
63755 if (S_ISDIR(inode->i_mode)) {
63756 /* DACs are overridable for directories */
63757 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
63758 - return 0;
63759 if (!(mask & MAY_WRITE))
63760 - if (capable_wrt_inode_uidgid(inode,
63761 - CAP_DAC_READ_SEARCH))
63762 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
63763 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
63764 return 0;
63765 + if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
63766 + return 0;
63767 return -EACCES;
63768 }
63769 /*
63770 + * Searching includes executable on directories, else just read.
63771 + */
63772 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
63773 + if (mask == MAY_READ)
63774 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
63775 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
63776 + return 0;
63777 +
63778 + /*
63779 * Read/write DACs are always overridable.
63780 * Executable DACs are overridable when there is
63781 * at least one exec bit set.
63782 @@ -350,14 +365,6 @@ int generic_permission(struct inode *inode, int mask)
63783 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
63784 return 0;
63785
63786 - /*
63787 - * Searching includes executable on directories, else just read.
63788 - */
63789 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
63790 - if (mask == MAY_READ)
63791 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
63792 - return 0;
63793 -
63794 return -EACCES;
63795 }
63796 EXPORT_SYMBOL(generic_permission);
63797 @@ -824,7 +831,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
63798 {
63799 struct dentry *dentry = link->dentry;
63800 int error;
63801 - char *s;
63802 + const char *s;
63803
63804 BUG_ON(nd->flags & LOOKUP_RCU);
63805
63806 @@ -845,6 +852,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
63807 if (error)
63808 goto out_put_nd_path;
63809
63810 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
63811 + dentry->d_inode, dentry, nd->path.mnt)) {
63812 + error = -EACCES;
63813 + goto out_put_nd_path;
63814 + }
63815 +
63816 nd->last_type = LAST_BIND;
63817 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
63818 error = PTR_ERR(*p);
63819 @@ -1608,6 +1621,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
63820 if (res)
63821 break;
63822 res = walk_component(nd, path, LOOKUP_FOLLOW);
63823 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
63824 + res = -EACCES;
63825 put_link(nd, &link, cookie);
63826 } while (res > 0);
63827
63828 @@ -1680,7 +1695,7 @@ EXPORT_SYMBOL(full_name_hash);
63829 static inline u64 hash_name(const char *name)
63830 {
63831 unsigned long a, b, adata, bdata, mask, hash, len;
63832 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
63833 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
63834
63835 hash = a = 0;
63836 len = -sizeof(unsigned long);
63837 @@ -1969,6 +1984,8 @@ static int path_lookupat(int dfd, const char *name,
63838 if (err)
63839 break;
63840 err = lookup_last(nd, &path);
63841 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
63842 + err = -EACCES;
63843 put_link(nd, &link, cookie);
63844 }
63845 }
63846 @@ -1976,6 +1993,13 @@ static int path_lookupat(int dfd, const char *name,
63847 if (!err)
63848 err = complete_walk(nd);
63849
63850 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
63851 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
63852 + path_put(&nd->path);
63853 + err = -ENOENT;
63854 + }
63855 + }
63856 +
63857 if (!err && nd->flags & LOOKUP_DIRECTORY) {
63858 if (!d_can_lookup(nd->path.dentry)) {
63859 path_put(&nd->path);
63860 @@ -2004,8 +2028,15 @@ static int filename_lookup(int dfd, struct filename *name,
63861 retval = path_lookupat(dfd, name->name,
63862 flags | LOOKUP_REVAL, nd);
63863
63864 - if (likely(!retval))
63865 + if (likely(!retval)) {
63866 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
63867 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
63868 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
63869 + path_put(&nd->path);
63870 + return -ENOENT;
63871 + }
63872 + }
63873 + }
63874 return retval;
63875 }
63876
63877 @@ -2582,6 +2613,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
63878 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
63879 return -EPERM;
63880
63881 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
63882 + return -EPERM;
63883 + if (gr_handle_rawio(inode))
63884 + return -EPERM;
63885 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
63886 + return -EACCES;
63887 +
63888 return 0;
63889 }
63890
63891 @@ -2813,7 +2851,7 @@ looked_up:
63892 * cleared otherwise prior to returning.
63893 */
63894 static int lookup_open(struct nameidata *nd, struct path *path,
63895 - struct file *file,
63896 + struct path *link, struct file *file,
63897 const struct open_flags *op,
63898 bool got_write, int *opened)
63899 {
63900 @@ -2848,6 +2886,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
63901 /* Negative dentry, just create the file */
63902 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
63903 umode_t mode = op->mode;
63904 +
63905 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
63906 + error = -EACCES;
63907 + goto out_dput;
63908 + }
63909 +
63910 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
63911 + error = -EACCES;
63912 + goto out_dput;
63913 + }
63914 +
63915 if (!IS_POSIXACL(dir->d_inode))
63916 mode &= ~current_umask();
63917 /*
63918 @@ -2869,6 +2918,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
63919 nd->flags & LOOKUP_EXCL);
63920 if (error)
63921 goto out_dput;
63922 + else
63923 + gr_handle_create(dentry, nd->path.mnt);
63924 }
63925 out_no_open:
63926 path->dentry = dentry;
63927 @@ -2883,7 +2934,7 @@ out_dput:
63928 /*
63929 * Handle the last step of open()
63930 */
63931 -static int do_last(struct nameidata *nd, struct path *path,
63932 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
63933 struct file *file, const struct open_flags *op,
63934 int *opened, struct filename *name)
63935 {
63936 @@ -2933,6 +2984,15 @@ static int do_last(struct nameidata *nd, struct path *path,
63937 if (error)
63938 return error;
63939
63940 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
63941 + error = -ENOENT;
63942 + goto out;
63943 + }
63944 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
63945 + error = -EACCES;
63946 + goto out;
63947 + }
63948 +
63949 audit_inode(name, dir, LOOKUP_PARENT);
63950 error = -EISDIR;
63951 /* trailing slashes? */
63952 @@ -2952,7 +3012,7 @@ retry_lookup:
63953 */
63954 }
63955 mutex_lock(&dir->d_inode->i_mutex);
63956 - error = lookup_open(nd, path, file, op, got_write, opened);
63957 + error = lookup_open(nd, path, link, file, op, got_write, opened);
63958 mutex_unlock(&dir->d_inode->i_mutex);
63959
63960 if (error <= 0) {
63961 @@ -2976,11 +3036,28 @@ retry_lookup:
63962 goto finish_open_created;
63963 }
63964
63965 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
63966 + error = -ENOENT;
63967 + goto exit_dput;
63968 + }
63969 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
63970 + error = -EACCES;
63971 + goto exit_dput;
63972 + }
63973 +
63974 /*
63975 * create/update audit record if it already exists.
63976 */
63977 - if (d_is_positive(path->dentry))
63978 + if (d_is_positive(path->dentry)) {
63979 + /* only check if O_CREAT is specified, all other checks need to go
63980 + into may_open */
63981 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
63982 + error = -EACCES;
63983 + goto exit_dput;
63984 + }
63985 +
63986 audit_inode(name, path->dentry, 0);
63987 + }
63988
63989 /*
63990 * If atomic_open() acquired write access it is dropped now due to
63991 @@ -3021,6 +3098,11 @@ finish_lookup:
63992 }
63993 }
63994 BUG_ON(inode != path->dentry->d_inode);
63995 + /* if we're resolving a symlink to another symlink */
63996 + if (link && gr_handle_symlink_owner(link, inode)) {
63997 + error = -EACCES;
63998 + goto out;
63999 + }
64000 return 1;
64001 }
64002
64003 @@ -3040,7 +3122,18 @@ finish_open:
64004 path_put(&save_parent);
64005 return error;
64006 }
64007 +
64008 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
64009 + error = -ENOENT;
64010 + goto out;
64011 + }
64012 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
64013 + error = -EACCES;
64014 + goto out;
64015 + }
64016 +
64017 audit_inode(name, nd->path.dentry, 0);
64018 +
64019 error = -EISDIR;
64020 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
64021 goto out;
64022 @@ -3207,7 +3300,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64023 if (unlikely(error))
64024 goto out;
64025
64026 - error = do_last(nd, &path, file, op, &opened, pathname);
64027 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
64028 while (unlikely(error > 0)) { /* trailing symlink */
64029 struct path link = path;
64030 void *cookie;
64031 @@ -3225,7 +3318,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64032 error = follow_link(&link, nd, &cookie);
64033 if (unlikely(error))
64034 break;
64035 - error = do_last(nd, &path, file, op, &opened, pathname);
64036 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
64037 put_link(nd, &link, cookie);
64038 }
64039 out:
64040 @@ -3325,9 +3418,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
64041 goto unlock;
64042
64043 error = -EEXIST;
64044 - if (d_is_positive(dentry))
64045 + if (d_is_positive(dentry)) {
64046 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
64047 + error = -ENOENT;
64048 goto fail;
64049 -
64050 + }
64051 /*
64052 * Special case - lookup gave negative, but... we had foo/bar/
64053 * From the vfs_mknod() POV we just have a negative dentry -
64054 @@ -3379,6 +3474,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
64055 }
64056 EXPORT_SYMBOL(user_path_create);
64057
64058 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
64059 +{
64060 + struct filename *tmp = getname(pathname);
64061 + struct dentry *res;
64062 + if (IS_ERR(tmp))
64063 + return ERR_CAST(tmp);
64064 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
64065 + if (IS_ERR(res))
64066 + putname(tmp);
64067 + else
64068 + *to = tmp;
64069 + return res;
64070 +}
64071 +
64072 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
64073 {
64074 int error = may_create(dir, dentry);
64075 @@ -3442,6 +3551,17 @@ retry:
64076
64077 if (!IS_POSIXACL(path.dentry->d_inode))
64078 mode &= ~current_umask();
64079 +
64080 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
64081 + error = -EPERM;
64082 + goto out;
64083 + }
64084 +
64085 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
64086 + error = -EACCES;
64087 + goto out;
64088 + }
64089 +
64090 error = security_path_mknod(&path, dentry, mode, dev);
64091 if (error)
64092 goto out;
64093 @@ -3457,6 +3577,8 @@ retry:
64094 error = vfs_mknod(path.dentry->d_inode,dentry,mode,0);
64095 break;
64096 }
64097 + if (!error)
64098 + gr_handle_create(dentry, path.mnt);
64099 out:
64100 done_path_create(&path, dentry);
64101 if (retry_estale(error, lookup_flags)) {
64102 @@ -3511,9 +3633,16 @@ retry:
64103
64104 if (!IS_POSIXACL(path.dentry->d_inode))
64105 mode &= ~current_umask();
64106 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
64107 + error = -EACCES;
64108 + goto out;
64109 + }
64110 error = security_path_mkdir(&path, dentry, mode);
64111 if (!error)
64112 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
64113 + if (!error)
64114 + gr_handle_create(dentry, path.mnt);
64115 +out:
64116 done_path_create(&path, dentry);
64117 if (retry_estale(error, lookup_flags)) {
64118 lookup_flags |= LOOKUP_REVAL;
64119 @@ -3597,6 +3726,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
64120 struct filename *name;
64121 struct dentry *dentry;
64122 struct nameidata nd;
64123 + ino_t saved_ino = 0;
64124 + dev_t saved_dev = 0;
64125 unsigned int lookup_flags = 0;
64126 retry:
64127 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64128 @@ -3629,10 +3760,21 @@ retry:
64129 error = -ENOENT;
64130 goto exit3;
64131 }
64132 +
64133 + saved_ino = dentry->d_inode->i_ino;
64134 + saved_dev = gr_get_dev_from_dentry(dentry);
64135 +
64136 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
64137 + error = -EACCES;
64138 + goto exit3;
64139 + }
64140 +
64141 error = security_path_rmdir(&nd.path, dentry);
64142 if (error)
64143 goto exit3;
64144 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
64145 + if (!error && (saved_dev || saved_ino))
64146 + gr_handle_delete(saved_ino, saved_dev);
64147 exit3:
64148 dput(dentry);
64149 exit2:
64150 @@ -3725,6 +3867,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
64151 struct nameidata nd;
64152 struct inode *inode = NULL;
64153 struct inode *delegated_inode = NULL;
64154 + ino_t saved_ino = 0;
64155 + dev_t saved_dev = 0;
64156 unsigned int lookup_flags = 0;
64157 retry:
64158 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64159 @@ -3751,10 +3895,22 @@ retry_deleg:
64160 if (d_is_negative(dentry))
64161 goto slashes;
64162 ihold(inode);
64163 +
64164 + if (inode->i_nlink <= 1) {
64165 + saved_ino = inode->i_ino;
64166 + saved_dev = gr_get_dev_from_dentry(dentry);
64167 + }
64168 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
64169 + error = -EACCES;
64170 + goto exit2;
64171 + }
64172 +
64173 error = security_path_unlink(&nd.path, dentry);
64174 if (error)
64175 goto exit2;
64176 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
64177 + if (!error && (saved_ino || saved_dev))
64178 + gr_handle_delete(saved_ino, saved_dev);
64179 exit2:
64180 dput(dentry);
64181 }
64182 @@ -3843,9 +3999,17 @@ retry:
64183 if (IS_ERR(dentry))
64184 goto out_putname;
64185
64186 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
64187 + error = -EACCES;
64188 + goto out;
64189 + }
64190 +
64191 error = security_path_symlink(&path, dentry, from->name);
64192 if (!error)
64193 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
64194 + if (!error)
64195 + gr_handle_create(dentry, path.mnt);
64196 +out:
64197 done_path_create(&path, dentry);
64198 if (retry_estale(error, lookup_flags)) {
64199 lookup_flags |= LOOKUP_REVAL;
64200 @@ -3949,6 +4113,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
64201 struct dentry *new_dentry;
64202 struct path old_path, new_path;
64203 struct inode *delegated_inode = NULL;
64204 + struct filename *to = NULL;
64205 int how = 0;
64206 int error;
64207
64208 @@ -3972,7 +4137,7 @@ retry:
64209 if (error)
64210 return error;
64211
64212 - new_dentry = user_path_create(newdfd, newname, &new_path,
64213 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
64214 (how & LOOKUP_REVAL));
64215 error = PTR_ERR(new_dentry);
64216 if (IS_ERR(new_dentry))
64217 @@ -3984,11 +4149,28 @@ retry:
64218 error = may_linkat(&old_path);
64219 if (unlikely(error))
64220 goto out_dput;
64221 +
64222 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
64223 + old_path.dentry->d_inode,
64224 + old_path.dentry->d_inode->i_mode, to)) {
64225 + error = -EACCES;
64226 + goto out_dput;
64227 + }
64228 +
64229 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
64230 + old_path.dentry, old_path.mnt, to)) {
64231 + error = -EACCES;
64232 + goto out_dput;
64233 + }
64234 +
64235 error = security_path_link(old_path.dentry, &new_path, new_dentry);
64236 if (error)
64237 goto out_dput;
64238 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
64239 + if (!error)
64240 + gr_handle_create(new_dentry, new_path.mnt);
64241 out_dput:
64242 + putname(to);
64243 done_path_create(&new_path, new_dentry);
64244 if (delegated_inode) {
64245 error = break_deleg_wait(&delegated_inode);
64246 @@ -4304,6 +4486,12 @@ retry_deleg:
64247 if (new_dentry == trap)
64248 goto exit5;
64249
64250 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
64251 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
64252 + to, flags);
64253 + if (error)
64254 + goto exit5;
64255 +
64256 error = security_path_rename(&oldnd.path, old_dentry,
64257 &newnd.path, new_dentry, flags);
64258 if (error)
64259 @@ -4311,6 +4499,9 @@ retry_deleg:
64260 error = vfs_rename(old_dir->d_inode, old_dentry,
64261 new_dir->d_inode, new_dentry,
64262 &delegated_inode, flags);
64263 + if (!error)
64264 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
64265 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
64266 exit5:
64267 dput(new_dentry);
64268 exit4:
64269 @@ -4367,14 +4558,24 @@ EXPORT_SYMBOL(vfs_whiteout);
64270
64271 int readlink_copy(char __user *buffer, int buflen, const char *link)
64272 {
64273 + char tmpbuf[64];
64274 + const char *newlink;
64275 int len = PTR_ERR(link);
64276 +
64277 if (IS_ERR(link))
64278 goto out;
64279
64280 len = strlen(link);
64281 if (len > (unsigned) buflen)
64282 len = buflen;
64283 - if (copy_to_user(buffer, link, len))
64284 +
64285 + if (len < sizeof(tmpbuf)) {
64286 + memcpy(tmpbuf, link, len);
64287 + newlink = tmpbuf;
64288 + } else
64289 + newlink = link;
64290 +
64291 + if (copy_to_user(buffer, newlink, len))
64292 len = -EFAULT;
64293 out:
64294 return len;
64295 diff --git a/fs/namespace.c b/fs/namespace.c
64296 index 5b66b2b..e7d6b893 100644
64297 --- a/fs/namespace.c
64298 +++ b/fs/namespace.c
64299 @@ -1369,6 +1369,8 @@ void umount_tree(struct mount *mnt, int how)
64300 }
64301 if (last) {
64302 last->mnt_hash.next = unmounted.first;
64303 + if (unmounted.first)
64304 + unmounted.first->pprev = &last->mnt_hash.next;
64305 unmounted.first = tmp_list.first;
64306 unmounted.first->pprev = &unmounted.first;
64307 }
64308 @@ -1445,6 +1447,9 @@ static int do_umount(struct mount *mnt, int flags)
64309 if (!(sb->s_flags & MS_RDONLY))
64310 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
64311 up_write(&sb->s_umount);
64312 +
64313 + gr_log_remount(mnt->mnt_devname, retval);
64314 +
64315 return retval;
64316 }
64317
64318 @@ -1467,6 +1472,9 @@ static int do_umount(struct mount *mnt, int flags)
64319 }
64320 unlock_mount_hash();
64321 namespace_unlock();
64322 +
64323 + gr_log_unmount(mnt->mnt_devname, retval);
64324 +
64325 return retval;
64326 }
64327
64328 @@ -1517,7 +1525,7 @@ static inline bool may_mount(void)
64329 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
64330 */
64331
64332 -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
64333 +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
64334 {
64335 struct path path;
64336 struct mount *mnt;
64337 @@ -1559,7 +1567,7 @@ out:
64338 /*
64339 * The 2.0 compatible umount. No flags.
64340 */
64341 -SYSCALL_DEFINE1(oldumount, char __user *, name)
64342 +SYSCALL_DEFINE1(oldumount, const char __user *, name)
64343 {
64344 return sys_umount(name, 0);
64345 }
64346 @@ -2621,6 +2629,16 @@ long do_mount(const char *dev_name, const char __user *dir_name,
64347 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
64348 MS_STRICTATIME);
64349
64350 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
64351 + retval = -EPERM;
64352 + goto dput_out;
64353 + }
64354 +
64355 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
64356 + retval = -EPERM;
64357 + goto dput_out;
64358 + }
64359 +
64360 if (flags & MS_REMOUNT)
64361 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
64362 data_page);
64363 @@ -2635,6 +2653,9 @@ long do_mount(const char *dev_name, const char __user *dir_name,
64364 dev_name, data_page);
64365 dput_out:
64366 path_put(&path);
64367 +
64368 + gr_log_mount(dev_name, dir_name, retval);
64369 +
64370 return retval;
64371 }
64372
64373 @@ -2652,7 +2673,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
64374 * number incrementing at 10Ghz will take 12,427 years to wrap which
64375 * is effectively never, so we can ignore the possibility.
64376 */
64377 -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
64378 +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
64379
64380 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64381 {
64382 @@ -2667,7 +2688,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64383 kfree(new_ns);
64384 return ERR_PTR(ret);
64385 }
64386 - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
64387 + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
64388 atomic_set(&new_ns->count, 1);
64389 new_ns->root = NULL;
64390 INIT_LIST_HEAD(&new_ns->list);
64391 @@ -2677,7 +2698,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64392 return new_ns;
64393 }
64394
64395 -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
64396 +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
64397 struct user_namespace *user_ns, struct fs_struct *new_fs)
64398 {
64399 struct mnt_namespace *new_ns;
64400 @@ -2798,8 +2819,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
64401 }
64402 EXPORT_SYMBOL(mount_subtree);
64403
64404 -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
64405 - char __user *, type, unsigned long, flags, void __user *, data)
64406 +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
64407 + const char __user *, type, unsigned long, flags, void __user *, data)
64408 {
64409 int ret;
64410 char *kernel_type;
64411 @@ -2905,6 +2926,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
64412 if (error)
64413 goto out2;
64414
64415 + if (gr_handle_chroot_pivot()) {
64416 + error = -EPERM;
64417 + goto out2;
64418 + }
64419 +
64420 get_fs_root(current->fs, &root);
64421 old_mp = lock_mount(&old);
64422 error = PTR_ERR(old_mp);
64423 @@ -3176,7 +3202,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
64424 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
64425 return -EPERM;
64426
64427 - if (fs->users != 1)
64428 + if (atomic_read(&fs->users) != 1)
64429 return -EINVAL;
64430
64431 get_mnt_ns(mnt_ns);
64432 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
64433 index f4ccfe6..a5cf064 100644
64434 --- a/fs/nfs/callback_xdr.c
64435 +++ b/fs/nfs/callback_xdr.c
64436 @@ -51,7 +51,7 @@ struct callback_op {
64437 callback_decode_arg_t decode_args;
64438 callback_encode_res_t encode_res;
64439 long res_maxsize;
64440 -};
64441 +} __do_const;
64442
64443 static struct callback_op callback_ops[];
64444
64445 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
64446 index 00689a8..b162632 100644
64447 --- a/fs/nfs/inode.c
64448 +++ b/fs/nfs/inode.c
64449 @@ -1232,16 +1232,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
64450 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
64451 }
64452
64453 -static atomic_long_t nfs_attr_generation_counter;
64454 +static atomic_long_unchecked_t nfs_attr_generation_counter;
64455
64456 static unsigned long nfs_read_attr_generation_counter(void)
64457 {
64458 - return atomic_long_read(&nfs_attr_generation_counter);
64459 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
64460 }
64461
64462 unsigned long nfs_inc_attr_generation_counter(void)
64463 {
64464 - return atomic_long_inc_return(&nfs_attr_generation_counter);
64465 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
64466 }
64467
64468 void nfs_fattr_init(struct nfs_fattr *fattr)
64469 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
64470 index 0beb023..3f685ec 100644
64471 --- a/fs/nfsd/nfs4proc.c
64472 +++ b/fs/nfsd/nfs4proc.c
64473 @@ -1198,7 +1198,7 @@ struct nfsd4_operation {
64474 nfsd4op_rsize op_rsize_bop;
64475 stateid_getter op_get_currentstateid;
64476 stateid_setter op_set_currentstateid;
64477 -};
64478 +} __do_const;
64479
64480 static struct nfsd4_operation nfsd4_ops[];
64481
64482 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
64483 index eeea7a9..f3ba422 100644
64484 --- a/fs/nfsd/nfs4xdr.c
64485 +++ b/fs/nfsd/nfs4xdr.c
64486 @@ -1543,7 +1543,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
64487
64488 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
64489
64490 -static nfsd4_dec nfsd4_dec_ops[] = {
64491 +static const nfsd4_dec nfsd4_dec_ops[] = {
64492 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
64493 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
64494 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
64495 diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
64496 index 122f691..a00e2e0 100644
64497 --- a/fs/nfsd/nfscache.c
64498 +++ b/fs/nfsd/nfscache.c
64499 @@ -537,7 +537,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64500 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
64501 u32 hash;
64502 struct nfsd_drc_bucket *b;
64503 - int len;
64504 + long len;
64505 size_t bufsize = 0;
64506
64507 if (!rp)
64508 @@ -546,11 +546,14 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64509 hash = nfsd_cache_hash(rp->c_xid);
64510 b = &drc_hashtbl[hash];
64511
64512 - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
64513 - len >>= 2;
64514 + if (statp) {
64515 + len = (char*)statp - (char*)resv->iov_base;
64516 + len = resv->iov_len - len;
64517 + len >>= 2;
64518 + }
64519
64520 /* Don't cache excessive amounts of data and XDR failures */
64521 - if (!statp || len > (256 >> 2)) {
64522 + if (!statp || len > (256 >> 2) || len < 0) {
64523 nfsd_reply_cache_free(b, rp);
64524 return;
64525 }
64526 @@ -558,7 +561,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64527 switch (cachetype) {
64528 case RC_REPLSTAT:
64529 if (len != 1)
64530 - printk("nfsd: RC_REPLSTAT/reply len %d!\n",len);
64531 + printk("nfsd: RC_REPLSTAT/reply len %ld!\n",len);
64532 rp->c_replstat = *statp;
64533 break;
64534 case RC_REPLBUFF:
64535 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
64536 index 989129e..42e019e 100644
64537 --- a/fs/nfsd/vfs.c
64538 +++ b/fs/nfsd/vfs.c
64539 @@ -872,7 +872,7 @@ __be32 nfsd_readv(struct file *file, loff_t offset, struct kvec *vec, int vlen,
64540
64541 oldfs = get_fs();
64542 set_fs(KERNEL_DS);
64543 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
64544 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
64545 set_fs(oldfs);
64546 return nfsd_finish_read(file, count, host_err);
64547 }
64548 @@ -960,7 +960,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
64549
64550 /* Write the data. */
64551 oldfs = get_fs(); set_fs(KERNEL_DS);
64552 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
64553 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
64554 set_fs(oldfs);
64555 if (host_err < 0)
64556 goto out_nfserr;
64557 @@ -1502,7 +1502,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
64558 */
64559
64560 oldfs = get_fs(); set_fs(KERNEL_DS);
64561 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
64562 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
64563 set_fs(oldfs);
64564
64565 if (host_err < 0)
64566 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
64567 index 52ccd34..7a6b202 100644
64568 --- a/fs/nls/nls_base.c
64569 +++ b/fs/nls/nls_base.c
64570 @@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
64571
64572 int __register_nls(struct nls_table *nls, struct module *owner)
64573 {
64574 - struct nls_table ** tmp = &tables;
64575 + struct nls_table *tmp = tables;
64576
64577 if (nls->next)
64578 return -EBUSY;
64579
64580 - nls->owner = owner;
64581 + pax_open_kernel();
64582 + *(void **)&nls->owner = owner;
64583 + pax_close_kernel();
64584 spin_lock(&nls_lock);
64585 - while (*tmp) {
64586 - if (nls == *tmp) {
64587 + while (tmp) {
64588 + if (nls == tmp) {
64589 spin_unlock(&nls_lock);
64590 return -EBUSY;
64591 }
64592 - tmp = &(*tmp)->next;
64593 + tmp = tmp->next;
64594 }
64595 - nls->next = tables;
64596 + pax_open_kernel();
64597 + *(struct nls_table **)&nls->next = tables;
64598 + pax_close_kernel();
64599 tables = nls;
64600 spin_unlock(&nls_lock);
64601 return 0;
64602 @@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
64603
64604 int unregister_nls(struct nls_table * nls)
64605 {
64606 - struct nls_table ** tmp = &tables;
64607 + struct nls_table * const * tmp = &tables;
64608
64609 spin_lock(&nls_lock);
64610 while (*tmp) {
64611 if (nls == *tmp) {
64612 - *tmp = nls->next;
64613 + pax_open_kernel();
64614 + *(struct nls_table **)tmp = nls->next;
64615 + pax_close_kernel();
64616 spin_unlock(&nls_lock);
64617 return 0;
64618 }
64619 @@ -272,7 +278,7 @@ int unregister_nls(struct nls_table * nls)
64620 return -EINVAL;
64621 }
64622
64623 -static struct nls_table *find_nls(char *charset)
64624 +static struct nls_table *find_nls(const char *charset)
64625 {
64626 struct nls_table *nls;
64627 spin_lock(&nls_lock);
64628 @@ -288,7 +294,7 @@ static struct nls_table *find_nls(char *charset)
64629 return nls;
64630 }
64631
64632 -struct nls_table *load_nls(char *charset)
64633 +struct nls_table *load_nls(const char *charset)
64634 {
64635 return try_then_request_module(find_nls(charset), "nls_%s", charset);
64636 }
64637 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
64638 index 162b3f1..6076a7c 100644
64639 --- a/fs/nls/nls_euc-jp.c
64640 +++ b/fs/nls/nls_euc-jp.c
64641 @@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
64642 p_nls = load_nls("cp932");
64643
64644 if (p_nls) {
64645 - table.charset2upper = p_nls->charset2upper;
64646 - table.charset2lower = p_nls->charset2lower;
64647 + pax_open_kernel();
64648 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
64649 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
64650 + pax_close_kernel();
64651 return register_nls(&table);
64652 }
64653
64654 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
64655 index a80a741..7b96e1b 100644
64656 --- a/fs/nls/nls_koi8-ru.c
64657 +++ b/fs/nls/nls_koi8-ru.c
64658 @@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
64659 p_nls = load_nls("koi8-u");
64660
64661 if (p_nls) {
64662 - table.charset2upper = p_nls->charset2upper;
64663 - table.charset2lower = p_nls->charset2lower;
64664 + pax_open_kernel();
64665 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
64666 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
64667 + pax_close_kernel();
64668 return register_nls(&table);
64669 }
64670
64671 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
64672 index c991616..5ae51af 100644
64673 --- a/fs/notify/fanotify/fanotify_user.c
64674 +++ b/fs/notify/fanotify/fanotify_user.c
64675 @@ -216,8 +216,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
64676
64677 fd = fanotify_event_metadata.fd;
64678 ret = -EFAULT;
64679 - if (copy_to_user(buf, &fanotify_event_metadata,
64680 - fanotify_event_metadata.event_len))
64681 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
64682 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
64683 goto out_close_fd;
64684
64685 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
64686 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
64687 index a95d8e0..a91a5fd 100644
64688 --- a/fs/notify/notification.c
64689 +++ b/fs/notify/notification.c
64690 @@ -48,7 +48,7 @@
64691 #include <linux/fsnotify_backend.h>
64692 #include "fsnotify.h"
64693
64694 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
64695 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
64696
64697 /**
64698 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
64699 @@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
64700 */
64701 u32 fsnotify_get_cookie(void)
64702 {
64703 - return atomic_inc_return(&fsnotify_sync_cookie);
64704 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
64705 }
64706 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
64707
64708 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
64709 index 9e38daf..5727cae 100644
64710 --- a/fs/ntfs/dir.c
64711 +++ b/fs/ntfs/dir.c
64712 @@ -1310,7 +1310,7 @@ find_next_index_buffer:
64713 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
64714 ~(s64)(ndir->itype.index.block_size - 1)));
64715 /* Bounds checks. */
64716 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
64717 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
64718 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
64719 "inode 0x%lx or driver bug.", vdir->i_ino);
64720 goto err_out;
64721 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
64722 index 643faa4..ef9027e 100644
64723 --- a/fs/ntfs/file.c
64724 +++ b/fs/ntfs/file.c
64725 @@ -1280,7 +1280,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
64726 char *addr;
64727 size_t total = 0;
64728 unsigned len;
64729 - int left;
64730 + unsigned left;
64731
64732 do {
64733 len = PAGE_CACHE_SIZE - ofs;
64734 diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
64735 index 9e1e112..241a52a 100644
64736 --- a/fs/ntfs/super.c
64737 +++ b/fs/ntfs/super.c
64738 @@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
64739 if (!silent)
64740 ntfs_error(sb, "Primary boot sector is invalid.");
64741 } else if (!silent)
64742 - ntfs_error(sb, read_err_str, "primary");
64743 + ntfs_error(sb, read_err_str, "%s", "primary");
64744 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
64745 if (bh_primary)
64746 brelse(bh_primary);
64747 @@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
64748 goto hotfix_primary_boot_sector;
64749 brelse(bh_backup);
64750 } else if (!silent)
64751 - ntfs_error(sb, read_err_str, "backup");
64752 + ntfs_error(sb, read_err_str, "%s", "backup");
64753 /* Try to read NT3.51- backup boot sector. */
64754 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
64755 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
64756 @@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
64757 "sector.");
64758 brelse(bh_backup);
64759 } else if (!silent)
64760 - ntfs_error(sb, read_err_str, "backup");
64761 + ntfs_error(sb, read_err_str, "%s", "backup");
64762 /* We failed. Cleanup and return. */
64763 if (bh_primary)
64764 brelse(bh_primary);
64765 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
64766 index 0440134..d52c93a 100644
64767 --- a/fs/ocfs2/localalloc.c
64768 +++ b/fs/ocfs2/localalloc.c
64769 @@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
64770 goto bail;
64771 }
64772
64773 - atomic_inc(&osb->alloc_stats.moves);
64774 + atomic_inc_unchecked(&osb->alloc_stats.moves);
64775
64776 bail:
64777 if (handle)
64778 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
64779 index bbec539..7b266d5 100644
64780 --- a/fs/ocfs2/ocfs2.h
64781 +++ b/fs/ocfs2/ocfs2.h
64782 @@ -236,11 +236,11 @@ enum ocfs2_vol_state
64783
64784 struct ocfs2_alloc_stats
64785 {
64786 - atomic_t moves;
64787 - atomic_t local_data;
64788 - atomic_t bitmap_data;
64789 - atomic_t bg_allocs;
64790 - atomic_t bg_extends;
64791 + atomic_unchecked_t moves;
64792 + atomic_unchecked_t local_data;
64793 + atomic_unchecked_t bitmap_data;
64794 + atomic_unchecked_t bg_allocs;
64795 + atomic_unchecked_t bg_extends;
64796 };
64797
64798 enum ocfs2_local_alloc_state
64799 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
64800 index 0cb889a..6a26b24 100644
64801 --- a/fs/ocfs2/suballoc.c
64802 +++ b/fs/ocfs2/suballoc.c
64803 @@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
64804 mlog_errno(status);
64805 goto bail;
64806 }
64807 - atomic_inc(&osb->alloc_stats.bg_extends);
64808 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
64809
64810 /* You should never ask for this much metadata */
64811 BUG_ON(bits_wanted >
64812 @@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
64813 mlog_errno(status);
64814 goto bail;
64815 }
64816 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
64817 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
64818
64819 *suballoc_loc = res.sr_bg_blkno;
64820 *suballoc_bit_start = res.sr_bit_offset;
64821 @@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
64822 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
64823 res->sr_bits);
64824
64825 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
64826 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
64827
64828 BUG_ON(res->sr_bits != 1);
64829
64830 @@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
64831 mlog_errno(status);
64832 goto bail;
64833 }
64834 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
64835 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
64836
64837 BUG_ON(res.sr_bits != 1);
64838
64839 @@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
64840 cluster_start,
64841 num_clusters);
64842 if (!status)
64843 - atomic_inc(&osb->alloc_stats.local_data);
64844 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
64845 } else {
64846 if (min_clusters > (osb->bitmap_cpg - 1)) {
64847 /* The only paths asking for contiguousness
64848 @@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
64849 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
64850 res.sr_bg_blkno,
64851 res.sr_bit_offset);
64852 - atomic_inc(&osb->alloc_stats.bitmap_data);
64853 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
64854 *num_clusters = res.sr_bits;
64855 }
64856 }
64857 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
64858 index 93c85bc..02f68a4 100644
64859 --- a/fs/ocfs2/super.c
64860 +++ b/fs/ocfs2/super.c
64861 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
64862 "%10s => GlobalAllocs: %d LocalAllocs: %d "
64863 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
64864 "Stats",
64865 - atomic_read(&osb->alloc_stats.bitmap_data),
64866 - atomic_read(&osb->alloc_stats.local_data),
64867 - atomic_read(&osb->alloc_stats.bg_allocs),
64868 - atomic_read(&osb->alloc_stats.moves),
64869 - atomic_read(&osb->alloc_stats.bg_extends));
64870 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
64871 + atomic_read_unchecked(&osb->alloc_stats.local_data),
64872 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
64873 + atomic_read_unchecked(&osb->alloc_stats.moves),
64874 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
64875
64876 out += snprintf(buf + out, len - out,
64877 "%10s => State: %u Descriptor: %llu Size: %u bits "
64878 @@ -2104,11 +2104,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
64879
64880 mutex_init(&osb->system_file_mutex);
64881
64882 - atomic_set(&osb->alloc_stats.moves, 0);
64883 - atomic_set(&osb->alloc_stats.local_data, 0);
64884 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
64885 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
64886 - atomic_set(&osb->alloc_stats.bg_extends, 0);
64887 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
64888 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
64889 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
64890 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
64891 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
64892
64893 /* Copy the blockcheck stats from the superblock probe */
64894 osb->osb_ecc_stats = *stats;
64895 diff --git a/fs/open.c b/fs/open.c
64896 index de92c13..52d2a6c 100644
64897 --- a/fs/open.c
64898 +++ b/fs/open.c
64899 @@ -32,6 +32,8 @@
64900 #include <linux/dnotify.h>
64901 #include <linux/compat.h>
64902
64903 +#define CREATE_TRACE_POINTS
64904 +#include <trace/events/fs.h>
64905 #include "internal.h"
64906
64907 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
64908 @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
64909 error = locks_verify_truncate(inode, NULL, length);
64910 if (!error)
64911 error = security_path_truncate(path);
64912 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
64913 + error = -EACCES;
64914 if (!error)
64915 error = do_truncate(path->dentry, length, 0, NULL);
64916
64917 @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
64918 error = locks_verify_truncate(inode, f.file, length);
64919 if (!error)
64920 error = security_path_truncate(&f.file->f_path);
64921 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
64922 + error = -EACCES;
64923 if (!error)
64924 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
64925 sb_end_write(inode->i_sb);
64926 @@ -380,6 +386,9 @@ retry:
64927 if (__mnt_is_readonly(path.mnt))
64928 res = -EROFS;
64929
64930 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
64931 + res = -EACCES;
64932 +
64933 out_path_release:
64934 path_put(&path);
64935 if (retry_estale(res, lookup_flags)) {
64936 @@ -411,6 +420,8 @@ retry:
64937 if (error)
64938 goto dput_and_out;
64939
64940 + gr_log_chdir(path.dentry, path.mnt);
64941 +
64942 set_fs_pwd(current->fs, &path);
64943
64944 dput_and_out:
64945 @@ -440,6 +451,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
64946 goto out_putf;
64947
64948 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
64949 +
64950 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
64951 + error = -EPERM;
64952 +
64953 + if (!error)
64954 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
64955 +
64956 if (!error)
64957 set_fs_pwd(current->fs, &f.file->f_path);
64958 out_putf:
64959 @@ -469,7 +487,13 @@ retry:
64960 if (error)
64961 goto dput_and_out;
64962
64963 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
64964 + goto dput_and_out;
64965 +
64966 set_fs_root(current->fs, &path);
64967 +
64968 + gr_handle_chroot_chdir(&path);
64969 +
64970 error = 0;
64971 dput_and_out:
64972 path_put(&path);
64973 @@ -493,6 +517,16 @@ static int chmod_common(struct path *path, umode_t mode)
64974 return error;
64975 retry_deleg:
64976 mutex_lock(&inode->i_mutex);
64977 +
64978 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
64979 + error = -EACCES;
64980 + goto out_unlock;
64981 + }
64982 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
64983 + error = -EACCES;
64984 + goto out_unlock;
64985 + }
64986 +
64987 error = security_path_chmod(path, mode);
64988 if (error)
64989 goto out_unlock;
64990 @@ -558,6 +592,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
64991 uid = make_kuid(current_user_ns(), user);
64992 gid = make_kgid(current_user_ns(), group);
64993
64994 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
64995 + return -EACCES;
64996 +
64997 newattrs.ia_valid = ATTR_CTIME;
64998 if (user != (uid_t) -1) {
64999 if (!uid_valid(uid))
65000 @@ -1002,6 +1039,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
65001 } else {
65002 fsnotify_open(f);
65003 fd_install(fd, f);
65004 + trace_do_sys_open(tmp->name, flags, mode);
65005 }
65006 }
65007 putname(tmp);
65008 diff --git a/fs/pipe.c b/fs/pipe.c
65009 index 21981e5..3d5f55c 100644
65010 --- a/fs/pipe.c
65011 +++ b/fs/pipe.c
65012 @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
65013
65014 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
65015 {
65016 - if (pipe->files)
65017 + if (atomic_read(&pipe->files))
65018 mutex_lock_nested(&pipe->mutex, subclass);
65019 }
65020
65021 @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
65022
65023 void pipe_unlock(struct pipe_inode_info *pipe)
65024 {
65025 - if (pipe->files)
65026 + if (atomic_read(&pipe->files))
65027 mutex_unlock(&pipe->mutex);
65028 }
65029 EXPORT_SYMBOL(pipe_unlock);
65030 @@ -292,9 +292,9 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
65031 }
65032 if (bufs) /* More to do? */
65033 continue;
65034 - if (!pipe->writers)
65035 + if (!atomic_read(&pipe->writers))
65036 break;
65037 - if (!pipe->waiting_writers) {
65038 + if (!atomic_read(&pipe->waiting_writers)) {
65039 /* syscall merging: Usually we must not sleep
65040 * if O_NONBLOCK is set, or if we got some data.
65041 * But if a writer sleeps in kernel space, then
65042 @@ -351,7 +351,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65043
65044 __pipe_lock(pipe);
65045
65046 - if (!pipe->readers) {
65047 + if (!atomic_read(&pipe->readers)) {
65048 send_sig(SIGPIPE, current, 0);
65049 ret = -EPIPE;
65050 goto out;
65051 @@ -387,7 +387,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65052 for (;;) {
65053 int bufs;
65054
65055 - if (!pipe->readers) {
65056 + if (!atomic_read(&pipe->readers)) {
65057 send_sig(SIGPIPE, current, 0);
65058 if (!ret)
65059 ret = -EPIPE;
65060 @@ -455,9 +455,9 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65061 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65062 do_wakeup = 0;
65063 }
65064 - pipe->waiting_writers++;
65065 + atomic_inc(&pipe->waiting_writers);
65066 pipe_wait(pipe);
65067 - pipe->waiting_writers--;
65068 + atomic_dec(&pipe->waiting_writers);
65069 }
65070 out:
65071 __pipe_unlock(pipe);
65072 @@ -512,7 +512,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65073 mask = 0;
65074 if (filp->f_mode & FMODE_READ) {
65075 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
65076 - if (!pipe->writers && filp->f_version != pipe->w_counter)
65077 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
65078 mask |= POLLHUP;
65079 }
65080
65081 @@ -522,7 +522,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65082 * Most Unices do not set POLLERR for FIFOs but on Linux they
65083 * behave exactly like pipes for poll().
65084 */
65085 - if (!pipe->readers)
65086 + if (!atomic_read(&pipe->readers))
65087 mask |= POLLERR;
65088 }
65089
65090 @@ -534,7 +534,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
65091 int kill = 0;
65092
65093 spin_lock(&inode->i_lock);
65094 - if (!--pipe->files) {
65095 + if (atomic_dec_and_test(&pipe->files)) {
65096 inode->i_pipe = NULL;
65097 kill = 1;
65098 }
65099 @@ -551,11 +551,11 @@ pipe_release(struct inode *inode, struct file *file)
65100
65101 __pipe_lock(pipe);
65102 if (file->f_mode & FMODE_READ)
65103 - pipe->readers--;
65104 + atomic_dec(&pipe->readers);
65105 if (file->f_mode & FMODE_WRITE)
65106 - pipe->writers--;
65107 + atomic_dec(&pipe->writers);
65108
65109 - if (pipe->readers || pipe->writers) {
65110 + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
65111 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
65112 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65113 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
65114 @@ -620,7 +620,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
65115 kfree(pipe);
65116 }
65117
65118 -static struct vfsmount *pipe_mnt __read_mostly;
65119 +struct vfsmount *pipe_mnt __read_mostly;
65120
65121 /*
65122 * pipefs_dname() is called from d_path().
65123 @@ -650,8 +650,9 @@ static struct inode * get_pipe_inode(void)
65124 goto fail_iput;
65125
65126 inode->i_pipe = pipe;
65127 - pipe->files = 2;
65128 - pipe->readers = pipe->writers = 1;
65129 + atomic_set(&pipe->files, 2);
65130 + atomic_set(&pipe->readers, 1);
65131 + atomic_set(&pipe->writers, 1);
65132 inode->i_fop = &pipefifo_fops;
65133
65134 /*
65135 @@ -830,17 +831,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
65136 spin_lock(&inode->i_lock);
65137 if (inode->i_pipe) {
65138 pipe = inode->i_pipe;
65139 - pipe->files++;
65140 + atomic_inc(&pipe->files);
65141 spin_unlock(&inode->i_lock);
65142 } else {
65143 spin_unlock(&inode->i_lock);
65144 pipe = alloc_pipe_info();
65145 if (!pipe)
65146 return -ENOMEM;
65147 - pipe->files = 1;
65148 + atomic_set(&pipe->files, 1);
65149 spin_lock(&inode->i_lock);
65150 if (unlikely(inode->i_pipe)) {
65151 - inode->i_pipe->files++;
65152 + atomic_inc(&inode->i_pipe->files);
65153 spin_unlock(&inode->i_lock);
65154 free_pipe_info(pipe);
65155 pipe = inode->i_pipe;
65156 @@ -865,10 +866,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
65157 * opened, even when there is no process writing the FIFO.
65158 */
65159 pipe->r_counter++;
65160 - if (pipe->readers++ == 0)
65161 + if (atomic_inc_return(&pipe->readers) == 1)
65162 wake_up_partner(pipe);
65163
65164 - if (!is_pipe && !pipe->writers) {
65165 + if (!is_pipe && !atomic_read(&pipe->writers)) {
65166 if ((filp->f_flags & O_NONBLOCK)) {
65167 /* suppress POLLHUP until we have
65168 * seen a writer */
65169 @@ -887,14 +888,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
65170 * errno=ENXIO when there is no process reading the FIFO.
65171 */
65172 ret = -ENXIO;
65173 - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
65174 + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
65175 goto err;
65176
65177 pipe->w_counter++;
65178 - if (!pipe->writers++)
65179 + if (atomic_inc_return(&pipe->writers) == 1)
65180 wake_up_partner(pipe);
65181
65182 - if (!is_pipe && !pipe->readers) {
65183 + if (!is_pipe && !atomic_read(&pipe->readers)) {
65184 if (wait_for_partner(pipe, &pipe->r_counter))
65185 goto err_wr;
65186 }
65187 @@ -908,11 +909,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
65188 * the process can at least talk to itself.
65189 */
65190
65191 - pipe->readers++;
65192 - pipe->writers++;
65193 + atomic_inc(&pipe->readers);
65194 + atomic_inc(&pipe->writers);
65195 pipe->r_counter++;
65196 pipe->w_counter++;
65197 - if (pipe->readers == 1 || pipe->writers == 1)
65198 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
65199 wake_up_partner(pipe);
65200 break;
65201
65202 @@ -926,13 +927,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
65203 return 0;
65204
65205 err_rd:
65206 - if (!--pipe->readers)
65207 + if (atomic_dec_and_test(&pipe->readers))
65208 wake_up_interruptible(&pipe->wait);
65209 ret = -ERESTARTSYS;
65210 goto err;
65211
65212 err_wr:
65213 - if (!--pipe->writers)
65214 + if (atomic_dec_and_test(&pipe->writers))
65215 wake_up_interruptible(&pipe->wait);
65216 ret = -ERESTARTSYS;
65217 goto err;
65218 diff --git a/fs/posix_acl.c b/fs/posix_acl.c
65219 index 0855f77..6787d50 100644
65220 --- a/fs/posix_acl.c
65221 +++ b/fs/posix_acl.c
65222 @@ -20,6 +20,7 @@
65223 #include <linux/xattr.h>
65224 #include <linux/export.h>
65225 #include <linux/user_namespace.h>
65226 +#include <linux/grsecurity.h>
65227
65228 struct posix_acl **acl_by_type(struct inode *inode, int type)
65229 {
65230 @@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
65231 }
65232 }
65233 if (mode_p)
65234 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
65235 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
65236 return not_equiv;
65237 }
65238 EXPORT_SYMBOL(posix_acl_equiv_mode);
65239 @@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
65240 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
65241 }
65242
65243 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
65244 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
65245 return not_equiv;
65246 }
65247
65248 @@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
65249 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
65250 int err = -ENOMEM;
65251 if (clone) {
65252 + *mode_p &= ~gr_acl_umask();
65253 +
65254 err = posix_acl_create_masq(clone, mode_p);
65255 if (err < 0) {
65256 posix_acl_release(clone);
65257 @@ -659,11 +662,12 @@ struct posix_acl *
65258 posix_acl_from_xattr(struct user_namespace *user_ns,
65259 const void *value, size_t size)
65260 {
65261 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
65262 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
65263 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
65264 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
65265 int count;
65266 struct posix_acl *acl;
65267 struct posix_acl_entry *acl_e;
65268 + umode_t umask = gr_acl_umask();
65269
65270 if (!value)
65271 return NULL;
65272 @@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65273
65274 switch(acl_e->e_tag) {
65275 case ACL_USER_OBJ:
65276 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65277 + break;
65278 case ACL_GROUP_OBJ:
65279 case ACL_MASK:
65280 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65281 + break;
65282 case ACL_OTHER:
65283 + acl_e->e_perm &= ~(umask & S_IRWXO);
65284 break;
65285
65286 case ACL_USER:
65287 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65288 acl_e->e_uid =
65289 make_kuid(user_ns,
65290 le32_to_cpu(entry->e_id));
65291 @@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65292 goto fail;
65293 break;
65294 case ACL_GROUP:
65295 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65296 acl_e->e_gid =
65297 make_kgid(user_ns,
65298 le32_to_cpu(entry->e_id));
65299 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
65300 index 2183fcf..3c32a98 100644
65301 --- a/fs/proc/Kconfig
65302 +++ b/fs/proc/Kconfig
65303 @@ -30,7 +30,7 @@ config PROC_FS
65304
65305 config PROC_KCORE
65306 bool "/proc/kcore support" if !ARM
65307 - depends on PROC_FS && MMU
65308 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
65309 help
65310 Provides a virtual ELF core file of the live kernel. This can
65311 be read with gdb and other ELF tools. No modifications can be
65312 @@ -38,8 +38,8 @@ config PROC_KCORE
65313
65314 config PROC_VMCORE
65315 bool "/proc/vmcore support"
65316 - depends on PROC_FS && CRASH_DUMP
65317 - default y
65318 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
65319 + default n
65320 help
65321 Exports the dump image of crashed kernel in ELF format.
65322
65323 @@ -63,8 +63,8 @@ config PROC_SYSCTL
65324 limited in memory.
65325
65326 config PROC_PAGE_MONITOR
65327 - default y
65328 - depends on PROC_FS && MMU
65329 + default n
65330 + depends on PROC_FS && MMU && !GRKERNSEC
65331 bool "Enable /proc page monitoring" if EXPERT
65332 help
65333 Various /proc files exist to monitor process memory utilization:
65334 diff --git a/fs/proc/array.c b/fs/proc/array.c
65335 index cd3653e..9b9b79a 100644
65336 --- a/fs/proc/array.c
65337 +++ b/fs/proc/array.c
65338 @@ -60,6 +60,7 @@
65339 #include <linux/tty.h>
65340 #include <linux/string.h>
65341 #include <linux/mman.h>
65342 +#include <linux/grsecurity.h>
65343 #include <linux/proc_fs.h>
65344 #include <linux/ioport.h>
65345 #include <linux/uaccess.h>
65346 @@ -347,6 +348,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
65347 seq_putc(m, '\n');
65348 }
65349
65350 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65351 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
65352 +{
65353 + if (p->mm)
65354 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
65355 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
65356 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
65357 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
65358 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
65359 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
65360 + else
65361 + seq_printf(m, "PaX:\t-----\n");
65362 +}
65363 +#endif
65364 +
65365 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
65366 struct pid *pid, struct task_struct *task)
65367 {
65368 @@ -365,9 +381,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
65369 task_cpus_allowed(m, task);
65370 cpuset_task_status_allowed(m, task);
65371 task_context_switch_counts(m, task);
65372 +
65373 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65374 + task_pax(m, task);
65375 +#endif
65376 +
65377 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
65378 + task_grsec_rbac(m, task);
65379 +#endif
65380 +
65381 return 0;
65382 }
65383
65384 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65385 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
65386 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
65387 + _mm->pax_flags & MF_PAX_SEGMEXEC))
65388 +#endif
65389 +
65390 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65391 struct pid *pid, struct task_struct *task, int whole)
65392 {
65393 @@ -389,6 +420,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65394 char tcomm[sizeof(task->comm)];
65395 unsigned long flags;
65396
65397 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65398 + if (current->exec_id != m->exec_id) {
65399 + gr_log_badprocpid("stat");
65400 + return 0;
65401 + }
65402 +#endif
65403 +
65404 state = *get_task_state(task);
65405 vsize = eip = esp = 0;
65406 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
65407 @@ -459,6 +497,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65408 gtime = task_gtime(task);
65409 }
65410
65411 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65412 + if (PAX_RAND_FLAGS(mm)) {
65413 + eip = 0;
65414 + esp = 0;
65415 + wchan = 0;
65416 + }
65417 +#endif
65418 +#ifdef CONFIG_GRKERNSEC_HIDESYM
65419 + wchan = 0;
65420 + eip =0;
65421 + esp =0;
65422 +#endif
65423 +
65424 /* scale priority and nice values from timeslices to -20..20 */
65425 /* to make it look like a "normal" Unix priority/nice value */
65426 priority = task_prio(task);
65427 @@ -490,9 +541,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65428 seq_put_decimal_ull(m, ' ', vsize);
65429 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
65430 seq_put_decimal_ull(m, ' ', rsslim);
65431 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65432 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
65433 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
65434 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
65435 +#else
65436 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
65437 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
65438 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
65439 +#endif
65440 seq_put_decimal_ull(m, ' ', esp);
65441 seq_put_decimal_ull(m, ' ', eip);
65442 /* The signal information here is obsolete.
65443 @@ -514,7 +571,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65444 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
65445 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
65446
65447 - if (mm && permitted) {
65448 + if (mm && permitted
65449 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65450 + && !PAX_RAND_FLAGS(mm)
65451 +#endif
65452 + ) {
65453 seq_put_decimal_ull(m, ' ', mm->start_data);
65454 seq_put_decimal_ull(m, ' ', mm->end_data);
65455 seq_put_decimal_ull(m, ' ', mm->start_brk);
65456 @@ -552,8 +613,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
65457 struct pid *pid, struct task_struct *task)
65458 {
65459 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
65460 - struct mm_struct *mm = get_task_mm(task);
65461 + struct mm_struct *mm;
65462
65463 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65464 + if (current->exec_id != m->exec_id) {
65465 + gr_log_badprocpid("statm");
65466 + return 0;
65467 + }
65468 +#endif
65469 + mm = get_task_mm(task);
65470 if (mm) {
65471 size = task_statm(mm, &shared, &text, &data, &resident);
65472 mmput(mm);
65473 @@ -576,6 +644,20 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
65474 return 0;
65475 }
65476
65477 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
65478 +int proc_pid_ipaddr(struct seq_file *m, struct pid_namespace *ns, struct pid *pid, struct task_struct *task)
65479 +{
65480 + unsigned long flags;
65481 + u32 curr_ip = 0;
65482 +
65483 + if (lock_task_sighand(task, &flags)) {
65484 + curr_ip = task->signal->curr_ip;
65485 + unlock_task_sighand(task, &flags);
65486 + }
65487 + return seq_printf(m, "%pI4\n", &curr_ip);
65488 +}
65489 +#endif
65490 +
65491 #ifdef CONFIG_CHECKPOINT_RESTORE
65492 static struct pid *
65493 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
65494 diff --git a/fs/proc/base.c b/fs/proc/base.c
65495 index 772efa4..e7f1a5c 100644
65496 --- a/fs/proc/base.c
65497 +++ b/fs/proc/base.c
65498 @@ -113,6 +113,14 @@ struct pid_entry {
65499 union proc_op op;
65500 };
65501
65502 +struct getdents_callback {
65503 + struct linux_dirent __user * current_dir;
65504 + struct linux_dirent __user * previous;
65505 + struct file * file;
65506 + int count;
65507 + int error;
65508 +};
65509 +
65510 #define NOD(NAME, MODE, IOP, FOP, OP) { \
65511 .name = (NAME), \
65512 .len = sizeof(NAME) - 1, \
65513 @@ -208,12 +216,28 @@ static int proc_pid_cmdline(struct seq_file *m, struct pid_namespace *ns,
65514 return 0;
65515 }
65516
65517 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65518 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
65519 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
65520 + _mm->pax_flags & MF_PAX_SEGMEXEC))
65521 +#endif
65522 +
65523 static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
65524 struct pid *pid, struct task_struct *task)
65525 {
65526 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
65527 if (mm && !IS_ERR(mm)) {
65528 unsigned int nwords = 0;
65529 +
65530 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65531 + /* allow if we're currently ptracing this task */
65532 + if (PAX_RAND_FLAGS(mm) &&
65533 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
65534 + mmput(mm);
65535 + return 0;
65536 + }
65537 +#endif
65538 +
65539 do {
65540 nwords += 2;
65541 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
65542 @@ -225,7 +249,7 @@ static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
65543 }
65544
65545
65546 -#ifdef CONFIG_KALLSYMS
65547 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65548 /*
65549 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
65550 * Returns the resolved symbol. If that fails, simply return the address.
65551 @@ -265,7 +289,7 @@ static void unlock_trace(struct task_struct *task)
65552 mutex_unlock(&task->signal->cred_guard_mutex);
65553 }
65554
65555 -#ifdef CONFIG_STACKTRACE
65556 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65557
65558 #define MAX_STACK_TRACE_DEPTH 64
65559
65560 @@ -456,7 +480,7 @@ static int proc_pid_limits(struct seq_file *m, struct pid_namespace *ns,
65561 return 0;
65562 }
65563
65564 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
65565 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
65566 static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
65567 struct pid *pid, struct task_struct *task)
65568 {
65569 @@ -486,7 +510,7 @@ static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
65570 /************************************************************************/
65571
65572 /* permission checks */
65573 -static int proc_fd_access_allowed(struct inode *inode)
65574 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
65575 {
65576 struct task_struct *task;
65577 int allowed = 0;
65578 @@ -496,7 +520,10 @@ static int proc_fd_access_allowed(struct inode *inode)
65579 */
65580 task = get_proc_task(inode);
65581 if (task) {
65582 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
65583 + if (log)
65584 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
65585 + else
65586 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
65587 put_task_struct(task);
65588 }
65589 return allowed;
65590 @@ -527,10 +554,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
65591 struct task_struct *task,
65592 int hide_pid_min)
65593 {
65594 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
65595 + return false;
65596 +
65597 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65598 + rcu_read_lock();
65599 + {
65600 + const struct cred *tmpcred = current_cred();
65601 + const struct cred *cred = __task_cred(task);
65602 +
65603 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
65604 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
65605 + || in_group_p(grsec_proc_gid)
65606 +#endif
65607 + ) {
65608 + rcu_read_unlock();
65609 + return true;
65610 + }
65611 + }
65612 + rcu_read_unlock();
65613 +
65614 + if (!pid->hide_pid)
65615 + return false;
65616 +#endif
65617 +
65618 if (pid->hide_pid < hide_pid_min)
65619 return true;
65620 if (in_group_p(pid->pid_gid))
65621 return true;
65622 +
65623 return ptrace_may_access(task, PTRACE_MODE_READ);
65624 }
65625
65626 @@ -548,7 +600,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
65627 put_task_struct(task);
65628
65629 if (!has_perms) {
65630 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65631 + {
65632 +#else
65633 if (pid->hide_pid == 2) {
65634 +#endif
65635 /*
65636 * Let's make getdents(), stat(), and open()
65637 * consistent with each other. If a process
65638 @@ -609,6 +665,8 @@ struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode)
65639
65640 if (task) {
65641 mm = mm_access(task, mode);
65642 + if (gr_acl_handle_procpidmem(task))
65643 + mm = ERR_PTR(-EPERM);
65644 put_task_struct(task);
65645
65646 if (!IS_ERR_OR_NULL(mm)) {
65647 @@ -630,6 +688,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
65648 return PTR_ERR(mm);
65649
65650 file->private_data = mm;
65651 +
65652 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65653 + file->f_version = current->exec_id;
65654 +#endif
65655 +
65656 return 0;
65657 }
65658
65659 @@ -651,6 +714,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
65660 ssize_t copied;
65661 char *page;
65662
65663 +#ifdef CONFIG_GRKERNSEC
65664 + if (write)
65665 + return -EPERM;
65666 +#endif
65667 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65668 + if (file->f_version != current->exec_id) {
65669 + gr_log_badprocpid("mem");
65670 + return 0;
65671 + }
65672 +#endif
65673 +
65674 if (!mm)
65675 return 0;
65676
65677 @@ -663,7 +737,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
65678 goto free;
65679
65680 while (count > 0) {
65681 - int this_len = min_t(int, count, PAGE_SIZE);
65682 + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
65683
65684 if (write && copy_from_user(page, buf, this_len)) {
65685 copied = -EFAULT;
65686 @@ -755,6 +829,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
65687 if (!mm)
65688 return 0;
65689
65690 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65691 + if (file->f_version != current->exec_id) {
65692 + gr_log_badprocpid("environ");
65693 + return 0;
65694 + }
65695 +#endif
65696 +
65697 page = (char *)__get_free_page(GFP_TEMPORARY);
65698 if (!page)
65699 return -ENOMEM;
65700 @@ -764,7 +845,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
65701 goto free;
65702 while (count > 0) {
65703 size_t this_len, max_len;
65704 - int retval;
65705 + ssize_t retval;
65706
65707 if (src >= (mm->env_end - mm->env_start))
65708 break;
65709 @@ -1378,7 +1459,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
65710 int error = -EACCES;
65711
65712 /* Are we allowed to snoop on the tasks file descriptors? */
65713 - if (!proc_fd_access_allowed(inode))
65714 + if (!proc_fd_access_allowed(inode, 0))
65715 goto out;
65716
65717 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
65718 @@ -1422,8 +1503,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
65719 struct path path;
65720
65721 /* Are we allowed to snoop on the tasks file descriptors? */
65722 - if (!proc_fd_access_allowed(inode))
65723 - goto out;
65724 + /* logging this is needed for learning on chromium to work properly,
65725 + but we don't want to flood the logs from 'ps' which does a readlink
65726 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
65727 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
65728 + */
65729 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
65730 + if (!proc_fd_access_allowed(inode,0))
65731 + goto out;
65732 + } else {
65733 + if (!proc_fd_access_allowed(inode,1))
65734 + goto out;
65735 + }
65736
65737 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
65738 if (error)
65739 @@ -1473,7 +1564,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
65740 rcu_read_lock();
65741 cred = __task_cred(task);
65742 inode->i_uid = cred->euid;
65743 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
65744 + inode->i_gid = grsec_proc_gid;
65745 +#else
65746 inode->i_gid = cred->egid;
65747 +#endif
65748 rcu_read_unlock();
65749 }
65750 security_task_to_inode(task, inode);
65751 @@ -1509,10 +1604,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
65752 return -ENOENT;
65753 }
65754 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
65755 +#ifdef CONFIG_GRKERNSEC_PROC_USER
65756 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
65757 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65758 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
65759 +#endif
65760 task_dumpable(task)) {
65761 cred = __task_cred(task);
65762 stat->uid = cred->euid;
65763 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
65764 + stat->gid = grsec_proc_gid;
65765 +#else
65766 stat->gid = cred->egid;
65767 +#endif
65768 }
65769 }
65770 rcu_read_unlock();
65771 @@ -1550,11 +1654,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
65772
65773 if (task) {
65774 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
65775 +#ifdef CONFIG_GRKERNSEC_PROC_USER
65776 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
65777 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65778 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
65779 +#endif
65780 task_dumpable(task)) {
65781 rcu_read_lock();
65782 cred = __task_cred(task);
65783 inode->i_uid = cred->euid;
65784 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
65785 + inode->i_gid = grsec_proc_gid;
65786 +#else
65787 inode->i_gid = cred->egid;
65788 +#endif
65789 rcu_read_unlock();
65790 } else {
65791 inode->i_uid = GLOBAL_ROOT_UID;
65792 @@ -2085,6 +2198,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
65793 if (!task)
65794 goto out_no_task;
65795
65796 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
65797 + goto out;
65798 +
65799 /*
65800 * Yes, it does not scale. And it should not. Don't add
65801 * new entries into /proc/<tgid>/ without very good reasons.
65802 @@ -2115,6 +2231,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
65803 if (!task)
65804 return -ENOENT;
65805
65806 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
65807 + goto out;
65808 +
65809 if (!dir_emit_dots(file, ctx))
65810 goto out;
65811
65812 @@ -2506,7 +2625,7 @@ static const struct pid_entry tgid_base_stuff[] = {
65813 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
65814 #endif
65815 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
65816 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
65817 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
65818 ONE("syscall", S_IRUSR, proc_pid_syscall),
65819 #endif
65820 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
65821 @@ -2531,10 +2650,10 @@ static const struct pid_entry tgid_base_stuff[] = {
65822 #ifdef CONFIG_SECURITY
65823 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
65824 #endif
65825 -#ifdef CONFIG_KALLSYMS
65826 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65827 ONE("wchan", S_IRUGO, proc_pid_wchan),
65828 #endif
65829 -#ifdef CONFIG_STACKTRACE
65830 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65831 ONE("stack", S_IRUSR, proc_pid_stack),
65832 #endif
65833 #ifdef CONFIG_SCHEDSTATS
65834 @@ -2568,6 +2687,9 @@ static const struct pid_entry tgid_base_stuff[] = {
65835 #ifdef CONFIG_HARDWALL
65836 ONE("hardwall", S_IRUGO, proc_pid_hardwall),
65837 #endif
65838 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
65839 + ONE("ipaddr", S_IRUSR, proc_pid_ipaddr),
65840 +#endif
65841 #ifdef CONFIG_USER_NS
65842 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
65843 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
65844 @@ -2696,7 +2818,14 @@ static int proc_pid_instantiate(struct inode *dir,
65845 if (!inode)
65846 goto out;
65847
65848 +#ifdef CONFIG_GRKERNSEC_PROC_USER
65849 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
65850 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65851 + inode->i_gid = grsec_proc_gid;
65852 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
65853 +#else
65854 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
65855 +#endif
65856 inode->i_op = &proc_tgid_base_inode_operations;
65857 inode->i_fop = &proc_tgid_base_operations;
65858 inode->i_flags|=S_IMMUTABLE;
65859 @@ -2734,7 +2863,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
65860 if (!task)
65861 goto out;
65862
65863 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
65864 + goto out_put_task;
65865 +
65866 result = proc_pid_instantiate(dir, dentry, task, NULL);
65867 +out_put_task:
65868 put_task_struct(task);
65869 out:
65870 return ERR_PTR(result);
65871 @@ -2848,7 +2981,7 @@ static const struct pid_entry tid_base_stuff[] = {
65872 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
65873 #endif
65874 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
65875 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
65876 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
65877 ONE("syscall", S_IRUSR, proc_pid_syscall),
65878 #endif
65879 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
65880 @@ -2875,10 +3008,10 @@ static const struct pid_entry tid_base_stuff[] = {
65881 #ifdef CONFIG_SECURITY
65882 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
65883 #endif
65884 -#ifdef CONFIG_KALLSYMS
65885 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65886 ONE("wchan", S_IRUGO, proc_pid_wchan),
65887 #endif
65888 -#ifdef CONFIG_STACKTRACE
65889 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65890 ONE("stack", S_IRUSR, proc_pid_stack),
65891 #endif
65892 #ifdef CONFIG_SCHEDSTATS
65893 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
65894 index cbd82df..c0407d2 100644
65895 --- a/fs/proc/cmdline.c
65896 +++ b/fs/proc/cmdline.c
65897 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
65898
65899 static int __init proc_cmdline_init(void)
65900 {
65901 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
65902 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
65903 +#else
65904 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
65905 +#endif
65906 return 0;
65907 }
65908 fs_initcall(proc_cmdline_init);
65909 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
65910 index 50493ed..248166b 100644
65911 --- a/fs/proc/devices.c
65912 +++ b/fs/proc/devices.c
65913 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
65914
65915 static int __init proc_devices_init(void)
65916 {
65917 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
65918 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
65919 +#else
65920 proc_create("devices", 0, NULL, &proc_devinfo_operations);
65921 +#endif
65922 return 0;
65923 }
65924 fs_initcall(proc_devices_init);
65925 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
65926 index e11d7c5..9128ce06 100644
65927 --- a/fs/proc/fd.c
65928 +++ b/fs/proc/fd.c
65929 @@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
65930 if (!task)
65931 return -ENOENT;
65932
65933 - files = get_files_struct(task);
65934 + if (!gr_acl_handle_procpidmem(task))
65935 + files = get_files_struct(task);
65936 put_task_struct(task);
65937
65938 if (files) {
65939 @@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
65940 */
65941 int proc_fd_permission(struct inode *inode, int mask)
65942 {
65943 + struct task_struct *task;
65944 int rv = generic_permission(inode, mask);
65945 - if (rv == 0)
65946 - return 0;
65947 +
65948 if (task_tgid(current) == proc_pid(inode))
65949 rv = 0;
65950 +
65951 + task = get_proc_task(inode);
65952 + if (task == NULL)
65953 + return rv;
65954 +
65955 + if (gr_acl_handle_procpidmem(task))
65956 + rv = -EACCES;
65957 +
65958 + put_task_struct(task);
65959 +
65960 return rv;
65961 }
65962
65963 diff --git a/fs/proc/generic.c b/fs/proc/generic.c
65964 index 317b726..e329aed 100644
65965 --- a/fs/proc/generic.c
65966 +++ b/fs/proc/generic.c
65967 @@ -23,6 +23,7 @@
65968 #include <linux/bitops.h>
65969 #include <linux/spinlock.h>
65970 #include <linux/completion.h>
65971 +#include <linux/grsecurity.h>
65972 #include <asm/uaccess.h>
65973
65974 #include "internal.h"
65975 @@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
65976 return proc_lookup_de(PDE(dir), dir, dentry);
65977 }
65978
65979 +struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
65980 + unsigned int flags)
65981 +{
65982 + if (gr_proc_is_restricted())
65983 + return ERR_PTR(-EACCES);
65984 +
65985 + return proc_lookup_de(PDE(dir), dir, dentry);
65986 +}
65987 +
65988 /*
65989 * This returns non-zero if at EOF, so that the /proc
65990 * root directory can use this and check if it should
65991 @@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
65992 return proc_readdir_de(PDE(inode), file, ctx);
65993 }
65994
65995 +int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
65996 +{
65997 + struct inode *inode = file_inode(file);
65998 +
65999 + if (gr_proc_is_restricted())
66000 + return -EACCES;
66001 +
66002 + return proc_readdir_de(PDE(inode), file, ctx);
66003 +}
66004 +
66005 /*
66006 * These are the generic /proc directory operations. They
66007 * use the in-memory "struct proc_dir_entry" tree to parse
66008 @@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
66009 .iterate = proc_readdir,
66010 };
66011
66012 +static const struct file_operations proc_dir_restricted_operations = {
66013 + .llseek = generic_file_llseek,
66014 + .read = generic_read_dir,
66015 + .iterate = proc_readdir_restrict,
66016 +};
66017 +
66018 /*
66019 * proc directories can do almost nothing..
66020 */
66021 @@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
66022 .setattr = proc_notify_change,
66023 };
66024
66025 +static const struct inode_operations proc_dir_restricted_inode_operations = {
66026 + .lookup = proc_lookup_restrict,
66027 + .getattr = proc_getattr,
66028 + .setattr = proc_notify_change,
66029 +};
66030 +
66031 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
66032 {
66033 struct proc_dir_entry *tmp;
66034 @@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
66035 return ret;
66036
66037 if (S_ISDIR(dp->mode)) {
66038 - dp->proc_fops = &proc_dir_operations;
66039 - dp->proc_iops = &proc_dir_inode_operations;
66040 + if (dp->restricted) {
66041 + dp->proc_fops = &proc_dir_restricted_operations;
66042 + dp->proc_iops = &proc_dir_restricted_inode_operations;
66043 + } else {
66044 + dp->proc_fops = &proc_dir_operations;
66045 + dp->proc_iops = &proc_dir_inode_operations;
66046 + }
66047 dir->nlink++;
66048 } else if (S_ISLNK(dp->mode)) {
66049 dp->proc_iops = &proc_link_inode_operations;
66050 @@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
66051 }
66052 EXPORT_SYMBOL_GPL(proc_mkdir_data);
66053
66054 +struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
66055 + struct proc_dir_entry *parent, void *data)
66056 +{
66057 + struct proc_dir_entry *ent;
66058 +
66059 + if (mode == 0)
66060 + mode = S_IRUGO | S_IXUGO;
66061 +
66062 + ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
66063 + if (ent) {
66064 + ent->data = data;
66065 + ent->restricted = 1;
66066 + if (proc_register(parent, ent) < 0) {
66067 + kfree(ent);
66068 + ent = NULL;
66069 + }
66070 + }
66071 + return ent;
66072 +}
66073 +EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
66074 +
66075 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
66076 struct proc_dir_entry *parent)
66077 {
66078 @@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
66079 }
66080 EXPORT_SYMBOL(proc_mkdir);
66081
66082 +struct proc_dir_entry *proc_mkdir_restrict(const char *name,
66083 + struct proc_dir_entry *parent)
66084 +{
66085 + return proc_mkdir_data_restrict(name, 0, parent, NULL);
66086 +}
66087 +EXPORT_SYMBOL(proc_mkdir_restrict);
66088 +
66089 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
66090 struct proc_dir_entry *parent,
66091 const struct file_operations *proc_fops,
66092 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
66093 index 333080d..0a35ec4 100644
66094 --- a/fs/proc/inode.c
66095 +++ b/fs/proc/inode.c
66096 @@ -23,11 +23,17 @@
66097 #include <linux/slab.h>
66098 #include <linux/mount.h>
66099 #include <linux/magic.h>
66100 +#include <linux/grsecurity.h>
66101
66102 #include <asm/uaccess.h>
66103
66104 #include "internal.h"
66105
66106 +#ifdef CONFIG_PROC_SYSCTL
66107 +extern const struct inode_operations proc_sys_inode_operations;
66108 +extern const struct inode_operations proc_sys_dir_operations;
66109 +#endif
66110 +
66111 static void proc_evict_inode(struct inode *inode)
66112 {
66113 struct proc_dir_entry *de;
66114 @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
66115 ns = PROC_I(inode)->ns.ns;
66116 if (ns_ops && ns)
66117 ns_ops->put(ns);
66118 +
66119 +#ifdef CONFIG_PROC_SYSCTL
66120 + if (inode->i_op == &proc_sys_inode_operations ||
66121 + inode->i_op == &proc_sys_dir_operations)
66122 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
66123 +#endif
66124 +
66125 }
66126
66127 static struct kmem_cache * proc_inode_cachep;
66128 @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
66129 if (de->mode) {
66130 inode->i_mode = de->mode;
66131 inode->i_uid = de->uid;
66132 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66133 + inode->i_gid = grsec_proc_gid;
66134 +#else
66135 inode->i_gid = de->gid;
66136 +#endif
66137 }
66138 if (de->size)
66139 inode->i_size = de->size;
66140 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
66141 index aa7a0ee..f2318df 100644
66142 --- a/fs/proc/internal.h
66143 +++ b/fs/proc/internal.h
66144 @@ -46,9 +46,10 @@ struct proc_dir_entry {
66145 struct completion *pde_unload_completion;
66146 struct list_head pde_openers; /* who did ->open, but not ->release */
66147 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
66148 + u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
66149 u8 namelen;
66150 char name[];
66151 -};
66152 +} __randomize_layout;
66153
66154 union proc_op {
66155 int (*proc_get_link)(struct dentry *, struct path *);
66156 @@ -66,7 +67,7 @@ struct proc_inode {
66157 struct ctl_table *sysctl_entry;
66158 struct proc_ns ns;
66159 struct inode vfs_inode;
66160 -};
66161 +} __randomize_layout;
66162
66163 /*
66164 * General functions
66165 @@ -154,6 +155,10 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
66166 struct pid *, struct task_struct *);
66167 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
66168 struct pid *, struct task_struct *);
66169 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66170 +extern int proc_pid_ipaddr(struct seq_file *, struct pid_namespace *,
66171 + struct pid *, struct task_struct *);
66172 +#endif
66173
66174 /*
66175 * base.c
66176 @@ -178,9 +183,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
66177 * generic.c
66178 */
66179 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
66180 +extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
66181 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
66182 struct dentry *);
66183 extern int proc_readdir(struct file *, struct dir_context *);
66184 +extern int proc_readdir_restrict(struct file *, struct dir_context *);
66185 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
66186
66187 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
66188 diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
66189 index a352d57..cb94a5c 100644
66190 --- a/fs/proc/interrupts.c
66191 +++ b/fs/proc/interrupts.c
66192 @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
66193
66194 static int __init proc_interrupts_init(void)
66195 {
66196 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66197 + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
66198 +#else
66199 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
66200 +#endif
66201 return 0;
66202 }
66203 fs_initcall(proc_interrupts_init);
66204 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
66205 index 91a4e64..cb007c0 100644
66206 --- a/fs/proc/kcore.c
66207 +++ b/fs/proc/kcore.c
66208 @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66209 * the addresses in the elf_phdr on our list.
66210 */
66211 start = kc_offset_to_vaddr(*fpos - elf_buflen);
66212 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
66213 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
66214 + if (tsz > buflen)
66215 tsz = buflen;
66216 -
66217 +
66218 while (buflen) {
66219 struct kcore_list *m;
66220
66221 @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66222 kfree(elf_buf);
66223 } else {
66224 if (kern_addr_valid(start)) {
66225 - unsigned long n;
66226 + char *elf_buf;
66227 + mm_segment_t oldfs;
66228
66229 - n = copy_to_user(buffer, (char *)start, tsz);
66230 - /*
66231 - * We cannot distinguish between fault on source
66232 - * and fault on destination. When this happens
66233 - * we clear too and hope it will trigger the
66234 - * EFAULT again.
66235 - */
66236 - if (n) {
66237 - if (clear_user(buffer + tsz - n,
66238 - n))
66239 + elf_buf = kmalloc(tsz, GFP_KERNEL);
66240 + if (!elf_buf)
66241 + return -ENOMEM;
66242 + oldfs = get_fs();
66243 + set_fs(KERNEL_DS);
66244 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
66245 + set_fs(oldfs);
66246 + if (copy_to_user(buffer, elf_buf, tsz)) {
66247 + kfree(elf_buf);
66248 return -EFAULT;
66249 + }
66250 }
66251 + set_fs(oldfs);
66252 + kfree(elf_buf);
66253 } else {
66254 if (clear_user(buffer, tsz))
66255 return -EFAULT;
66256 @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66257
66258 static int open_kcore(struct inode *inode, struct file *filp)
66259 {
66260 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66261 + return -EPERM;
66262 +#endif
66263 if (!capable(CAP_SYS_RAWIO))
66264 return -EPERM;
66265 if (kcore_need_update)
66266 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
66267 index aa1eee0..03dda72 100644
66268 --- a/fs/proc/meminfo.c
66269 +++ b/fs/proc/meminfo.c
66270 @@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
66271 vmi.used >> 10,
66272 vmi.largest_chunk >> 10
66273 #ifdef CONFIG_MEMORY_FAILURE
66274 - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
66275 + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
66276 #endif
66277 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
66278 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
66279 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
66280 index d4a3574..b421ce9 100644
66281 --- a/fs/proc/nommu.c
66282 +++ b/fs/proc/nommu.c
66283 @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
66284
66285 if (file) {
66286 seq_pad(m, ' ');
66287 - seq_path(m, &file->f_path, "");
66288 + seq_path(m, &file->f_path, "\n\\");
66289 }
66290
66291 seq_putc(m, '\n');
66292 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
66293 index a63af3e..b4f262a 100644
66294 --- a/fs/proc/proc_net.c
66295 +++ b/fs/proc/proc_net.c
66296 @@ -23,9 +23,27 @@
66297 #include <linux/nsproxy.h>
66298 #include <net/net_namespace.h>
66299 #include <linux/seq_file.h>
66300 +#include <linux/grsecurity.h>
66301
66302 #include "internal.h"
66303
66304 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
66305 +static struct seq_operations *ipv6_seq_ops_addr;
66306 +
66307 +void register_ipv6_seq_ops_addr(struct seq_operations *addr)
66308 +{
66309 + ipv6_seq_ops_addr = addr;
66310 +}
66311 +
66312 +void unregister_ipv6_seq_ops_addr(void)
66313 +{
66314 + ipv6_seq_ops_addr = NULL;
66315 +}
66316 +
66317 +EXPORT_SYMBOL_GPL(register_ipv6_seq_ops_addr);
66318 +EXPORT_SYMBOL_GPL(unregister_ipv6_seq_ops_addr);
66319 +#endif
66320 +
66321 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
66322 {
66323 return pde->parent->data;
66324 @@ -36,6 +54,8 @@ static struct net *get_proc_net(const struct inode *inode)
66325 return maybe_get_net(PDE_NET(PDE(inode)));
66326 }
66327
66328 +extern const struct seq_operations dev_seq_ops;
66329 +
66330 int seq_open_net(struct inode *ino, struct file *f,
66331 const struct seq_operations *ops, int size)
66332 {
66333 @@ -44,6 +64,14 @@ int seq_open_net(struct inode *ino, struct file *f,
66334
66335 BUG_ON(size < sizeof(*p));
66336
66337 + /* only permit access to /proc/net/dev */
66338 + if (
66339 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
66340 + ops != ipv6_seq_ops_addr &&
66341 +#endif
66342 + ops != &dev_seq_ops && gr_proc_is_restricted())
66343 + return -EACCES;
66344 +
66345 net = get_proc_net(ino);
66346 if (net == NULL)
66347 return -ENXIO;
66348 @@ -66,6 +94,9 @@ int single_open_net(struct inode *inode, struct file *file,
66349 int err;
66350 struct net *net;
66351
66352 + if (gr_proc_is_restricted())
66353 + return -EACCES;
66354 +
66355 err = -ENXIO;
66356 net = get_proc_net(inode);
66357 if (net == NULL)
66358 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
66359 index f92d5dd..26398ac 100644
66360 --- a/fs/proc/proc_sysctl.c
66361 +++ b/fs/proc/proc_sysctl.c
66362 @@ -11,13 +11,21 @@
66363 #include <linux/namei.h>
66364 #include <linux/mm.h>
66365 #include <linux/module.h>
66366 +#include <linux/nsproxy.h>
66367 +#ifdef CONFIG_GRKERNSEC
66368 +#include <net/net_namespace.h>
66369 +#endif
66370 #include "internal.h"
66371
66372 +extern int gr_handle_chroot_sysctl(const int op);
66373 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
66374 + const int op);
66375 +
66376 static const struct dentry_operations proc_sys_dentry_operations;
66377 static const struct file_operations proc_sys_file_operations;
66378 -static const struct inode_operations proc_sys_inode_operations;
66379 +const struct inode_operations proc_sys_inode_operations;
66380 static const struct file_operations proc_sys_dir_file_operations;
66381 -static const struct inode_operations proc_sys_dir_operations;
66382 +const struct inode_operations proc_sys_dir_operations;
66383
66384 void proc_sys_poll_notify(struct ctl_table_poll *poll)
66385 {
66386 @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
66387
66388 err = NULL;
66389 d_set_d_op(dentry, &proc_sys_dentry_operations);
66390 +
66391 + gr_handle_proc_create(dentry, inode);
66392 +
66393 d_add(dentry, inode);
66394
66395 out:
66396 @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66397 struct inode *inode = file_inode(filp);
66398 struct ctl_table_header *head = grab_header(inode);
66399 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
66400 + int op = write ? MAY_WRITE : MAY_READ;
66401 ssize_t error;
66402 size_t res;
66403
66404 @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66405 * and won't be until we finish.
66406 */
66407 error = -EPERM;
66408 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
66409 + if (sysctl_perm(head, table, op))
66410 goto out;
66411
66412 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
66413 @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66414 if (!table->proc_handler)
66415 goto out;
66416
66417 +#ifdef CONFIG_GRKERNSEC
66418 + error = -EPERM;
66419 + if (gr_handle_chroot_sysctl(op))
66420 + goto out;
66421 + dget(filp->f_path.dentry);
66422 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
66423 + dput(filp->f_path.dentry);
66424 + goto out;
66425 + }
66426 + dput(filp->f_path.dentry);
66427 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
66428 + goto out;
66429 + if (write) {
66430 + if (current->nsproxy->net_ns != table->extra2) {
66431 + if (!capable(CAP_SYS_ADMIN))
66432 + goto out;
66433 + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
66434 + goto out;
66435 + }
66436 +#endif
66437 +
66438 /* careful: calling conventions are nasty here */
66439 res = count;
66440 error = table->proc_handler(table, write, buf, &res, ppos);
66441 @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
66442 return false;
66443 } else {
66444 d_set_d_op(child, &proc_sys_dentry_operations);
66445 +
66446 + gr_handle_proc_create(child, inode);
66447 +
66448 d_add(child, inode);
66449 }
66450 } else {
66451 @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, struct ctl_table *table,
66452 if ((*pos)++ < ctx->pos)
66453 return true;
66454
66455 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
66456 + return 0;
66457 +
66458 if (unlikely(S_ISLNK(table->mode)))
66459 res = proc_sys_link_fill_cache(file, ctx, head, table);
66460 else
66461 @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
66462 if (IS_ERR(head))
66463 return PTR_ERR(head);
66464
66465 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
66466 + return -ENOENT;
66467 +
66468 generic_fillattr(inode, stat);
66469 if (table)
66470 stat->mode = (stat->mode & S_IFMT) | table->mode;
66471 @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
66472 .llseek = generic_file_llseek,
66473 };
66474
66475 -static const struct inode_operations proc_sys_inode_operations = {
66476 +const struct inode_operations proc_sys_inode_operations = {
66477 .permission = proc_sys_permission,
66478 .setattr = proc_sys_setattr,
66479 .getattr = proc_sys_getattr,
66480 };
66481
66482 -static const struct inode_operations proc_sys_dir_operations = {
66483 +const struct inode_operations proc_sys_dir_operations = {
66484 .lookup = proc_sys_lookup,
66485 .permission = proc_sys_permission,
66486 .setattr = proc_sys_setattr,
66487 @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
66488 static struct ctl_dir *new_dir(struct ctl_table_set *set,
66489 const char *name, int namelen)
66490 {
66491 - struct ctl_table *table;
66492 + ctl_table_no_const *table;
66493 struct ctl_dir *new;
66494 struct ctl_node *node;
66495 char *new_name;
66496 @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
66497 return NULL;
66498
66499 node = (struct ctl_node *)(new + 1);
66500 - table = (struct ctl_table *)(node + 1);
66501 + table = (ctl_table_no_const *)(node + 1);
66502 new_name = (char *)(table + 2);
66503 memcpy(new_name, name, namelen);
66504 new_name[namelen] = '\0';
66505 @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
66506 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
66507 struct ctl_table_root *link_root)
66508 {
66509 - struct ctl_table *link_table, *entry, *link;
66510 + ctl_table_no_const *link_table, *link;
66511 + struct ctl_table *entry;
66512 struct ctl_table_header *links;
66513 struct ctl_node *node;
66514 char *link_name;
66515 @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
66516 return NULL;
66517
66518 node = (struct ctl_node *)(links + 1);
66519 - link_table = (struct ctl_table *)(node + nr_entries);
66520 + link_table = (ctl_table_no_const *)(node + nr_entries);
66521 link_name = (char *)&link_table[nr_entries + 1];
66522
66523 for (link = link_table, entry = table; entry->procname; link++, entry++) {
66524 @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66525 struct ctl_table_header ***subheader, struct ctl_table_set *set,
66526 struct ctl_table *table)
66527 {
66528 - struct ctl_table *ctl_table_arg = NULL;
66529 - struct ctl_table *entry, *files;
66530 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
66531 + struct ctl_table *entry;
66532 int nr_files = 0;
66533 int nr_dirs = 0;
66534 int err = -ENOMEM;
66535 @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66536 nr_files++;
66537 }
66538
66539 - files = table;
66540 /* If there are mixed files and directories we need a new table */
66541 if (nr_dirs && nr_files) {
66542 - struct ctl_table *new;
66543 + ctl_table_no_const *new;
66544 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
66545 GFP_KERNEL);
66546 if (!files)
66547 @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66548 /* Register everything except a directory full of subdirectories */
66549 if (nr_files || !nr_dirs) {
66550 struct ctl_table_header *header;
66551 - header = __register_sysctl_table(set, path, files);
66552 + header = __register_sysctl_table(set, path, files ? files : table);
66553 if (!header) {
66554 kfree(ctl_table_arg);
66555 goto out;
66556 diff --git a/fs/proc/root.c b/fs/proc/root.c
66557 index 094e44d..085a877 100644
66558 --- a/fs/proc/root.c
66559 +++ b/fs/proc/root.c
66560 @@ -188,7 +188,15 @@ void __init proc_root_init(void)
66561 proc_mkdir("openprom", NULL);
66562 #endif
66563 proc_tty_init();
66564 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66565 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66566 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
66567 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66568 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
66569 +#endif
66570 +#else
66571 proc_mkdir("bus", NULL);
66572 +#endif
66573 proc_sys_init();
66574 }
66575
66576 diff --git a/fs/proc/stat.c b/fs/proc/stat.c
66577 index bf2d03f..f058f9c 100644
66578 --- a/fs/proc/stat.c
66579 +++ b/fs/proc/stat.c
66580 @@ -11,6 +11,7 @@
66581 #include <linux/irqnr.h>
66582 #include <linux/cputime.h>
66583 #include <linux/tick.h>
66584 +#include <linux/grsecurity.h>
66585
66586 #ifndef arch_irq_stat_cpu
66587 #define arch_irq_stat_cpu(cpu) 0
66588 @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
66589 u64 sum_softirq = 0;
66590 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
66591 struct timespec boottime;
66592 + int unrestricted = 1;
66593 +
66594 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66595 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66596 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
66597 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66598 + && !in_group_p(grsec_proc_gid)
66599 +#endif
66600 + )
66601 + unrestricted = 0;
66602 +#endif
66603 +#endif
66604
66605 user = nice = system = idle = iowait =
66606 irq = softirq = steal = 0;
66607 @@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
66608 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
66609 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
66610 idle += get_idle_time(i);
66611 - iowait += get_iowait_time(i);
66612 - irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
66613 - softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
66614 - steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
66615 - guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
66616 - guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
66617 - sum += kstat_cpu_irqs_sum(i);
66618 - sum += arch_irq_stat_cpu(i);
66619 + if (unrestricted) {
66620 + iowait += get_iowait_time(i);
66621 + irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
66622 + softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
66623 + steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
66624 + guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
66625 + guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
66626 + sum += kstat_cpu_irqs_sum(i);
66627 + sum += arch_irq_stat_cpu(i);
66628 + for (j = 0; j < NR_SOFTIRQS; j++) {
66629 + unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
66630
66631 - for (j = 0; j < NR_SOFTIRQS; j++) {
66632 - unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
66633 -
66634 - per_softirq_sums[j] += softirq_stat;
66635 - sum_softirq += softirq_stat;
66636 + per_softirq_sums[j] += softirq_stat;
66637 + sum_softirq += softirq_stat;
66638 + }
66639 }
66640 }
66641 - sum += arch_irq_stat();
66642 + if (unrestricted)
66643 + sum += arch_irq_stat();
66644
66645 seq_puts(p, "cpu ");
66646 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
66647 @@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
66648 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
66649 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
66650 idle = get_idle_time(i);
66651 - iowait = get_iowait_time(i);
66652 - irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
66653 - softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
66654 - steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
66655 - guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
66656 - guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
66657 + if (unrestricted) {
66658 + iowait = get_iowait_time(i);
66659 + irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
66660 + softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
66661 + steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
66662 + guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
66663 + guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
66664 + }
66665 seq_printf(p, "cpu%d", i);
66666 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
66667 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
66668 @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
66669
66670 /* sum again ? it could be updated? */
66671 for_each_irq_nr(j)
66672 - seq_put_decimal_ull(p, ' ', kstat_irqs(j));
66673 + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
66674
66675 seq_printf(p,
66676 "\nctxt %llu\n"
66677 @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
66678 "processes %lu\n"
66679 "procs_running %lu\n"
66680 "procs_blocked %lu\n",
66681 - nr_context_switches(),
66682 + unrestricted ? nr_context_switches() : 0ULL,
66683 (unsigned long)jif,
66684 - total_forks,
66685 - nr_running(),
66686 - nr_iowait());
66687 + unrestricted ? total_forks : 0UL,
66688 + unrestricted ? nr_running() : 0UL,
66689 + unrestricted ? nr_iowait() : 0UL);
66690
66691 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
66692
66693 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
66694 index 4e0388c..fc6a0e1 100644
66695 --- a/fs/proc/task_mmu.c
66696 +++ b/fs/proc/task_mmu.c
66697 @@ -13,12 +13,19 @@
66698 #include <linux/swap.h>
66699 #include <linux/swapops.h>
66700 #include <linux/mmu_notifier.h>
66701 +#include <linux/grsecurity.h>
66702
66703 #include <asm/elf.h>
66704 #include <asm/uaccess.h>
66705 #include <asm/tlbflush.h>
66706 #include "internal.h"
66707
66708 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66709 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
66710 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
66711 + _mm->pax_flags & MF_PAX_SEGMEXEC))
66712 +#endif
66713 +
66714 void task_mem(struct seq_file *m, struct mm_struct *mm)
66715 {
66716 unsigned long data, text, lib, swap;
66717 @@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
66718 "VmExe:\t%8lu kB\n"
66719 "VmLib:\t%8lu kB\n"
66720 "VmPTE:\t%8lu kB\n"
66721 - "VmSwap:\t%8lu kB\n",
66722 - hiwater_vm << (PAGE_SHIFT-10),
66723 + "VmSwap:\t%8lu kB\n"
66724 +
66725 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
66726 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
66727 +#endif
66728 +
66729 + ,hiwater_vm << (PAGE_SHIFT-10),
66730 total_vm << (PAGE_SHIFT-10),
66731 mm->locked_vm << (PAGE_SHIFT-10),
66732 mm->pinned_vm << (PAGE_SHIFT-10),
66733 @@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
66734 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
66735 (PTRS_PER_PTE * sizeof(pte_t) *
66736 atomic_long_read(&mm->nr_ptes)) >> 10,
66737 - swap << (PAGE_SHIFT-10));
66738 + swap << (PAGE_SHIFT-10)
66739 +
66740 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
66741 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66742 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
66743 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
66744 +#else
66745 + , mm->context.user_cs_base
66746 + , mm->context.user_cs_limit
66747 +#endif
66748 +#endif
66749 +
66750 + );
66751 }
66752
66753 unsigned long task_vsize(struct mm_struct *mm)
66754 @@ -282,13 +306,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
66755 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
66756 }
66757
66758 - /* We don't show the stack guard page in /proc/maps */
66759 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66760 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
66761 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
66762 +#else
66763 start = vma->vm_start;
66764 - if (stack_guard_page_start(vma, start))
66765 - start += PAGE_SIZE;
66766 end = vma->vm_end;
66767 - if (stack_guard_page_end(vma, end))
66768 - end -= PAGE_SIZE;
66769 +#endif
66770
66771 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
66772 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
66773 @@ -298,7 +322,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
66774 flags & VM_WRITE ? 'w' : '-',
66775 flags & VM_EXEC ? 'x' : '-',
66776 flags & VM_MAYSHARE ? 's' : 'p',
66777 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66778 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
66779 +#else
66780 pgoff,
66781 +#endif
66782 MAJOR(dev), MINOR(dev), ino);
66783
66784 /*
66785 @@ -307,7 +335,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
66786 */
66787 if (file) {
66788 seq_pad(m, ' ');
66789 - seq_path(m, &file->f_path, "\n");
66790 + seq_path(m, &file->f_path, "\n\\");
66791 goto done;
66792 }
66793
66794 @@ -338,8 +366,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
66795 * Thread stack in /proc/PID/task/TID/maps or
66796 * the main process stack.
66797 */
66798 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
66799 - vma->vm_end >= mm->start_stack)) {
66800 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
66801 + (vma->vm_start <= mm->start_stack &&
66802 + vma->vm_end >= mm->start_stack)) {
66803 name = "[stack]";
66804 } else {
66805 /* Thread stack in /proc/PID/maps */
66806 @@ -359,6 +388,12 @@ done:
66807
66808 static int show_map(struct seq_file *m, void *v, int is_pid)
66809 {
66810 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66811 + if (current->exec_id != m->exec_id) {
66812 + gr_log_badprocpid("maps");
66813 + return 0;
66814 + }
66815 +#endif
66816 show_map_vma(m, v, is_pid);
66817 m_cache_vma(m, v);
66818 return 0;
66819 @@ -594,12 +629,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
66820 .private = &mss,
66821 };
66822
66823 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66824 + if (current->exec_id != m->exec_id) {
66825 + gr_log_badprocpid("smaps");
66826 + return 0;
66827 + }
66828 +#endif
66829 memset(&mss, 0, sizeof mss);
66830 - mss.vma = vma;
66831 - /* mmap_sem is held in m_start */
66832 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
66833 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
66834 -
66835 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66836 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
66837 +#endif
66838 + mss.vma = vma;
66839 + /* mmap_sem is held in m_start */
66840 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
66841 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
66842 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66843 + }
66844 +#endif
66845 show_map_vma(m, vma, is_pid);
66846
66847 seq_printf(m,
66848 @@ -617,7 +663,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
66849 "KernelPageSize: %8lu kB\n"
66850 "MMUPageSize: %8lu kB\n"
66851 "Locked: %8lu kB\n",
66852 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66853 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
66854 +#else
66855 (vma->vm_end - vma->vm_start) >> 10,
66856 +#endif
66857 mss.resident >> 10,
66858 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
66859 mss.shared_clean >> 10,
66860 @@ -1447,6 +1497,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
66861 char buffer[64];
66862 int nid;
66863
66864 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66865 + if (current->exec_id != m->exec_id) {
66866 + gr_log_badprocpid("numa_maps");
66867 + return 0;
66868 + }
66869 +#endif
66870 +
66871 if (!mm)
66872 return 0;
66873
66874 @@ -1468,11 +1525,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
66875 mpol_to_str(buffer, sizeof(buffer), proc_priv->task_mempolicy);
66876 }
66877
66878 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66879 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
66880 +#else
66881 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
66882 +#endif
66883
66884 if (file) {
66885 seq_puts(m, " file=");
66886 - seq_path(m, &file->f_path, "\n\t= ");
66887 + seq_path(m, &file->f_path, "\n\t\\= ");
66888 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
66889 seq_puts(m, " heap");
66890 } else {
66891 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
66892 index 599ec2e..f1413ae 100644
66893 --- a/fs/proc/task_nommu.c
66894 +++ b/fs/proc/task_nommu.c
66895 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
66896 else
66897 bytes += kobjsize(mm);
66898
66899 - if (current->fs && current->fs->users > 1)
66900 + if (current->fs && atomic_read(&current->fs->users) > 1)
66901 sbytes += kobjsize(current->fs);
66902 else
66903 bytes += kobjsize(current->fs);
66904 @@ -180,7 +180,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
66905
66906 if (file) {
66907 seq_pad(m, ' ');
66908 - seq_path(m, &file->f_path, "");
66909 + seq_path(m, &file->f_path, "\n\\");
66910 } else if (mm) {
66911 pid_t tid = pid_of_stack(priv, vma, is_pid);
66912
66913 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
66914 index a90d6d35..d08047c 100644
66915 --- a/fs/proc/vmcore.c
66916 +++ b/fs/proc/vmcore.c
66917 @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
66918 nr_bytes = count;
66919
66920 /* If pfn is not ram, return zeros for sparse dump files */
66921 - if (pfn_is_ram(pfn) == 0)
66922 - memset(buf, 0, nr_bytes);
66923 - else {
66924 + if (pfn_is_ram(pfn) == 0) {
66925 + if (userbuf) {
66926 + if (clear_user((char __force_user *)buf, nr_bytes))
66927 + return -EFAULT;
66928 + } else
66929 + memset(buf, 0, nr_bytes);
66930 + } else {
66931 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
66932 offset, userbuf);
66933 if (tmp < 0)
66934 @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
66935 static int copy_to(void *target, void *src, size_t size, int userbuf)
66936 {
66937 if (userbuf) {
66938 - if (copy_to_user((char __user *) target, src, size))
66939 + if (copy_to_user((char __force_user *) target, src, size))
66940 return -EFAULT;
66941 } else {
66942 memcpy(target, src, size);
66943 @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
66944 if (*fpos < m->offset + m->size) {
66945 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
66946 start = m->paddr + *fpos - m->offset;
66947 - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
66948 + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
66949 if (tmp < 0)
66950 return tmp;
66951 buflen -= tsz;
66952 @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
66953 static ssize_t read_vmcore(struct file *file, char __user *buffer,
66954 size_t buflen, loff_t *fpos)
66955 {
66956 - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
66957 + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
66958 }
66959
66960 /*
66961 diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
66962 index d3fb2b6..43a8140 100644
66963 --- a/fs/qnx6/qnx6.h
66964 +++ b/fs/qnx6/qnx6.h
66965 @@ -74,7 +74,7 @@ enum {
66966 BYTESEX_BE,
66967 };
66968
66969 -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
66970 +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
66971 {
66972 if (sbi->s_bytesex == BYTESEX_LE)
66973 return le64_to_cpu((__force __le64)n);
66974 @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
66975 return (__force __fs64)cpu_to_be64(n);
66976 }
66977
66978 -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
66979 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
66980 {
66981 if (sbi->s_bytesex == BYTESEX_LE)
66982 return le32_to_cpu((__force __le32)n);
66983 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
66984 index bb2869f..d34ada8 100644
66985 --- a/fs/quota/netlink.c
66986 +++ b/fs/quota/netlink.c
66987 @@ -44,7 +44,7 @@ static struct genl_family quota_genl_family = {
66988 void quota_send_warning(struct kqid qid, dev_t dev,
66989 const char warntype)
66990 {
66991 - static atomic_t seq;
66992 + static atomic_unchecked_t seq;
66993 struct sk_buff *skb;
66994 void *msg_head;
66995 int ret;
66996 @@ -60,7 +60,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
66997 "VFS: Not enough memory to send quota warning.\n");
66998 return;
66999 }
67000 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
67001 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
67002 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
67003 if (!msg_head) {
67004 printk(KERN_ERR
67005 diff --git a/fs/read_write.c b/fs/read_write.c
67006 index 7d9318c..51b336f 100644
67007 --- a/fs/read_write.c
67008 +++ b/fs/read_write.c
67009 @@ -495,7 +495,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
67010
67011 old_fs = get_fs();
67012 set_fs(get_ds());
67013 - p = (__force const char __user *)buf;
67014 + p = (const char __force_user *)buf;
67015 if (count > MAX_RW_COUNT)
67016 count = MAX_RW_COUNT;
67017 if (file->f_op->write)
67018 diff --git a/fs/readdir.c b/fs/readdir.c
67019 index 33fd922..e0d6094 100644
67020 --- a/fs/readdir.c
67021 +++ b/fs/readdir.c
67022 @@ -18,6 +18,7 @@
67023 #include <linux/security.h>
67024 #include <linux/syscalls.h>
67025 #include <linux/unistd.h>
67026 +#include <linux/namei.h>
67027
67028 #include <asm/uaccess.h>
67029
67030 @@ -71,6 +72,7 @@ struct old_linux_dirent {
67031 struct readdir_callback {
67032 struct dir_context ctx;
67033 struct old_linux_dirent __user * dirent;
67034 + struct file * file;
67035 int result;
67036 };
67037
67038 @@ -88,6 +90,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
67039 buf->result = -EOVERFLOW;
67040 return -EOVERFLOW;
67041 }
67042 +
67043 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67044 + return 0;
67045 +
67046 buf->result++;
67047 dirent = buf->dirent;
67048 if (!access_ok(VERIFY_WRITE, dirent,
67049 @@ -119,6 +125,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
67050 if (!f.file)
67051 return -EBADF;
67052
67053 + buf.file = f.file;
67054 error = iterate_dir(f.file, &buf.ctx);
67055 if (buf.result)
67056 error = buf.result;
67057 @@ -144,6 +151,7 @@ struct getdents_callback {
67058 struct dir_context ctx;
67059 struct linux_dirent __user * current_dir;
67060 struct linux_dirent __user * previous;
67061 + struct file * file;
67062 int count;
67063 int error;
67064 };
67065 @@ -165,6 +173,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
67066 buf->error = -EOVERFLOW;
67067 return -EOVERFLOW;
67068 }
67069 +
67070 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67071 + return 0;
67072 +
67073 dirent = buf->previous;
67074 if (dirent) {
67075 if (__put_user(offset, &dirent->d_off))
67076 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
67077 if (!f.file)
67078 return -EBADF;
67079
67080 + buf.file = f.file;
67081 error = iterate_dir(f.file, &buf.ctx);
67082 if (error >= 0)
67083 error = buf.error;
67084 @@ -228,6 +241,7 @@ struct getdents_callback64 {
67085 struct dir_context ctx;
67086 struct linux_dirent64 __user * current_dir;
67087 struct linux_dirent64 __user * previous;
67088 + struct file *file;
67089 int count;
67090 int error;
67091 };
67092 @@ -243,6 +257,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
67093 buf->error = -EINVAL; /* only used if we fail.. */
67094 if (reclen > buf->count)
67095 return -EINVAL;
67096 +
67097 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67098 + return 0;
67099 +
67100 dirent = buf->previous;
67101 if (dirent) {
67102 if (__put_user(offset, &dirent->d_off))
67103 @@ -290,6 +308,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
67104 if (!f.file)
67105 return -EBADF;
67106
67107 + buf.file = f.file;
67108 error = iterate_dir(f.file, &buf.ctx);
67109 if (error >= 0)
67110 error = buf.error;
67111 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
67112 index 9c02d96..6562c10 100644
67113 --- a/fs/reiserfs/do_balan.c
67114 +++ b/fs/reiserfs/do_balan.c
67115 @@ -1887,7 +1887,7 @@ void do_balance(struct tree_balance *tb, struct item_head *ih,
67116 return;
67117 }
67118
67119 - atomic_inc(&fs_generation(tb->tb_sb));
67120 + atomic_inc_unchecked(&fs_generation(tb->tb_sb));
67121 do_balance_starts(tb);
67122
67123 /*
67124 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
67125 index aca73dd..e3c558d 100644
67126 --- a/fs/reiserfs/item_ops.c
67127 +++ b/fs/reiserfs/item_ops.c
67128 @@ -724,18 +724,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
67129 }
67130
67131 static struct item_operations errcatch_ops = {
67132 - errcatch_bytes_number,
67133 - errcatch_decrement_key,
67134 - errcatch_is_left_mergeable,
67135 - errcatch_print_item,
67136 - errcatch_check_item,
67137 + .bytes_number = errcatch_bytes_number,
67138 + .decrement_key = errcatch_decrement_key,
67139 + .is_left_mergeable = errcatch_is_left_mergeable,
67140 + .print_item = errcatch_print_item,
67141 + .check_item = errcatch_check_item,
67142
67143 - errcatch_create_vi,
67144 - errcatch_check_left,
67145 - errcatch_check_right,
67146 - errcatch_part_size,
67147 - errcatch_unit_num,
67148 - errcatch_print_vi
67149 + .create_vi = errcatch_create_vi,
67150 + .check_left = errcatch_check_left,
67151 + .check_right = errcatch_check_right,
67152 + .part_size = errcatch_part_size,
67153 + .unit_num = errcatch_unit_num,
67154 + .print_vi = errcatch_print_vi
67155 };
67156
67157 #if ! (TYPE_STAT_DATA == 0 && TYPE_INDIRECT == 1 && TYPE_DIRECT == 2 && TYPE_DIRENTRY == 3)
67158 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
67159 index 621b9f3..af527fd 100644
67160 --- a/fs/reiserfs/procfs.c
67161 +++ b/fs/reiserfs/procfs.c
67162 @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
67163 "SMALL_TAILS " : "NO_TAILS ",
67164 replay_only(sb) ? "REPLAY_ONLY " : "",
67165 convert_reiserfs(sb) ? "CONV " : "",
67166 - atomic_read(&r->s_generation_counter),
67167 + atomic_read_unchecked(&r->s_generation_counter),
67168 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
67169 SF(s_do_balance), SF(s_unneeded_left_neighbor),
67170 SF(s_good_search_by_key_reada), SF(s_bmaps),
67171 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
67172 index 1894d96..1dfd1c2 100644
67173 --- a/fs/reiserfs/reiserfs.h
67174 +++ b/fs/reiserfs/reiserfs.h
67175 @@ -576,7 +576,7 @@ struct reiserfs_sb_info {
67176 /* Comment? -Hans */
67177 wait_queue_head_t s_wait;
67178 /* increased by one every time the tree gets re-balanced */
67179 - atomic_t s_generation_counter;
67180 + atomic_unchecked_t s_generation_counter;
67181
67182 /* File system properties. Currently holds on-disk FS format */
67183 unsigned long s_properties;
67184 @@ -2297,7 +2297,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
67185 #define REISERFS_USER_MEM 1 /* user memory mode */
67186
67187 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
67188 -#define get_generation(s) atomic_read (&fs_generation(s))
67189 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
67190 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
67191 #define __fs_changed(gen,s) (gen != get_generation (s))
67192 #define fs_changed(gen,s) \
67193 diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
67194 index f1376c9..f9378e9 100644
67195 --- a/fs/reiserfs/super.c
67196 +++ b/fs/reiserfs/super.c
67197 @@ -1857,6 +1857,10 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
67198 sbi->s_mount_opt |= (1 << REISERFS_SMALLTAIL);
67199 sbi->s_mount_opt |= (1 << REISERFS_ERROR_RO);
67200 sbi->s_mount_opt |= (1 << REISERFS_BARRIER_FLUSH);
67201 +#ifdef CONFIG_REISERFS_FS_XATTR
67202 + /* turn on user xattrs by default */
67203 + sbi->s_mount_opt |= (1 << REISERFS_XATTRS_USER);
67204 +#endif
67205 /* no preallocation minimum, be smart in reiserfs_file_write instead */
67206 sbi->s_alloc_options.preallocmin = 0;
67207 /* Preallocate by 16 blocks (17-1) at once */
67208 diff --git a/fs/select.c b/fs/select.c
67209 index 467bb1c..cf9d65a 100644
67210 --- a/fs/select.c
67211 +++ b/fs/select.c
67212 @@ -20,6 +20,7 @@
67213 #include <linux/export.h>
67214 #include <linux/slab.h>
67215 #include <linux/poll.h>
67216 +#include <linux/security.h>
67217 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
67218 #include <linux/file.h>
67219 #include <linux/fdtable.h>
67220 @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
67221 struct poll_list *walk = head;
67222 unsigned long todo = nfds;
67223
67224 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
67225 if (nfds > rlimit(RLIMIT_NOFILE))
67226 return -EINVAL;
67227
67228 diff --git a/fs/seq_file.c b/fs/seq_file.c
67229 index 3857b72..0b7281e 100644
67230 --- a/fs/seq_file.c
67231 +++ b/fs/seq_file.c
67232 @@ -12,6 +12,8 @@
67233 #include <linux/slab.h>
67234 #include <linux/cred.h>
67235 #include <linux/mm.h>
67236 +#include <linux/sched.h>
67237 +#include <linux/grsecurity.h>
67238
67239 #include <asm/uaccess.h>
67240 #include <asm/page.h>
67241 @@ -34,12 +36,7 @@ static void seq_set_overflow(struct seq_file *m)
67242
67243 static void *seq_buf_alloc(unsigned long size)
67244 {
67245 - void *buf;
67246 -
67247 - buf = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
67248 - if (!buf && size > PAGE_SIZE)
67249 - buf = vmalloc(size);
67250 - return buf;
67251 + return kmalloc(size, GFP_KERNEL | GFP_USERCOPY);
67252 }
67253
67254 /**
67255 @@ -72,6 +69,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
67256 #ifdef CONFIG_USER_NS
67257 p->user_ns = file->f_cred->user_ns;
67258 #endif
67259 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67260 + p->exec_id = current->exec_id;
67261 +#endif
67262
67263 /*
67264 * Wrappers around seq_open(e.g. swaps_open) need to be
67265 @@ -94,6 +94,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
67266 }
67267 EXPORT_SYMBOL(seq_open);
67268
67269 +
67270 +int seq_open_restrict(struct file *file, const struct seq_operations *op)
67271 +{
67272 + if (gr_proc_is_restricted())
67273 + return -EACCES;
67274 +
67275 + return seq_open(file, op);
67276 +}
67277 +EXPORT_SYMBOL(seq_open_restrict);
67278 +
67279 static int traverse(struct seq_file *m, loff_t offset)
67280 {
67281 loff_t pos = 0, index;
67282 @@ -165,7 +175,7 @@ Eoverflow:
67283 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
67284 {
67285 struct seq_file *m = file->private_data;
67286 - size_t copied = 0;
67287 + ssize_t copied = 0;
67288 loff_t pos;
67289 size_t n;
67290 void *p;
67291 @@ -596,7 +606,7 @@ static void single_stop(struct seq_file *p, void *v)
67292 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
67293 void *data)
67294 {
67295 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
67296 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
67297 int res = -ENOMEM;
67298
67299 if (op) {
67300 @@ -632,6 +642,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
67301 }
67302 EXPORT_SYMBOL(single_open_size);
67303
67304 +int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
67305 + void *data)
67306 +{
67307 + if (gr_proc_is_restricted())
67308 + return -EACCES;
67309 +
67310 + return single_open(file, show, data);
67311 +}
67312 +EXPORT_SYMBOL(single_open_restrict);
67313 +
67314 +
67315 int single_release(struct inode *inode, struct file *file)
67316 {
67317 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
67318 diff --git a/fs/splice.c b/fs/splice.c
67319 index 75c6058..770d40c 100644
67320 --- a/fs/splice.c
67321 +++ b/fs/splice.c
67322 @@ -193,7 +193,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67323 pipe_lock(pipe);
67324
67325 for (;;) {
67326 - if (!pipe->readers) {
67327 + if (!atomic_read(&pipe->readers)) {
67328 send_sig(SIGPIPE, current, 0);
67329 if (!ret)
67330 ret = -EPIPE;
67331 @@ -216,7 +216,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67332 page_nr++;
67333 ret += buf->len;
67334
67335 - if (pipe->files)
67336 + if (atomic_read(&pipe->files))
67337 do_wakeup = 1;
67338
67339 if (!--spd->nr_pages)
67340 @@ -247,9 +247,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67341 do_wakeup = 0;
67342 }
67343
67344 - pipe->waiting_writers++;
67345 + atomic_inc(&pipe->waiting_writers);
67346 pipe_wait(pipe);
67347 - pipe->waiting_writers--;
67348 + atomic_dec(&pipe->waiting_writers);
67349 }
67350
67351 pipe_unlock(pipe);
67352 @@ -576,7 +576,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
67353 old_fs = get_fs();
67354 set_fs(get_ds());
67355 /* The cast to a user pointer is valid due to the set_fs() */
67356 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
67357 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
67358 set_fs(old_fs);
67359
67360 return res;
67361 @@ -591,7 +591,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
67362 old_fs = get_fs();
67363 set_fs(get_ds());
67364 /* The cast to a user pointer is valid due to the set_fs() */
67365 - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
67366 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
67367 set_fs(old_fs);
67368
67369 return res;
67370 @@ -644,7 +644,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
67371 goto err;
67372
67373 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
67374 - vec[i].iov_base = (void __user *) page_address(page);
67375 + vec[i].iov_base = (void __force_user *) page_address(page);
67376 vec[i].iov_len = this_len;
67377 spd.pages[i] = page;
67378 spd.nr_pages++;
67379 @@ -783,7 +783,7 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
67380 ops->release(pipe, buf);
67381 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
67382 pipe->nrbufs--;
67383 - if (pipe->files)
67384 + if (atomic_read(&pipe->files))
67385 sd->need_wakeup = true;
67386 }
67387
67388 @@ -807,10 +807,10 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
67389 static int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
67390 {
67391 while (!pipe->nrbufs) {
67392 - if (!pipe->writers)
67393 + if (!atomic_read(&pipe->writers))
67394 return 0;
67395
67396 - if (!pipe->waiting_writers && sd->num_spliced)
67397 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
67398 return 0;
67399
67400 if (sd->flags & SPLICE_F_NONBLOCK)
67401 @@ -1040,7 +1040,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
67402 ops->release(pipe, buf);
67403 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
67404 pipe->nrbufs--;
67405 - if (pipe->files)
67406 + if (atomic_read(&pipe->files))
67407 sd.need_wakeup = true;
67408 } else {
67409 buf->offset += ret;
67410 @@ -1200,7 +1200,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
67411 * out of the pipe right after the splice_to_pipe(). So set
67412 * PIPE_READERS appropriately.
67413 */
67414 - pipe->readers = 1;
67415 + atomic_set(&pipe->readers, 1);
67416
67417 current->splice_pipe = pipe;
67418 }
67419 @@ -1497,6 +1497,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
67420
67421 partial[buffers].offset = off;
67422 partial[buffers].len = plen;
67423 + partial[buffers].private = 0;
67424
67425 off = 0;
67426 len -= plen;
67427 @@ -1733,9 +1734,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67428 ret = -ERESTARTSYS;
67429 break;
67430 }
67431 - if (!pipe->writers)
67432 + if (!atomic_read(&pipe->writers))
67433 break;
67434 - if (!pipe->waiting_writers) {
67435 + if (!atomic_read(&pipe->waiting_writers)) {
67436 if (flags & SPLICE_F_NONBLOCK) {
67437 ret = -EAGAIN;
67438 break;
67439 @@ -1767,7 +1768,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67440 pipe_lock(pipe);
67441
67442 while (pipe->nrbufs >= pipe->buffers) {
67443 - if (!pipe->readers) {
67444 + if (!atomic_read(&pipe->readers)) {
67445 send_sig(SIGPIPE, current, 0);
67446 ret = -EPIPE;
67447 break;
67448 @@ -1780,9 +1781,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67449 ret = -ERESTARTSYS;
67450 break;
67451 }
67452 - pipe->waiting_writers++;
67453 + atomic_inc(&pipe->waiting_writers);
67454 pipe_wait(pipe);
67455 - pipe->waiting_writers--;
67456 + atomic_dec(&pipe->waiting_writers);
67457 }
67458
67459 pipe_unlock(pipe);
67460 @@ -1818,14 +1819,14 @@ retry:
67461 pipe_double_lock(ipipe, opipe);
67462
67463 do {
67464 - if (!opipe->readers) {
67465 + if (!atomic_read(&opipe->readers)) {
67466 send_sig(SIGPIPE, current, 0);
67467 if (!ret)
67468 ret = -EPIPE;
67469 break;
67470 }
67471
67472 - if (!ipipe->nrbufs && !ipipe->writers)
67473 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
67474 break;
67475
67476 /*
67477 @@ -1922,7 +1923,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
67478 pipe_double_lock(ipipe, opipe);
67479
67480 do {
67481 - if (!opipe->readers) {
67482 + if (!atomic_read(&opipe->readers)) {
67483 send_sig(SIGPIPE, current, 0);
67484 if (!ret)
67485 ret = -EPIPE;
67486 @@ -1967,7 +1968,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
67487 * return EAGAIN if we have the potential of some data in the
67488 * future, otherwise just return 0
67489 */
67490 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
67491 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
67492 ret = -EAGAIN;
67493
67494 pipe_unlock(ipipe);
67495 diff --git a/fs/stat.c b/fs/stat.c
67496 index ae0c3ce..9ee641c 100644
67497 --- a/fs/stat.c
67498 +++ b/fs/stat.c
67499 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
67500 stat->gid = inode->i_gid;
67501 stat->rdev = inode->i_rdev;
67502 stat->size = i_size_read(inode);
67503 - stat->atime = inode->i_atime;
67504 - stat->mtime = inode->i_mtime;
67505 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
67506 + stat->atime = inode->i_ctime;
67507 + stat->mtime = inode->i_ctime;
67508 + } else {
67509 + stat->atime = inode->i_atime;
67510 + stat->mtime = inode->i_mtime;
67511 + }
67512 stat->ctime = inode->i_ctime;
67513 stat->blksize = (1 << inode->i_blkbits);
67514 stat->blocks = inode->i_blocks;
67515 @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
67516 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
67517 {
67518 struct inode *inode = path->dentry->d_inode;
67519 + int retval;
67520
67521 - if (inode->i_op->getattr)
67522 - return inode->i_op->getattr(path->mnt, path->dentry, stat);
67523 + if (inode->i_op->getattr) {
67524 + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
67525 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
67526 + stat->atime = stat->ctime;
67527 + stat->mtime = stat->ctime;
67528 + }
67529 + return retval;
67530 + }
67531
67532 generic_fillattr(inode, stat);
67533 return 0;
67534 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
67535 index 0b45ff4..847de5b 100644
67536 --- a/fs/sysfs/dir.c
67537 +++ b/fs/sysfs/dir.c
67538 @@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
67539 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
67540 {
67541 struct kernfs_node *parent, *kn;
67542 + const char *name;
67543 + umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
67544 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
67545 + const char *parent_name;
67546 +#endif
67547
67548 BUG_ON(!kobj);
67549
67550 + name = kobject_name(kobj);
67551 +
67552 if (kobj->parent)
67553 parent = kobj->parent->sd;
67554 else
67555 @@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
67556 if (!parent)
67557 return -ENOENT;
67558
67559 - kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
67560 - S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
67561 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
67562 + parent_name = parent->name;
67563 + mode = S_IRWXU;
67564 +
67565 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
67566 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
67567 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
67568 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
67569 + mode = S_IRWXU | S_IRUGO | S_IXUGO;
67570 +#endif
67571 +
67572 + kn = kernfs_create_dir_ns(parent, name,
67573 + mode, kobj, ns);
67574 if (IS_ERR(kn)) {
67575 if (PTR_ERR(kn) == -EEXIST)
67576 - sysfs_warn_dup(parent, kobject_name(kobj));
67577 + sysfs_warn_dup(parent, name);
67578 return PTR_ERR(kn);
67579 }
67580
67581 diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
67582 index 69d4889..a810bd4 100644
67583 --- a/fs/sysv/sysv.h
67584 +++ b/fs/sysv/sysv.h
67585 @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
67586 #endif
67587 }
67588
67589 -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
67590 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
67591 {
67592 if (sbi->s_bytesex == BYTESEX_PDP)
67593 return PDP_swab((__force __u32)n);
67594 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
67595 index fb08b0c..65fcc7e 100644
67596 --- a/fs/ubifs/io.c
67597 +++ b/fs/ubifs/io.c
67598 @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
67599 return err;
67600 }
67601
67602 -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
67603 +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
67604 {
67605 int err;
67606
67607 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
67608 index c175b4d..8f36a16 100644
67609 --- a/fs/udf/misc.c
67610 +++ b/fs/udf/misc.c
67611 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
67612
67613 u8 udf_tag_checksum(const struct tag *t)
67614 {
67615 - u8 *data = (u8 *)t;
67616 + const u8 *data = (const u8 *)t;
67617 u8 checksum = 0;
67618 int i;
67619 for (i = 0; i < sizeof(struct tag); ++i)
67620 diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
67621 index 8d974c4..b82f6ec 100644
67622 --- a/fs/ufs/swab.h
67623 +++ b/fs/ufs/swab.h
67624 @@ -22,7 +22,7 @@ enum {
67625 BYTESEX_BE
67626 };
67627
67628 -static inline u64
67629 +static inline u64 __intentional_overflow(-1)
67630 fs64_to_cpu(struct super_block *sbp, __fs64 n)
67631 {
67632 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
67633 @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
67634 return (__force __fs64)cpu_to_be64(n);
67635 }
67636
67637 -static inline u32
67638 +static inline u32 __intentional_overflow(-1)
67639 fs32_to_cpu(struct super_block *sbp, __fs32 n)
67640 {
67641 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
67642 diff --git a/fs/utimes.c b/fs/utimes.c
67643 index aa138d6..5f3a811 100644
67644 --- a/fs/utimes.c
67645 +++ b/fs/utimes.c
67646 @@ -1,6 +1,7 @@
67647 #include <linux/compiler.h>
67648 #include <linux/file.h>
67649 #include <linux/fs.h>
67650 +#include <linux/security.h>
67651 #include <linux/linkage.h>
67652 #include <linux/mount.h>
67653 #include <linux/namei.h>
67654 @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
67655 }
67656 }
67657 retry_deleg:
67658 +
67659 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
67660 + error = -EACCES;
67661 + goto mnt_drop_write_and_out;
67662 + }
67663 +
67664 mutex_lock(&inode->i_mutex);
67665 error = notify_change(path->dentry, &newattrs, &delegated_inode);
67666 mutex_unlock(&inode->i_mutex);
67667 diff --git a/fs/xattr.c b/fs/xattr.c
67668 index 64e83ef..b6be154 100644
67669 --- a/fs/xattr.c
67670 +++ b/fs/xattr.c
67671 @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
67672 return rc;
67673 }
67674
67675 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
67676 +ssize_t
67677 +pax_getxattr(struct dentry *dentry, void *value, size_t size)
67678 +{
67679 + struct inode *inode = dentry->d_inode;
67680 + ssize_t error;
67681 +
67682 + error = inode_permission(inode, MAY_EXEC);
67683 + if (error)
67684 + return error;
67685 +
67686 + if (inode->i_op->getxattr)
67687 + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
67688 + else
67689 + error = -EOPNOTSUPP;
67690 +
67691 + return error;
67692 +}
67693 +EXPORT_SYMBOL(pax_getxattr);
67694 +#endif
67695 +
67696 ssize_t
67697 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
67698 {
67699 @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
67700 * Extended attribute SET operations
67701 */
67702 static long
67703 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
67704 +setxattr(struct path *path, const char __user *name, const void __user *value,
67705 size_t size, int flags)
67706 {
67707 int error;
67708 @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
67709 posix_acl_fix_xattr_from_user(kvalue, size);
67710 }
67711
67712 - error = vfs_setxattr(d, kname, kvalue, size, flags);
67713 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
67714 + error = -EACCES;
67715 + goto out;
67716 + }
67717 +
67718 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
67719 out:
67720 if (vvalue)
67721 vfree(vvalue);
67722 @@ -376,7 +402,7 @@ retry:
67723 return error;
67724 error = mnt_want_write(path.mnt);
67725 if (!error) {
67726 - error = setxattr(path.dentry, name, value, size, flags);
67727 + error = setxattr(&path, name, value, size, flags);
67728 mnt_drop_write(path.mnt);
67729 }
67730 path_put(&path);
67731 @@ -405,16 +431,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
67732 const void __user *,value, size_t, size, int, flags)
67733 {
67734 struct fd f = fdget(fd);
67735 - struct dentry *dentry;
67736 int error = -EBADF;
67737
67738 if (!f.file)
67739 return error;
67740 - dentry = f.file->f_path.dentry;
67741 - audit_inode(NULL, dentry, 0);
67742 + audit_inode(NULL, f.file->f_path.dentry, 0);
67743 error = mnt_want_write_file(f.file);
67744 if (!error) {
67745 - error = setxattr(dentry, name, value, size, flags);
67746 + error = setxattr(&f.file->f_path, name, value, size, flags);
67747 mnt_drop_write_file(f.file);
67748 }
67749 fdput(f);
67750 @@ -600,7 +624,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
67751 * Extended attribute REMOVE operations
67752 */
67753 static long
67754 -removexattr(struct dentry *d, const char __user *name)
67755 +removexattr(struct path *path, const char __user *name)
67756 {
67757 int error;
67758 char kname[XATTR_NAME_MAX + 1];
67759 @@ -611,7 +635,10 @@ removexattr(struct dentry *d, const char __user *name)
67760 if (error < 0)
67761 return error;
67762
67763 - return vfs_removexattr(d, kname);
67764 + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
67765 + return -EACCES;
67766 +
67767 + return vfs_removexattr(path->dentry, kname);
67768 }
67769
67770 static int path_removexattr(const char __user *pathname,
67771 @@ -625,7 +652,7 @@ retry:
67772 return error;
67773 error = mnt_want_write(path.mnt);
67774 if (!error) {
67775 - error = removexattr(path.dentry, name);
67776 + error = removexattr(&path, name);
67777 mnt_drop_write(path.mnt);
67778 }
67779 path_put(&path);
67780 @@ -651,16 +678,16 @@ SYSCALL_DEFINE2(lremovexattr, const char __user *, pathname,
67781 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
67782 {
67783 struct fd f = fdget(fd);
67784 - struct dentry *dentry;
67785 + struct path *path;
67786 int error = -EBADF;
67787
67788 if (!f.file)
67789 return error;
67790 - dentry = f.file->f_path.dentry;
67791 - audit_inode(NULL, dentry, 0);
67792 + path = &f.file->f_path;
67793 + audit_inode(NULL, path->dentry, 0);
67794 error = mnt_want_write_file(f.file);
67795 if (!error) {
67796 - error = removexattr(dentry, name);
67797 + error = removexattr(path, name);
67798 mnt_drop_write_file(f.file);
67799 }
67800 fdput(f);
67801 diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
67802 index 79c9819..22226b4 100644
67803 --- a/fs/xfs/libxfs/xfs_bmap.c
67804 +++ b/fs/xfs/libxfs/xfs_bmap.c
67805 @@ -583,7 +583,7 @@ xfs_bmap_validate_ret(
67806
67807 #else
67808 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
67809 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
67810 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
67811 #endif /* DEBUG */
67812
67813 /*
67814 diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
67815 index f1b69ed..3d0222f 100644
67816 --- a/fs/xfs/xfs_dir2_readdir.c
67817 +++ b/fs/xfs/xfs_dir2_readdir.c
67818 @@ -159,7 +159,12 @@ xfs_dir2_sf_getdents(
67819 ino = dp->d_ops->sf_get_ino(sfp, sfep);
67820 filetype = dp->d_ops->sf_get_ftype(sfep);
67821 ctx->pos = off & 0x7fffffff;
67822 - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
67823 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
67824 + char name[sfep->namelen];
67825 + memcpy(name, sfep->name, sfep->namelen);
67826 + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(dp->i_mount, filetype)))
67827 + return 0;
67828 + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
67829 xfs_dir3_get_dtype(dp->i_mount, filetype)))
67830 return 0;
67831 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
67832 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
67833 index 24c926b6..8726af88 100644
67834 --- a/fs/xfs/xfs_ioctl.c
67835 +++ b/fs/xfs/xfs_ioctl.c
67836 @@ -122,7 +122,7 @@ xfs_find_handle(
67837 }
67838
67839 error = -EFAULT;
67840 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
67841 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
67842 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
67843 goto out_put;
67844
67845 diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h
67846 index 6a51619..9592e1b 100644
67847 --- a/fs/xfs/xfs_linux.h
67848 +++ b/fs/xfs/xfs_linux.h
67849 @@ -234,7 +234,7 @@ static inline kgid_t xfs_gid_to_kgid(__uint32_t gid)
67850 * of the compiler which do not like us using do_div in the middle
67851 * of large functions.
67852 */
67853 -static inline __u32 xfs_do_div(void *a, __u32 b, int n)
67854 +static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
67855 {
67856 __u32 mod;
67857
67858 @@ -290,7 +290,7 @@ static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
67859 return 0;
67860 }
67861 #else
67862 -static inline __u32 xfs_do_div(void *a, __u32 b, int n)
67863 +static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
67864 {
67865 __u32 mod;
67866
67867 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
67868 new file mode 100644
67869 index 0000000..f27264e
67870 --- /dev/null
67871 +++ b/grsecurity/Kconfig
67872 @@ -0,0 +1,1166 @@
67873 +#
67874 +# grecurity configuration
67875 +#
67876 +menu "Memory Protections"
67877 +depends on GRKERNSEC
67878 +
67879 +config GRKERNSEC_KMEM
67880 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
67881 + default y if GRKERNSEC_CONFIG_AUTO
67882 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
67883 + help
67884 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
67885 + be written to or read from to modify or leak the contents of the running
67886 + kernel. /dev/port will also not be allowed to be opened, writing to
67887 + /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
67888 + If you have module support disabled, enabling this will close up several
67889 + ways that are currently used to insert malicious code into the running
67890 + kernel.
67891 +
67892 + Even with this feature enabled, we still highly recommend that
67893 + you use the RBAC system, as it is still possible for an attacker to
67894 + modify the running kernel through other more obscure methods.
67895 +
67896 + It is highly recommended that you say Y here if you meet all the
67897 + conditions above.
67898 +
67899 +config GRKERNSEC_VM86
67900 + bool "Restrict VM86 mode"
67901 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
67902 + depends on X86_32
67903 +
67904 + help
67905 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
67906 + make use of a special execution mode on 32bit x86 processors called
67907 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
67908 + video cards and will still work with this option enabled. The purpose
67909 + of the option is to prevent exploitation of emulation errors in
67910 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
67911 + Nearly all users should be able to enable this option.
67912 +
67913 +config GRKERNSEC_IO
67914 + bool "Disable privileged I/O"
67915 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
67916 + depends on X86
67917 + select RTC_CLASS
67918 + select RTC_INTF_DEV
67919 + select RTC_DRV_CMOS
67920 +
67921 + help
67922 + If you say Y here, all ioperm and iopl calls will return an error.
67923 + Ioperm and iopl can be used to modify the running kernel.
67924 + Unfortunately, some programs need this access to operate properly,
67925 + the most notable of which are XFree86 and hwclock. hwclock can be
67926 + remedied by having RTC support in the kernel, so real-time
67927 + clock support is enabled if this option is enabled, to ensure
67928 + that hwclock operates correctly. If hwclock still does not work,
67929 + either update udev or symlink /dev/rtc to /dev/rtc0.
67930 +
67931 + If you're using XFree86 or a version of Xorg from 2012 or earlier,
67932 + you may not be able to boot into a graphical environment with this
67933 + option enabled. In this case, you should use the RBAC system instead.
67934 +
67935 +config GRKERNSEC_BPF_HARDEN
67936 + bool "Harden BPF interpreter"
67937 + default y if GRKERNSEC_CONFIG_AUTO
67938 + help
67939 + Unlike previous versions of grsecurity that hardened both the BPF
67940 + interpreted code against corruption at rest as well as the JIT code
67941 + against JIT-spray attacks and attacker-controlled immediate values
67942 + for ROP, this feature will enforce disabling of the new eBPF JIT engine
67943 + and will ensure the interpreted code is read-only at rest. This feature
67944 + may be removed at a later time when eBPF stabilizes to entirely revert
67945 + back to the more secure pre-3.16 BPF interpreter/JIT.
67946 +
67947 + If you're using KERNEXEC, it's recommended that you enable this option
67948 + to supplement the hardening of the kernel.
67949 +
67950 +config GRKERNSEC_PERF_HARDEN
67951 + bool "Disable unprivileged PERF_EVENTS usage by default"
67952 + default y if GRKERNSEC_CONFIG_AUTO
67953 + depends on PERF_EVENTS
67954 + help
67955 + If you say Y here, the range of acceptable values for the
67956 + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
67957 + default to a new value: 3. When the sysctl is set to this value, no
67958 + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
67959 +
67960 + Though PERF_EVENTS can be used legitimately for performance monitoring
67961 + and low-level application profiling, it is forced on regardless of
67962 + configuration, has been at fault for several vulnerabilities, and
67963 + creates new opportunities for side channels and other information leaks.
67964 +
67965 + This feature puts PERF_EVENTS into a secure default state and permits
67966 + the administrator to change out of it temporarily if unprivileged
67967 + application profiling is needed.
67968 +
67969 +config GRKERNSEC_RAND_THREADSTACK
67970 + bool "Insert random gaps between thread stacks"
67971 + default y if GRKERNSEC_CONFIG_AUTO
67972 + depends on PAX_RANDMMAP && !PPC
67973 + help
67974 + If you say Y here, a random-sized gap will be enforced between allocated
67975 + thread stacks. Glibc's NPTL and other threading libraries that
67976 + pass MAP_STACK to the kernel for thread stack allocation are supported.
67977 + The implementation currently provides 8 bits of entropy for the gap.
67978 +
67979 + Many distributions do not compile threaded remote services with the
67980 + -fstack-check argument to GCC, causing the variable-sized stack-based
67981 + allocator, alloca(), to not probe the stack on allocation. This
67982 + permits an unbounded alloca() to skip over any guard page and potentially
67983 + modify another thread's stack reliably. An enforced random gap
67984 + reduces the reliability of such an attack and increases the chance
67985 + that such a read/write to another thread's stack instead lands in
67986 + an unmapped area, causing a crash and triggering grsecurity's
67987 + anti-bruteforcing logic.
67988 +
67989 +config GRKERNSEC_PROC_MEMMAP
67990 + bool "Harden ASLR against information leaks and entropy reduction"
67991 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
67992 + depends on PAX_NOEXEC || PAX_ASLR
67993 + help
67994 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
67995 + give no information about the addresses of its mappings if
67996 + PaX features that rely on random addresses are enabled on the task.
67997 + In addition to sanitizing this information and disabling other
67998 + dangerous sources of information, this option causes reads of sensitive
67999 + /proc/<pid> entries where the file descriptor was opened in a different
68000 + task than the one performing the read. Such attempts are logged.
68001 + This option also limits argv/env strings for suid/sgid binaries
68002 + to 512KB to prevent a complete exhaustion of the stack entropy provided
68003 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
68004 + binaries to prevent alternative mmap layouts from being abused.
68005 +
68006 + If you use PaX it is essential that you say Y here as it closes up
68007 + several holes that make full ASLR useless locally.
68008 +
68009 +
68010 +config GRKERNSEC_KSTACKOVERFLOW
68011 + bool "Prevent kernel stack overflows"
68012 + default y if GRKERNSEC_CONFIG_AUTO
68013 + depends on !IA64 && 64BIT
68014 + help
68015 + If you say Y here, the kernel's process stacks will be allocated
68016 + with vmalloc instead of the kernel's default allocator. This
68017 + introduces guard pages that in combination with the alloca checking
68018 + of the STACKLEAK feature prevents all forms of kernel process stack
68019 + overflow abuse. Note that this is different from kernel stack
68020 + buffer overflows.
68021 +
68022 +config GRKERNSEC_BRUTE
68023 + bool "Deter exploit bruteforcing"
68024 + default y if GRKERNSEC_CONFIG_AUTO
68025 + help
68026 + If you say Y here, attempts to bruteforce exploits against forking
68027 + daemons such as apache or sshd, as well as against suid/sgid binaries
68028 + will be deterred. When a child of a forking daemon is killed by PaX
68029 + or crashes due to an illegal instruction or other suspicious signal,
68030 + the parent process will be delayed 30 seconds upon every subsequent
68031 + fork until the administrator is able to assess the situation and
68032 + restart the daemon.
68033 + In the suid/sgid case, the attempt is logged, the user has all their
68034 + existing instances of the suid/sgid binary terminated and will
68035 + be unable to execute any suid/sgid binaries for 15 minutes.
68036 +
68037 + It is recommended that you also enable signal logging in the auditing
68038 + section so that logs are generated when a process triggers a suspicious
68039 + signal.
68040 + If the sysctl option is enabled, a sysctl option with name
68041 + "deter_bruteforce" is created.
68042 +
68043 +config GRKERNSEC_MODHARDEN
68044 + bool "Harden module auto-loading"
68045 + default y if GRKERNSEC_CONFIG_AUTO
68046 + depends on MODULES
68047 + help
68048 + If you say Y here, module auto-loading in response to use of some
68049 + feature implemented by an unloaded module will be restricted to
68050 + root users. Enabling this option helps defend against attacks
68051 + by unprivileged users who abuse the auto-loading behavior to
68052 + cause a vulnerable module to load that is then exploited.
68053 +
68054 + If this option prevents a legitimate use of auto-loading for a
68055 + non-root user, the administrator can execute modprobe manually
68056 + with the exact name of the module mentioned in the alert log.
68057 + Alternatively, the administrator can add the module to the list
68058 + of modules loaded at boot by modifying init scripts.
68059 +
68060 + Modification of init scripts will most likely be needed on
68061 + Ubuntu servers with encrypted home directory support enabled,
68062 + as the first non-root user logging in will cause the ecb(aes),
68063 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
68064 +
68065 +config GRKERNSEC_HIDESYM
68066 + bool "Hide kernel symbols"
68067 + default y if GRKERNSEC_CONFIG_AUTO
68068 + select PAX_USERCOPY_SLABS
68069 + help
68070 + If you say Y here, getting information on loaded modules, and
68071 + displaying all kernel symbols through a syscall will be restricted
68072 + to users with CAP_SYS_MODULE. For software compatibility reasons,
68073 + /proc/kallsyms will be restricted to the root user. The RBAC
68074 + system can hide that entry even from root.
68075 +
68076 + This option also prevents leaking of kernel addresses through
68077 + several /proc entries.
68078 +
68079 + Note that this option is only effective provided the following
68080 + conditions are met:
68081 + 1) The kernel using grsecurity is not precompiled by some distribution
68082 + 2) You have also enabled GRKERNSEC_DMESG
68083 + 3) You are using the RBAC system and hiding other files such as your
68084 + kernel image and System.map. Alternatively, enabling this option
68085 + causes the permissions on /boot, /lib/modules, and the kernel
68086 + source directory to change at compile time to prevent
68087 + reading by non-root users.
68088 + If the above conditions are met, this option will aid in providing a
68089 + useful protection against local kernel exploitation of overflows
68090 + and arbitrary read/write vulnerabilities.
68091 +
68092 + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
68093 + in addition to this feature.
68094 +
68095 +config GRKERNSEC_RANDSTRUCT
68096 + bool "Randomize layout of sensitive kernel structures"
68097 + default y if GRKERNSEC_CONFIG_AUTO
68098 + select GRKERNSEC_HIDESYM
68099 + select MODVERSIONS if MODULES
68100 + help
68101 + If you say Y here, the layouts of a number of sensitive kernel
68102 + structures (task, fs, cred, etc) and all structures composed entirely
68103 + of function pointers (aka "ops" structs) will be randomized at compile-time.
68104 + This can introduce the requirement of an additional infoleak
68105 + vulnerability for exploits targeting these structure types.
68106 +
68107 + Enabling this feature will introduce some performance impact, slightly
68108 + increase memory usage, and prevent the use of forensic tools like
68109 + Volatility against the system (unless the kernel source tree isn't
68110 + cleaned after kernel installation).
68111 +
68112 + The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
68113 + It remains after a make clean to allow for external modules to be compiled
68114 + with the existing seed and will be removed by a make mrproper or
68115 + make distclean.
68116 +
68117 + Note that the implementation requires gcc 4.6.4. or newer. You may need
68118 + to install the supporting headers explicitly in addition to the normal
68119 + gcc package.
68120 +
68121 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
68122 + bool "Use cacheline-aware structure randomization"
68123 + depends on GRKERNSEC_RANDSTRUCT
68124 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
68125 + help
68126 + If you say Y here, the RANDSTRUCT randomization will make a best effort
68127 + at restricting randomization to cacheline-sized groups of elements. It
68128 + will further not randomize bitfields in structures. This reduces the
68129 + performance hit of RANDSTRUCT at the cost of weakened randomization.
68130 +
68131 +config GRKERNSEC_KERN_LOCKOUT
68132 + bool "Active kernel exploit response"
68133 + default y if GRKERNSEC_CONFIG_AUTO
68134 + depends on X86 || ARM || PPC || SPARC
68135 + help
68136 + If you say Y here, when a PaX alert is triggered due to suspicious
68137 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
68138 + or an OOPS occurs due to bad memory accesses, instead of just
68139 + terminating the offending process (and potentially allowing
68140 + a subsequent exploit from the same user), we will take one of two
68141 + actions:
68142 + If the user was root, we will panic the system
68143 + If the user was non-root, we will log the attempt, terminate
68144 + all processes owned by the user, then prevent them from creating
68145 + any new processes until the system is restarted
68146 + This deters repeated kernel exploitation/bruteforcing attempts
68147 + and is useful for later forensics.
68148 +
68149 +config GRKERNSEC_OLD_ARM_USERLAND
68150 + bool "Old ARM userland compatibility"
68151 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
68152 + help
68153 + If you say Y here, stubs of executable code to perform such operations
68154 + as "compare-exchange" will be placed at fixed locations in the ARM vector
68155 + table. This is unfortunately needed for old ARM userland meant to run
68156 + across a wide range of processors. Without this option enabled,
68157 + the get_tls and data memory barrier stubs will be emulated by the kernel,
68158 + which is enough for Linaro userlands or other userlands designed for v6
68159 + and newer ARM CPUs. It's recommended that you try without this option enabled
68160 + first, and only enable it if your userland does not boot (it will likely fail
68161 + at init time).
68162 +
68163 +endmenu
68164 +menu "Role Based Access Control Options"
68165 +depends on GRKERNSEC
68166 +
68167 +config GRKERNSEC_RBAC_DEBUG
68168 + bool
68169 +
68170 +config GRKERNSEC_NO_RBAC
68171 + bool "Disable RBAC system"
68172 + help
68173 + If you say Y here, the /dev/grsec device will be removed from the kernel,
68174 + preventing the RBAC system from being enabled. You should only say Y
68175 + here if you have no intention of using the RBAC system, so as to prevent
68176 + an attacker with root access from misusing the RBAC system to hide files
68177 + and processes when loadable module support and /dev/[k]mem have been
68178 + locked down.
68179 +
68180 +config GRKERNSEC_ACL_HIDEKERN
68181 + bool "Hide kernel processes"
68182 + help
68183 + If you say Y here, all kernel threads will be hidden to all
68184 + processes but those whose subject has the "view hidden processes"
68185 + flag.
68186 +
68187 +config GRKERNSEC_ACL_MAXTRIES
68188 + int "Maximum tries before password lockout"
68189 + default 3
68190 + help
68191 + This option enforces the maximum number of times a user can attempt
68192 + to authorize themselves with the grsecurity RBAC system before being
68193 + denied the ability to attempt authorization again for a specified time.
68194 + The lower the number, the harder it will be to brute-force a password.
68195 +
68196 +config GRKERNSEC_ACL_TIMEOUT
68197 + int "Time to wait after max password tries, in seconds"
68198 + default 30
68199 + help
68200 + This option specifies the time the user must wait after attempting to
68201 + authorize to the RBAC system with the maximum number of invalid
68202 + passwords. The higher the number, the harder it will be to brute-force
68203 + a password.
68204 +
68205 +endmenu
68206 +menu "Filesystem Protections"
68207 +depends on GRKERNSEC
68208 +
68209 +config GRKERNSEC_PROC
68210 + bool "Proc restrictions"
68211 + default y if GRKERNSEC_CONFIG_AUTO
68212 + help
68213 + If you say Y here, the permissions of the /proc filesystem
68214 + will be altered to enhance system security and privacy. You MUST
68215 + choose either a user only restriction or a user and group restriction.
68216 + Depending upon the option you choose, you can either restrict users to
68217 + see only the processes they themselves run, or choose a group that can
68218 + view all processes and files normally restricted to root if you choose
68219 + the "restrict to user only" option. NOTE: If you're running identd or
68220 + ntpd as a non-root user, you will have to run it as the group you
68221 + specify here.
68222 +
68223 +config GRKERNSEC_PROC_USER
68224 + bool "Restrict /proc to user only"
68225 + depends on GRKERNSEC_PROC
68226 + help
68227 + If you say Y here, non-root users will only be able to view their own
68228 + processes, and restricts them from viewing network-related information,
68229 + and viewing kernel symbol and module information.
68230 +
68231 +config GRKERNSEC_PROC_USERGROUP
68232 + bool "Allow special group"
68233 + default y if GRKERNSEC_CONFIG_AUTO
68234 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
68235 + help
68236 + If you say Y here, you will be able to select a group that will be
68237 + able to view all processes and network-related information. If you've
68238 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
68239 + remain hidden. This option is useful if you want to run identd as
68240 + a non-root user. The group you select may also be chosen at boot time
68241 + via "grsec_proc_gid=" on the kernel commandline.
68242 +
68243 +config GRKERNSEC_PROC_GID
68244 + int "GID for special group"
68245 + depends on GRKERNSEC_PROC_USERGROUP
68246 + default 1001
68247 +
68248 +config GRKERNSEC_PROC_ADD
68249 + bool "Additional restrictions"
68250 + default y if GRKERNSEC_CONFIG_AUTO
68251 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
68252 + help
68253 + If you say Y here, additional restrictions will be placed on
68254 + /proc that keep normal users from viewing device information and
68255 + slabinfo information that could be useful for exploits.
68256 +
68257 +config GRKERNSEC_LINK
68258 + bool "Linking restrictions"
68259 + default y if GRKERNSEC_CONFIG_AUTO
68260 + help
68261 + If you say Y here, /tmp race exploits will be prevented, since users
68262 + will no longer be able to follow symlinks owned by other users in
68263 + world-writable +t directories (e.g. /tmp), unless the owner of the
68264 + symlink is the owner of the directory. users will also not be
68265 + able to hardlink to files they do not own. If the sysctl option is
68266 + enabled, a sysctl option with name "linking_restrictions" is created.
68267 +
68268 +config GRKERNSEC_SYMLINKOWN
68269 + bool "Kernel-enforced SymlinksIfOwnerMatch"
68270 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
68271 + help
68272 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
68273 + that prevents it from being used as a security feature. As Apache
68274 + verifies the symlink by performing a stat() against the target of
68275 + the symlink before it is followed, an attacker can setup a symlink
68276 + to point to a same-owned file, then replace the symlink with one
68277 + that targets another user's file just after Apache "validates" the
68278 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
68279 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
68280 + will be in place for the group you specify. If the sysctl option
68281 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
68282 + created.
68283 +
68284 +config GRKERNSEC_SYMLINKOWN_GID
68285 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
68286 + depends on GRKERNSEC_SYMLINKOWN
68287 + default 1006
68288 + help
68289 + Setting this GID determines what group kernel-enforced
68290 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
68291 + is enabled, a sysctl option with name "symlinkown_gid" is created.
68292 +
68293 +config GRKERNSEC_FIFO
68294 + bool "FIFO restrictions"
68295 + default y if GRKERNSEC_CONFIG_AUTO
68296 + help
68297 + If you say Y here, users will not be able to write to FIFOs they don't
68298 + own in world-writable +t directories (e.g. /tmp), unless the owner of
68299 + the FIFO is the same owner of the directory it's held in. If the sysctl
68300 + option is enabled, a sysctl option with name "fifo_restrictions" is
68301 + created.
68302 +
68303 +config GRKERNSEC_SYSFS_RESTRICT
68304 + bool "Sysfs/debugfs restriction"
68305 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68306 + depends on SYSFS
68307 + help
68308 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
68309 + any filesystem normally mounted under it (e.g. debugfs) will be
68310 + mostly accessible only by root. These filesystems generally provide access
68311 + to hardware and debug information that isn't appropriate for unprivileged
68312 + users of the system. Sysfs and debugfs have also become a large source
68313 + of new vulnerabilities, ranging from infoleaks to local compromise.
68314 + There has been very little oversight with an eye toward security involved
68315 + in adding new exporters of information to these filesystems, so their
68316 + use is discouraged.
68317 + For reasons of compatibility, a few directories have been whitelisted
68318 + for access by non-root users:
68319 + /sys/fs/selinux
68320 + /sys/fs/fuse
68321 + /sys/devices/system/cpu
68322 +
68323 +config GRKERNSEC_ROFS
68324 + bool "Runtime read-only mount protection"
68325 + depends on SYSCTL
68326 + help
68327 + If you say Y here, a sysctl option with name "romount_protect" will
68328 + be created. By setting this option to 1 at runtime, filesystems
68329 + will be protected in the following ways:
68330 + * No new writable mounts will be allowed
68331 + * Existing read-only mounts won't be able to be remounted read/write
68332 + * Write operations will be denied on all block devices
68333 + This option acts independently of grsec_lock: once it is set to 1,
68334 + it cannot be turned off. Therefore, please be mindful of the resulting
68335 + behavior if this option is enabled in an init script on a read-only
68336 + filesystem.
68337 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
68338 + and GRKERNSEC_IO should be enabled and module loading disabled via
68339 + config or at runtime.
68340 + This feature is mainly intended for secure embedded systems.
68341 +
68342 +
68343 +config GRKERNSEC_DEVICE_SIDECHANNEL
68344 + bool "Eliminate stat/notify-based device sidechannels"
68345 + default y if GRKERNSEC_CONFIG_AUTO
68346 + help
68347 + If you say Y here, timing analyses on block or character
68348 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
68349 + will be thwarted for unprivileged users. If a process without
68350 + CAP_MKNOD stats such a device, the last access and last modify times
68351 + will match the device's create time. No access or modify events
68352 + will be triggered through inotify/dnotify/fanotify for such devices.
68353 + This feature will prevent attacks that may at a minimum
68354 + allow an attacker to determine the administrator's password length.
68355 +
68356 +config GRKERNSEC_CHROOT
68357 + bool "Chroot jail restrictions"
68358 + default y if GRKERNSEC_CONFIG_AUTO
68359 + help
68360 + If you say Y here, you will be able to choose several options that will
68361 + make breaking out of a chrooted jail much more difficult. If you
68362 + encounter no software incompatibilities with the following options, it
68363 + is recommended that you enable each one.
68364 +
68365 + Note that the chroot restrictions are not intended to apply to "chroots"
68366 + to directories that are simple bind mounts of the global root filesystem.
68367 + For several other reasons, a user shouldn't expect any significant
68368 + security by performing such a chroot.
68369 +
68370 +config GRKERNSEC_CHROOT_MOUNT
68371 + bool "Deny mounts"
68372 + default y if GRKERNSEC_CONFIG_AUTO
68373 + depends on GRKERNSEC_CHROOT
68374 + help
68375 + If you say Y here, processes inside a chroot will not be able to
68376 + mount or remount filesystems. If the sysctl option is enabled, a
68377 + sysctl option with name "chroot_deny_mount" is created.
68378 +
68379 +config GRKERNSEC_CHROOT_DOUBLE
68380 + bool "Deny double-chroots"
68381 + default y if GRKERNSEC_CONFIG_AUTO
68382 + depends on GRKERNSEC_CHROOT
68383 + help
68384 + If you say Y here, processes inside a chroot will not be able to chroot
68385 + again outside the chroot. This is a widely used method of breaking
68386 + out of a chroot jail and should not be allowed. If the sysctl
68387 + option is enabled, a sysctl option with name
68388 + "chroot_deny_chroot" is created.
68389 +
68390 +config GRKERNSEC_CHROOT_PIVOT
68391 + bool "Deny pivot_root in chroot"
68392 + default y if GRKERNSEC_CONFIG_AUTO
68393 + depends on GRKERNSEC_CHROOT
68394 + help
68395 + If you say Y here, processes inside a chroot will not be able to use
68396 + a function called pivot_root() that was introduced in Linux 2.3.41. It
68397 + works similar to chroot in that it changes the root filesystem. This
68398 + function could be misused in a chrooted process to attempt to break out
68399 + of the chroot, and therefore should not be allowed. If the sysctl
68400 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
68401 + created.
68402 +
68403 +config GRKERNSEC_CHROOT_CHDIR
68404 + bool "Enforce chdir(\"/\") on all chroots"
68405 + default y if GRKERNSEC_CONFIG_AUTO
68406 + depends on GRKERNSEC_CHROOT
68407 + help
68408 + If you say Y here, the current working directory of all newly-chrooted
68409 + applications will be set to the the root directory of the chroot.
68410 + The man page on chroot(2) states:
68411 + Note that this call does not change the current working
68412 + directory, so that `.' can be outside the tree rooted at
68413 + `/'. In particular, the super-user can escape from a
68414 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
68415 +
68416 + It is recommended that you say Y here, since it's not known to break
68417 + any software. If the sysctl option is enabled, a sysctl option with
68418 + name "chroot_enforce_chdir" is created.
68419 +
68420 +config GRKERNSEC_CHROOT_CHMOD
68421 + bool "Deny (f)chmod +s"
68422 + default y if GRKERNSEC_CONFIG_AUTO
68423 + depends on GRKERNSEC_CHROOT
68424 + help
68425 + If you say Y here, processes inside a chroot will not be able to chmod
68426 + or fchmod files to make them have suid or sgid bits. This protects
68427 + against another published method of breaking a chroot. If the sysctl
68428 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
68429 + created.
68430 +
68431 +config GRKERNSEC_CHROOT_FCHDIR
68432 + bool "Deny fchdir and fhandle out of chroot"
68433 + default y if GRKERNSEC_CONFIG_AUTO
68434 + depends on GRKERNSEC_CHROOT
68435 + help
68436 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
68437 + to a file descriptor of the chrooting process that points to a directory
68438 + outside the filesystem will be stopped. Additionally, this option prevents
68439 + use of the recently-created syscall for opening files by a guessable "file
68440 + handle" inside a chroot. If the sysctl option is enabled, a sysctl option
68441 + with name "chroot_deny_fchdir" is created.
68442 +
68443 +config GRKERNSEC_CHROOT_MKNOD
68444 + bool "Deny mknod"
68445 + default y if GRKERNSEC_CONFIG_AUTO
68446 + depends on GRKERNSEC_CHROOT
68447 + help
68448 + If you say Y here, processes inside a chroot will not be allowed to
68449 + mknod. The problem with using mknod inside a chroot is that it
68450 + would allow an attacker to create a device entry that is the same
68451 + as one on the physical root of your system, which could range from
68452 + anything from the console device to a device for your harddrive (which
68453 + they could then use to wipe the drive or steal data). It is recommended
68454 + that you say Y here, unless you run into software incompatibilities.
68455 + If the sysctl option is enabled, a sysctl option with name
68456 + "chroot_deny_mknod" is created.
68457 +
68458 +config GRKERNSEC_CHROOT_SHMAT
68459 + bool "Deny shmat() out of chroot"
68460 + default y if GRKERNSEC_CONFIG_AUTO
68461 + depends on GRKERNSEC_CHROOT
68462 + help
68463 + If you say Y here, processes inside a chroot will not be able to attach
68464 + to shared memory segments that were created outside of the chroot jail.
68465 + It is recommended that you say Y here. If the sysctl option is enabled,
68466 + a sysctl option with name "chroot_deny_shmat" is created.
68467 +
68468 +config GRKERNSEC_CHROOT_UNIX
68469 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
68470 + default y if GRKERNSEC_CONFIG_AUTO
68471 + depends on GRKERNSEC_CHROOT
68472 + help
68473 + If you say Y here, processes inside a chroot will not be able to
68474 + connect to abstract (meaning not belonging to a filesystem) Unix
68475 + domain sockets that were bound outside of a chroot. It is recommended
68476 + that you say Y here. If the sysctl option is enabled, a sysctl option
68477 + with name "chroot_deny_unix" is created.
68478 +
68479 +config GRKERNSEC_CHROOT_FINDTASK
68480 + bool "Protect outside processes"
68481 + default y if GRKERNSEC_CONFIG_AUTO
68482 + depends on GRKERNSEC_CHROOT
68483 + help
68484 + If you say Y here, processes inside a chroot will not be able to
68485 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
68486 + getsid, or view any process outside of the chroot. If the sysctl
68487 + option is enabled, a sysctl option with name "chroot_findtask" is
68488 + created.
68489 +
68490 +config GRKERNSEC_CHROOT_NICE
68491 + bool "Restrict priority changes"
68492 + default y if GRKERNSEC_CONFIG_AUTO
68493 + depends on GRKERNSEC_CHROOT
68494 + help
68495 + If you say Y here, processes inside a chroot will not be able to raise
68496 + the priority of processes in the chroot, or alter the priority of
68497 + processes outside the chroot. This provides more security than simply
68498 + removing CAP_SYS_NICE from the process' capability set. If the
68499 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
68500 + is created.
68501 +
68502 +config GRKERNSEC_CHROOT_SYSCTL
68503 + bool "Deny sysctl writes"
68504 + default y if GRKERNSEC_CONFIG_AUTO
68505 + depends on GRKERNSEC_CHROOT
68506 + help
68507 + If you say Y here, an attacker in a chroot will not be able to
68508 + write to sysctl entries, either by sysctl(2) or through a /proc
68509 + interface. It is strongly recommended that you say Y here. If the
68510 + sysctl option is enabled, a sysctl option with name
68511 + "chroot_deny_sysctl" is created.
68512 +
68513 +config GRKERNSEC_CHROOT_CAPS
68514 + bool "Capability restrictions"
68515 + default y if GRKERNSEC_CONFIG_AUTO
68516 + depends on GRKERNSEC_CHROOT
68517 + help
68518 + If you say Y here, the capabilities on all processes within a
68519 + chroot jail will be lowered to stop module insertion, raw i/o,
68520 + system and net admin tasks, rebooting the system, modifying immutable
68521 + files, modifying IPC owned by another, and changing the system time.
68522 + This is left an option because it can break some apps. Disable this
68523 + if your chrooted apps are having problems performing those kinds of
68524 + tasks. If the sysctl option is enabled, a sysctl option with
68525 + name "chroot_caps" is created.
68526 +
68527 +config GRKERNSEC_CHROOT_INITRD
68528 + bool "Exempt initrd tasks from restrictions"
68529 + default y if GRKERNSEC_CONFIG_AUTO
68530 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
68531 + help
68532 + If you say Y here, tasks started prior to init will be exempted from
68533 + grsecurity's chroot restrictions. This option is mainly meant to
68534 + resolve Plymouth's performing privileged operations unnecessarily
68535 + in a chroot.
68536 +
68537 +endmenu
68538 +menu "Kernel Auditing"
68539 +depends on GRKERNSEC
68540 +
68541 +config GRKERNSEC_AUDIT_GROUP
68542 + bool "Single group for auditing"
68543 + help
68544 + If you say Y here, the exec and chdir logging features will only operate
68545 + on a group you specify. This option is recommended if you only want to
68546 + watch certain users instead of having a large amount of logs from the
68547 + entire system. If the sysctl option is enabled, a sysctl option with
68548 + name "audit_group" is created.
68549 +
68550 +config GRKERNSEC_AUDIT_GID
68551 + int "GID for auditing"
68552 + depends on GRKERNSEC_AUDIT_GROUP
68553 + default 1007
68554 +
68555 +config GRKERNSEC_EXECLOG
68556 + bool "Exec logging"
68557 + help
68558 + If you say Y here, all execve() calls will be logged (since the
68559 + other exec*() calls are frontends to execve(), all execution
68560 + will be logged). Useful for shell-servers that like to keep track
68561 + of their users. If the sysctl option is enabled, a sysctl option with
68562 + name "exec_logging" is created.
68563 + WARNING: This option when enabled will produce a LOT of logs, especially
68564 + on an active system.
68565 +
68566 +config GRKERNSEC_RESLOG
68567 + bool "Resource logging"
68568 + default y if GRKERNSEC_CONFIG_AUTO
68569 + help
68570 + If you say Y here, all attempts to overstep resource limits will
68571 + be logged with the resource name, the requested size, and the current
68572 + limit. It is highly recommended that you say Y here. If the sysctl
68573 + option is enabled, a sysctl option with name "resource_logging" is
68574 + created. If the RBAC system is enabled, the sysctl value is ignored.
68575 +
68576 +config GRKERNSEC_CHROOT_EXECLOG
68577 + bool "Log execs within chroot"
68578 + help
68579 + If you say Y here, all executions inside a chroot jail will be logged
68580 + to syslog. This can cause a large amount of logs if certain
68581 + applications (eg. djb's daemontools) are installed on the system, and
68582 + is therefore left as an option. If the sysctl option is enabled, a
68583 + sysctl option with name "chroot_execlog" is created.
68584 +
68585 +config GRKERNSEC_AUDIT_PTRACE
68586 + bool "Ptrace logging"
68587 + help
68588 + If you say Y here, all attempts to attach to a process via ptrace
68589 + will be logged. If the sysctl option is enabled, a sysctl option
68590 + with name "audit_ptrace" is created.
68591 +
68592 +config GRKERNSEC_AUDIT_CHDIR
68593 + bool "Chdir logging"
68594 + help
68595 + If you say Y here, all chdir() calls will be logged. If the sysctl
68596 + option is enabled, a sysctl option with name "audit_chdir" is created.
68597 +
68598 +config GRKERNSEC_AUDIT_MOUNT
68599 + bool "(Un)Mount logging"
68600 + help
68601 + If you say Y here, all mounts and unmounts will be logged. If the
68602 + sysctl option is enabled, a sysctl option with name "audit_mount" is
68603 + created.
68604 +
68605 +config GRKERNSEC_SIGNAL
68606 + bool "Signal logging"
68607 + default y if GRKERNSEC_CONFIG_AUTO
68608 + help
68609 + If you say Y here, certain important signals will be logged, such as
68610 + SIGSEGV, which will as a result inform you of when a error in a program
68611 + occurred, which in some cases could mean a possible exploit attempt.
68612 + If the sysctl option is enabled, a sysctl option with name
68613 + "signal_logging" is created.
68614 +
68615 +config GRKERNSEC_FORKFAIL
68616 + bool "Fork failure logging"
68617 + help
68618 + If you say Y here, all failed fork() attempts will be logged.
68619 + This could suggest a fork bomb, or someone attempting to overstep
68620 + their process limit. If the sysctl option is enabled, a sysctl option
68621 + with name "forkfail_logging" is created.
68622 +
68623 +config GRKERNSEC_TIME
68624 + bool "Time change logging"
68625 + default y if GRKERNSEC_CONFIG_AUTO
68626 + help
68627 + If you say Y here, any changes of the system clock will be logged.
68628 + If the sysctl option is enabled, a sysctl option with name
68629 + "timechange_logging" is created.
68630 +
68631 +config GRKERNSEC_PROC_IPADDR
68632 + bool "/proc/<pid>/ipaddr support"
68633 + default y if GRKERNSEC_CONFIG_AUTO
68634 + help
68635 + If you say Y here, a new entry will be added to each /proc/<pid>
68636 + directory that contains the IP address of the person using the task.
68637 + The IP is carried across local TCP and AF_UNIX stream sockets.
68638 + This information can be useful for IDS/IPSes to perform remote response
68639 + to a local attack. The entry is readable by only the owner of the
68640 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
68641 + the RBAC system), and thus does not create privacy concerns.
68642 +
68643 +config GRKERNSEC_RWXMAP_LOG
68644 + bool 'Denied RWX mmap/mprotect logging'
68645 + default y if GRKERNSEC_CONFIG_AUTO
68646 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
68647 + help
68648 + If you say Y here, calls to mmap() and mprotect() with explicit
68649 + usage of PROT_WRITE and PROT_EXEC together will be logged when
68650 + denied by the PAX_MPROTECT feature. This feature will also
68651 + log other problematic scenarios that can occur when PAX_MPROTECT
68652 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
68653 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
68654 + is created.
68655 +
68656 +endmenu
68657 +
68658 +menu "Executable Protections"
68659 +depends on GRKERNSEC
68660 +
68661 +config GRKERNSEC_DMESG
68662 + bool "Dmesg(8) restriction"
68663 + default y if GRKERNSEC_CONFIG_AUTO
68664 + help
68665 + If you say Y here, non-root users will not be able to use dmesg(8)
68666 + to view the contents of the kernel's circular log buffer.
68667 + The kernel's log buffer often contains kernel addresses and other
68668 + identifying information useful to an attacker in fingerprinting a
68669 + system for a targeted exploit.
68670 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
68671 + created.
68672 +
68673 +config GRKERNSEC_HARDEN_PTRACE
68674 + bool "Deter ptrace-based process snooping"
68675 + default y if GRKERNSEC_CONFIG_AUTO
68676 + help
68677 + If you say Y here, TTY sniffers and other malicious monitoring
68678 + programs implemented through ptrace will be defeated. If you
68679 + have been using the RBAC system, this option has already been
68680 + enabled for several years for all users, with the ability to make
68681 + fine-grained exceptions.
68682 +
68683 + This option only affects the ability of non-root users to ptrace
68684 + processes that are not a descendent of the ptracing process.
68685 + This means that strace ./binary and gdb ./binary will still work,
68686 + but attaching to arbitrary processes will not. If the sysctl
68687 + option is enabled, a sysctl option with name "harden_ptrace" is
68688 + created.
68689 +
68690 +config GRKERNSEC_PTRACE_READEXEC
68691 + bool "Require read access to ptrace sensitive binaries"
68692 + default y if GRKERNSEC_CONFIG_AUTO
68693 + help
68694 + If you say Y here, unprivileged users will not be able to ptrace unreadable
68695 + binaries. This option is useful in environments that
68696 + remove the read bits (e.g. file mode 4711) from suid binaries to
68697 + prevent infoleaking of their contents. This option adds
68698 + consistency to the use of that file mode, as the binary could normally
68699 + be read out when run without privileges while ptracing.
68700 +
68701 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
68702 + is created.
68703 +
68704 +config GRKERNSEC_SETXID
68705 + bool "Enforce consistent multithreaded privileges"
68706 + default y if GRKERNSEC_CONFIG_AUTO
68707 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
68708 + help
68709 + If you say Y here, a change from a root uid to a non-root uid
68710 + in a multithreaded application will cause the resulting uids,
68711 + gids, supplementary groups, and capabilities in that thread
68712 + to be propagated to the other threads of the process. In most
68713 + cases this is unnecessary, as glibc will emulate this behavior
68714 + on behalf of the application. Other libcs do not act in the
68715 + same way, allowing the other threads of the process to continue
68716 + running with root privileges. If the sysctl option is enabled,
68717 + a sysctl option with name "consistent_setxid" is created.
68718 +
68719 +config GRKERNSEC_HARDEN_IPC
68720 + bool "Disallow access to overly-permissive IPC objects"
68721 + default y if GRKERNSEC_CONFIG_AUTO
68722 + depends on SYSVIPC
68723 + help
68724 + If you say Y here, access to overly-permissive IPC objects (shared
68725 + memory, message queues, and semaphores) will be denied for processes
68726 + given the following criteria beyond normal permission checks:
68727 + 1) If the IPC object is world-accessible and the euid doesn't match
68728 + that of the creator or current uid for the IPC object
68729 + 2) If the IPC object is group-accessible and the egid doesn't
68730 + match that of the creator or current gid for the IPC object
68731 + It's a common error to grant too much permission to these objects,
68732 + with impact ranging from denial of service and information leaking to
68733 + privilege escalation. This feature was developed in response to
68734 + research by Tim Brown:
68735 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
68736 + who found hundreds of such insecure usages. Processes with
68737 + CAP_IPC_OWNER are still permitted to access these IPC objects.
68738 + If the sysctl option is enabled, a sysctl option with name
68739 + "harden_ipc" is created.
68740 +
68741 +config GRKERNSEC_TPE
68742 + bool "Trusted Path Execution (TPE)"
68743 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
68744 + help
68745 + If you say Y here, you will be able to choose a gid to add to the
68746 + supplementary groups of users you want to mark as "untrusted."
68747 + These users will not be able to execute any files that are not in
68748 + root-owned directories writable only by root. If the sysctl option
68749 + is enabled, a sysctl option with name "tpe" is created.
68750 +
68751 +config GRKERNSEC_TPE_ALL
68752 + bool "Partially restrict all non-root users"
68753 + depends on GRKERNSEC_TPE
68754 + help
68755 + If you say Y here, all non-root users will be covered under
68756 + a weaker TPE restriction. This is separate from, and in addition to,
68757 + the main TPE options that you have selected elsewhere. Thus, if a
68758 + "trusted" GID is chosen, this restriction applies to even that GID.
68759 + Under this restriction, all non-root users will only be allowed to
68760 + execute files in directories they own that are not group or
68761 + world-writable, or in directories owned by root and writable only by
68762 + root. If the sysctl option is enabled, a sysctl option with name
68763 + "tpe_restrict_all" is created.
68764 +
68765 +config GRKERNSEC_TPE_INVERT
68766 + bool "Invert GID option"
68767 + depends on GRKERNSEC_TPE
68768 + help
68769 + If you say Y here, the group you specify in the TPE configuration will
68770 + decide what group TPE restrictions will be *disabled* for. This
68771 + option is useful if you want TPE restrictions to be applied to most
68772 + users on the system. If the sysctl option is enabled, a sysctl option
68773 + with name "tpe_invert" is created. Unlike other sysctl options, this
68774 + entry will default to on for backward-compatibility.
68775 +
68776 +config GRKERNSEC_TPE_GID
68777 + int
68778 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
68779 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
68780 +
68781 +config GRKERNSEC_TPE_UNTRUSTED_GID
68782 + int "GID for TPE-untrusted users"
68783 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
68784 + default 1005
68785 + help
68786 + Setting this GID determines what group TPE restrictions will be
68787 + *enabled* for. If the sysctl option is enabled, a sysctl option
68788 + with name "tpe_gid" is created.
68789 +
68790 +config GRKERNSEC_TPE_TRUSTED_GID
68791 + int "GID for TPE-trusted users"
68792 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
68793 + default 1005
68794 + help
68795 + Setting this GID determines what group TPE restrictions will be
68796 + *disabled* for. If the sysctl option is enabled, a sysctl option
68797 + with name "tpe_gid" is created.
68798 +
68799 +endmenu
68800 +menu "Network Protections"
68801 +depends on GRKERNSEC
68802 +
68803 +config GRKERNSEC_BLACKHOLE
68804 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
68805 + default y if GRKERNSEC_CONFIG_AUTO
68806 + depends on NET
68807 + help
68808 + If you say Y here, neither TCP resets nor ICMP
68809 + destination-unreachable packets will be sent in response to packets
68810 + sent to ports for which no associated listening process exists.
68811 + It will also prevent the sending of ICMP protocol unreachable packets
68812 + in response to packets with unknown protocols.
68813 + This feature supports both IPV4 and IPV6 and exempts the
68814 + loopback interface from blackholing. Enabling this feature
68815 + makes a host more resilient to DoS attacks and reduces network
68816 + visibility against scanners.
68817 +
68818 + The blackhole feature as-implemented is equivalent to the FreeBSD
68819 + blackhole feature, as it prevents RST responses to all packets, not
68820 + just SYNs. Under most application behavior this causes no
68821 + problems, but applications (like haproxy) may not close certain
68822 + connections in a way that cleanly terminates them on the remote
68823 + end, leaving the remote host in LAST_ACK state. Because of this
68824 + side-effect and to prevent intentional LAST_ACK DoSes, this
68825 + feature also adds automatic mitigation against such attacks.
68826 + The mitigation drastically reduces the amount of time a socket
68827 + can spend in LAST_ACK state. If you're using haproxy and not
68828 + all servers it connects to have this option enabled, consider
68829 + disabling this feature on the haproxy host.
68830 +
68831 + If the sysctl option is enabled, two sysctl options with names
68832 + "ip_blackhole" and "lastack_retries" will be created.
68833 + While "ip_blackhole" takes the standard zero/non-zero on/off
68834 + toggle, "lastack_retries" uses the same kinds of values as
68835 + "tcp_retries1" and "tcp_retries2". The default value of 4
68836 + prevents a socket from lasting more than 45 seconds in LAST_ACK
68837 + state.
68838 +
68839 +config GRKERNSEC_NO_SIMULT_CONNECT
68840 + bool "Disable TCP Simultaneous Connect"
68841 + default y if GRKERNSEC_CONFIG_AUTO
68842 + depends on NET
68843 + help
68844 + If you say Y here, a feature by Willy Tarreau will be enabled that
68845 + removes a weakness in Linux's strict implementation of TCP that
68846 + allows two clients to connect to each other without either entering
68847 + a listening state. The weakness allows an attacker to easily prevent
68848 + a client from connecting to a known server provided the source port
68849 + for the connection is guessed correctly.
68850 +
68851 + As the weakness could be used to prevent an antivirus or IPS from
68852 + fetching updates, or prevent an SSL gateway from fetching a CRL,
68853 + it should be eliminated by enabling this option. Though Linux is
68854 + one of few operating systems supporting simultaneous connect, it
68855 + has no legitimate use in practice and is rarely supported by firewalls.
68856 +
68857 +config GRKERNSEC_SOCKET
68858 + bool "Socket restrictions"
68859 + depends on NET
68860 + help
68861 + If you say Y here, you will be able to choose from several options.
68862 + If you assign a GID on your system and add it to the supplementary
68863 + groups of users you want to restrict socket access to, this patch
68864 + will perform up to three things, based on the option(s) you choose.
68865 +
68866 +config GRKERNSEC_SOCKET_ALL
68867 + bool "Deny any sockets to group"
68868 + depends on GRKERNSEC_SOCKET
68869 + help
68870 + If you say Y here, you will be able to choose a GID of whose users will
68871 + be unable to connect to other hosts from your machine or run server
68872 + applications from your machine. If the sysctl option is enabled, a
68873 + sysctl option with name "socket_all" is created.
68874 +
68875 +config GRKERNSEC_SOCKET_ALL_GID
68876 + int "GID to deny all sockets for"
68877 + depends on GRKERNSEC_SOCKET_ALL
68878 + default 1004
68879 + help
68880 + Here you can choose the GID to disable socket access for. Remember to
68881 + add the users you want socket access disabled for to the GID
68882 + specified here. If the sysctl option is enabled, a sysctl option
68883 + with name "socket_all_gid" is created.
68884 +
68885 +config GRKERNSEC_SOCKET_CLIENT
68886 + bool "Deny client sockets to group"
68887 + depends on GRKERNSEC_SOCKET
68888 + help
68889 + If you say Y here, you will be able to choose a GID of whose users will
68890 + be unable to connect to other hosts from your machine, but will be
68891 + able to run servers. If this option is enabled, all users in the group
68892 + you specify will have to use passive mode when initiating ftp transfers
68893 + from the shell on your machine. If the sysctl option is enabled, a
68894 + sysctl option with name "socket_client" is created.
68895 +
68896 +config GRKERNSEC_SOCKET_CLIENT_GID
68897 + int "GID to deny client sockets for"
68898 + depends on GRKERNSEC_SOCKET_CLIENT
68899 + default 1003
68900 + help
68901 + Here you can choose the GID to disable client socket access for.
68902 + Remember to add the users you want client socket access disabled for to
68903 + the GID specified here. If the sysctl option is enabled, a sysctl
68904 + option with name "socket_client_gid" is created.
68905 +
68906 +config GRKERNSEC_SOCKET_SERVER
68907 + bool "Deny server sockets to group"
68908 + depends on GRKERNSEC_SOCKET
68909 + help
68910 + If you say Y here, you will be able to choose a GID of whose users will
68911 + be unable to run server applications from your machine. If the sysctl
68912 + option is enabled, a sysctl option with name "socket_server" is created.
68913 +
68914 +config GRKERNSEC_SOCKET_SERVER_GID
68915 + int "GID to deny server sockets for"
68916 + depends on GRKERNSEC_SOCKET_SERVER
68917 + default 1002
68918 + help
68919 + Here you can choose the GID to disable server socket access for.
68920 + Remember to add the users you want server socket access disabled for to
68921 + the GID specified here. If the sysctl option is enabled, a sysctl
68922 + option with name "socket_server_gid" is created.
68923 +
68924 +endmenu
68925 +
68926 +menu "Physical Protections"
68927 +depends on GRKERNSEC
68928 +
68929 +config GRKERNSEC_DENYUSB
68930 + bool "Deny new USB connections after toggle"
68931 + default y if GRKERNSEC_CONFIG_AUTO
68932 + depends on SYSCTL && USB_SUPPORT
68933 + help
68934 + If you say Y here, a new sysctl option with name "deny_new_usb"
68935 + will be created. Setting its value to 1 will prevent any new
68936 + USB devices from being recognized by the OS. Any attempted USB
68937 + device insertion will be logged. This option is intended to be
68938 + used against custom USB devices designed to exploit vulnerabilities
68939 + in various USB device drivers.
68940 +
68941 + For greatest effectiveness, this sysctl should be set after any
68942 + relevant init scripts. This option is safe to enable in distros
68943 + as each user can choose whether or not to toggle the sysctl.
68944 +
68945 +config GRKERNSEC_DENYUSB_FORCE
68946 + bool "Reject all USB devices not connected at boot"
68947 + select USB
68948 + depends on GRKERNSEC_DENYUSB
68949 + help
68950 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
68951 + that doesn't involve a sysctl entry. This option should only be
68952 + enabled if you're sure you want to deny all new USB connections
68953 + at runtime and don't want to modify init scripts. This should not
68954 + be enabled by distros. It forces the core USB code to be built
68955 + into the kernel image so that all devices connected at boot time
68956 + can be recognized and new USB device connections can be prevented
68957 + prior to init running.
68958 +
68959 +endmenu
68960 +
68961 +menu "Sysctl Support"
68962 +depends on GRKERNSEC && SYSCTL
68963 +
68964 +config GRKERNSEC_SYSCTL
68965 + bool "Sysctl support"
68966 + default y if GRKERNSEC_CONFIG_AUTO
68967 + help
68968 + If you say Y here, you will be able to change the options that
68969 + grsecurity runs with at bootup, without having to recompile your
68970 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
68971 + to enable (1) or disable (0) various features. All the sysctl entries
68972 + are mutable until the "grsec_lock" entry is set to a non-zero value.
68973 + All features enabled in the kernel configuration are disabled at boot
68974 + if you do not say Y to the "Turn on features by default" option.
68975 + All options should be set at startup, and the grsec_lock entry should
68976 + be set to a non-zero value after all the options are set.
68977 + *THIS IS EXTREMELY IMPORTANT*
68978 +
68979 +config GRKERNSEC_SYSCTL_DISTRO
68980 + bool "Extra sysctl support for distro makers (READ HELP)"
68981 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
68982 + help
68983 + If you say Y here, additional sysctl options will be created
68984 + for features that affect processes running as root. Therefore,
68985 + it is critical when using this option that the grsec_lock entry be
68986 + enabled after boot. Only distros with prebuilt kernel packages
68987 + with this option enabled that can ensure grsec_lock is enabled
68988 + after boot should use this option.
68989 + *Failure to set grsec_lock after boot makes all grsec features
68990 + this option covers useless*
68991 +
68992 + Currently this option creates the following sysctl entries:
68993 + "Disable Privileged I/O": "disable_priv_io"
68994 +
68995 +config GRKERNSEC_SYSCTL_ON
68996 + bool "Turn on features by default"
68997 + default y if GRKERNSEC_CONFIG_AUTO
68998 + depends on GRKERNSEC_SYSCTL
68999 + help
69000 + If you say Y here, instead of having all features enabled in the
69001 + kernel configuration disabled at boot time, the features will be
69002 + enabled at boot time. It is recommended you say Y here unless
69003 + there is some reason you would want all sysctl-tunable features to
69004 + be disabled by default. As mentioned elsewhere, it is important
69005 + to enable the grsec_lock entry once you have finished modifying
69006 + the sysctl entries.
69007 +
69008 +endmenu
69009 +menu "Logging Options"
69010 +depends on GRKERNSEC
69011 +
69012 +config GRKERNSEC_FLOODTIME
69013 + int "Seconds in between log messages (minimum)"
69014 + default 10
69015 + help
69016 + This option allows you to enforce the number of seconds between
69017 + grsecurity log messages. The default should be suitable for most
69018 + people, however, if you choose to change it, choose a value small enough
69019 + to allow informative logs to be produced, but large enough to
69020 + prevent flooding.
69021 +
69022 + Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
69023 + any rate limiting on grsecurity log messages.
69024 +
69025 +config GRKERNSEC_FLOODBURST
69026 + int "Number of messages in a burst (maximum)"
69027 + default 6
69028 + help
69029 + This option allows you to choose the maximum number of messages allowed
69030 + within the flood time interval you chose in a separate option. The
69031 + default should be suitable for most people, however if you find that
69032 + many of your logs are being interpreted as flooding, you may want to
69033 + raise this value.
69034 +
69035 + Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
69036 + any rate limiting on grsecurity log messages.
69037 +
69038 +endmenu
69039 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
69040 new file mode 100644
69041 index 0000000..30ababb
69042 --- /dev/null
69043 +++ b/grsecurity/Makefile
69044 @@ -0,0 +1,54 @@
69045 +# grsecurity – access control and security hardening for Linux
69046 +# All code in this directory and various hooks located throughout the Linux kernel are
69047 +# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
69048 +# http://www.grsecurity.net spender@grsecurity.net
69049 +#
69050 +# This program is free software; you can redistribute it and/or
69051 +# modify it under the terms of the GNU General Public License version 2
69052 +# as published by the Free Software Foundation.
69053 +#
69054 +# This program is distributed in the hope that it will be useful,
69055 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
69056 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69057 +# GNU General Public License for more details.
69058 +#
69059 +# You should have received a copy of the GNU General Public License
69060 +# along with this program; if not, write to the Free Software
69061 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
69062 +
69063 +KBUILD_CFLAGS += -Werror
69064 +
69065 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
69066 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
69067 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
69068 + grsec_usb.o grsec_ipc.o grsec_proc.o
69069 +
69070 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
69071 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
69072 + gracl_learn.o grsec_log.o gracl_policy.o
69073 +ifdef CONFIG_COMPAT
69074 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
69075 +endif
69076 +
69077 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
69078 +
69079 +ifdef CONFIG_NET
69080 +obj-y += grsec_sock.o
69081 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
69082 +endif
69083 +
69084 +ifndef CONFIG_GRKERNSEC
69085 +obj-y += grsec_disabled.o
69086 +endif
69087 +
69088 +ifdef CONFIG_GRKERNSEC_HIDESYM
69089 +extra-y := grsec_hidesym.o
69090 +$(obj)/grsec_hidesym.o:
69091 + @-chmod -f 500 /boot
69092 + @-chmod -f 500 /lib/modules
69093 + @-chmod -f 500 /lib64/modules
69094 + @-chmod -f 500 /lib32/modules
69095 + @-chmod -f 700 .
69096 + @-chmod -f 700 $(objtree)
69097 + @echo ' grsec: protected kernel image paths'
69098 +endif
69099 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
69100 new file mode 100644
69101 index 0000000..6ae3aa0
69102 --- /dev/null
69103 +++ b/grsecurity/gracl.c
69104 @@ -0,0 +1,2703 @@
69105 +#include <linux/kernel.h>
69106 +#include <linux/module.h>
69107 +#include <linux/sched.h>
69108 +#include <linux/mm.h>
69109 +#include <linux/file.h>
69110 +#include <linux/fs.h>
69111 +#include <linux/namei.h>
69112 +#include <linux/mount.h>
69113 +#include <linux/tty.h>
69114 +#include <linux/proc_fs.h>
69115 +#include <linux/lglock.h>
69116 +#include <linux/slab.h>
69117 +#include <linux/vmalloc.h>
69118 +#include <linux/types.h>
69119 +#include <linux/sysctl.h>
69120 +#include <linux/netdevice.h>
69121 +#include <linux/ptrace.h>
69122 +#include <linux/gracl.h>
69123 +#include <linux/gralloc.h>
69124 +#include <linux/security.h>
69125 +#include <linux/grinternal.h>
69126 +#include <linux/pid_namespace.h>
69127 +#include <linux/stop_machine.h>
69128 +#include <linux/fdtable.h>
69129 +#include <linux/percpu.h>
69130 +#include <linux/lglock.h>
69131 +#include <linux/hugetlb.h>
69132 +#include <linux/posix-timers.h>
69133 +#include <linux/prefetch.h>
69134 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69135 +#include <linux/magic.h>
69136 +#include <linux/pagemap.h>
69137 +#include "../fs/btrfs/async-thread.h"
69138 +#include "../fs/btrfs/ctree.h"
69139 +#include "../fs/btrfs/btrfs_inode.h"
69140 +#endif
69141 +#include "../fs/mount.h"
69142 +
69143 +#include <asm/uaccess.h>
69144 +#include <asm/errno.h>
69145 +#include <asm/mman.h>
69146 +
69147 +#define FOR_EACH_ROLE_START(role) \
69148 + role = running_polstate.role_list; \
69149 + while (role) {
69150 +
69151 +#define FOR_EACH_ROLE_END(role) \
69152 + role = role->prev; \
69153 + }
69154 +
69155 +extern struct path gr_real_root;
69156 +
69157 +static struct gr_policy_state running_polstate;
69158 +struct gr_policy_state *polstate = &running_polstate;
69159 +extern struct gr_alloc_state *current_alloc_state;
69160 +
69161 +extern char *gr_shared_page[4];
69162 +DEFINE_RWLOCK(gr_inode_lock);
69163 +
69164 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
69165 +
69166 +#ifdef CONFIG_NET
69167 +extern struct vfsmount *sock_mnt;
69168 +#endif
69169 +
69170 +extern struct vfsmount *pipe_mnt;
69171 +extern struct vfsmount *shm_mnt;
69172 +
69173 +#ifdef CONFIG_HUGETLBFS
69174 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
69175 +#endif
69176 +
69177 +extern u16 acl_sp_role_value;
69178 +extern struct acl_object_label *fakefs_obj_rw;
69179 +extern struct acl_object_label *fakefs_obj_rwx;
69180 +
69181 +int gr_acl_is_enabled(void)
69182 +{
69183 + return (gr_status & GR_READY);
69184 +}
69185 +
69186 +void gr_enable_rbac_system(void)
69187 +{
69188 + pax_open_kernel();
69189 + gr_status |= GR_READY;
69190 + pax_close_kernel();
69191 +}
69192 +
69193 +int gr_rbac_disable(void *unused)
69194 +{
69195 + pax_open_kernel();
69196 + gr_status &= ~GR_READY;
69197 + pax_close_kernel();
69198 +
69199 + return 0;
69200 +}
69201 +
69202 +static inline dev_t __get_dev(const struct dentry *dentry)
69203 +{
69204 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69205 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
69206 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
69207 + else
69208 +#endif
69209 + return dentry->d_sb->s_dev;
69210 +}
69211 +
69212 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
69213 +{
69214 + return __get_dev(dentry);
69215 +}
69216 +
69217 +static char gr_task_roletype_to_char(struct task_struct *task)
69218 +{
69219 + switch (task->role->roletype &
69220 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
69221 + GR_ROLE_SPECIAL)) {
69222 + case GR_ROLE_DEFAULT:
69223 + return 'D';
69224 + case GR_ROLE_USER:
69225 + return 'U';
69226 + case GR_ROLE_GROUP:
69227 + return 'G';
69228 + case GR_ROLE_SPECIAL:
69229 + return 'S';
69230 + }
69231 +
69232 + return 'X';
69233 +}
69234 +
69235 +char gr_roletype_to_char(void)
69236 +{
69237 + return gr_task_roletype_to_char(current);
69238 +}
69239 +
69240 +__inline__ int
69241 +gr_acl_tpe_check(void)
69242 +{
69243 + if (unlikely(!(gr_status & GR_READY)))
69244 + return 0;
69245 + if (current->role->roletype & GR_ROLE_TPE)
69246 + return 1;
69247 + else
69248 + return 0;
69249 +}
69250 +
69251 +int
69252 +gr_handle_rawio(const struct inode *inode)
69253 +{
69254 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69255 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
69256 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
69257 + !capable(CAP_SYS_RAWIO))
69258 + return 1;
69259 +#endif
69260 + return 0;
69261 +}
69262 +
69263 +int
69264 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
69265 +{
69266 + if (likely(lena != lenb))
69267 + return 0;
69268 +
69269 + return !memcmp(a, b, lena);
69270 +}
69271 +
69272 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
69273 +{
69274 + *buflen -= namelen;
69275 + if (*buflen < 0)
69276 + return -ENAMETOOLONG;
69277 + *buffer -= namelen;
69278 + memcpy(*buffer, str, namelen);
69279 + return 0;
69280 +}
69281 +
69282 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
69283 +{
69284 + return prepend(buffer, buflen, name->name, name->len);
69285 +}
69286 +
69287 +static int prepend_path(const struct path *path, struct path *root,
69288 + char **buffer, int *buflen)
69289 +{
69290 + struct dentry *dentry = path->dentry;
69291 + struct vfsmount *vfsmnt = path->mnt;
69292 + struct mount *mnt = real_mount(vfsmnt);
69293 + bool slash = false;
69294 + int error = 0;
69295 +
69296 + while (dentry != root->dentry || vfsmnt != root->mnt) {
69297 + struct dentry * parent;
69298 +
69299 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
69300 + /* Global root? */
69301 + if (!mnt_has_parent(mnt)) {
69302 + goto out;
69303 + }
69304 + dentry = mnt->mnt_mountpoint;
69305 + mnt = mnt->mnt_parent;
69306 + vfsmnt = &mnt->mnt;
69307 + continue;
69308 + }
69309 + parent = dentry->d_parent;
69310 + prefetch(parent);
69311 + spin_lock(&dentry->d_lock);
69312 + error = prepend_name(buffer, buflen, &dentry->d_name);
69313 + spin_unlock(&dentry->d_lock);
69314 + if (!error)
69315 + error = prepend(buffer, buflen, "/", 1);
69316 + if (error)
69317 + break;
69318 +
69319 + slash = true;
69320 + dentry = parent;
69321 + }
69322 +
69323 +out:
69324 + if (!error && !slash)
69325 + error = prepend(buffer, buflen, "/", 1);
69326 +
69327 + return error;
69328 +}
69329 +
69330 +/* this must be called with mount_lock and rename_lock held */
69331 +
69332 +static char *__our_d_path(const struct path *path, struct path *root,
69333 + char *buf, int buflen)
69334 +{
69335 + char *res = buf + buflen;
69336 + int error;
69337 +
69338 + prepend(&res, &buflen, "\0", 1);
69339 + error = prepend_path(path, root, &res, &buflen);
69340 + if (error)
69341 + return ERR_PTR(error);
69342 +
69343 + return res;
69344 +}
69345 +
69346 +static char *
69347 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
69348 +{
69349 + char *retval;
69350 +
69351 + retval = __our_d_path(path, root, buf, buflen);
69352 + if (unlikely(IS_ERR(retval)))
69353 + retval = strcpy(buf, "<path too long>");
69354 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
69355 + retval[1] = '\0';
69356 +
69357 + return retval;
69358 +}
69359 +
69360 +static char *
69361 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
69362 + char *buf, int buflen)
69363 +{
69364 + struct path path;
69365 + char *res;
69366 +
69367 + path.dentry = (struct dentry *)dentry;
69368 + path.mnt = (struct vfsmount *)vfsmnt;
69369 +
69370 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
69371 + by the RBAC system */
69372 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
69373 +
69374 + return res;
69375 +}
69376 +
69377 +static char *
69378 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
69379 + char *buf, int buflen)
69380 +{
69381 + char *res;
69382 + struct path path;
69383 + struct path root;
69384 + struct task_struct *reaper = init_pid_ns.child_reaper;
69385 +
69386 + path.dentry = (struct dentry *)dentry;
69387 + path.mnt = (struct vfsmount *)vfsmnt;
69388 +
69389 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
69390 + get_fs_root(reaper->fs, &root);
69391 +
69392 + read_seqlock_excl(&mount_lock);
69393 + write_seqlock(&rename_lock);
69394 + res = gen_full_path(&path, &root, buf, buflen);
69395 + write_sequnlock(&rename_lock);
69396 + read_sequnlock_excl(&mount_lock);
69397 +
69398 + path_put(&root);
69399 + return res;
69400 +}
69401 +
69402 +char *
69403 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
69404 +{
69405 + char *ret;
69406 + read_seqlock_excl(&mount_lock);
69407 + write_seqlock(&rename_lock);
69408 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
69409 + PAGE_SIZE);
69410 + write_sequnlock(&rename_lock);
69411 + read_sequnlock_excl(&mount_lock);
69412 + return ret;
69413 +}
69414 +
69415 +static char *
69416 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
69417 +{
69418 + char *ret;
69419 + char *buf;
69420 + int buflen;
69421 +
69422 + read_seqlock_excl(&mount_lock);
69423 + write_seqlock(&rename_lock);
69424 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
69425 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
69426 + buflen = (int)(ret - buf);
69427 + if (buflen >= 5)
69428 + prepend(&ret, &buflen, "/proc", 5);
69429 + else
69430 + ret = strcpy(buf, "<path too long>");
69431 + write_sequnlock(&rename_lock);
69432 + read_sequnlock_excl(&mount_lock);
69433 + return ret;
69434 +}
69435 +
69436 +char *
69437 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
69438 +{
69439 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
69440 + PAGE_SIZE);
69441 +}
69442 +
69443 +char *
69444 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
69445 +{
69446 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69447 + PAGE_SIZE);
69448 +}
69449 +
69450 +char *
69451 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
69452 +{
69453 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
69454 + PAGE_SIZE);
69455 +}
69456 +
69457 +char *
69458 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
69459 +{
69460 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
69461 + PAGE_SIZE);
69462 +}
69463 +
69464 +char *
69465 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
69466 +{
69467 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
69468 + PAGE_SIZE);
69469 +}
69470 +
69471 +__inline__ __u32
69472 +to_gr_audit(const __u32 reqmode)
69473 +{
69474 + /* masks off auditable permission flags, then shifts them to create
69475 + auditing flags, and adds the special case of append auditing if
69476 + we're requesting write */
69477 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
69478 +}
69479 +
69480 +struct acl_role_label *
69481 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
69482 + const gid_t gid)
69483 +{
69484 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
69485 + struct acl_role_label *match;
69486 + struct role_allowed_ip *ipp;
69487 + unsigned int x;
69488 + u32 curr_ip = task->signal->saved_ip;
69489 +
69490 + match = state->acl_role_set.r_hash[index];
69491 +
69492 + while (match) {
69493 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
69494 + for (x = 0; x < match->domain_child_num; x++) {
69495 + if (match->domain_children[x] == uid)
69496 + goto found;
69497 + }
69498 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
69499 + break;
69500 + match = match->next;
69501 + }
69502 +found:
69503 + if (match == NULL) {
69504 + try_group:
69505 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
69506 + match = state->acl_role_set.r_hash[index];
69507 +
69508 + while (match) {
69509 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
69510 + for (x = 0; x < match->domain_child_num; x++) {
69511 + if (match->domain_children[x] == gid)
69512 + goto found2;
69513 + }
69514 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
69515 + break;
69516 + match = match->next;
69517 + }
69518 +found2:
69519 + if (match == NULL)
69520 + match = state->default_role;
69521 + if (match->allowed_ips == NULL)
69522 + return match;
69523 + else {
69524 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
69525 + if (likely
69526 + ((ntohl(curr_ip) & ipp->netmask) ==
69527 + (ntohl(ipp->addr) & ipp->netmask)))
69528 + return match;
69529 + }
69530 + match = state->default_role;
69531 + }
69532 + } else if (match->allowed_ips == NULL) {
69533 + return match;
69534 + } else {
69535 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
69536 + if (likely
69537 + ((ntohl(curr_ip) & ipp->netmask) ==
69538 + (ntohl(ipp->addr) & ipp->netmask)))
69539 + return match;
69540 + }
69541 + goto try_group;
69542 + }
69543 +
69544 + return match;
69545 +}
69546 +
69547 +static struct acl_role_label *
69548 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
69549 + const gid_t gid)
69550 +{
69551 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
69552 +}
69553 +
69554 +struct acl_subject_label *
69555 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
69556 + const struct acl_role_label *role)
69557 +{
69558 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
69559 + struct acl_subject_label *match;
69560 +
69561 + match = role->subj_hash[index];
69562 +
69563 + while (match && (match->inode != ino || match->device != dev ||
69564 + (match->mode & GR_DELETED))) {
69565 + match = match->next;
69566 + }
69567 +
69568 + if (match && !(match->mode & GR_DELETED))
69569 + return match;
69570 + else
69571 + return NULL;
69572 +}
69573 +
69574 +struct acl_subject_label *
69575 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
69576 + const struct acl_role_label *role)
69577 +{
69578 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
69579 + struct acl_subject_label *match;
69580 +
69581 + match = role->subj_hash[index];
69582 +
69583 + while (match && (match->inode != ino || match->device != dev ||
69584 + !(match->mode & GR_DELETED))) {
69585 + match = match->next;
69586 + }
69587 +
69588 + if (match && (match->mode & GR_DELETED))
69589 + return match;
69590 + else
69591 + return NULL;
69592 +}
69593 +
69594 +static struct acl_object_label *
69595 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
69596 + const struct acl_subject_label *subj)
69597 +{
69598 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
69599 + struct acl_object_label *match;
69600 +
69601 + match = subj->obj_hash[index];
69602 +
69603 + while (match && (match->inode != ino || match->device != dev ||
69604 + (match->mode & GR_DELETED))) {
69605 + match = match->next;
69606 + }
69607 +
69608 + if (match && !(match->mode & GR_DELETED))
69609 + return match;
69610 + else
69611 + return NULL;
69612 +}
69613 +
69614 +static struct acl_object_label *
69615 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
69616 + const struct acl_subject_label *subj)
69617 +{
69618 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
69619 + struct acl_object_label *match;
69620 +
69621 + match = subj->obj_hash[index];
69622 +
69623 + while (match && (match->inode != ino || match->device != dev ||
69624 + !(match->mode & GR_DELETED))) {
69625 + match = match->next;
69626 + }
69627 +
69628 + if (match && (match->mode & GR_DELETED))
69629 + return match;
69630 +
69631 + match = subj->obj_hash[index];
69632 +
69633 + while (match && (match->inode != ino || match->device != dev ||
69634 + (match->mode & GR_DELETED))) {
69635 + match = match->next;
69636 + }
69637 +
69638 + if (match && !(match->mode & GR_DELETED))
69639 + return match;
69640 + else
69641 + return NULL;
69642 +}
69643 +
69644 +struct name_entry *
69645 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
69646 +{
69647 + unsigned int len = strlen(name);
69648 + unsigned int key = full_name_hash(name, len);
69649 + unsigned int index = key % state->name_set.n_size;
69650 + struct name_entry *match;
69651 +
69652 + match = state->name_set.n_hash[index];
69653 +
69654 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
69655 + match = match->next;
69656 +
69657 + return match;
69658 +}
69659 +
69660 +static struct name_entry *
69661 +lookup_name_entry(const char *name)
69662 +{
69663 + return __lookup_name_entry(&running_polstate, name);
69664 +}
69665 +
69666 +static struct name_entry *
69667 +lookup_name_entry_create(const char *name)
69668 +{
69669 + unsigned int len = strlen(name);
69670 + unsigned int key = full_name_hash(name, len);
69671 + unsigned int index = key % running_polstate.name_set.n_size;
69672 + struct name_entry *match;
69673 +
69674 + match = running_polstate.name_set.n_hash[index];
69675 +
69676 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
69677 + !match->deleted))
69678 + match = match->next;
69679 +
69680 + if (match && match->deleted)
69681 + return match;
69682 +
69683 + match = running_polstate.name_set.n_hash[index];
69684 +
69685 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
69686 + match->deleted))
69687 + match = match->next;
69688 +
69689 + if (match && !match->deleted)
69690 + return match;
69691 + else
69692 + return NULL;
69693 +}
69694 +
69695 +static struct inodev_entry *
69696 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
69697 +{
69698 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
69699 + struct inodev_entry *match;
69700 +
69701 + match = running_polstate.inodev_set.i_hash[index];
69702 +
69703 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
69704 + match = match->next;
69705 +
69706 + return match;
69707 +}
69708 +
69709 +void
69710 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
69711 +{
69712 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
69713 + state->inodev_set.i_size);
69714 + struct inodev_entry **curr;
69715 +
69716 + entry->prev = NULL;
69717 +
69718 + curr = &state->inodev_set.i_hash[index];
69719 + if (*curr != NULL)
69720 + (*curr)->prev = entry;
69721 +
69722 + entry->next = *curr;
69723 + *curr = entry;
69724 +
69725 + return;
69726 +}
69727 +
69728 +static void
69729 +insert_inodev_entry(struct inodev_entry *entry)
69730 +{
69731 + __insert_inodev_entry(&running_polstate, entry);
69732 +}
69733 +
69734 +void
69735 +insert_acl_obj_label(struct acl_object_label *obj,
69736 + struct acl_subject_label *subj)
69737 +{
69738 + unsigned int index =
69739 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
69740 + struct acl_object_label **curr;
69741 +
69742 + obj->prev = NULL;
69743 +
69744 + curr = &subj->obj_hash[index];
69745 + if (*curr != NULL)
69746 + (*curr)->prev = obj;
69747 +
69748 + obj->next = *curr;
69749 + *curr = obj;
69750 +
69751 + return;
69752 +}
69753 +
69754 +void
69755 +insert_acl_subj_label(struct acl_subject_label *obj,
69756 + struct acl_role_label *role)
69757 +{
69758 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
69759 + struct acl_subject_label **curr;
69760 +
69761 + obj->prev = NULL;
69762 +
69763 + curr = &role->subj_hash[index];
69764 + if (*curr != NULL)
69765 + (*curr)->prev = obj;
69766 +
69767 + obj->next = *curr;
69768 + *curr = obj;
69769 +
69770 + return;
69771 +}
69772 +
69773 +/* derived from glibc fnmatch() 0: match, 1: no match*/
69774 +
69775 +static int
69776 +glob_match(const char *p, const char *n)
69777 +{
69778 + char c;
69779 +
69780 + while ((c = *p++) != '\0') {
69781 + switch (c) {
69782 + case '?':
69783 + if (*n == '\0')
69784 + return 1;
69785 + else if (*n == '/')
69786 + return 1;
69787 + break;
69788 + case '\\':
69789 + if (*n != c)
69790 + return 1;
69791 + break;
69792 + case '*':
69793 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
69794 + if (*n == '/')
69795 + return 1;
69796 + else if (c == '?') {
69797 + if (*n == '\0')
69798 + return 1;
69799 + else
69800 + ++n;
69801 + }
69802 + }
69803 + if (c == '\0') {
69804 + return 0;
69805 + } else {
69806 + const char *endp;
69807 +
69808 + if ((endp = strchr(n, '/')) == NULL)
69809 + endp = n + strlen(n);
69810 +
69811 + if (c == '[') {
69812 + for (--p; n < endp; ++n)
69813 + if (!glob_match(p, n))
69814 + return 0;
69815 + } else if (c == '/') {
69816 + while (*n != '\0' && *n != '/')
69817 + ++n;
69818 + if (*n == '/' && !glob_match(p, n + 1))
69819 + return 0;
69820 + } else {
69821 + for (--p; n < endp; ++n)
69822 + if (*n == c && !glob_match(p, n))
69823 + return 0;
69824 + }
69825 +
69826 + return 1;
69827 + }
69828 + case '[':
69829 + {
69830 + int not;
69831 + char cold;
69832 +
69833 + if (*n == '\0' || *n == '/')
69834 + return 1;
69835 +
69836 + not = (*p == '!' || *p == '^');
69837 + if (not)
69838 + ++p;
69839 +
69840 + c = *p++;
69841 + for (;;) {
69842 + unsigned char fn = (unsigned char)*n;
69843 +
69844 + if (c == '\0')
69845 + return 1;
69846 + else {
69847 + if (c == fn)
69848 + goto matched;
69849 + cold = c;
69850 + c = *p++;
69851 +
69852 + if (c == '-' && *p != ']') {
69853 + unsigned char cend = *p++;
69854 +
69855 + if (cend == '\0')
69856 + return 1;
69857 +
69858 + if (cold <= fn && fn <= cend)
69859 + goto matched;
69860 +
69861 + c = *p++;
69862 + }
69863 + }
69864 +
69865 + if (c == ']')
69866 + break;
69867 + }
69868 + if (!not)
69869 + return 1;
69870 + break;
69871 + matched:
69872 + while (c != ']') {
69873 + if (c == '\0')
69874 + return 1;
69875 +
69876 + c = *p++;
69877 + }
69878 + if (not)
69879 + return 1;
69880 + }
69881 + break;
69882 + default:
69883 + if (c != *n)
69884 + return 1;
69885 + }
69886 +
69887 + ++n;
69888 + }
69889 +
69890 + if (*n == '\0')
69891 + return 0;
69892 +
69893 + if (*n == '/')
69894 + return 0;
69895 +
69896 + return 1;
69897 +}
69898 +
69899 +static struct acl_object_label *
69900 +chk_glob_label(struct acl_object_label *globbed,
69901 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
69902 +{
69903 + struct acl_object_label *tmp;
69904 +
69905 + if (*path == NULL)
69906 + *path = gr_to_filename_nolock(dentry, mnt);
69907 +
69908 + tmp = globbed;
69909 +
69910 + while (tmp) {
69911 + if (!glob_match(tmp->filename, *path))
69912 + return tmp;
69913 + tmp = tmp->next;
69914 + }
69915 +
69916 + return NULL;
69917 +}
69918 +
69919 +static struct acl_object_label *
69920 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
69921 + const ino_t curr_ino, const dev_t curr_dev,
69922 + const struct acl_subject_label *subj, char **path, const int checkglob)
69923 +{
69924 + struct acl_subject_label *tmpsubj;
69925 + struct acl_object_label *retval;
69926 + struct acl_object_label *retval2;
69927 +
69928 + tmpsubj = (struct acl_subject_label *) subj;
69929 + read_lock(&gr_inode_lock);
69930 + do {
69931 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
69932 + if (retval) {
69933 + if (checkglob && retval->globbed) {
69934 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
69935 + if (retval2)
69936 + retval = retval2;
69937 + }
69938 + break;
69939 + }
69940 + } while ((tmpsubj = tmpsubj->parent_subject));
69941 + read_unlock(&gr_inode_lock);
69942 +
69943 + return retval;
69944 +}
69945 +
69946 +static __inline__ struct acl_object_label *
69947 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
69948 + struct dentry *curr_dentry,
69949 + const struct acl_subject_label *subj, char **path, const int checkglob)
69950 +{
69951 + int newglob = checkglob;
69952 + ino_t inode;
69953 + dev_t device;
69954 +
69955 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
69956 + as we don't want a / * rule to match instead of the / object
69957 + don't do this for create lookups that call this function though, since they're looking up
69958 + on the parent and thus need globbing checks on all paths
69959 + */
69960 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
69961 + newglob = GR_NO_GLOB;
69962 +
69963 + spin_lock(&curr_dentry->d_lock);
69964 + inode = curr_dentry->d_inode->i_ino;
69965 + device = __get_dev(curr_dentry);
69966 + spin_unlock(&curr_dentry->d_lock);
69967 +
69968 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
69969 +}
69970 +
69971 +#ifdef CONFIG_HUGETLBFS
69972 +static inline bool
69973 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
69974 +{
69975 + int i;
69976 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
69977 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
69978 + return true;
69979 + }
69980 +
69981 + return false;
69982 +}
69983 +#endif
69984 +
69985 +static struct acl_object_label *
69986 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
69987 + const struct acl_subject_label *subj, char *path, const int checkglob)
69988 +{
69989 + struct dentry *dentry = (struct dentry *) l_dentry;
69990 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
69991 + struct mount *real_mnt = real_mount(mnt);
69992 + struct acl_object_label *retval;
69993 + struct dentry *parent;
69994 +
69995 + read_seqlock_excl(&mount_lock);
69996 + write_seqlock(&rename_lock);
69997 +
69998 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
69999 +#ifdef CONFIG_NET
70000 + mnt == sock_mnt ||
70001 +#endif
70002 +#ifdef CONFIG_HUGETLBFS
70003 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
70004 +#endif
70005 + /* ignore Eric Biederman */
70006 + IS_PRIVATE(l_dentry->d_inode))) {
70007 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
70008 + goto out;
70009 + }
70010 +
70011 + for (;;) {
70012 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70013 + break;
70014 +
70015 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70016 + if (!mnt_has_parent(real_mnt))
70017 + break;
70018 +
70019 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70020 + if (retval != NULL)
70021 + goto out;
70022 +
70023 + dentry = real_mnt->mnt_mountpoint;
70024 + real_mnt = real_mnt->mnt_parent;
70025 + mnt = &real_mnt->mnt;
70026 + continue;
70027 + }
70028 +
70029 + parent = dentry->d_parent;
70030 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70031 + if (retval != NULL)
70032 + goto out;
70033 +
70034 + dentry = parent;
70035 + }
70036 +
70037 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70038 +
70039 + /* gr_real_root is pinned so we don't have to hold a reference */
70040 + if (retval == NULL)
70041 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
70042 +out:
70043 + write_sequnlock(&rename_lock);
70044 + read_sequnlock_excl(&mount_lock);
70045 +
70046 + BUG_ON(retval == NULL);
70047 +
70048 + return retval;
70049 +}
70050 +
70051 +static __inline__ struct acl_object_label *
70052 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70053 + const struct acl_subject_label *subj)
70054 +{
70055 + char *path = NULL;
70056 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
70057 +}
70058 +
70059 +static __inline__ struct acl_object_label *
70060 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70061 + const struct acl_subject_label *subj)
70062 +{
70063 + char *path = NULL;
70064 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
70065 +}
70066 +
70067 +static __inline__ struct acl_object_label *
70068 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70069 + const struct acl_subject_label *subj, char *path)
70070 +{
70071 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
70072 +}
70073 +
70074 +struct acl_subject_label *
70075 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70076 + const struct acl_role_label *role)
70077 +{
70078 + struct dentry *dentry = (struct dentry *) l_dentry;
70079 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70080 + struct mount *real_mnt = real_mount(mnt);
70081 + struct acl_subject_label *retval;
70082 + struct dentry *parent;
70083 +
70084 + read_seqlock_excl(&mount_lock);
70085 + write_seqlock(&rename_lock);
70086 +
70087 + for (;;) {
70088 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70089 + break;
70090 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70091 + if (!mnt_has_parent(real_mnt))
70092 + break;
70093 +
70094 + spin_lock(&dentry->d_lock);
70095 + read_lock(&gr_inode_lock);
70096 + retval =
70097 + lookup_acl_subj_label(dentry->d_inode->i_ino,
70098 + __get_dev(dentry), role);
70099 + read_unlock(&gr_inode_lock);
70100 + spin_unlock(&dentry->d_lock);
70101 + if (retval != NULL)
70102 + goto out;
70103 +
70104 + dentry = real_mnt->mnt_mountpoint;
70105 + real_mnt = real_mnt->mnt_parent;
70106 + mnt = &real_mnt->mnt;
70107 + continue;
70108 + }
70109 +
70110 + spin_lock(&dentry->d_lock);
70111 + read_lock(&gr_inode_lock);
70112 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
70113 + __get_dev(dentry), role);
70114 + read_unlock(&gr_inode_lock);
70115 + parent = dentry->d_parent;
70116 + spin_unlock(&dentry->d_lock);
70117 +
70118 + if (retval != NULL)
70119 + goto out;
70120 +
70121 + dentry = parent;
70122 + }
70123 +
70124 + spin_lock(&dentry->d_lock);
70125 + read_lock(&gr_inode_lock);
70126 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
70127 + __get_dev(dentry), role);
70128 + read_unlock(&gr_inode_lock);
70129 + spin_unlock(&dentry->d_lock);
70130 +
70131 + if (unlikely(retval == NULL)) {
70132 + /* gr_real_root is pinned, we don't need to hold a reference */
70133 + read_lock(&gr_inode_lock);
70134 + retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
70135 + __get_dev(gr_real_root.dentry), role);
70136 + read_unlock(&gr_inode_lock);
70137 + }
70138 +out:
70139 + write_sequnlock(&rename_lock);
70140 + read_sequnlock_excl(&mount_lock);
70141 +
70142 + BUG_ON(retval == NULL);
70143 +
70144 + return retval;
70145 +}
70146 +
70147 +void
70148 +assign_special_role(const char *rolename)
70149 +{
70150 + struct acl_object_label *obj;
70151 + struct acl_role_label *r;
70152 + struct acl_role_label *assigned = NULL;
70153 + struct task_struct *tsk;
70154 + struct file *filp;
70155 +
70156 + FOR_EACH_ROLE_START(r)
70157 + if (!strcmp(rolename, r->rolename) &&
70158 + (r->roletype & GR_ROLE_SPECIAL)) {
70159 + assigned = r;
70160 + break;
70161 + }
70162 + FOR_EACH_ROLE_END(r)
70163 +
70164 + if (!assigned)
70165 + return;
70166 +
70167 + read_lock(&tasklist_lock);
70168 + read_lock(&grsec_exec_file_lock);
70169 +
70170 + tsk = current->real_parent;
70171 + if (tsk == NULL)
70172 + goto out_unlock;
70173 +
70174 + filp = tsk->exec_file;
70175 + if (filp == NULL)
70176 + goto out_unlock;
70177 +
70178 + tsk->is_writable = 0;
70179 + tsk->inherited = 0;
70180 +
70181 + tsk->acl_sp_role = 1;
70182 + tsk->acl_role_id = ++acl_sp_role_value;
70183 + tsk->role = assigned;
70184 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
70185 +
70186 + /* ignore additional mmap checks for processes that are writable
70187 + by the default ACL */
70188 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
70189 + if (unlikely(obj->mode & GR_WRITE))
70190 + tsk->is_writable = 1;
70191 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
70192 + if (unlikely(obj->mode & GR_WRITE))
70193 + tsk->is_writable = 1;
70194 +
70195 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70196 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
70197 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
70198 +#endif
70199 +
70200 +out_unlock:
70201 + read_unlock(&grsec_exec_file_lock);
70202 + read_unlock(&tasklist_lock);
70203 + return;
70204 +}
70205 +
70206 +
70207 +static void
70208 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
70209 +{
70210 + struct task_struct *task = current;
70211 + const struct cred *cred = current_cred();
70212 +
70213 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
70214 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70215 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70216 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
70217 +
70218 + return;
70219 +}
70220 +
70221 +static void
70222 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
70223 +{
70224 + struct task_struct *task = current;
70225 + const struct cred *cred = current_cred();
70226 +
70227 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
70228 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70229 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70230 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
70231 +
70232 + return;
70233 +}
70234 +
70235 +static void
70236 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
70237 +{
70238 + struct task_struct *task = current;
70239 + const struct cred *cred = current_cred();
70240 +
70241 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
70242 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70243 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70244 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
70245 +
70246 + return;
70247 +}
70248 +
70249 +static void
70250 +gr_set_proc_res(struct task_struct *task)
70251 +{
70252 + struct acl_subject_label *proc;
70253 + unsigned short i;
70254 +
70255 + proc = task->acl;
70256 +
70257 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
70258 + return;
70259 +
70260 + for (i = 0; i < RLIM_NLIMITS; i++) {
70261 + if (!(proc->resmask & (1U << i)))
70262 + continue;
70263 +
70264 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
70265 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
70266 +
70267 + if (i == RLIMIT_CPU)
70268 + update_rlimit_cpu(task, proc->res[i].rlim_cur);
70269 + }
70270 +
70271 + return;
70272 +}
70273 +
70274 +/* both of the below must be called with
70275 + rcu_read_lock();
70276 + read_lock(&tasklist_lock);
70277 + read_lock(&grsec_exec_file_lock);
70278 +*/
70279 +
70280 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
70281 +{
70282 + char *tmpname;
70283 + struct acl_subject_label *tmpsubj;
70284 + struct file *filp;
70285 + struct name_entry *nmatch;
70286 +
70287 + filp = task->exec_file;
70288 + if (filp == NULL)
70289 + return NULL;
70290 +
70291 + /* the following is to apply the correct subject
70292 + on binaries running when the RBAC system
70293 + is enabled, when the binaries have been
70294 + replaced or deleted since their execution
70295 + -----
70296 + when the RBAC system starts, the inode/dev
70297 + from exec_file will be one the RBAC system
70298 + is unaware of. It only knows the inode/dev
70299 + of the present file on disk, or the absence
70300 + of it.
70301 + */
70302 +
70303 + if (filename)
70304 + nmatch = __lookup_name_entry(state, filename);
70305 + else {
70306 + preempt_disable();
70307 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
70308 +
70309 + nmatch = __lookup_name_entry(state, tmpname);
70310 + preempt_enable();
70311 + }
70312 + tmpsubj = NULL;
70313 + if (nmatch) {
70314 + if (nmatch->deleted)
70315 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
70316 + else
70317 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
70318 + }
70319 + /* this also works for the reload case -- if we don't match a potentially inherited subject
70320 + then we fall back to a normal lookup based on the binary's ino/dev
70321 + */
70322 + if (tmpsubj == NULL)
70323 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
70324 +
70325 + return tmpsubj;
70326 +}
70327 +
70328 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
70329 +{
70330 + return __gr_get_subject_for_task(&running_polstate, task, filename);
70331 +}
70332 +
70333 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
70334 +{
70335 + struct acl_object_label *obj;
70336 + struct file *filp;
70337 +
70338 + filp = task->exec_file;
70339 +
70340 + task->acl = subj;
70341 + task->is_writable = 0;
70342 + /* ignore additional mmap checks for processes that are writable
70343 + by the default ACL */
70344 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
70345 + if (unlikely(obj->mode & GR_WRITE))
70346 + task->is_writable = 1;
70347 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
70348 + if (unlikely(obj->mode & GR_WRITE))
70349 + task->is_writable = 1;
70350 +
70351 + gr_set_proc_res(task);
70352 +
70353 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70354 + 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);
70355 +#endif
70356 +}
70357 +
70358 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
70359 +{
70360 + __gr_apply_subject_to_task(&running_polstate, task, subj);
70361 +}
70362 +
70363 +__u32
70364 +gr_search_file(const struct dentry * dentry, const __u32 mode,
70365 + const struct vfsmount * mnt)
70366 +{
70367 + __u32 retval = mode;
70368 + struct acl_subject_label *curracl;
70369 + struct acl_object_label *currobj;
70370 +
70371 + if (unlikely(!(gr_status & GR_READY)))
70372 + return (mode & ~GR_AUDITS);
70373 +
70374 + curracl = current->acl;
70375 +
70376 + currobj = chk_obj_label(dentry, mnt, curracl);
70377 + retval = currobj->mode & mode;
70378 +
70379 + /* if we're opening a specified transfer file for writing
70380 + (e.g. /dev/initctl), then transfer our role to init
70381 + */
70382 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
70383 + current->role->roletype & GR_ROLE_PERSIST)) {
70384 + struct task_struct *task = init_pid_ns.child_reaper;
70385 +
70386 + if (task->role != current->role) {
70387 + struct acl_subject_label *subj;
70388 +
70389 + task->acl_sp_role = 0;
70390 + task->acl_role_id = current->acl_role_id;
70391 + task->role = current->role;
70392 + rcu_read_lock();
70393 + read_lock(&grsec_exec_file_lock);
70394 + subj = gr_get_subject_for_task(task, NULL);
70395 + gr_apply_subject_to_task(task, subj);
70396 + read_unlock(&grsec_exec_file_lock);
70397 + rcu_read_unlock();
70398 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
70399 + }
70400 + }
70401 +
70402 + if (unlikely
70403 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
70404 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
70405 + __u32 new_mode = mode;
70406 +
70407 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
70408 +
70409 + retval = new_mode;
70410 +
70411 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
70412 + new_mode |= GR_INHERIT;
70413 +
70414 + if (!(mode & GR_NOLEARN))
70415 + gr_log_learn(dentry, mnt, new_mode);
70416 + }
70417 +
70418 + return retval;
70419 +}
70420 +
70421 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
70422 + const struct dentry *parent,
70423 + const struct vfsmount *mnt)
70424 +{
70425 + struct name_entry *match;
70426 + struct acl_object_label *matchpo;
70427 + struct acl_subject_label *curracl;
70428 + char *path;
70429 +
70430 + if (unlikely(!(gr_status & GR_READY)))
70431 + return NULL;
70432 +
70433 + preempt_disable();
70434 + path = gr_to_filename_rbac(new_dentry, mnt);
70435 + match = lookup_name_entry_create(path);
70436 +
70437 + curracl = current->acl;
70438 +
70439 + if (match) {
70440 + read_lock(&gr_inode_lock);
70441 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
70442 + read_unlock(&gr_inode_lock);
70443 +
70444 + if (matchpo) {
70445 + preempt_enable();
70446 + return matchpo;
70447 + }
70448 + }
70449 +
70450 + // lookup parent
70451 +
70452 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
70453 +
70454 + preempt_enable();
70455 + return matchpo;
70456 +}
70457 +
70458 +__u32
70459 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
70460 + const struct vfsmount * mnt, const __u32 mode)
70461 +{
70462 + struct acl_object_label *matchpo;
70463 + __u32 retval;
70464 +
70465 + if (unlikely(!(gr_status & GR_READY)))
70466 + return (mode & ~GR_AUDITS);
70467 +
70468 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
70469 +
70470 + retval = matchpo->mode & mode;
70471 +
70472 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
70473 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
70474 + __u32 new_mode = mode;
70475 +
70476 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
70477 +
70478 + gr_log_learn(new_dentry, mnt, new_mode);
70479 + return new_mode;
70480 + }
70481 +
70482 + return retval;
70483 +}
70484 +
70485 +__u32
70486 +gr_check_link(const struct dentry * new_dentry,
70487 + const struct dentry * parent_dentry,
70488 + const struct vfsmount * parent_mnt,
70489 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
70490 +{
70491 + struct acl_object_label *obj;
70492 + __u32 oldmode, newmode;
70493 + __u32 needmode;
70494 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
70495 + GR_DELETE | GR_INHERIT;
70496 +
70497 + if (unlikely(!(gr_status & GR_READY)))
70498 + return (GR_CREATE | GR_LINK);
70499 +
70500 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
70501 + oldmode = obj->mode;
70502 +
70503 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
70504 + newmode = obj->mode;
70505 +
70506 + needmode = newmode & checkmodes;
70507 +
70508 + // old name for hardlink must have at least the permissions of the new name
70509 + if ((oldmode & needmode) != needmode)
70510 + goto bad;
70511 +
70512 + // if old name had restrictions/auditing, make sure the new name does as well
70513 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
70514 +
70515 + // don't allow hardlinking of suid/sgid/fcapped files without permission
70516 + if (is_privileged_binary(old_dentry))
70517 + needmode |= GR_SETID;
70518 +
70519 + if ((newmode & needmode) != needmode)
70520 + goto bad;
70521 +
70522 + // enforce minimum permissions
70523 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
70524 + return newmode;
70525 +bad:
70526 + needmode = oldmode;
70527 + if (is_privileged_binary(old_dentry))
70528 + needmode |= GR_SETID;
70529 +
70530 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
70531 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
70532 + return (GR_CREATE | GR_LINK);
70533 + } else if (newmode & GR_SUPPRESS)
70534 + return GR_SUPPRESS;
70535 + else
70536 + return 0;
70537 +}
70538 +
70539 +int
70540 +gr_check_hidden_task(const struct task_struct *task)
70541 +{
70542 + if (unlikely(!(gr_status & GR_READY)))
70543 + return 0;
70544 +
70545 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
70546 + return 1;
70547 +
70548 + return 0;
70549 +}
70550 +
70551 +int
70552 +gr_check_protected_task(const struct task_struct *task)
70553 +{
70554 + if (unlikely(!(gr_status & GR_READY) || !task))
70555 + return 0;
70556 +
70557 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
70558 + task->acl != current->acl)
70559 + return 1;
70560 +
70561 + return 0;
70562 +}
70563 +
70564 +int
70565 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
70566 +{
70567 + struct task_struct *p;
70568 + int ret = 0;
70569 +
70570 + if (unlikely(!(gr_status & GR_READY) || !pid))
70571 + return ret;
70572 +
70573 + read_lock(&tasklist_lock);
70574 + do_each_pid_task(pid, type, p) {
70575 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
70576 + p->acl != current->acl) {
70577 + ret = 1;
70578 + goto out;
70579 + }
70580 + } while_each_pid_task(pid, type, p);
70581 +out:
70582 + read_unlock(&tasklist_lock);
70583 +
70584 + return ret;
70585 +}
70586 +
70587 +void
70588 +gr_copy_label(struct task_struct *tsk)
70589 +{
70590 + struct task_struct *p = current;
70591 +
70592 + tsk->inherited = p->inherited;
70593 + tsk->acl_sp_role = 0;
70594 + tsk->acl_role_id = p->acl_role_id;
70595 + tsk->acl = p->acl;
70596 + tsk->role = p->role;
70597 + tsk->signal->used_accept = 0;
70598 + tsk->signal->curr_ip = p->signal->curr_ip;
70599 + tsk->signal->saved_ip = p->signal->saved_ip;
70600 + if (p->exec_file)
70601 + get_file(p->exec_file);
70602 + tsk->exec_file = p->exec_file;
70603 + tsk->is_writable = p->is_writable;
70604 + if (unlikely(p->signal->used_accept)) {
70605 + p->signal->curr_ip = 0;
70606 + p->signal->saved_ip = 0;
70607 + }
70608 +
70609 + return;
70610 +}
70611 +
70612 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
70613 +
70614 +int
70615 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
70616 +{
70617 + unsigned int i;
70618 + __u16 num;
70619 + uid_t *uidlist;
70620 + uid_t curuid;
70621 + int realok = 0;
70622 + int effectiveok = 0;
70623 + int fsok = 0;
70624 + uid_t globalreal, globaleffective, globalfs;
70625 +
70626 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
70627 + struct user_struct *user;
70628 +
70629 + if (!uid_valid(real))
70630 + goto skipit;
70631 +
70632 + /* find user based on global namespace */
70633 +
70634 + globalreal = GR_GLOBAL_UID(real);
70635 +
70636 + user = find_user(make_kuid(&init_user_ns, globalreal));
70637 + if (user == NULL)
70638 + goto skipit;
70639 +
70640 + if (gr_process_kernel_setuid_ban(user)) {
70641 + /* for find_user */
70642 + free_uid(user);
70643 + return 1;
70644 + }
70645 +
70646 + /* for find_user */
70647 + free_uid(user);
70648 +
70649 +skipit:
70650 +#endif
70651 +
70652 + if (unlikely(!(gr_status & GR_READY)))
70653 + return 0;
70654 +
70655 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
70656 + gr_log_learn_uid_change(real, effective, fs);
70657 +
70658 + num = current->acl->user_trans_num;
70659 + uidlist = current->acl->user_transitions;
70660 +
70661 + if (uidlist == NULL)
70662 + return 0;
70663 +
70664 + if (!uid_valid(real)) {
70665 + realok = 1;
70666 + globalreal = (uid_t)-1;
70667 + } else {
70668 + globalreal = GR_GLOBAL_UID(real);
70669 + }
70670 + if (!uid_valid(effective)) {
70671 + effectiveok = 1;
70672 + globaleffective = (uid_t)-1;
70673 + } else {
70674 + globaleffective = GR_GLOBAL_UID(effective);
70675 + }
70676 + if (!uid_valid(fs)) {
70677 + fsok = 1;
70678 + globalfs = (uid_t)-1;
70679 + } else {
70680 + globalfs = GR_GLOBAL_UID(fs);
70681 + }
70682 +
70683 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
70684 + for (i = 0; i < num; i++) {
70685 + curuid = uidlist[i];
70686 + if (globalreal == curuid)
70687 + realok = 1;
70688 + if (globaleffective == curuid)
70689 + effectiveok = 1;
70690 + if (globalfs == curuid)
70691 + fsok = 1;
70692 + }
70693 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
70694 + for (i = 0; i < num; i++) {
70695 + curuid = uidlist[i];
70696 + if (globalreal == curuid)
70697 + break;
70698 + if (globaleffective == curuid)
70699 + break;
70700 + if (globalfs == curuid)
70701 + break;
70702 + }
70703 + /* not in deny list */
70704 + if (i == num) {
70705 + realok = 1;
70706 + effectiveok = 1;
70707 + fsok = 1;
70708 + }
70709 + }
70710 +
70711 + if (realok && effectiveok && fsok)
70712 + return 0;
70713 + else {
70714 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
70715 + return 1;
70716 + }
70717 +}
70718 +
70719 +int
70720 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
70721 +{
70722 + unsigned int i;
70723 + __u16 num;
70724 + gid_t *gidlist;
70725 + gid_t curgid;
70726 + int realok = 0;
70727 + int effectiveok = 0;
70728 + int fsok = 0;
70729 + gid_t globalreal, globaleffective, globalfs;
70730 +
70731 + if (unlikely(!(gr_status & GR_READY)))
70732 + return 0;
70733 +
70734 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
70735 + gr_log_learn_gid_change(real, effective, fs);
70736 +
70737 + num = current->acl->group_trans_num;
70738 + gidlist = current->acl->group_transitions;
70739 +
70740 + if (gidlist == NULL)
70741 + return 0;
70742 +
70743 + if (!gid_valid(real)) {
70744 + realok = 1;
70745 + globalreal = (gid_t)-1;
70746 + } else {
70747 + globalreal = GR_GLOBAL_GID(real);
70748 + }
70749 + if (!gid_valid(effective)) {
70750 + effectiveok = 1;
70751 + globaleffective = (gid_t)-1;
70752 + } else {
70753 + globaleffective = GR_GLOBAL_GID(effective);
70754 + }
70755 + if (!gid_valid(fs)) {
70756 + fsok = 1;
70757 + globalfs = (gid_t)-1;
70758 + } else {
70759 + globalfs = GR_GLOBAL_GID(fs);
70760 + }
70761 +
70762 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
70763 + for (i = 0; i < num; i++) {
70764 + curgid = gidlist[i];
70765 + if (globalreal == curgid)
70766 + realok = 1;
70767 + if (globaleffective == curgid)
70768 + effectiveok = 1;
70769 + if (globalfs == curgid)
70770 + fsok = 1;
70771 + }
70772 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
70773 + for (i = 0; i < num; i++) {
70774 + curgid = gidlist[i];
70775 + if (globalreal == curgid)
70776 + break;
70777 + if (globaleffective == curgid)
70778 + break;
70779 + if (globalfs == curgid)
70780 + break;
70781 + }
70782 + /* not in deny list */
70783 + if (i == num) {
70784 + realok = 1;
70785 + effectiveok = 1;
70786 + fsok = 1;
70787 + }
70788 + }
70789 +
70790 + if (realok && effectiveok && fsok)
70791 + return 0;
70792 + else {
70793 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
70794 + return 1;
70795 + }
70796 +}
70797 +
70798 +extern int gr_acl_is_capable(const int cap);
70799 +
70800 +void
70801 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
70802 +{
70803 + struct acl_role_label *role = task->role;
70804 + struct acl_subject_label *subj = NULL;
70805 + struct acl_object_label *obj;
70806 + struct file *filp;
70807 + uid_t uid;
70808 + gid_t gid;
70809 +
70810 + if (unlikely(!(gr_status & GR_READY)))
70811 + return;
70812 +
70813 + uid = GR_GLOBAL_UID(kuid);
70814 + gid = GR_GLOBAL_GID(kgid);
70815 +
70816 + filp = task->exec_file;
70817 +
70818 + /* kernel process, we'll give them the kernel role */
70819 + if (unlikely(!filp)) {
70820 + task->role = running_polstate.kernel_role;
70821 + task->acl = running_polstate.kernel_role->root_label;
70822 + return;
70823 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
70824 + /* save the current ip at time of role lookup so that the proper
70825 + IP will be learned for role_allowed_ip */
70826 + task->signal->saved_ip = task->signal->curr_ip;
70827 + role = lookup_acl_role_label(task, uid, gid);
70828 + }
70829 +
70830 + /* don't change the role if we're not a privileged process */
70831 + if (role && task->role != role &&
70832 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
70833 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
70834 + return;
70835 +
70836 + /* perform subject lookup in possibly new role
70837 + we can use this result below in the case where role == task->role
70838 + */
70839 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
70840 +
70841 + /* if we changed uid/gid, but result in the same role
70842 + and are using inheritance, don't lose the inherited subject
70843 + if current subject is other than what normal lookup
70844 + would result in, we arrived via inheritance, don't
70845 + lose subject
70846 + */
70847 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
70848 + (subj == task->acl)))
70849 + task->acl = subj;
70850 +
70851 + /* leave task->inherited unaffected */
70852 +
70853 + task->role = role;
70854 +
70855 + task->is_writable = 0;
70856 +
70857 + /* ignore additional mmap checks for processes that are writable
70858 + by the default ACL */
70859 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
70860 + if (unlikely(obj->mode & GR_WRITE))
70861 + task->is_writable = 1;
70862 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
70863 + if (unlikely(obj->mode & GR_WRITE))
70864 + task->is_writable = 1;
70865 +
70866 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70867 + 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);
70868 +#endif
70869 +
70870 + gr_set_proc_res(task);
70871 +
70872 + return;
70873 +}
70874 +
70875 +int
70876 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
70877 + const int unsafe_flags)
70878 +{
70879 + struct task_struct *task = current;
70880 + struct acl_subject_label *newacl;
70881 + struct acl_object_label *obj;
70882 + __u32 retmode;
70883 +
70884 + if (unlikely(!(gr_status & GR_READY)))
70885 + return 0;
70886 +
70887 + newacl = chk_subj_label(dentry, mnt, task->role);
70888 +
70889 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
70890 + did an exec
70891 + */
70892 + rcu_read_lock();
70893 + read_lock(&tasklist_lock);
70894 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
70895 + (task->parent->acl->mode & GR_POVERRIDE))) {
70896 + read_unlock(&tasklist_lock);
70897 + rcu_read_unlock();
70898 + goto skip_check;
70899 + }
70900 + read_unlock(&tasklist_lock);
70901 + rcu_read_unlock();
70902 +
70903 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
70904 + !(task->role->roletype & GR_ROLE_GOD) &&
70905 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
70906 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
70907 + if (unsafe_flags & LSM_UNSAFE_SHARE)
70908 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
70909 + else
70910 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
70911 + return -EACCES;
70912 + }
70913 +
70914 +skip_check:
70915 +
70916 + obj = chk_obj_label(dentry, mnt, task->acl);
70917 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
70918 +
70919 + if (!(task->acl->mode & GR_INHERITLEARN) &&
70920 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
70921 + if (obj->nested)
70922 + task->acl = obj->nested;
70923 + else
70924 + task->acl = newacl;
70925 + task->inherited = 0;
70926 + } else {
70927 + task->inherited = 1;
70928 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
70929 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
70930 + }
70931 +
70932 + task->is_writable = 0;
70933 +
70934 + /* ignore additional mmap checks for processes that are writable
70935 + by the default ACL */
70936 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
70937 + if (unlikely(obj->mode & GR_WRITE))
70938 + task->is_writable = 1;
70939 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
70940 + if (unlikely(obj->mode & GR_WRITE))
70941 + task->is_writable = 1;
70942 +
70943 + gr_set_proc_res(task);
70944 +
70945 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70946 + 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);
70947 +#endif
70948 + return 0;
70949 +}
70950 +
70951 +/* always called with valid inodev ptr */
70952 +static void
70953 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
70954 +{
70955 + struct acl_object_label *matchpo;
70956 + struct acl_subject_label *matchps;
70957 + struct acl_subject_label *subj;
70958 + struct acl_role_label *role;
70959 + unsigned int x;
70960 +
70961 + FOR_EACH_ROLE_START(role)
70962 + FOR_EACH_SUBJECT_START(role, subj, x)
70963 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
70964 + matchpo->mode |= GR_DELETED;
70965 + FOR_EACH_SUBJECT_END(subj,x)
70966 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
70967 + /* nested subjects aren't in the role's subj_hash table */
70968 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
70969 + matchpo->mode |= GR_DELETED;
70970 + FOR_EACH_NESTED_SUBJECT_END(subj)
70971 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
70972 + matchps->mode |= GR_DELETED;
70973 + FOR_EACH_ROLE_END(role)
70974 +
70975 + inodev->nentry->deleted = 1;
70976 +
70977 + return;
70978 +}
70979 +
70980 +void
70981 +gr_handle_delete(const ino_t ino, const dev_t dev)
70982 +{
70983 + struct inodev_entry *inodev;
70984 +
70985 + if (unlikely(!(gr_status & GR_READY)))
70986 + return;
70987 +
70988 + write_lock(&gr_inode_lock);
70989 + inodev = lookup_inodev_entry(ino, dev);
70990 + if (inodev != NULL)
70991 + do_handle_delete(inodev, ino, dev);
70992 + write_unlock(&gr_inode_lock);
70993 +
70994 + return;
70995 +}
70996 +
70997 +static void
70998 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
70999 + const ino_t newinode, const dev_t newdevice,
71000 + struct acl_subject_label *subj)
71001 +{
71002 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
71003 + struct acl_object_label *match;
71004 +
71005 + match = subj->obj_hash[index];
71006 +
71007 + while (match && (match->inode != oldinode ||
71008 + match->device != olddevice ||
71009 + !(match->mode & GR_DELETED)))
71010 + match = match->next;
71011 +
71012 + if (match && (match->inode == oldinode)
71013 + && (match->device == olddevice)
71014 + && (match->mode & GR_DELETED)) {
71015 + if (match->prev == NULL) {
71016 + subj->obj_hash[index] = match->next;
71017 + if (match->next != NULL)
71018 + match->next->prev = NULL;
71019 + } else {
71020 + match->prev->next = match->next;
71021 + if (match->next != NULL)
71022 + match->next->prev = match->prev;
71023 + }
71024 + match->prev = NULL;
71025 + match->next = NULL;
71026 + match->inode = newinode;
71027 + match->device = newdevice;
71028 + match->mode &= ~GR_DELETED;
71029 +
71030 + insert_acl_obj_label(match, subj);
71031 + }
71032 +
71033 + return;
71034 +}
71035 +
71036 +static void
71037 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
71038 + const ino_t newinode, const dev_t newdevice,
71039 + struct acl_role_label *role)
71040 +{
71041 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
71042 + struct acl_subject_label *match;
71043 +
71044 + match = role->subj_hash[index];
71045 +
71046 + while (match && (match->inode != oldinode ||
71047 + match->device != olddevice ||
71048 + !(match->mode & GR_DELETED)))
71049 + match = match->next;
71050 +
71051 + if (match && (match->inode == oldinode)
71052 + && (match->device == olddevice)
71053 + && (match->mode & GR_DELETED)) {
71054 + if (match->prev == NULL) {
71055 + role->subj_hash[index] = match->next;
71056 + if (match->next != NULL)
71057 + match->next->prev = NULL;
71058 + } else {
71059 + match->prev->next = match->next;
71060 + if (match->next != NULL)
71061 + match->next->prev = match->prev;
71062 + }
71063 + match->prev = NULL;
71064 + match->next = NULL;
71065 + match->inode = newinode;
71066 + match->device = newdevice;
71067 + match->mode &= ~GR_DELETED;
71068 +
71069 + insert_acl_subj_label(match, role);
71070 + }
71071 +
71072 + return;
71073 +}
71074 +
71075 +static void
71076 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
71077 + const ino_t newinode, const dev_t newdevice)
71078 +{
71079 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
71080 + struct inodev_entry *match;
71081 +
71082 + match = running_polstate.inodev_set.i_hash[index];
71083 +
71084 + while (match && (match->nentry->inode != oldinode ||
71085 + match->nentry->device != olddevice || !match->nentry->deleted))
71086 + match = match->next;
71087 +
71088 + if (match && (match->nentry->inode == oldinode)
71089 + && (match->nentry->device == olddevice) &&
71090 + match->nentry->deleted) {
71091 + if (match->prev == NULL) {
71092 + running_polstate.inodev_set.i_hash[index] = match->next;
71093 + if (match->next != NULL)
71094 + match->next->prev = NULL;
71095 + } else {
71096 + match->prev->next = match->next;
71097 + if (match->next != NULL)
71098 + match->next->prev = match->prev;
71099 + }
71100 + match->prev = NULL;
71101 + match->next = NULL;
71102 + match->nentry->inode = newinode;
71103 + match->nentry->device = newdevice;
71104 + match->nentry->deleted = 0;
71105 +
71106 + insert_inodev_entry(match);
71107 + }
71108 +
71109 + return;
71110 +}
71111 +
71112 +static void
71113 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
71114 +{
71115 + struct acl_subject_label *subj;
71116 + struct acl_role_label *role;
71117 + unsigned int x;
71118 +
71119 + FOR_EACH_ROLE_START(role)
71120 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
71121 +
71122 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
71123 + if ((subj->inode == ino) && (subj->device == dev)) {
71124 + subj->inode = ino;
71125 + subj->device = dev;
71126 + }
71127 + /* nested subjects aren't in the role's subj_hash table */
71128 + update_acl_obj_label(matchn->inode, matchn->device,
71129 + ino, dev, subj);
71130 + FOR_EACH_NESTED_SUBJECT_END(subj)
71131 + FOR_EACH_SUBJECT_START(role, subj, x)
71132 + update_acl_obj_label(matchn->inode, matchn->device,
71133 + ino, dev, subj);
71134 + FOR_EACH_SUBJECT_END(subj,x)
71135 + FOR_EACH_ROLE_END(role)
71136 +
71137 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
71138 +
71139 + return;
71140 +}
71141 +
71142 +static void
71143 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
71144 + const struct vfsmount *mnt)
71145 +{
71146 + ino_t ino = dentry->d_inode->i_ino;
71147 + dev_t dev = __get_dev(dentry);
71148 +
71149 + __do_handle_create(matchn, ino, dev);
71150 +
71151 + return;
71152 +}
71153 +
71154 +void
71155 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
71156 +{
71157 + struct name_entry *matchn;
71158 +
71159 + if (unlikely(!(gr_status & GR_READY)))
71160 + return;
71161 +
71162 + preempt_disable();
71163 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
71164 +
71165 + if (unlikely((unsigned long)matchn)) {
71166 + write_lock(&gr_inode_lock);
71167 + do_handle_create(matchn, dentry, mnt);
71168 + write_unlock(&gr_inode_lock);
71169 + }
71170 + preempt_enable();
71171 +
71172 + return;
71173 +}
71174 +
71175 +void
71176 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
71177 +{
71178 + struct name_entry *matchn;
71179 +
71180 + if (unlikely(!(gr_status & GR_READY)))
71181 + return;
71182 +
71183 + preempt_disable();
71184 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
71185 +
71186 + if (unlikely((unsigned long)matchn)) {
71187 + write_lock(&gr_inode_lock);
71188 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
71189 + write_unlock(&gr_inode_lock);
71190 + }
71191 + preempt_enable();
71192 +
71193 + return;
71194 +}
71195 +
71196 +void
71197 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
71198 + struct dentry *old_dentry,
71199 + struct dentry *new_dentry,
71200 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
71201 +{
71202 + struct name_entry *matchn;
71203 + struct name_entry *matchn2 = NULL;
71204 + struct inodev_entry *inodev;
71205 + struct inode *inode = new_dentry->d_inode;
71206 + ino_t old_ino = old_dentry->d_inode->i_ino;
71207 + dev_t old_dev = __get_dev(old_dentry);
71208 + unsigned int exchange = flags & RENAME_EXCHANGE;
71209 +
71210 + /* vfs_rename swaps the name and parent link for old_dentry and
71211 + new_dentry
71212 + at this point, old_dentry has the new name, parent link, and inode
71213 + for the renamed file
71214 + if a file is being replaced by a rename, new_dentry has the inode
71215 + and name for the replaced file
71216 + */
71217 +
71218 + if (unlikely(!(gr_status & GR_READY)))
71219 + return;
71220 +
71221 + preempt_disable();
71222 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
71223 +
71224 + /* exchange cases:
71225 + a filename exists for the source, but not dest
71226 + do a recreate on source
71227 + a filename exists for the dest, but not source
71228 + do a recreate on dest
71229 + a filename exists for both source and dest
71230 + delete source and dest, then create source and dest
71231 + a filename exists for neither source nor dest
71232 + no updates needed
71233 +
71234 + the name entry lookups get us the old inode/dev associated with
71235 + each name, so do the deletes first (if possible) so that when
71236 + we do the create, we pick up on the right entries
71237 + */
71238 +
71239 + if (exchange)
71240 + matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
71241 +
71242 + /* we wouldn't have to check d_inode if it weren't for
71243 + NFS silly-renaming
71244 + */
71245 +
71246 + write_lock(&gr_inode_lock);
71247 + if (unlikely((replace || exchange) && inode)) {
71248 + ino_t new_ino = inode->i_ino;
71249 + dev_t new_dev = __get_dev(new_dentry);
71250 +
71251 + inodev = lookup_inodev_entry(new_ino, new_dev);
71252 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
71253 + do_handle_delete(inodev, new_ino, new_dev);
71254 + }
71255 +
71256 + inodev = lookup_inodev_entry(old_ino, old_dev);
71257 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
71258 + do_handle_delete(inodev, old_ino, old_dev);
71259 +
71260 + if (unlikely(matchn != NULL))
71261 + do_handle_create(matchn, old_dentry, mnt);
71262 +
71263 + if (unlikely(matchn2 != NULL))
71264 + do_handle_create(matchn2, new_dentry, mnt);
71265 +
71266 + write_unlock(&gr_inode_lock);
71267 + preempt_enable();
71268 +
71269 + return;
71270 +}
71271 +
71272 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
71273 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
71274 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
71275 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
71276 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
71277 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
71278 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
71279 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
71280 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
71281 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
71282 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
71283 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
71284 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
71285 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
71286 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
71287 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
71288 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
71289 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
71290 +};
71291 +
71292 +void
71293 +gr_learn_resource(const struct task_struct *task,
71294 + const int res, const unsigned long wanted, const int gt)
71295 +{
71296 + struct acl_subject_label *acl;
71297 + const struct cred *cred;
71298 +
71299 + if (unlikely((gr_status & GR_READY) &&
71300 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
71301 + goto skip_reslog;
71302 +
71303 + gr_log_resource(task, res, wanted, gt);
71304 +skip_reslog:
71305 +
71306 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
71307 + return;
71308 +
71309 + acl = task->acl;
71310 +
71311 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
71312 + !(acl->resmask & (1U << (unsigned short) res))))
71313 + return;
71314 +
71315 + if (wanted >= acl->res[res].rlim_cur) {
71316 + unsigned long res_add;
71317 +
71318 + res_add = wanted + res_learn_bumps[res];
71319 +
71320 + acl->res[res].rlim_cur = res_add;
71321 +
71322 + if (wanted > acl->res[res].rlim_max)
71323 + acl->res[res].rlim_max = res_add;
71324 +
71325 + /* only log the subject filename, since resource logging is supported for
71326 + single-subject learning only */
71327 + rcu_read_lock();
71328 + cred = __task_cred(task);
71329 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
71330 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
71331 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
71332 + "", (unsigned long) res, &task->signal->saved_ip);
71333 + rcu_read_unlock();
71334 + }
71335 +
71336 + return;
71337 +}
71338 +EXPORT_SYMBOL_GPL(gr_learn_resource);
71339 +#endif
71340 +
71341 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
71342 +void
71343 +pax_set_initial_flags(struct linux_binprm *bprm)
71344 +{
71345 + struct task_struct *task = current;
71346 + struct acl_subject_label *proc;
71347 + unsigned long flags;
71348 +
71349 + if (unlikely(!(gr_status & GR_READY)))
71350 + return;
71351 +
71352 + flags = pax_get_flags(task);
71353 +
71354 + proc = task->acl;
71355 +
71356 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
71357 + flags &= ~MF_PAX_PAGEEXEC;
71358 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
71359 + flags &= ~MF_PAX_SEGMEXEC;
71360 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
71361 + flags &= ~MF_PAX_RANDMMAP;
71362 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
71363 + flags &= ~MF_PAX_EMUTRAMP;
71364 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
71365 + flags &= ~MF_PAX_MPROTECT;
71366 +
71367 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
71368 + flags |= MF_PAX_PAGEEXEC;
71369 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
71370 + flags |= MF_PAX_SEGMEXEC;
71371 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
71372 + flags |= MF_PAX_RANDMMAP;
71373 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
71374 + flags |= MF_PAX_EMUTRAMP;
71375 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
71376 + flags |= MF_PAX_MPROTECT;
71377 +
71378 + pax_set_flags(task, flags);
71379 +
71380 + return;
71381 +}
71382 +#endif
71383 +
71384 +int
71385 +gr_handle_proc_ptrace(struct task_struct *task)
71386 +{
71387 + struct file *filp;
71388 + struct task_struct *tmp = task;
71389 + struct task_struct *curtemp = current;
71390 + __u32 retmode;
71391 +
71392 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
71393 + if (unlikely(!(gr_status & GR_READY)))
71394 + return 0;
71395 +#endif
71396 +
71397 + read_lock(&tasklist_lock);
71398 + read_lock(&grsec_exec_file_lock);
71399 + filp = task->exec_file;
71400 +
71401 + while (task_pid_nr(tmp) > 0) {
71402 + if (tmp == curtemp)
71403 + break;
71404 + tmp = tmp->real_parent;
71405 + }
71406 +
71407 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
71408 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
71409 + read_unlock(&grsec_exec_file_lock);
71410 + read_unlock(&tasklist_lock);
71411 + return 1;
71412 + }
71413 +
71414 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71415 + if (!(gr_status & GR_READY)) {
71416 + read_unlock(&grsec_exec_file_lock);
71417 + read_unlock(&tasklist_lock);
71418 + return 0;
71419 + }
71420 +#endif
71421 +
71422 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
71423 + read_unlock(&grsec_exec_file_lock);
71424 + read_unlock(&tasklist_lock);
71425 +
71426 + if (retmode & GR_NOPTRACE)
71427 + return 1;
71428 +
71429 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
71430 + && (current->acl != task->acl || (current->acl != current->role->root_label
71431 + && task_pid_nr(current) != task_pid_nr(task))))
71432 + return 1;
71433 +
71434 + return 0;
71435 +}
71436 +
71437 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
71438 +{
71439 + if (unlikely(!(gr_status & GR_READY)))
71440 + return;
71441 +
71442 + if (!(current->role->roletype & GR_ROLE_GOD))
71443 + return;
71444 +
71445 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
71446 + p->role->rolename, gr_task_roletype_to_char(p),
71447 + p->acl->filename);
71448 +}
71449 +
71450 +int
71451 +gr_handle_ptrace(struct task_struct *task, const long request)
71452 +{
71453 + struct task_struct *tmp = task;
71454 + struct task_struct *curtemp = current;
71455 + __u32 retmode;
71456 +
71457 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
71458 + if (unlikely(!(gr_status & GR_READY)))
71459 + return 0;
71460 +#endif
71461 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71462 + read_lock(&tasklist_lock);
71463 + while (task_pid_nr(tmp) > 0) {
71464 + if (tmp == curtemp)
71465 + break;
71466 + tmp = tmp->real_parent;
71467 + }
71468 +
71469 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
71470 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
71471 + read_unlock(&tasklist_lock);
71472 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71473 + return 1;
71474 + }
71475 + read_unlock(&tasklist_lock);
71476 + }
71477 +
71478 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71479 + if (!(gr_status & GR_READY))
71480 + return 0;
71481 +#endif
71482 +
71483 + read_lock(&grsec_exec_file_lock);
71484 + if (unlikely(!task->exec_file)) {
71485 + read_unlock(&grsec_exec_file_lock);
71486 + return 0;
71487 + }
71488 +
71489 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
71490 + read_unlock(&grsec_exec_file_lock);
71491 +
71492 + if (retmode & GR_NOPTRACE) {
71493 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71494 + return 1;
71495 + }
71496 +
71497 + if (retmode & GR_PTRACERD) {
71498 + switch (request) {
71499 + case PTRACE_SEIZE:
71500 + case PTRACE_POKETEXT:
71501 + case PTRACE_POKEDATA:
71502 + case PTRACE_POKEUSR:
71503 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
71504 + case PTRACE_SETREGS:
71505 + case PTRACE_SETFPREGS:
71506 +#endif
71507 +#ifdef CONFIG_X86
71508 + case PTRACE_SETFPXREGS:
71509 +#endif
71510 +#ifdef CONFIG_ALTIVEC
71511 + case PTRACE_SETVRREGS:
71512 +#endif
71513 + return 1;
71514 + default:
71515 + return 0;
71516 + }
71517 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
71518 + !(current->role->roletype & GR_ROLE_GOD) &&
71519 + (current->acl != task->acl)) {
71520 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71521 + return 1;
71522 + }
71523 +
71524 + return 0;
71525 +}
71526 +
71527 +static int is_writable_mmap(const struct file *filp)
71528 +{
71529 + struct task_struct *task = current;
71530 + struct acl_object_label *obj, *obj2;
71531 +
71532 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
71533 + !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))) {
71534 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
71535 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
71536 + task->role->root_label);
71537 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
71538 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
71539 + return 1;
71540 + }
71541 + }
71542 + return 0;
71543 +}
71544 +
71545 +int
71546 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
71547 +{
71548 + __u32 mode;
71549 +
71550 + if (unlikely(!file || !(prot & PROT_EXEC)))
71551 + return 1;
71552 +
71553 + if (is_writable_mmap(file))
71554 + return 0;
71555 +
71556 + mode =
71557 + gr_search_file(file->f_path.dentry,
71558 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
71559 + file->f_path.mnt);
71560 +
71561 + if (!gr_tpe_allow(file))
71562 + return 0;
71563 +
71564 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
71565 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
71566 + return 0;
71567 + } else if (unlikely(!(mode & GR_EXEC))) {
71568 + return 0;
71569 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
71570 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
71571 + return 1;
71572 + }
71573 +
71574 + return 1;
71575 +}
71576 +
71577 +int
71578 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
71579 +{
71580 + __u32 mode;
71581 +
71582 + if (unlikely(!file || !(prot & PROT_EXEC)))
71583 + return 1;
71584 +
71585 + if (is_writable_mmap(file))
71586 + return 0;
71587 +
71588 + mode =
71589 + gr_search_file(file->f_path.dentry,
71590 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
71591 + file->f_path.mnt);
71592 +
71593 + if (!gr_tpe_allow(file))
71594 + return 0;
71595 +
71596 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
71597 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
71598 + return 0;
71599 + } else if (unlikely(!(mode & GR_EXEC))) {
71600 + return 0;
71601 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
71602 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
71603 + return 1;
71604 + }
71605 +
71606 + return 1;
71607 +}
71608 +
71609 +void
71610 +gr_acl_handle_psacct(struct task_struct *task, const long code)
71611 +{
71612 + unsigned long runtime, cputime;
71613 + cputime_t utime, stime;
71614 + unsigned int wday, cday;
71615 + __u8 whr, chr;
71616 + __u8 wmin, cmin;
71617 + __u8 wsec, csec;
71618 + struct timespec curtime, starttime;
71619 +
71620 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
71621 + !(task->acl->mode & GR_PROCACCT)))
71622 + return;
71623 +
71624 + curtime = ns_to_timespec(ktime_get_ns());
71625 + starttime = ns_to_timespec(task->start_time);
71626 + runtime = curtime.tv_sec - starttime.tv_sec;
71627 + wday = runtime / (60 * 60 * 24);
71628 + runtime -= wday * (60 * 60 * 24);
71629 + whr = runtime / (60 * 60);
71630 + runtime -= whr * (60 * 60);
71631 + wmin = runtime / 60;
71632 + runtime -= wmin * 60;
71633 + wsec = runtime;
71634 +
71635 + task_cputime(task, &utime, &stime);
71636 + cputime = cputime_to_secs(utime + stime);
71637 + cday = cputime / (60 * 60 * 24);
71638 + cputime -= cday * (60 * 60 * 24);
71639 + chr = cputime / (60 * 60);
71640 + cputime -= chr * (60 * 60);
71641 + cmin = cputime / 60;
71642 + cputime -= cmin * 60;
71643 + csec = cputime;
71644 +
71645 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
71646 +
71647 + return;
71648 +}
71649 +
71650 +#ifdef CONFIG_TASKSTATS
71651 +int gr_is_taskstats_denied(int pid)
71652 +{
71653 + struct task_struct *task;
71654 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71655 + const struct cred *cred;
71656 +#endif
71657 + int ret = 0;
71658 +
71659 + /* restrict taskstats viewing to un-chrooted root users
71660 + who have the 'view' subject flag if the RBAC system is enabled
71661 + */
71662 +
71663 + rcu_read_lock();
71664 + read_lock(&tasklist_lock);
71665 + task = find_task_by_vpid(pid);
71666 + if (task) {
71667 +#ifdef CONFIG_GRKERNSEC_CHROOT
71668 + if (proc_is_chrooted(task))
71669 + ret = -EACCES;
71670 +#endif
71671 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71672 + cred = __task_cred(task);
71673 +#ifdef CONFIG_GRKERNSEC_PROC_USER
71674 + if (gr_is_global_nonroot(cred->uid))
71675 + ret = -EACCES;
71676 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71677 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
71678 + ret = -EACCES;
71679 +#endif
71680 +#endif
71681 + if (gr_status & GR_READY) {
71682 + if (!(task->acl->mode & GR_VIEW))
71683 + ret = -EACCES;
71684 + }
71685 + } else
71686 + ret = -ENOENT;
71687 +
71688 + read_unlock(&tasklist_lock);
71689 + rcu_read_unlock();
71690 +
71691 + return ret;
71692 +}
71693 +#endif
71694 +
71695 +/* AUXV entries are filled via a descendant of search_binary_handler
71696 + after we've already applied the subject for the target
71697 +*/
71698 +int gr_acl_enable_at_secure(void)
71699 +{
71700 + if (unlikely(!(gr_status & GR_READY)))
71701 + return 0;
71702 +
71703 + if (current->acl->mode & GR_ATSECURE)
71704 + return 1;
71705 +
71706 + return 0;
71707 +}
71708 +
71709 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
71710 +{
71711 + struct task_struct *task = current;
71712 + struct dentry *dentry = file->f_path.dentry;
71713 + struct vfsmount *mnt = file->f_path.mnt;
71714 + struct acl_object_label *obj, *tmp;
71715 + struct acl_subject_label *subj;
71716 + unsigned int bufsize;
71717 + int is_not_root;
71718 + char *path;
71719 + dev_t dev = __get_dev(dentry);
71720 +
71721 + if (unlikely(!(gr_status & GR_READY)))
71722 + return 1;
71723 +
71724 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71725 + return 1;
71726 +
71727 + /* ignore Eric Biederman */
71728 + if (IS_PRIVATE(dentry->d_inode))
71729 + return 1;
71730 +
71731 + subj = task->acl;
71732 + read_lock(&gr_inode_lock);
71733 + do {
71734 + obj = lookup_acl_obj_label(ino, dev, subj);
71735 + if (obj != NULL) {
71736 + read_unlock(&gr_inode_lock);
71737 + return (obj->mode & GR_FIND) ? 1 : 0;
71738 + }
71739 + } while ((subj = subj->parent_subject));
71740 + read_unlock(&gr_inode_lock);
71741 +
71742 + /* this is purely an optimization since we're looking for an object
71743 + for the directory we're doing a readdir on
71744 + if it's possible for any globbed object to match the entry we're
71745 + filling into the directory, then the object we find here will be
71746 + an anchor point with attached globbed objects
71747 + */
71748 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
71749 + if (obj->globbed == NULL)
71750 + return (obj->mode & GR_FIND) ? 1 : 0;
71751 +
71752 + is_not_root = ((obj->filename[0] == '/') &&
71753 + (obj->filename[1] == '\0')) ? 0 : 1;
71754 + bufsize = PAGE_SIZE - namelen - is_not_root;
71755 +
71756 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
71757 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
71758 + return 1;
71759 +
71760 + preempt_disable();
71761 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
71762 + bufsize);
71763 +
71764 + bufsize = strlen(path);
71765 +
71766 + /* if base is "/", don't append an additional slash */
71767 + if (is_not_root)
71768 + *(path + bufsize) = '/';
71769 + memcpy(path + bufsize + is_not_root, name, namelen);
71770 + *(path + bufsize + namelen + is_not_root) = '\0';
71771 +
71772 + tmp = obj->globbed;
71773 + while (tmp) {
71774 + if (!glob_match(tmp->filename, path)) {
71775 + preempt_enable();
71776 + return (tmp->mode & GR_FIND) ? 1 : 0;
71777 + }
71778 + tmp = tmp->next;
71779 + }
71780 + preempt_enable();
71781 + return (obj->mode & GR_FIND) ? 1 : 0;
71782 +}
71783 +
71784 +void gr_put_exec_file(struct task_struct *task)
71785 +{
71786 + struct file *filp;
71787 +
71788 + write_lock(&grsec_exec_file_lock);
71789 + filp = task->exec_file;
71790 + task->exec_file = NULL;
71791 + write_unlock(&grsec_exec_file_lock);
71792 +
71793 + if (filp)
71794 + fput(filp);
71795 +
71796 + return;
71797 +}
71798 +
71799 +
71800 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
71801 +EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
71802 +#endif
71803 +#ifdef CONFIG_SECURITY
71804 +EXPORT_SYMBOL_GPL(gr_check_user_change);
71805 +EXPORT_SYMBOL_GPL(gr_check_group_change);
71806 +#endif
71807 +
71808 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
71809 new file mode 100644
71810 index 0000000..18ffbbd
71811 --- /dev/null
71812 +++ b/grsecurity/gracl_alloc.c
71813 @@ -0,0 +1,105 @@
71814 +#include <linux/kernel.h>
71815 +#include <linux/mm.h>
71816 +#include <linux/slab.h>
71817 +#include <linux/vmalloc.h>
71818 +#include <linux/gracl.h>
71819 +#include <linux/grsecurity.h>
71820 +
71821 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
71822 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
71823 +
71824 +static __inline__ int
71825 +alloc_pop(void)
71826 +{
71827 + if (current_alloc_state->alloc_stack_next == 1)
71828 + return 0;
71829 +
71830 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
71831 +
71832 + current_alloc_state->alloc_stack_next--;
71833 +
71834 + return 1;
71835 +}
71836 +
71837 +static __inline__ int
71838 +alloc_push(void *buf)
71839 +{
71840 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
71841 + return 1;
71842 +
71843 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
71844 +
71845 + current_alloc_state->alloc_stack_next++;
71846 +
71847 + return 0;
71848 +}
71849 +
71850 +void *
71851 +acl_alloc(unsigned long len)
71852 +{
71853 + void *ret = NULL;
71854 +
71855 + if (!len || len > PAGE_SIZE)
71856 + goto out;
71857 +
71858 + ret = kmalloc(len, GFP_KERNEL);
71859 +
71860 + if (ret) {
71861 + if (alloc_push(ret)) {
71862 + kfree(ret);
71863 + ret = NULL;
71864 + }
71865 + }
71866 +
71867 +out:
71868 + return ret;
71869 +}
71870 +
71871 +void *
71872 +acl_alloc_num(unsigned long num, unsigned long len)
71873 +{
71874 + if (!len || (num > (PAGE_SIZE / len)))
71875 + return NULL;
71876 +
71877 + return acl_alloc(num * len);
71878 +}
71879 +
71880 +void
71881 +acl_free_all(void)
71882 +{
71883 + if (!current_alloc_state->alloc_stack)
71884 + return;
71885 +
71886 + while (alloc_pop()) ;
71887 +
71888 + if (current_alloc_state->alloc_stack) {
71889 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
71890 + kfree(current_alloc_state->alloc_stack);
71891 + else
71892 + vfree(current_alloc_state->alloc_stack);
71893 + }
71894 +
71895 + current_alloc_state->alloc_stack = NULL;
71896 + current_alloc_state->alloc_stack_size = 1;
71897 + current_alloc_state->alloc_stack_next = 1;
71898 +
71899 + return;
71900 +}
71901 +
71902 +int
71903 +acl_alloc_stack_init(unsigned long size)
71904 +{
71905 + if ((size * sizeof (void *)) <= PAGE_SIZE)
71906 + current_alloc_state->alloc_stack =
71907 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
71908 + else
71909 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
71910 +
71911 + current_alloc_state->alloc_stack_size = size;
71912 + current_alloc_state->alloc_stack_next = 1;
71913 +
71914 + if (!current_alloc_state->alloc_stack)
71915 + return 0;
71916 + else
71917 + return 1;
71918 +}
71919 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
71920 new file mode 100644
71921 index 0000000..1a94c11
71922 --- /dev/null
71923 +++ b/grsecurity/gracl_cap.c
71924 @@ -0,0 +1,127 @@
71925 +#include <linux/kernel.h>
71926 +#include <linux/module.h>
71927 +#include <linux/sched.h>
71928 +#include <linux/gracl.h>
71929 +#include <linux/grsecurity.h>
71930 +#include <linux/grinternal.h>
71931 +
71932 +extern const char *captab_log[];
71933 +extern int captab_log_entries;
71934 +
71935 +int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
71936 +{
71937 + struct acl_subject_label *curracl;
71938 +
71939 + if (!gr_acl_is_enabled())
71940 + return 1;
71941 +
71942 + curracl = task->acl;
71943 +
71944 + if (curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
71945 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
71946 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
71947 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
71948 + gr_to_filename(task->exec_file->f_path.dentry,
71949 + task->exec_file->f_path.mnt) : curracl->filename,
71950 + curracl->filename, 0UL,
71951 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
71952 + return 1;
71953 + }
71954 +
71955 + return 0;
71956 +}
71957 +
71958 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
71959 +{
71960 + struct acl_subject_label *curracl;
71961 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
71962 + kernel_cap_t cap_audit = __cap_empty_set;
71963 +
71964 + if (!gr_acl_is_enabled())
71965 + return 1;
71966 +
71967 + curracl = task->acl;
71968 +
71969 + cap_drop = curracl->cap_lower;
71970 + cap_mask = curracl->cap_mask;
71971 + cap_audit = curracl->cap_invert_audit;
71972 +
71973 + while ((curracl = curracl->parent_subject)) {
71974 + /* if the cap isn't specified in the current computed mask but is specified in the
71975 + current level subject, and is lowered in the current level subject, then add
71976 + it to the set of dropped capabilities
71977 + otherwise, add the current level subject's mask to the current computed mask
71978 + */
71979 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
71980 + cap_raise(cap_mask, cap);
71981 + if (cap_raised(curracl->cap_lower, cap))
71982 + cap_raise(cap_drop, cap);
71983 + if (cap_raised(curracl->cap_invert_audit, cap))
71984 + cap_raise(cap_audit, cap);
71985 + }
71986 + }
71987 +
71988 + if (!cap_raised(cap_drop, cap)) {
71989 + if (cap_raised(cap_audit, cap))
71990 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
71991 + return 1;
71992 + }
71993 +
71994 + /* only learn the capability use if the process has the capability in the
71995 + general case, the two uses in sys.c of gr_learn_cap are an exception
71996 + to this rule to ensure any role transition involves what the full-learned
71997 + policy believes in a privileged process
71998 + */
71999 + if (cap_raised(cred->cap_effective, cap) && gr_learn_cap(task, cred, cap))
72000 + return 1;
72001 +
72002 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
72003 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
72004 +
72005 + return 0;
72006 +}
72007 +
72008 +int
72009 +gr_acl_is_capable(const int cap)
72010 +{
72011 + return gr_task_acl_is_capable(current, current_cred(), cap);
72012 +}
72013 +
72014 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
72015 +{
72016 + struct acl_subject_label *curracl;
72017 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72018 +
72019 + if (!gr_acl_is_enabled())
72020 + return 1;
72021 +
72022 + curracl = task->acl;
72023 +
72024 + cap_drop = curracl->cap_lower;
72025 + cap_mask = curracl->cap_mask;
72026 +
72027 + while ((curracl = curracl->parent_subject)) {
72028 + /* if the cap isn't specified in the current computed mask but is specified in the
72029 + current level subject, and is lowered in the current level subject, then add
72030 + it to the set of dropped capabilities
72031 + otherwise, add the current level subject's mask to the current computed mask
72032 + */
72033 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72034 + cap_raise(cap_mask, cap);
72035 + if (cap_raised(curracl->cap_lower, cap))
72036 + cap_raise(cap_drop, cap);
72037 + }
72038 + }
72039 +
72040 + if (!cap_raised(cap_drop, cap))
72041 + return 1;
72042 +
72043 + return 0;
72044 +}
72045 +
72046 +int
72047 +gr_acl_is_capable_nolog(const int cap)
72048 +{
72049 + return gr_task_acl_is_capable_nolog(current, cap);
72050 +}
72051 +
72052 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
72053 new file mode 100644
72054 index 0000000..ca25605
72055 --- /dev/null
72056 +++ b/grsecurity/gracl_compat.c
72057 @@ -0,0 +1,270 @@
72058 +#include <linux/kernel.h>
72059 +#include <linux/gracl.h>
72060 +#include <linux/compat.h>
72061 +#include <linux/gracl_compat.h>
72062 +
72063 +#include <asm/uaccess.h>
72064 +
72065 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
72066 +{
72067 + struct gr_arg_wrapper_compat uwrapcompat;
72068 +
72069 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
72070 + return -EFAULT;
72071 +
72072 + if (((uwrapcompat.version != GRSECURITY_VERSION) &&
72073 + (uwrapcompat.version != 0x2901)) ||
72074 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
72075 + return -EINVAL;
72076 +
72077 + uwrap->arg = compat_ptr(uwrapcompat.arg);
72078 + uwrap->version = uwrapcompat.version;
72079 + uwrap->size = sizeof(struct gr_arg);
72080 +
72081 + return 0;
72082 +}
72083 +
72084 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
72085 +{
72086 + struct gr_arg_compat argcompat;
72087 +
72088 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
72089 + return -EFAULT;
72090 +
72091 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
72092 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
72093 + arg->role_db.num_roles = argcompat.role_db.num_roles;
72094 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
72095 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
72096 + arg->role_db.num_objects = argcompat.role_db.num_objects;
72097 +
72098 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
72099 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
72100 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
72101 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
72102 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
72103 + arg->segv_device = argcompat.segv_device;
72104 + arg->segv_inode = argcompat.segv_inode;
72105 + arg->segv_uid = argcompat.segv_uid;
72106 + arg->num_sprole_pws = argcompat.num_sprole_pws;
72107 + arg->mode = argcompat.mode;
72108 +
72109 + return 0;
72110 +}
72111 +
72112 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
72113 +{
72114 + struct acl_object_label_compat objcompat;
72115 +
72116 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
72117 + return -EFAULT;
72118 +
72119 + obj->filename = compat_ptr(objcompat.filename);
72120 + obj->inode = objcompat.inode;
72121 + obj->device = objcompat.device;
72122 + obj->mode = objcompat.mode;
72123 +
72124 + obj->nested = compat_ptr(objcompat.nested);
72125 + obj->globbed = compat_ptr(objcompat.globbed);
72126 +
72127 + obj->prev = compat_ptr(objcompat.prev);
72128 + obj->next = compat_ptr(objcompat.next);
72129 +
72130 + return 0;
72131 +}
72132 +
72133 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
72134 +{
72135 + unsigned int i;
72136 + struct acl_subject_label_compat subjcompat;
72137 +
72138 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
72139 + return -EFAULT;
72140 +
72141 + subj->filename = compat_ptr(subjcompat.filename);
72142 + subj->inode = subjcompat.inode;
72143 + subj->device = subjcompat.device;
72144 + subj->mode = subjcompat.mode;
72145 + subj->cap_mask = subjcompat.cap_mask;
72146 + subj->cap_lower = subjcompat.cap_lower;
72147 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
72148 +
72149 + for (i = 0; i < GR_NLIMITS; i++) {
72150 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
72151 + subj->res[i].rlim_cur = RLIM_INFINITY;
72152 + else
72153 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
72154 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
72155 + subj->res[i].rlim_max = RLIM_INFINITY;
72156 + else
72157 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
72158 + }
72159 + subj->resmask = subjcompat.resmask;
72160 +
72161 + subj->user_trans_type = subjcompat.user_trans_type;
72162 + subj->group_trans_type = subjcompat.group_trans_type;
72163 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
72164 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
72165 + subj->user_trans_num = subjcompat.user_trans_num;
72166 + subj->group_trans_num = subjcompat.group_trans_num;
72167 +
72168 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
72169 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
72170 + subj->ip_type = subjcompat.ip_type;
72171 + subj->ips = compat_ptr(subjcompat.ips);
72172 + subj->ip_num = subjcompat.ip_num;
72173 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
72174 +
72175 + subj->crashes = subjcompat.crashes;
72176 + subj->expires = subjcompat.expires;
72177 +
72178 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
72179 + subj->hash = compat_ptr(subjcompat.hash);
72180 + subj->prev = compat_ptr(subjcompat.prev);
72181 + subj->next = compat_ptr(subjcompat.next);
72182 +
72183 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
72184 + subj->obj_hash_size = subjcompat.obj_hash_size;
72185 + subj->pax_flags = subjcompat.pax_flags;
72186 +
72187 + return 0;
72188 +}
72189 +
72190 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
72191 +{
72192 + struct acl_role_label_compat rolecompat;
72193 +
72194 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
72195 + return -EFAULT;
72196 +
72197 + role->rolename = compat_ptr(rolecompat.rolename);
72198 + role->uidgid = rolecompat.uidgid;
72199 + role->roletype = rolecompat.roletype;
72200 +
72201 + role->auth_attempts = rolecompat.auth_attempts;
72202 + role->expires = rolecompat.expires;
72203 +
72204 + role->root_label = compat_ptr(rolecompat.root_label);
72205 + role->hash = compat_ptr(rolecompat.hash);
72206 +
72207 + role->prev = compat_ptr(rolecompat.prev);
72208 + role->next = compat_ptr(rolecompat.next);
72209 +
72210 + role->transitions = compat_ptr(rolecompat.transitions);
72211 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
72212 + role->domain_children = compat_ptr(rolecompat.domain_children);
72213 + role->domain_child_num = rolecompat.domain_child_num;
72214 +
72215 + role->umask = rolecompat.umask;
72216 +
72217 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
72218 + role->subj_hash_size = rolecompat.subj_hash_size;
72219 +
72220 + return 0;
72221 +}
72222 +
72223 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
72224 +{
72225 + struct role_allowed_ip_compat roleip_compat;
72226 +
72227 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
72228 + return -EFAULT;
72229 +
72230 + roleip->addr = roleip_compat.addr;
72231 + roleip->netmask = roleip_compat.netmask;
72232 +
72233 + roleip->prev = compat_ptr(roleip_compat.prev);
72234 + roleip->next = compat_ptr(roleip_compat.next);
72235 +
72236 + return 0;
72237 +}
72238 +
72239 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
72240 +{
72241 + struct role_transition_compat trans_compat;
72242 +
72243 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
72244 + return -EFAULT;
72245 +
72246 + trans->rolename = compat_ptr(trans_compat.rolename);
72247 +
72248 + trans->prev = compat_ptr(trans_compat.prev);
72249 + trans->next = compat_ptr(trans_compat.next);
72250 +
72251 + return 0;
72252 +
72253 +}
72254 +
72255 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
72256 +{
72257 + struct gr_hash_struct_compat hash_compat;
72258 +
72259 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
72260 + return -EFAULT;
72261 +
72262 + hash->table = compat_ptr(hash_compat.table);
72263 + hash->nametable = compat_ptr(hash_compat.nametable);
72264 + hash->first = compat_ptr(hash_compat.first);
72265 +
72266 + hash->table_size = hash_compat.table_size;
72267 + hash->used_size = hash_compat.used_size;
72268 +
72269 + hash->type = hash_compat.type;
72270 +
72271 + return 0;
72272 +}
72273 +
72274 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
72275 +{
72276 + compat_uptr_t ptrcompat;
72277 +
72278 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
72279 + return -EFAULT;
72280 +
72281 + *(void **)ptr = compat_ptr(ptrcompat);
72282 +
72283 + return 0;
72284 +}
72285 +
72286 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
72287 +{
72288 + struct acl_ip_label_compat ip_compat;
72289 +
72290 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
72291 + return -EFAULT;
72292 +
72293 + ip->iface = compat_ptr(ip_compat.iface);
72294 + ip->addr = ip_compat.addr;
72295 + ip->netmask = ip_compat.netmask;
72296 + ip->low = ip_compat.low;
72297 + ip->high = ip_compat.high;
72298 + ip->mode = ip_compat.mode;
72299 + ip->type = ip_compat.type;
72300 +
72301 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
72302 +
72303 + ip->prev = compat_ptr(ip_compat.prev);
72304 + ip->next = compat_ptr(ip_compat.next);
72305 +
72306 + return 0;
72307 +}
72308 +
72309 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
72310 +{
72311 + struct sprole_pw_compat pw_compat;
72312 +
72313 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
72314 + return -EFAULT;
72315 +
72316 + pw->rolename = compat_ptr(pw_compat.rolename);
72317 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
72318 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
72319 +
72320 + return 0;
72321 +}
72322 +
72323 +size_t get_gr_arg_wrapper_size_compat(void)
72324 +{
72325 + return sizeof(struct gr_arg_wrapper_compat);
72326 +}
72327 +
72328 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
72329 new file mode 100644
72330 index 0000000..4008fdc
72331 --- /dev/null
72332 +++ b/grsecurity/gracl_fs.c
72333 @@ -0,0 +1,445 @@
72334 +#include <linux/kernel.h>
72335 +#include <linux/sched.h>
72336 +#include <linux/types.h>
72337 +#include <linux/fs.h>
72338 +#include <linux/file.h>
72339 +#include <linux/stat.h>
72340 +#include <linux/grsecurity.h>
72341 +#include <linux/grinternal.h>
72342 +#include <linux/gracl.h>
72343 +
72344 +umode_t
72345 +gr_acl_umask(void)
72346 +{
72347 + if (unlikely(!gr_acl_is_enabled()))
72348 + return 0;
72349 +
72350 + return current->role->umask;
72351 +}
72352 +
72353 +__u32
72354 +gr_acl_handle_hidden_file(const struct dentry * dentry,
72355 + const struct vfsmount * mnt)
72356 +{
72357 + __u32 mode;
72358 +
72359 + if (unlikely(d_is_negative(dentry)))
72360 + return GR_FIND;
72361 +
72362 + mode =
72363 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
72364 +
72365 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
72366 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
72367 + return mode;
72368 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
72369 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
72370 + return 0;
72371 + } else if (unlikely(!(mode & GR_FIND)))
72372 + return 0;
72373 +
72374 + return GR_FIND;
72375 +}
72376 +
72377 +__u32
72378 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
72379 + int acc_mode)
72380 +{
72381 + __u32 reqmode = GR_FIND;
72382 + __u32 mode;
72383 +
72384 + if (unlikely(d_is_negative(dentry)))
72385 + return reqmode;
72386 +
72387 + if (acc_mode & MAY_APPEND)
72388 + reqmode |= GR_APPEND;
72389 + else if (acc_mode & MAY_WRITE)
72390 + reqmode |= GR_WRITE;
72391 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
72392 + reqmode |= GR_READ;
72393 +
72394 + mode =
72395 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
72396 + mnt);
72397 +
72398 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72399 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
72400 + reqmode & GR_READ ? " reading" : "",
72401 + reqmode & GR_WRITE ? " writing" : reqmode &
72402 + GR_APPEND ? " appending" : "");
72403 + return reqmode;
72404 + } else
72405 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72406 + {
72407 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
72408 + reqmode & GR_READ ? " reading" : "",
72409 + reqmode & GR_WRITE ? " writing" : reqmode &
72410 + GR_APPEND ? " appending" : "");
72411 + return 0;
72412 + } else if (unlikely((mode & reqmode) != reqmode))
72413 + return 0;
72414 +
72415 + return reqmode;
72416 +}
72417 +
72418 +__u32
72419 +gr_acl_handle_creat(const struct dentry * dentry,
72420 + const struct dentry * p_dentry,
72421 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
72422 + const int imode)
72423 +{
72424 + __u32 reqmode = GR_WRITE | GR_CREATE;
72425 + __u32 mode;
72426 +
72427 + if (acc_mode & MAY_APPEND)
72428 + reqmode |= GR_APPEND;
72429 + // if a directory was required or the directory already exists, then
72430 + // don't count this open as a read
72431 + if ((acc_mode & MAY_READ) &&
72432 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
72433 + reqmode |= GR_READ;
72434 + if ((open_flags & O_CREAT) &&
72435 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
72436 + reqmode |= GR_SETID;
72437 +
72438 + mode =
72439 + gr_check_create(dentry, p_dentry, p_mnt,
72440 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
72441 +
72442 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72443 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
72444 + reqmode & GR_READ ? " reading" : "",
72445 + reqmode & GR_WRITE ? " writing" : reqmode &
72446 + GR_APPEND ? " appending" : "");
72447 + return reqmode;
72448 + } else
72449 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72450 + {
72451 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
72452 + reqmode & GR_READ ? " reading" : "",
72453 + reqmode & GR_WRITE ? " writing" : reqmode &
72454 + GR_APPEND ? " appending" : "");
72455 + return 0;
72456 + } else if (unlikely((mode & reqmode) != reqmode))
72457 + return 0;
72458 +
72459 + return reqmode;
72460 +}
72461 +
72462 +__u32
72463 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
72464 + const int fmode)
72465 +{
72466 + __u32 mode, reqmode = GR_FIND;
72467 +
72468 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
72469 + reqmode |= GR_EXEC;
72470 + if (fmode & S_IWOTH)
72471 + reqmode |= GR_WRITE;
72472 + if (fmode & S_IROTH)
72473 + reqmode |= GR_READ;
72474 +
72475 + mode =
72476 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
72477 + mnt);
72478 +
72479 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72480 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
72481 + reqmode & GR_READ ? " reading" : "",
72482 + reqmode & GR_WRITE ? " writing" : "",
72483 + reqmode & GR_EXEC ? " executing" : "");
72484 + return reqmode;
72485 + } else
72486 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72487 + {
72488 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
72489 + reqmode & GR_READ ? " reading" : "",
72490 + reqmode & GR_WRITE ? " writing" : "",
72491 + reqmode & GR_EXEC ? " executing" : "");
72492 + return 0;
72493 + } else if (unlikely((mode & reqmode) != reqmode))
72494 + return 0;
72495 +
72496 + return reqmode;
72497 +}
72498 +
72499 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
72500 +{
72501 + __u32 mode;
72502 +
72503 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
72504 +
72505 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
72506 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
72507 + return mode;
72508 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
72509 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
72510 + return 0;
72511 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
72512 + return 0;
72513 +
72514 + return (reqmode);
72515 +}
72516 +
72517 +__u32
72518 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
72519 +{
72520 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
72521 +}
72522 +
72523 +__u32
72524 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
72525 +{
72526 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
72527 +}
72528 +
72529 +__u32
72530 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
72531 +{
72532 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
72533 +}
72534 +
72535 +__u32
72536 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
72537 +{
72538 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
72539 +}
72540 +
72541 +__u32
72542 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
72543 + umode_t *modeptr)
72544 +{
72545 + umode_t mode;
72546 +
72547 + *modeptr &= ~gr_acl_umask();
72548 + mode = *modeptr;
72549 +
72550 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
72551 + return 1;
72552 +
72553 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
72554 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
72555 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
72556 + GR_CHMOD_ACL_MSG);
72557 + } else {
72558 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
72559 + }
72560 +}
72561 +
72562 +__u32
72563 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
72564 +{
72565 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
72566 +}
72567 +
72568 +__u32
72569 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
72570 +{
72571 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
72572 +}
72573 +
72574 +__u32
72575 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
72576 +{
72577 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
72578 +}
72579 +
72580 +__u32
72581 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
72582 +{
72583 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
72584 +}
72585 +
72586 +__u32
72587 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
72588 +{
72589 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
72590 + GR_UNIXCONNECT_ACL_MSG);
72591 +}
72592 +
72593 +/* hardlinks require at minimum create and link permission,
72594 + any additional privilege required is based on the
72595 + privilege of the file being linked to
72596 +*/
72597 +__u32
72598 +gr_acl_handle_link(const struct dentry * new_dentry,
72599 + const struct dentry * parent_dentry,
72600 + const struct vfsmount * parent_mnt,
72601 + const struct dentry * old_dentry,
72602 + const struct vfsmount * old_mnt, const struct filename *to)
72603 +{
72604 + __u32 mode;
72605 + __u32 needmode = GR_CREATE | GR_LINK;
72606 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
72607 +
72608 + mode =
72609 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
72610 + old_mnt);
72611 +
72612 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
72613 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
72614 + return mode;
72615 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
72616 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
72617 + return 0;
72618 + } else if (unlikely((mode & needmode) != needmode))
72619 + return 0;
72620 +
72621 + return 1;
72622 +}
72623 +
72624 +__u32
72625 +gr_acl_handle_symlink(const struct dentry * new_dentry,
72626 + const struct dentry * parent_dentry,
72627 + const struct vfsmount * parent_mnt, const struct filename *from)
72628 +{
72629 + __u32 needmode = GR_WRITE | GR_CREATE;
72630 + __u32 mode;
72631 +
72632 + mode =
72633 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
72634 + GR_CREATE | GR_AUDIT_CREATE |
72635 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
72636 +
72637 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
72638 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
72639 + return mode;
72640 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
72641 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
72642 + return 0;
72643 + } else if (unlikely((mode & needmode) != needmode))
72644 + return 0;
72645 +
72646 + return (GR_WRITE | GR_CREATE);
72647 +}
72648 +
72649 +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)
72650 +{
72651 + __u32 mode;
72652 +
72653 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
72654 +
72655 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
72656 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
72657 + return mode;
72658 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
72659 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
72660 + return 0;
72661 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
72662 + return 0;
72663 +
72664 + return (reqmode);
72665 +}
72666 +
72667 +__u32
72668 +gr_acl_handle_mknod(const struct dentry * new_dentry,
72669 + const struct dentry * parent_dentry,
72670 + const struct vfsmount * parent_mnt,
72671 + const int mode)
72672 +{
72673 + __u32 reqmode = GR_WRITE | GR_CREATE;
72674 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
72675 + reqmode |= GR_SETID;
72676 +
72677 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
72678 + reqmode, GR_MKNOD_ACL_MSG);
72679 +}
72680 +
72681 +__u32
72682 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
72683 + const struct dentry *parent_dentry,
72684 + const struct vfsmount *parent_mnt)
72685 +{
72686 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
72687 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
72688 +}
72689 +
72690 +#define RENAME_CHECK_SUCCESS(old, new) \
72691 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
72692 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
72693 +
72694 +int
72695 +gr_acl_handle_rename(struct dentry *new_dentry,
72696 + struct dentry *parent_dentry,
72697 + const struct vfsmount *parent_mnt,
72698 + struct dentry *old_dentry,
72699 + struct inode *old_parent_inode,
72700 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
72701 +{
72702 + __u32 comp1, comp2;
72703 + int error = 0;
72704 +
72705 + if (unlikely(!gr_acl_is_enabled()))
72706 + return 0;
72707 +
72708 + if (flags & RENAME_EXCHANGE) {
72709 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
72710 + GR_AUDIT_READ | GR_AUDIT_WRITE |
72711 + GR_SUPPRESS, parent_mnt);
72712 + comp2 =
72713 + gr_search_file(old_dentry,
72714 + GR_READ | GR_WRITE | GR_AUDIT_READ |
72715 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
72716 + } else if (d_is_negative(new_dentry)) {
72717 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
72718 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
72719 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
72720 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
72721 + GR_DELETE | GR_AUDIT_DELETE |
72722 + GR_AUDIT_READ | GR_AUDIT_WRITE |
72723 + GR_SUPPRESS, old_mnt);
72724 + } else {
72725 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
72726 + GR_CREATE | GR_DELETE |
72727 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
72728 + GR_AUDIT_READ | GR_AUDIT_WRITE |
72729 + GR_SUPPRESS, parent_mnt);
72730 + comp2 =
72731 + gr_search_file(old_dentry,
72732 + GR_READ | GR_WRITE | GR_AUDIT_READ |
72733 + GR_DELETE | GR_AUDIT_DELETE |
72734 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
72735 + }
72736 +
72737 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
72738 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
72739 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
72740 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
72741 + && !(comp2 & GR_SUPPRESS)) {
72742 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
72743 + error = -EACCES;
72744 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
72745 + error = -EACCES;
72746 +
72747 + return error;
72748 +}
72749 +
72750 +void
72751 +gr_acl_handle_exit(void)
72752 +{
72753 + u16 id;
72754 + char *rolename;
72755 +
72756 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
72757 + !(current->role->roletype & GR_ROLE_PERSIST))) {
72758 + id = current->acl_role_id;
72759 + rolename = current->role->rolename;
72760 + gr_set_acls(1);
72761 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
72762 + }
72763 +
72764 + gr_put_exec_file(current);
72765 + return;
72766 +}
72767 +
72768 +int
72769 +gr_acl_handle_procpidmem(const struct task_struct *task)
72770 +{
72771 + if (unlikely(!gr_acl_is_enabled()))
72772 + return 0;
72773 +
72774 + if (task != current && task->acl->mode & GR_PROTPROCFD)
72775 + return -EACCES;
72776 +
72777 + return 0;
72778 +}
72779 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
72780 new file mode 100644
72781 index 0000000..f056b81
72782 --- /dev/null
72783 +++ b/grsecurity/gracl_ip.c
72784 @@ -0,0 +1,386 @@
72785 +#include <linux/kernel.h>
72786 +#include <asm/uaccess.h>
72787 +#include <asm/errno.h>
72788 +#include <net/sock.h>
72789 +#include <linux/file.h>
72790 +#include <linux/fs.h>
72791 +#include <linux/net.h>
72792 +#include <linux/in.h>
72793 +#include <linux/skbuff.h>
72794 +#include <linux/ip.h>
72795 +#include <linux/udp.h>
72796 +#include <linux/types.h>
72797 +#include <linux/sched.h>
72798 +#include <linux/netdevice.h>
72799 +#include <linux/inetdevice.h>
72800 +#include <linux/gracl.h>
72801 +#include <linux/grsecurity.h>
72802 +#include <linux/grinternal.h>
72803 +
72804 +#define GR_BIND 0x01
72805 +#define GR_CONNECT 0x02
72806 +#define GR_INVERT 0x04
72807 +#define GR_BINDOVERRIDE 0x08
72808 +#define GR_CONNECTOVERRIDE 0x10
72809 +#define GR_SOCK_FAMILY 0x20
72810 +
72811 +static const char * gr_protocols[IPPROTO_MAX] = {
72812 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
72813 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
72814 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
72815 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
72816 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
72817 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
72818 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
72819 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
72820 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
72821 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
72822 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
72823 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
72824 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
72825 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
72826 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
72827 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
72828 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
72829 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
72830 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
72831 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
72832 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
72833 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
72834 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
72835 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
72836 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
72837 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
72838 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
72839 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
72840 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
72841 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
72842 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
72843 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
72844 + };
72845 +
72846 +static const char * gr_socktypes[SOCK_MAX] = {
72847 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
72848 + "unknown:7", "unknown:8", "unknown:9", "packet"
72849 + };
72850 +
72851 +static const char * gr_sockfamilies[AF_MAX+1] = {
72852 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
72853 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
72854 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
72855 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
72856 + };
72857 +
72858 +const char *
72859 +gr_proto_to_name(unsigned char proto)
72860 +{
72861 + return gr_protocols[proto];
72862 +}
72863 +
72864 +const char *
72865 +gr_socktype_to_name(unsigned char type)
72866 +{
72867 + return gr_socktypes[type];
72868 +}
72869 +
72870 +const char *
72871 +gr_sockfamily_to_name(unsigned char family)
72872 +{
72873 + return gr_sockfamilies[family];
72874 +}
72875 +
72876 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
72877 +
72878 +int
72879 +gr_search_socket(const int domain, const int type, const int protocol)
72880 +{
72881 + struct acl_subject_label *curr;
72882 + const struct cred *cred = current_cred();
72883 +
72884 + if (unlikely(!gr_acl_is_enabled()))
72885 + goto exit;
72886 +
72887 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
72888 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
72889 + goto exit; // let the kernel handle it
72890 +
72891 + curr = current->acl;
72892 +
72893 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
72894 + /* the family is allowed, if this is PF_INET allow it only if
72895 + the extra sock type/protocol checks pass */
72896 + if (domain == PF_INET)
72897 + goto inet_check;
72898 + goto exit;
72899 + } else {
72900 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
72901 + __u32 fakeip = 0;
72902 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
72903 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
72904 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
72905 + gr_to_filename(current->exec_file->f_path.dentry,
72906 + current->exec_file->f_path.mnt) :
72907 + curr->filename, curr->filename,
72908 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
72909 + &current->signal->saved_ip);
72910 + goto exit;
72911 + }
72912 + goto exit_fail;
72913 + }
72914 +
72915 +inet_check:
72916 + /* the rest of this checking is for IPv4 only */
72917 + if (!curr->ips)
72918 + goto exit;
72919 +
72920 + if ((curr->ip_type & (1U << type)) &&
72921 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
72922 + goto exit;
72923 +
72924 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
72925 + /* we don't place acls on raw sockets , and sometimes
72926 + dgram/ip sockets are opened for ioctl and not
72927 + bind/connect, so we'll fake a bind learn log */
72928 + if (type == SOCK_RAW || type == SOCK_PACKET) {
72929 + __u32 fakeip = 0;
72930 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
72931 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
72932 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
72933 + gr_to_filename(current->exec_file->f_path.dentry,
72934 + current->exec_file->f_path.mnt) :
72935 + curr->filename, curr->filename,
72936 + &fakeip, 0, type,
72937 + protocol, GR_CONNECT, &current->signal->saved_ip);
72938 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
72939 + __u32 fakeip = 0;
72940 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
72941 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
72942 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
72943 + gr_to_filename(current->exec_file->f_path.dentry,
72944 + current->exec_file->f_path.mnt) :
72945 + curr->filename, curr->filename,
72946 + &fakeip, 0, type,
72947 + protocol, GR_BIND, &current->signal->saved_ip);
72948 + }
72949 + /* we'll log when they use connect or bind */
72950 + goto exit;
72951 + }
72952 +
72953 +exit_fail:
72954 + if (domain == PF_INET)
72955 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
72956 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
72957 + else if (rcu_access_pointer(net_families[domain]) != NULL)
72958 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
72959 + gr_socktype_to_name(type), protocol);
72960 +
72961 + return 0;
72962 +exit:
72963 + return 1;
72964 +}
72965 +
72966 +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)
72967 +{
72968 + if ((ip->mode & mode) &&
72969 + (ip_port >= ip->low) &&
72970 + (ip_port <= ip->high) &&
72971 + ((ntohl(ip_addr) & our_netmask) ==
72972 + (ntohl(our_addr) & our_netmask))
72973 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
72974 + && (ip->type & (1U << type))) {
72975 + if (ip->mode & GR_INVERT)
72976 + return 2; // specifically denied
72977 + else
72978 + return 1; // allowed
72979 + }
72980 +
72981 + return 0; // not specifically allowed, may continue parsing
72982 +}
72983 +
72984 +static int
72985 +gr_search_connectbind(const int full_mode, struct sock *sk,
72986 + struct sockaddr_in *addr, const int type)
72987 +{
72988 + char iface[IFNAMSIZ] = {0};
72989 + struct acl_subject_label *curr;
72990 + struct acl_ip_label *ip;
72991 + struct inet_sock *isk;
72992 + struct net_device *dev;
72993 + struct in_device *idev;
72994 + unsigned long i;
72995 + int ret;
72996 + int mode = full_mode & (GR_BIND | GR_CONNECT);
72997 + __u32 ip_addr = 0;
72998 + __u32 our_addr;
72999 + __u32 our_netmask;
73000 + char *p;
73001 + __u16 ip_port = 0;
73002 + const struct cred *cred = current_cred();
73003 +
73004 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
73005 + return 0;
73006 +
73007 + curr = current->acl;
73008 + isk = inet_sk(sk);
73009 +
73010 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
73011 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
73012 + addr->sin_addr.s_addr = curr->inaddr_any_override;
73013 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
73014 + struct sockaddr_in saddr;
73015 + int err;
73016 +
73017 + saddr.sin_family = AF_INET;
73018 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
73019 + saddr.sin_port = isk->inet_sport;
73020 +
73021 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73022 + if (err)
73023 + return err;
73024 +
73025 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73026 + if (err)
73027 + return err;
73028 + }
73029 +
73030 + if (!curr->ips)
73031 + return 0;
73032 +
73033 + ip_addr = addr->sin_addr.s_addr;
73034 + ip_port = ntohs(addr->sin_port);
73035 +
73036 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73037 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73038 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73039 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73040 + gr_to_filename(current->exec_file->f_path.dentry,
73041 + current->exec_file->f_path.mnt) :
73042 + curr->filename, curr->filename,
73043 + &ip_addr, ip_port, type,
73044 + sk->sk_protocol, mode, &current->signal->saved_ip);
73045 + return 0;
73046 + }
73047 +
73048 + for (i = 0; i < curr->ip_num; i++) {
73049 + ip = *(curr->ips + i);
73050 + if (ip->iface != NULL) {
73051 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
73052 + p = strchr(iface, ':');
73053 + if (p != NULL)
73054 + *p = '\0';
73055 + dev = dev_get_by_name(sock_net(sk), iface);
73056 + if (dev == NULL)
73057 + continue;
73058 + idev = in_dev_get(dev);
73059 + if (idev == NULL) {
73060 + dev_put(dev);
73061 + continue;
73062 + }
73063 + rcu_read_lock();
73064 + for_ifa(idev) {
73065 + if (!strcmp(ip->iface, ifa->ifa_label)) {
73066 + our_addr = ifa->ifa_address;
73067 + our_netmask = 0xffffffff;
73068 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73069 + if (ret == 1) {
73070 + rcu_read_unlock();
73071 + in_dev_put(idev);
73072 + dev_put(dev);
73073 + return 0;
73074 + } else if (ret == 2) {
73075 + rcu_read_unlock();
73076 + in_dev_put(idev);
73077 + dev_put(dev);
73078 + goto denied;
73079 + }
73080 + }
73081 + } endfor_ifa(idev);
73082 + rcu_read_unlock();
73083 + in_dev_put(idev);
73084 + dev_put(dev);
73085 + } else {
73086 + our_addr = ip->addr;
73087 + our_netmask = ip->netmask;
73088 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73089 + if (ret == 1)
73090 + return 0;
73091 + else if (ret == 2)
73092 + goto denied;
73093 + }
73094 + }
73095 +
73096 +denied:
73097 + if (mode == GR_BIND)
73098 + 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));
73099 + else if (mode == GR_CONNECT)
73100 + 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));
73101 +
73102 + return -EACCES;
73103 +}
73104 +
73105 +int
73106 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
73107 +{
73108 + /* always allow disconnection of dgram sockets with connect */
73109 + if (addr->sin_family == AF_UNSPEC)
73110 + return 0;
73111 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
73112 +}
73113 +
73114 +int
73115 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
73116 +{
73117 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
73118 +}
73119 +
73120 +int gr_search_listen(struct socket *sock)
73121 +{
73122 + struct sock *sk = sock->sk;
73123 + struct sockaddr_in addr;
73124 +
73125 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73126 + addr.sin_port = inet_sk(sk)->inet_sport;
73127 +
73128 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73129 +}
73130 +
73131 +int gr_search_accept(struct socket *sock)
73132 +{
73133 + struct sock *sk = sock->sk;
73134 + struct sockaddr_in addr;
73135 +
73136 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73137 + addr.sin_port = inet_sk(sk)->inet_sport;
73138 +
73139 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73140 +}
73141 +
73142 +int
73143 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
73144 +{
73145 + if (addr)
73146 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
73147 + else {
73148 + struct sockaddr_in sin;
73149 + const struct inet_sock *inet = inet_sk(sk);
73150 +
73151 + sin.sin_addr.s_addr = inet->inet_daddr;
73152 + sin.sin_port = inet->inet_dport;
73153 +
73154 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73155 + }
73156 +}
73157 +
73158 +int
73159 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
73160 +{
73161 + struct sockaddr_in sin;
73162 +
73163 + if (unlikely(skb->len < sizeof (struct udphdr)))
73164 + return 0; // skip this packet
73165 +
73166 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
73167 + sin.sin_port = udp_hdr(skb)->source;
73168 +
73169 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73170 +}
73171 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
73172 new file mode 100644
73173 index 0000000..25f54ef
73174 --- /dev/null
73175 +++ b/grsecurity/gracl_learn.c
73176 @@ -0,0 +1,207 @@
73177 +#include <linux/kernel.h>
73178 +#include <linux/mm.h>
73179 +#include <linux/sched.h>
73180 +#include <linux/poll.h>
73181 +#include <linux/string.h>
73182 +#include <linux/file.h>
73183 +#include <linux/types.h>
73184 +#include <linux/vmalloc.h>
73185 +#include <linux/grinternal.h>
73186 +
73187 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
73188 + size_t count, loff_t *ppos);
73189 +extern int gr_acl_is_enabled(void);
73190 +
73191 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
73192 +static int gr_learn_attached;
73193 +
73194 +/* use a 512k buffer */
73195 +#define LEARN_BUFFER_SIZE (512 * 1024)
73196 +
73197 +static DEFINE_SPINLOCK(gr_learn_lock);
73198 +static DEFINE_MUTEX(gr_learn_user_mutex);
73199 +
73200 +/* we need to maintain two buffers, so that the kernel context of grlearn
73201 + uses a semaphore around the userspace copying, and the other kernel contexts
73202 + use a spinlock when copying into the buffer, since they cannot sleep
73203 +*/
73204 +static char *learn_buffer;
73205 +static char *learn_buffer_user;
73206 +static int learn_buffer_len;
73207 +static int learn_buffer_user_len;
73208 +
73209 +static ssize_t
73210 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
73211 +{
73212 + DECLARE_WAITQUEUE(wait, current);
73213 + ssize_t retval = 0;
73214 +
73215 + add_wait_queue(&learn_wait, &wait);
73216 + set_current_state(TASK_INTERRUPTIBLE);
73217 + do {
73218 + mutex_lock(&gr_learn_user_mutex);
73219 + spin_lock(&gr_learn_lock);
73220 + if (learn_buffer_len)
73221 + break;
73222 + spin_unlock(&gr_learn_lock);
73223 + mutex_unlock(&gr_learn_user_mutex);
73224 + if (file->f_flags & O_NONBLOCK) {
73225 + retval = -EAGAIN;
73226 + goto out;
73227 + }
73228 + if (signal_pending(current)) {
73229 + retval = -ERESTARTSYS;
73230 + goto out;
73231 + }
73232 +
73233 + schedule();
73234 + } while (1);
73235 +
73236 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
73237 + learn_buffer_user_len = learn_buffer_len;
73238 + retval = learn_buffer_len;
73239 + learn_buffer_len = 0;
73240 +
73241 + spin_unlock(&gr_learn_lock);
73242 +
73243 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
73244 + retval = -EFAULT;
73245 +
73246 + mutex_unlock(&gr_learn_user_mutex);
73247 +out:
73248 + set_current_state(TASK_RUNNING);
73249 + remove_wait_queue(&learn_wait, &wait);
73250 + return retval;
73251 +}
73252 +
73253 +static unsigned int
73254 +poll_learn(struct file * file, poll_table * wait)
73255 +{
73256 + poll_wait(file, &learn_wait, wait);
73257 +
73258 + if (learn_buffer_len)
73259 + return (POLLIN | POLLRDNORM);
73260 +
73261 + return 0;
73262 +}
73263 +
73264 +void
73265 +gr_clear_learn_entries(void)
73266 +{
73267 + char *tmp;
73268 +
73269 + mutex_lock(&gr_learn_user_mutex);
73270 + spin_lock(&gr_learn_lock);
73271 + tmp = learn_buffer;
73272 + learn_buffer = NULL;
73273 + spin_unlock(&gr_learn_lock);
73274 + if (tmp)
73275 + vfree(tmp);
73276 + if (learn_buffer_user != NULL) {
73277 + vfree(learn_buffer_user);
73278 + learn_buffer_user = NULL;
73279 + }
73280 + learn_buffer_len = 0;
73281 + mutex_unlock(&gr_learn_user_mutex);
73282 +
73283 + return;
73284 +}
73285 +
73286 +void
73287 +gr_add_learn_entry(const char *fmt, ...)
73288 +{
73289 + va_list args;
73290 + unsigned int len;
73291 +
73292 + if (!gr_learn_attached)
73293 + return;
73294 +
73295 + spin_lock(&gr_learn_lock);
73296 +
73297 + /* leave a gap at the end so we know when it's "full" but don't have to
73298 + compute the exact length of the string we're trying to append
73299 + */
73300 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
73301 + spin_unlock(&gr_learn_lock);
73302 + wake_up_interruptible(&learn_wait);
73303 + return;
73304 + }
73305 + if (learn_buffer == NULL) {
73306 + spin_unlock(&gr_learn_lock);
73307 + return;
73308 + }
73309 +
73310 + va_start(args, fmt);
73311 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
73312 + va_end(args);
73313 +
73314 + learn_buffer_len += len + 1;
73315 +
73316 + spin_unlock(&gr_learn_lock);
73317 + wake_up_interruptible(&learn_wait);
73318 +
73319 + return;
73320 +}
73321 +
73322 +static int
73323 +open_learn(struct inode *inode, struct file *file)
73324 +{
73325 + if (file->f_mode & FMODE_READ && gr_learn_attached)
73326 + return -EBUSY;
73327 + if (file->f_mode & FMODE_READ) {
73328 + int retval = 0;
73329 + mutex_lock(&gr_learn_user_mutex);
73330 + if (learn_buffer == NULL)
73331 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
73332 + if (learn_buffer_user == NULL)
73333 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
73334 + if (learn_buffer == NULL) {
73335 + retval = -ENOMEM;
73336 + goto out_error;
73337 + }
73338 + if (learn_buffer_user == NULL) {
73339 + retval = -ENOMEM;
73340 + goto out_error;
73341 + }
73342 + learn_buffer_len = 0;
73343 + learn_buffer_user_len = 0;
73344 + gr_learn_attached = 1;
73345 +out_error:
73346 + mutex_unlock(&gr_learn_user_mutex);
73347 + return retval;
73348 + }
73349 + return 0;
73350 +}
73351 +
73352 +static int
73353 +close_learn(struct inode *inode, struct file *file)
73354 +{
73355 + if (file->f_mode & FMODE_READ) {
73356 + char *tmp = NULL;
73357 + mutex_lock(&gr_learn_user_mutex);
73358 + spin_lock(&gr_learn_lock);
73359 + tmp = learn_buffer;
73360 + learn_buffer = NULL;
73361 + spin_unlock(&gr_learn_lock);
73362 + if (tmp)
73363 + vfree(tmp);
73364 + if (learn_buffer_user != NULL) {
73365 + vfree(learn_buffer_user);
73366 + learn_buffer_user = NULL;
73367 + }
73368 + learn_buffer_len = 0;
73369 + learn_buffer_user_len = 0;
73370 + gr_learn_attached = 0;
73371 + mutex_unlock(&gr_learn_user_mutex);
73372 + }
73373 +
73374 + return 0;
73375 +}
73376 +
73377 +const struct file_operations grsec_fops = {
73378 + .read = read_learn,
73379 + .write = write_grsec_handler,
73380 + .open = open_learn,
73381 + .release = close_learn,
73382 + .poll = poll_learn,
73383 +};
73384 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
73385 new file mode 100644
73386 index 0000000..3f8ade0
73387 --- /dev/null
73388 +++ b/grsecurity/gracl_policy.c
73389 @@ -0,0 +1,1782 @@
73390 +#include <linux/kernel.h>
73391 +#include <linux/module.h>
73392 +#include <linux/sched.h>
73393 +#include <linux/mm.h>
73394 +#include <linux/file.h>
73395 +#include <linux/fs.h>
73396 +#include <linux/namei.h>
73397 +#include <linux/mount.h>
73398 +#include <linux/tty.h>
73399 +#include <linux/proc_fs.h>
73400 +#include <linux/lglock.h>
73401 +#include <linux/slab.h>
73402 +#include <linux/vmalloc.h>
73403 +#include <linux/types.h>
73404 +#include <linux/sysctl.h>
73405 +#include <linux/netdevice.h>
73406 +#include <linux/ptrace.h>
73407 +#include <linux/gracl.h>
73408 +#include <linux/gralloc.h>
73409 +#include <linux/security.h>
73410 +#include <linux/grinternal.h>
73411 +#include <linux/pid_namespace.h>
73412 +#include <linux/stop_machine.h>
73413 +#include <linux/fdtable.h>
73414 +#include <linux/percpu.h>
73415 +#include <linux/lglock.h>
73416 +#include <linux/hugetlb.h>
73417 +#include <linux/posix-timers.h>
73418 +#include "../fs/mount.h"
73419 +
73420 +#include <asm/uaccess.h>
73421 +#include <asm/errno.h>
73422 +#include <asm/mman.h>
73423 +
73424 +extern struct gr_policy_state *polstate;
73425 +
73426 +#define FOR_EACH_ROLE_START(role) \
73427 + role = polstate->role_list; \
73428 + while (role) {
73429 +
73430 +#define FOR_EACH_ROLE_END(role) \
73431 + role = role->prev; \
73432 + }
73433 +
73434 +struct path gr_real_root;
73435 +
73436 +extern struct gr_alloc_state *current_alloc_state;
73437 +
73438 +u16 acl_sp_role_value;
73439 +
73440 +static DEFINE_MUTEX(gr_dev_mutex);
73441 +
73442 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
73443 +extern void gr_clear_learn_entries(void);
73444 +
73445 +struct gr_arg *gr_usermode __read_only;
73446 +unsigned char *gr_system_salt __read_only;
73447 +unsigned char *gr_system_sum __read_only;
73448 +
73449 +static unsigned int gr_auth_attempts = 0;
73450 +static unsigned long gr_auth_expires = 0UL;
73451 +
73452 +struct acl_object_label *fakefs_obj_rw;
73453 +struct acl_object_label *fakefs_obj_rwx;
73454 +
73455 +extern int gr_init_uidset(void);
73456 +extern void gr_free_uidset(void);
73457 +extern void gr_remove_uid(uid_t uid);
73458 +extern int gr_find_uid(uid_t uid);
73459 +
73460 +extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
73461 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
73462 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
73463 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
73464 +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);
73465 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
73466 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
73467 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
73468 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
73469 +extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
73470 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
73471 +extern void assign_special_role(const char *rolename);
73472 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
73473 +extern int gr_rbac_disable(void *unused);
73474 +extern void gr_enable_rbac_system(void);
73475 +
73476 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
73477 +{
73478 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
73479 + return -EFAULT;
73480 +
73481 + return 0;
73482 +}
73483 +
73484 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
73485 +{
73486 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
73487 + return -EFAULT;
73488 +
73489 + return 0;
73490 +}
73491 +
73492 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
73493 +{
73494 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
73495 + return -EFAULT;
73496 +
73497 + return 0;
73498 +}
73499 +
73500 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
73501 +{
73502 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
73503 + return -EFAULT;
73504 +
73505 + return 0;
73506 +}
73507 +
73508 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
73509 +{
73510 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
73511 + return -EFAULT;
73512 +
73513 + return 0;
73514 +}
73515 +
73516 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
73517 +{
73518 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
73519 + return -EFAULT;
73520 +
73521 + return 0;
73522 +}
73523 +
73524 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
73525 +{
73526 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
73527 + return -EFAULT;
73528 +
73529 + return 0;
73530 +}
73531 +
73532 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
73533 +{
73534 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
73535 + return -EFAULT;
73536 +
73537 + return 0;
73538 +}
73539 +
73540 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
73541 +{
73542 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
73543 + return -EFAULT;
73544 +
73545 + return 0;
73546 +}
73547 +
73548 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
73549 +{
73550 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
73551 + return -EFAULT;
73552 +
73553 + if (((uwrap->version != GRSECURITY_VERSION) &&
73554 + (uwrap->version != 0x2901)) ||
73555 + (uwrap->size != sizeof(struct gr_arg)))
73556 + return -EINVAL;
73557 +
73558 + return 0;
73559 +}
73560 +
73561 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
73562 +{
73563 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
73564 + return -EFAULT;
73565 +
73566 + return 0;
73567 +}
73568 +
73569 +static size_t get_gr_arg_wrapper_size_normal(void)
73570 +{
73571 + return sizeof(struct gr_arg_wrapper);
73572 +}
73573 +
73574 +#ifdef CONFIG_COMPAT
73575 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
73576 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
73577 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
73578 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
73579 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
73580 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
73581 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
73582 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
73583 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
73584 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
73585 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
73586 +extern size_t get_gr_arg_wrapper_size_compat(void);
73587 +
73588 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
73589 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
73590 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
73591 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
73592 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
73593 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
73594 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
73595 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
73596 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
73597 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
73598 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
73599 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
73600 +
73601 +#else
73602 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
73603 +#define copy_gr_arg copy_gr_arg_normal
73604 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
73605 +#define copy_acl_object_label copy_acl_object_label_normal
73606 +#define copy_acl_subject_label copy_acl_subject_label_normal
73607 +#define copy_acl_role_label copy_acl_role_label_normal
73608 +#define copy_acl_ip_label copy_acl_ip_label_normal
73609 +#define copy_pointer_from_array copy_pointer_from_array_normal
73610 +#define copy_sprole_pw copy_sprole_pw_normal
73611 +#define copy_role_transition copy_role_transition_normal
73612 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
73613 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
73614 +#endif
73615 +
73616 +static struct acl_subject_label *
73617 +lookup_subject_map(const struct acl_subject_label *userp)
73618 +{
73619 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
73620 + struct subject_map *match;
73621 +
73622 + match = polstate->subj_map_set.s_hash[index];
73623 +
73624 + while (match && match->user != userp)
73625 + match = match->next;
73626 +
73627 + if (match != NULL)
73628 + return match->kernel;
73629 + else
73630 + return NULL;
73631 +}
73632 +
73633 +static void
73634 +insert_subj_map_entry(struct subject_map *subjmap)
73635 +{
73636 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
73637 + struct subject_map **curr;
73638 +
73639 + subjmap->prev = NULL;
73640 +
73641 + curr = &polstate->subj_map_set.s_hash[index];
73642 + if (*curr != NULL)
73643 + (*curr)->prev = subjmap;
73644 +
73645 + subjmap->next = *curr;
73646 + *curr = subjmap;
73647 +
73648 + return;
73649 +}
73650 +
73651 +static void
73652 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
73653 +{
73654 + unsigned int index =
73655 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
73656 + struct acl_role_label **curr;
73657 + struct acl_role_label *tmp, *tmp2;
73658 +
73659 + curr = &polstate->acl_role_set.r_hash[index];
73660 +
73661 + /* simple case, slot is empty, just set it to our role */
73662 + if (*curr == NULL) {
73663 + *curr = role;
73664 + } else {
73665 + /* example:
73666 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
73667 + 2 -> 3
73668 + */
73669 + /* first check to see if we can already be reached via this slot */
73670 + tmp = *curr;
73671 + while (tmp && tmp != role)
73672 + tmp = tmp->next;
73673 + if (tmp == role) {
73674 + /* we don't need to add ourselves to this slot's chain */
73675 + return;
73676 + }
73677 + /* we need to add ourselves to this chain, two cases */
73678 + if (role->next == NULL) {
73679 + /* simple case, append the current chain to our role */
73680 + role->next = *curr;
73681 + *curr = role;
73682 + } else {
73683 + /* 1 -> 2 -> 3 -> 4
73684 + 2 -> 3 -> 4
73685 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
73686 + */
73687 + /* trickier case: walk our role's chain until we find
73688 + the role for the start of the current slot's chain */
73689 + tmp = role;
73690 + tmp2 = *curr;
73691 + while (tmp->next && tmp->next != tmp2)
73692 + tmp = tmp->next;
73693 + if (tmp->next == tmp2) {
73694 + /* from example above, we found 3, so just
73695 + replace this slot's chain with ours */
73696 + *curr = role;
73697 + } else {
73698 + /* we didn't find a subset of our role's chain
73699 + in the current slot's chain, so append their
73700 + chain to ours, and set us as the first role in
73701 + the slot's chain
73702 +
73703 + we could fold this case with the case above,
73704 + but making it explicit for clarity
73705 + */
73706 + tmp->next = tmp2;
73707 + *curr = role;
73708 + }
73709 + }
73710 + }
73711 +
73712 + return;
73713 +}
73714 +
73715 +static void
73716 +insert_acl_role_label(struct acl_role_label *role)
73717 +{
73718 + int i;
73719 +
73720 + if (polstate->role_list == NULL) {
73721 + polstate->role_list = role;
73722 + role->prev = NULL;
73723 + } else {
73724 + role->prev = polstate->role_list;
73725 + polstate->role_list = role;
73726 + }
73727 +
73728 + /* used for hash chains */
73729 + role->next = NULL;
73730 +
73731 + if (role->roletype & GR_ROLE_DOMAIN) {
73732 + for (i = 0; i < role->domain_child_num; i++)
73733 + __insert_acl_role_label(role, role->domain_children[i]);
73734 + } else
73735 + __insert_acl_role_label(role, role->uidgid);
73736 +}
73737 +
73738 +static int
73739 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
73740 +{
73741 + struct name_entry **curr, *nentry;
73742 + struct inodev_entry *ientry;
73743 + unsigned int len = strlen(name);
73744 + unsigned int key = full_name_hash(name, len);
73745 + unsigned int index = key % polstate->name_set.n_size;
73746 +
73747 + curr = &polstate->name_set.n_hash[index];
73748 +
73749 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
73750 + curr = &((*curr)->next);
73751 +
73752 + if (*curr != NULL)
73753 + return 1;
73754 +
73755 + nentry = acl_alloc(sizeof (struct name_entry));
73756 + if (nentry == NULL)
73757 + return 0;
73758 + ientry = acl_alloc(sizeof (struct inodev_entry));
73759 + if (ientry == NULL)
73760 + return 0;
73761 + ientry->nentry = nentry;
73762 +
73763 + nentry->key = key;
73764 + nentry->name = name;
73765 + nentry->inode = inode;
73766 + nentry->device = device;
73767 + nentry->len = len;
73768 + nentry->deleted = deleted;
73769 +
73770 + nentry->prev = NULL;
73771 + curr = &polstate->name_set.n_hash[index];
73772 + if (*curr != NULL)
73773 + (*curr)->prev = nentry;
73774 + nentry->next = *curr;
73775 + *curr = nentry;
73776 +
73777 + /* insert us into the table searchable by inode/dev */
73778 + __insert_inodev_entry(polstate, ientry);
73779 +
73780 + return 1;
73781 +}
73782 +
73783 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
73784 +
73785 +static void *
73786 +create_table(__u32 * len, int elementsize)
73787 +{
73788 + unsigned int table_sizes[] = {
73789 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
73790 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
73791 + 4194301, 8388593, 16777213, 33554393, 67108859
73792 + };
73793 + void *newtable = NULL;
73794 + unsigned int pwr = 0;
73795 +
73796 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
73797 + table_sizes[pwr] <= *len)
73798 + pwr++;
73799 +
73800 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
73801 + return newtable;
73802 +
73803 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
73804 + newtable =
73805 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
73806 + else
73807 + newtable = vmalloc(table_sizes[pwr] * elementsize);
73808 +
73809 + *len = table_sizes[pwr];
73810 +
73811 + return newtable;
73812 +}
73813 +
73814 +static int
73815 +init_variables(const struct gr_arg *arg, bool reload)
73816 +{
73817 + struct task_struct *reaper = init_pid_ns.child_reaper;
73818 + unsigned int stacksize;
73819 +
73820 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
73821 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
73822 + polstate->name_set.n_size = arg->role_db.num_objects;
73823 + polstate->inodev_set.i_size = arg->role_db.num_objects;
73824 +
73825 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
73826 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
73827 + return 1;
73828 +
73829 + if (!reload) {
73830 + if (!gr_init_uidset())
73831 + return 1;
73832 + }
73833 +
73834 + /* set up the stack that holds allocation info */
73835 +
73836 + stacksize = arg->role_db.num_pointers + 5;
73837 +
73838 + if (!acl_alloc_stack_init(stacksize))
73839 + return 1;
73840 +
73841 + if (!reload) {
73842 + /* grab reference for the real root dentry and vfsmount */
73843 + get_fs_root(reaper->fs, &gr_real_root);
73844 +
73845 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
73846 + 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);
73847 +#endif
73848 +
73849 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
73850 + if (fakefs_obj_rw == NULL)
73851 + return 1;
73852 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
73853 +
73854 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
73855 + if (fakefs_obj_rwx == NULL)
73856 + return 1;
73857 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
73858 + }
73859 +
73860 + polstate->subj_map_set.s_hash =
73861 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
73862 + polstate->acl_role_set.r_hash =
73863 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
73864 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
73865 + polstate->inodev_set.i_hash =
73866 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
73867 +
73868 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
73869 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
73870 + return 1;
73871 +
73872 + memset(polstate->subj_map_set.s_hash, 0,
73873 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
73874 + memset(polstate->acl_role_set.r_hash, 0,
73875 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
73876 + memset(polstate->name_set.n_hash, 0,
73877 + sizeof (struct name_entry *) * polstate->name_set.n_size);
73878 + memset(polstate->inodev_set.i_hash, 0,
73879 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
73880 +
73881 + return 0;
73882 +}
73883 +
73884 +/* free information not needed after startup
73885 + currently contains user->kernel pointer mappings for subjects
73886 +*/
73887 +
73888 +static void
73889 +free_init_variables(void)
73890 +{
73891 + __u32 i;
73892 +
73893 + if (polstate->subj_map_set.s_hash) {
73894 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
73895 + if (polstate->subj_map_set.s_hash[i]) {
73896 + kfree(polstate->subj_map_set.s_hash[i]);
73897 + polstate->subj_map_set.s_hash[i] = NULL;
73898 + }
73899 + }
73900 +
73901 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
73902 + PAGE_SIZE)
73903 + kfree(polstate->subj_map_set.s_hash);
73904 + else
73905 + vfree(polstate->subj_map_set.s_hash);
73906 + }
73907 +
73908 + return;
73909 +}
73910 +
73911 +static void
73912 +free_variables(bool reload)
73913 +{
73914 + struct acl_subject_label *s;
73915 + struct acl_role_label *r;
73916 + struct task_struct *task, *task2;
73917 + unsigned int x;
73918 +
73919 + if (!reload) {
73920 + gr_clear_learn_entries();
73921 +
73922 + read_lock(&tasklist_lock);
73923 + do_each_thread(task2, task) {
73924 + task->acl_sp_role = 0;
73925 + task->acl_role_id = 0;
73926 + task->inherited = 0;
73927 + task->acl = NULL;
73928 + task->role = NULL;
73929 + } while_each_thread(task2, task);
73930 + read_unlock(&tasklist_lock);
73931 +
73932 + kfree(fakefs_obj_rw);
73933 + fakefs_obj_rw = NULL;
73934 + kfree(fakefs_obj_rwx);
73935 + fakefs_obj_rwx = NULL;
73936 +
73937 + /* release the reference to the real root dentry and vfsmount */
73938 + path_put(&gr_real_root);
73939 + memset(&gr_real_root, 0, sizeof(gr_real_root));
73940 + }
73941 +
73942 + /* free all object hash tables */
73943 +
73944 + FOR_EACH_ROLE_START(r)
73945 + if (r->subj_hash == NULL)
73946 + goto next_role;
73947 + FOR_EACH_SUBJECT_START(r, s, x)
73948 + if (s->obj_hash == NULL)
73949 + break;
73950 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
73951 + kfree(s->obj_hash);
73952 + else
73953 + vfree(s->obj_hash);
73954 + FOR_EACH_SUBJECT_END(s, x)
73955 + FOR_EACH_NESTED_SUBJECT_START(r, s)
73956 + if (s->obj_hash == NULL)
73957 + break;
73958 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
73959 + kfree(s->obj_hash);
73960 + else
73961 + vfree(s->obj_hash);
73962 + FOR_EACH_NESTED_SUBJECT_END(s)
73963 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
73964 + kfree(r->subj_hash);
73965 + else
73966 + vfree(r->subj_hash);
73967 + r->subj_hash = NULL;
73968 +next_role:
73969 + FOR_EACH_ROLE_END(r)
73970 +
73971 + acl_free_all();
73972 +
73973 + if (polstate->acl_role_set.r_hash) {
73974 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
73975 + PAGE_SIZE)
73976 + kfree(polstate->acl_role_set.r_hash);
73977 + else
73978 + vfree(polstate->acl_role_set.r_hash);
73979 + }
73980 + if (polstate->name_set.n_hash) {
73981 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
73982 + PAGE_SIZE)
73983 + kfree(polstate->name_set.n_hash);
73984 + else
73985 + vfree(polstate->name_set.n_hash);
73986 + }
73987 +
73988 + if (polstate->inodev_set.i_hash) {
73989 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
73990 + PAGE_SIZE)
73991 + kfree(polstate->inodev_set.i_hash);
73992 + else
73993 + vfree(polstate->inodev_set.i_hash);
73994 + }
73995 +
73996 + if (!reload)
73997 + gr_free_uidset();
73998 +
73999 + memset(&polstate->name_set, 0, sizeof (struct name_db));
74000 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
74001 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
74002 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
74003 +
74004 + polstate->default_role = NULL;
74005 + polstate->kernel_role = NULL;
74006 + polstate->role_list = NULL;
74007 +
74008 + return;
74009 +}
74010 +
74011 +static struct acl_subject_label *
74012 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
74013 +
74014 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
74015 +{
74016 + unsigned int len = strnlen_user(*name, maxlen);
74017 + char *tmp;
74018 +
74019 + if (!len || len >= maxlen)
74020 + return -EINVAL;
74021 +
74022 + if ((tmp = (char *) acl_alloc(len)) == NULL)
74023 + return -ENOMEM;
74024 +
74025 + if (copy_from_user(tmp, *name, len))
74026 + return -EFAULT;
74027 +
74028 + tmp[len-1] = '\0';
74029 + *name = tmp;
74030 +
74031 + return 0;
74032 +}
74033 +
74034 +static int
74035 +copy_user_glob(struct acl_object_label *obj)
74036 +{
74037 + struct acl_object_label *g_tmp, **guser;
74038 + int error;
74039 +
74040 + if (obj->globbed == NULL)
74041 + return 0;
74042 +
74043 + guser = &obj->globbed;
74044 + while (*guser) {
74045 + g_tmp = (struct acl_object_label *)
74046 + acl_alloc(sizeof (struct acl_object_label));
74047 + if (g_tmp == NULL)
74048 + return -ENOMEM;
74049 +
74050 + if (copy_acl_object_label(g_tmp, *guser))
74051 + return -EFAULT;
74052 +
74053 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
74054 + if (error)
74055 + return error;
74056 +
74057 + *guser = g_tmp;
74058 + guser = &(g_tmp->next);
74059 + }
74060 +
74061 + return 0;
74062 +}
74063 +
74064 +static int
74065 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
74066 + struct acl_role_label *role)
74067 +{
74068 + struct acl_object_label *o_tmp;
74069 + int ret;
74070 +
74071 + while (userp) {
74072 + if ((o_tmp = (struct acl_object_label *)
74073 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
74074 + return -ENOMEM;
74075 +
74076 + if (copy_acl_object_label(o_tmp, userp))
74077 + return -EFAULT;
74078 +
74079 + userp = o_tmp->prev;
74080 +
74081 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
74082 + if (ret)
74083 + return ret;
74084 +
74085 + insert_acl_obj_label(o_tmp, subj);
74086 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
74087 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
74088 + return -ENOMEM;
74089 +
74090 + ret = copy_user_glob(o_tmp);
74091 + if (ret)
74092 + return ret;
74093 +
74094 + if (o_tmp->nested) {
74095 + int already_copied;
74096 +
74097 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
74098 + if (IS_ERR(o_tmp->nested))
74099 + return PTR_ERR(o_tmp->nested);
74100 +
74101 + /* insert into nested subject list if we haven't copied this one yet
74102 + to prevent duplicate entries */
74103 + if (!already_copied) {
74104 + o_tmp->nested->next = role->hash->first;
74105 + role->hash->first = o_tmp->nested;
74106 + }
74107 + }
74108 + }
74109 +
74110 + return 0;
74111 +}
74112 +
74113 +static __u32
74114 +count_user_subjs(struct acl_subject_label *userp)
74115 +{
74116 + struct acl_subject_label s_tmp;
74117 + __u32 num = 0;
74118 +
74119 + while (userp) {
74120 + if (copy_acl_subject_label(&s_tmp, userp))
74121 + break;
74122 +
74123 + userp = s_tmp.prev;
74124 + }
74125 +
74126 + return num;
74127 +}
74128 +
74129 +static int
74130 +copy_user_allowedips(struct acl_role_label *rolep)
74131 +{
74132 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
74133 +
74134 + ruserip = rolep->allowed_ips;
74135 +
74136 + while (ruserip) {
74137 + rlast = rtmp;
74138 +
74139 + if ((rtmp = (struct role_allowed_ip *)
74140 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
74141 + return -ENOMEM;
74142 +
74143 + if (copy_role_allowed_ip(rtmp, ruserip))
74144 + return -EFAULT;
74145 +
74146 + ruserip = rtmp->prev;
74147 +
74148 + if (!rlast) {
74149 + rtmp->prev = NULL;
74150 + rolep->allowed_ips = rtmp;
74151 + } else {
74152 + rlast->next = rtmp;
74153 + rtmp->prev = rlast;
74154 + }
74155 +
74156 + if (!ruserip)
74157 + rtmp->next = NULL;
74158 + }
74159 +
74160 + return 0;
74161 +}
74162 +
74163 +static int
74164 +copy_user_transitions(struct acl_role_label *rolep)
74165 +{
74166 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
74167 + int error;
74168 +
74169 + rusertp = rolep->transitions;
74170 +
74171 + while (rusertp) {
74172 + rlast = rtmp;
74173 +
74174 + if ((rtmp = (struct role_transition *)
74175 + acl_alloc(sizeof (struct role_transition))) == NULL)
74176 + return -ENOMEM;
74177 +
74178 + if (copy_role_transition(rtmp, rusertp))
74179 + return -EFAULT;
74180 +
74181 + rusertp = rtmp->prev;
74182 +
74183 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
74184 + if (error)
74185 + return error;
74186 +
74187 + if (!rlast) {
74188 + rtmp->prev = NULL;
74189 + rolep->transitions = rtmp;
74190 + } else {
74191 + rlast->next = rtmp;
74192 + rtmp->prev = rlast;
74193 + }
74194 +
74195 + if (!rusertp)
74196 + rtmp->next = NULL;
74197 + }
74198 +
74199 + return 0;
74200 +}
74201 +
74202 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
74203 +{
74204 + struct acl_object_label o_tmp;
74205 + __u32 num = 0;
74206 +
74207 + while (userp) {
74208 + if (copy_acl_object_label(&o_tmp, userp))
74209 + break;
74210 +
74211 + userp = o_tmp.prev;
74212 + num++;
74213 + }
74214 +
74215 + return num;
74216 +}
74217 +
74218 +static struct acl_subject_label *
74219 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
74220 +{
74221 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
74222 + __u32 num_objs;
74223 + struct acl_ip_label **i_tmp, *i_utmp2;
74224 + struct gr_hash_struct ghash;
74225 + struct subject_map *subjmap;
74226 + unsigned int i_num;
74227 + int err;
74228 +
74229 + if (already_copied != NULL)
74230 + *already_copied = 0;
74231 +
74232 + s_tmp = lookup_subject_map(userp);
74233 +
74234 + /* we've already copied this subject into the kernel, just return
74235 + the reference to it, and don't copy it over again
74236 + */
74237 + if (s_tmp) {
74238 + if (already_copied != NULL)
74239 + *already_copied = 1;
74240 + return(s_tmp);
74241 + }
74242 +
74243 + if ((s_tmp = (struct acl_subject_label *)
74244 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
74245 + return ERR_PTR(-ENOMEM);
74246 +
74247 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
74248 + if (subjmap == NULL)
74249 + return ERR_PTR(-ENOMEM);
74250 +
74251 + subjmap->user = userp;
74252 + subjmap->kernel = s_tmp;
74253 + insert_subj_map_entry(subjmap);
74254 +
74255 + if (copy_acl_subject_label(s_tmp, userp))
74256 + return ERR_PTR(-EFAULT);
74257 +
74258 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
74259 + if (err)
74260 + return ERR_PTR(err);
74261 +
74262 + if (!strcmp(s_tmp->filename, "/"))
74263 + role->root_label = s_tmp;
74264 +
74265 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
74266 + return ERR_PTR(-EFAULT);
74267 +
74268 + /* copy user and group transition tables */
74269 +
74270 + if (s_tmp->user_trans_num) {
74271 + uid_t *uidlist;
74272 +
74273 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
74274 + if (uidlist == NULL)
74275 + return ERR_PTR(-ENOMEM);
74276 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
74277 + return ERR_PTR(-EFAULT);
74278 +
74279 + s_tmp->user_transitions = uidlist;
74280 + }
74281 +
74282 + if (s_tmp->group_trans_num) {
74283 + gid_t *gidlist;
74284 +
74285 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
74286 + if (gidlist == NULL)
74287 + return ERR_PTR(-ENOMEM);
74288 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
74289 + return ERR_PTR(-EFAULT);
74290 +
74291 + s_tmp->group_transitions = gidlist;
74292 + }
74293 +
74294 + /* set up object hash table */
74295 + num_objs = count_user_objs(ghash.first);
74296 +
74297 + s_tmp->obj_hash_size = num_objs;
74298 + s_tmp->obj_hash =
74299 + (struct acl_object_label **)
74300 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
74301 +
74302 + if (!s_tmp->obj_hash)
74303 + return ERR_PTR(-ENOMEM);
74304 +
74305 + memset(s_tmp->obj_hash, 0,
74306 + s_tmp->obj_hash_size *
74307 + sizeof (struct acl_object_label *));
74308 +
74309 + /* add in objects */
74310 + err = copy_user_objs(ghash.first, s_tmp, role);
74311 +
74312 + if (err)
74313 + return ERR_PTR(err);
74314 +
74315 + /* set pointer for parent subject */
74316 + if (s_tmp->parent_subject) {
74317 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
74318 +
74319 + if (IS_ERR(s_tmp2))
74320 + return s_tmp2;
74321 +
74322 + s_tmp->parent_subject = s_tmp2;
74323 + }
74324 +
74325 + /* add in ip acls */
74326 +
74327 + if (!s_tmp->ip_num) {
74328 + s_tmp->ips = NULL;
74329 + goto insert;
74330 + }
74331 +
74332 + i_tmp =
74333 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
74334 + sizeof (struct acl_ip_label *));
74335 +
74336 + if (!i_tmp)
74337 + return ERR_PTR(-ENOMEM);
74338 +
74339 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
74340 + *(i_tmp + i_num) =
74341 + (struct acl_ip_label *)
74342 + acl_alloc(sizeof (struct acl_ip_label));
74343 + if (!*(i_tmp + i_num))
74344 + return ERR_PTR(-ENOMEM);
74345 +
74346 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
74347 + return ERR_PTR(-EFAULT);
74348 +
74349 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
74350 + return ERR_PTR(-EFAULT);
74351 +
74352 + if ((*(i_tmp + i_num))->iface == NULL)
74353 + continue;
74354 +
74355 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
74356 + if (err)
74357 + return ERR_PTR(err);
74358 + }
74359 +
74360 + s_tmp->ips = i_tmp;
74361 +
74362 +insert:
74363 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
74364 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
74365 + return ERR_PTR(-ENOMEM);
74366 +
74367 + return s_tmp;
74368 +}
74369 +
74370 +static int
74371 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
74372 +{
74373 + struct acl_subject_label s_pre;
74374 + struct acl_subject_label * ret;
74375 + int err;
74376 +
74377 + while (userp) {
74378 + if (copy_acl_subject_label(&s_pre, userp))
74379 + return -EFAULT;
74380 +
74381 + ret = do_copy_user_subj(userp, role, NULL);
74382 +
74383 + err = PTR_ERR(ret);
74384 + if (IS_ERR(ret))
74385 + return err;
74386 +
74387 + insert_acl_subj_label(ret, role);
74388 +
74389 + userp = s_pre.prev;
74390 + }
74391 +
74392 + return 0;
74393 +}
74394 +
74395 +static int
74396 +copy_user_acl(struct gr_arg *arg)
74397 +{
74398 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
74399 + struct acl_subject_label *subj_list;
74400 + struct sprole_pw *sptmp;
74401 + struct gr_hash_struct *ghash;
74402 + uid_t *domainlist;
74403 + unsigned int r_num;
74404 + int err = 0;
74405 + __u16 i;
74406 + __u32 num_subjs;
74407 +
74408 + /* we need a default and kernel role */
74409 + if (arg->role_db.num_roles < 2)
74410 + return -EINVAL;
74411 +
74412 + /* copy special role authentication info from userspace */
74413 +
74414 + polstate->num_sprole_pws = arg->num_sprole_pws;
74415 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
74416 +
74417 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
74418 + return -ENOMEM;
74419 +
74420 + for (i = 0; i < polstate->num_sprole_pws; i++) {
74421 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
74422 + if (!sptmp)
74423 + return -ENOMEM;
74424 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
74425 + return -EFAULT;
74426 +
74427 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
74428 + if (err)
74429 + return err;
74430 +
74431 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
74432 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
74433 +#endif
74434 +
74435 + polstate->acl_special_roles[i] = sptmp;
74436 + }
74437 +
74438 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
74439 +
74440 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
74441 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
74442 +
74443 + if (!r_tmp)
74444 + return -ENOMEM;
74445 +
74446 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
74447 + return -EFAULT;
74448 +
74449 + if (copy_acl_role_label(r_tmp, r_utmp2))
74450 + return -EFAULT;
74451 +
74452 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
74453 + if (err)
74454 + return err;
74455 +
74456 + if (!strcmp(r_tmp->rolename, "default")
74457 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
74458 + polstate->default_role = r_tmp;
74459 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
74460 + polstate->kernel_role = r_tmp;
74461 + }
74462 +
74463 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
74464 + return -ENOMEM;
74465 +
74466 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
74467 + return -EFAULT;
74468 +
74469 + r_tmp->hash = ghash;
74470 +
74471 + num_subjs = count_user_subjs(r_tmp->hash->first);
74472 +
74473 + r_tmp->subj_hash_size = num_subjs;
74474 + r_tmp->subj_hash =
74475 + (struct acl_subject_label **)
74476 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
74477 +
74478 + if (!r_tmp->subj_hash)
74479 + return -ENOMEM;
74480 +
74481 + err = copy_user_allowedips(r_tmp);
74482 + if (err)
74483 + return err;
74484 +
74485 + /* copy domain info */
74486 + if (r_tmp->domain_children != NULL) {
74487 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
74488 + if (domainlist == NULL)
74489 + return -ENOMEM;
74490 +
74491 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
74492 + return -EFAULT;
74493 +
74494 + r_tmp->domain_children = domainlist;
74495 + }
74496 +
74497 + err = copy_user_transitions(r_tmp);
74498 + if (err)
74499 + return err;
74500 +
74501 + memset(r_tmp->subj_hash, 0,
74502 + r_tmp->subj_hash_size *
74503 + sizeof (struct acl_subject_label *));
74504 +
74505 + /* acquire the list of subjects, then NULL out
74506 + the list prior to parsing the subjects for this role,
74507 + as during this parsing the list is replaced with a list
74508 + of *nested* subjects for the role
74509 + */
74510 + subj_list = r_tmp->hash->first;
74511 +
74512 + /* set nested subject list to null */
74513 + r_tmp->hash->first = NULL;
74514 +
74515 + err = copy_user_subjs(subj_list, r_tmp);
74516 +
74517 + if (err)
74518 + return err;
74519 +
74520 + insert_acl_role_label(r_tmp);
74521 + }
74522 +
74523 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
74524 + return -EINVAL;
74525 +
74526 + return err;
74527 +}
74528 +
74529 +static int gracl_reload_apply_policies(void *reload)
74530 +{
74531 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
74532 + struct task_struct *task, *task2;
74533 + struct acl_role_label *role, *rtmp;
74534 + struct acl_subject_label *subj;
74535 + const struct cred *cred;
74536 + int role_applied;
74537 + int ret = 0;
74538 +
74539 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
74540 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
74541 +
74542 + /* first make sure we'll be able to apply the new policy cleanly */
74543 + do_each_thread(task2, task) {
74544 + if (task->exec_file == NULL)
74545 + continue;
74546 + role_applied = 0;
74547 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
74548 + /* preserve special roles */
74549 + FOR_EACH_ROLE_START(role)
74550 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
74551 + rtmp = task->role;
74552 + task->role = role;
74553 + role_applied = 1;
74554 + break;
74555 + }
74556 + FOR_EACH_ROLE_END(role)
74557 + }
74558 + if (!role_applied) {
74559 + cred = __task_cred(task);
74560 + rtmp = task->role;
74561 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
74562 + }
74563 + /* this handles non-nested inherited subjects, nested subjects will still
74564 + be dropped currently */
74565 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
74566 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
74567 + /* change the role back so that we've made no modifications to the policy */
74568 + task->role = rtmp;
74569 +
74570 + if (subj == NULL || task->tmpacl == NULL) {
74571 + ret = -EINVAL;
74572 + goto out;
74573 + }
74574 + } while_each_thread(task2, task);
74575 +
74576 + /* now actually apply the policy */
74577 +
74578 + do_each_thread(task2, task) {
74579 + if (task->exec_file) {
74580 + role_applied = 0;
74581 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
74582 + /* preserve special roles */
74583 + FOR_EACH_ROLE_START(role)
74584 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
74585 + task->role = role;
74586 + role_applied = 1;
74587 + break;
74588 + }
74589 + FOR_EACH_ROLE_END(role)
74590 + }
74591 + if (!role_applied) {
74592 + cred = __task_cred(task);
74593 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
74594 + }
74595 + /* this handles non-nested inherited subjects, nested subjects will still
74596 + be dropped currently */
74597 + if (!reload_state->oldmode && task->inherited)
74598 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
74599 + else {
74600 + /* looked up and tagged to the task previously */
74601 + subj = task->tmpacl;
74602 + }
74603 + /* subj will be non-null */
74604 + __gr_apply_subject_to_task(polstate, task, subj);
74605 + if (reload_state->oldmode) {
74606 + task->acl_role_id = 0;
74607 + task->acl_sp_role = 0;
74608 + task->inherited = 0;
74609 + }
74610 + } else {
74611 + // it's a kernel process
74612 + task->role = polstate->kernel_role;
74613 + task->acl = polstate->kernel_role->root_label;
74614 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
74615 + task->acl->mode &= ~GR_PROCFIND;
74616 +#endif
74617 + }
74618 + } while_each_thread(task2, task);
74619 +
74620 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
74621 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
74622 +
74623 +out:
74624 +
74625 + return ret;
74626 +}
74627 +
74628 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
74629 +{
74630 + struct gr_reload_state new_reload_state = { };
74631 + int err;
74632 +
74633 + new_reload_state.oldpolicy_ptr = polstate;
74634 + new_reload_state.oldalloc_ptr = current_alloc_state;
74635 + new_reload_state.oldmode = oldmode;
74636 +
74637 + current_alloc_state = &new_reload_state.newalloc;
74638 + polstate = &new_reload_state.newpolicy;
74639 +
74640 + /* everything relevant is now saved off, copy in the new policy */
74641 + if (init_variables(args, true)) {
74642 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
74643 + err = -ENOMEM;
74644 + goto error;
74645 + }
74646 +
74647 + err = copy_user_acl(args);
74648 + free_init_variables();
74649 + if (err)
74650 + goto error;
74651 + /* the new policy is copied in, with the old policy available via saved_state
74652 + first go through applying roles, making sure to preserve special roles
74653 + then apply new subjects, making sure to preserve inherited and nested subjects,
74654 + though currently only inherited subjects will be preserved
74655 + */
74656 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
74657 + if (err)
74658 + goto error;
74659 +
74660 + /* we've now applied the new policy, so restore the old policy state to free it */
74661 + polstate = &new_reload_state.oldpolicy;
74662 + current_alloc_state = &new_reload_state.oldalloc;
74663 + free_variables(true);
74664 +
74665 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
74666 + to running_polstate/current_alloc_state inside stop_machine
74667 + */
74668 + err = 0;
74669 + goto out;
74670 +error:
74671 + /* on error of loading the new policy, we'll just keep the previous
74672 + policy set around
74673 + */
74674 + free_variables(true);
74675 +
74676 + /* doesn't affect runtime, but maintains consistent state */
74677 +out:
74678 + polstate = new_reload_state.oldpolicy_ptr;
74679 + current_alloc_state = new_reload_state.oldalloc_ptr;
74680 +
74681 + return err;
74682 +}
74683 +
74684 +static int
74685 +gracl_init(struct gr_arg *args)
74686 +{
74687 + int error = 0;
74688 +
74689 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
74690 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
74691 +
74692 + if (init_variables(args, false)) {
74693 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
74694 + error = -ENOMEM;
74695 + goto out;
74696 + }
74697 +
74698 + error = copy_user_acl(args);
74699 + free_init_variables();
74700 + if (error)
74701 + goto out;
74702 +
74703 + error = gr_set_acls(0);
74704 + if (error)
74705 + goto out;
74706 +
74707 + gr_enable_rbac_system();
74708 +
74709 + return 0;
74710 +
74711 +out:
74712 + free_variables(false);
74713 + return error;
74714 +}
74715 +
74716 +static int
74717 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
74718 + unsigned char **sum)
74719 +{
74720 + struct acl_role_label *r;
74721 + struct role_allowed_ip *ipp;
74722 + struct role_transition *trans;
74723 + unsigned int i;
74724 + int found = 0;
74725 + u32 curr_ip = current->signal->curr_ip;
74726 +
74727 + current->signal->saved_ip = curr_ip;
74728 +
74729 + /* check transition table */
74730 +
74731 + for (trans = current->role->transitions; trans; trans = trans->next) {
74732 + if (!strcmp(rolename, trans->rolename)) {
74733 + found = 1;
74734 + break;
74735 + }
74736 + }
74737 +
74738 + if (!found)
74739 + return 0;
74740 +
74741 + /* handle special roles that do not require authentication
74742 + and check ip */
74743 +
74744 + FOR_EACH_ROLE_START(r)
74745 + if (!strcmp(rolename, r->rolename) &&
74746 + (r->roletype & GR_ROLE_SPECIAL)) {
74747 + found = 0;
74748 + if (r->allowed_ips != NULL) {
74749 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
74750 + if ((ntohl(curr_ip) & ipp->netmask) ==
74751 + (ntohl(ipp->addr) & ipp->netmask))
74752 + found = 1;
74753 + }
74754 + } else
74755 + found = 2;
74756 + if (!found)
74757 + return 0;
74758 +
74759 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
74760 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
74761 + *salt = NULL;
74762 + *sum = NULL;
74763 + return 1;
74764 + }
74765 + }
74766 + FOR_EACH_ROLE_END(r)
74767 +
74768 + for (i = 0; i < polstate->num_sprole_pws; i++) {
74769 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
74770 + *salt = polstate->acl_special_roles[i]->salt;
74771 + *sum = polstate->acl_special_roles[i]->sum;
74772 + return 1;
74773 + }
74774 + }
74775 +
74776 + return 0;
74777 +}
74778 +
74779 +int gr_check_secure_terminal(struct task_struct *task)
74780 +{
74781 + struct task_struct *p, *p2, *p3;
74782 + struct files_struct *files;
74783 + struct fdtable *fdt;
74784 + struct file *our_file = NULL, *file;
74785 + int i;
74786 +
74787 + if (task->signal->tty == NULL)
74788 + return 1;
74789 +
74790 + files = get_files_struct(task);
74791 + if (files != NULL) {
74792 + rcu_read_lock();
74793 + fdt = files_fdtable(files);
74794 + for (i=0; i < fdt->max_fds; i++) {
74795 + file = fcheck_files(files, i);
74796 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
74797 + get_file(file);
74798 + our_file = file;
74799 + }
74800 + }
74801 + rcu_read_unlock();
74802 + put_files_struct(files);
74803 + }
74804 +
74805 + if (our_file == NULL)
74806 + return 1;
74807 +
74808 + read_lock(&tasklist_lock);
74809 + do_each_thread(p2, p) {
74810 + files = get_files_struct(p);
74811 + if (files == NULL ||
74812 + (p->signal && p->signal->tty == task->signal->tty)) {
74813 + if (files != NULL)
74814 + put_files_struct(files);
74815 + continue;
74816 + }
74817 + rcu_read_lock();
74818 + fdt = files_fdtable(files);
74819 + for (i=0; i < fdt->max_fds; i++) {
74820 + file = fcheck_files(files, i);
74821 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
74822 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
74823 + p3 = task;
74824 + while (task_pid_nr(p3) > 0) {
74825 + if (p3 == p)
74826 + break;
74827 + p3 = p3->real_parent;
74828 + }
74829 + if (p3 == p)
74830 + break;
74831 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
74832 + gr_handle_alertkill(p);
74833 + rcu_read_unlock();
74834 + put_files_struct(files);
74835 + read_unlock(&tasklist_lock);
74836 + fput(our_file);
74837 + return 0;
74838 + }
74839 + }
74840 + rcu_read_unlock();
74841 + put_files_struct(files);
74842 + } while_each_thread(p2, p);
74843 + read_unlock(&tasklist_lock);
74844 +
74845 + fput(our_file);
74846 + return 1;
74847 +}
74848 +
74849 +ssize_t
74850 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
74851 +{
74852 + struct gr_arg_wrapper uwrap;
74853 + unsigned char *sprole_salt = NULL;
74854 + unsigned char *sprole_sum = NULL;
74855 + int error = 0;
74856 + int error2 = 0;
74857 + size_t req_count = 0;
74858 + unsigned char oldmode = 0;
74859 +
74860 + mutex_lock(&gr_dev_mutex);
74861 +
74862 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
74863 + error = -EPERM;
74864 + goto out;
74865 + }
74866 +
74867 +#ifdef CONFIG_COMPAT
74868 + pax_open_kernel();
74869 + if (is_compat_task()) {
74870 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
74871 + copy_gr_arg = &copy_gr_arg_compat;
74872 + copy_acl_object_label = &copy_acl_object_label_compat;
74873 + copy_acl_subject_label = &copy_acl_subject_label_compat;
74874 + copy_acl_role_label = &copy_acl_role_label_compat;
74875 + copy_acl_ip_label = &copy_acl_ip_label_compat;
74876 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
74877 + copy_role_transition = &copy_role_transition_compat;
74878 + copy_sprole_pw = &copy_sprole_pw_compat;
74879 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
74880 + copy_pointer_from_array = &copy_pointer_from_array_compat;
74881 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
74882 + } else {
74883 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
74884 + copy_gr_arg = &copy_gr_arg_normal;
74885 + copy_acl_object_label = &copy_acl_object_label_normal;
74886 + copy_acl_subject_label = &copy_acl_subject_label_normal;
74887 + copy_acl_role_label = &copy_acl_role_label_normal;
74888 + copy_acl_ip_label = &copy_acl_ip_label_normal;
74889 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
74890 + copy_role_transition = &copy_role_transition_normal;
74891 + copy_sprole_pw = &copy_sprole_pw_normal;
74892 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
74893 + copy_pointer_from_array = &copy_pointer_from_array_normal;
74894 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
74895 + }
74896 + pax_close_kernel();
74897 +#endif
74898 +
74899 + req_count = get_gr_arg_wrapper_size();
74900 +
74901 + if (count != req_count) {
74902 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
74903 + error = -EINVAL;
74904 + goto out;
74905 + }
74906 +
74907 +
74908 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
74909 + gr_auth_expires = 0;
74910 + gr_auth_attempts = 0;
74911 + }
74912 +
74913 + error = copy_gr_arg_wrapper(buf, &uwrap);
74914 + if (error)
74915 + goto out;
74916 +
74917 + error = copy_gr_arg(uwrap.arg, gr_usermode);
74918 + if (error)
74919 + goto out;
74920 +
74921 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
74922 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
74923 + time_after(gr_auth_expires, get_seconds())) {
74924 + error = -EBUSY;
74925 + goto out;
74926 + }
74927 +
74928 + /* if non-root trying to do anything other than use a special role,
74929 + do not attempt authentication, do not count towards authentication
74930 + locking
74931 + */
74932 +
74933 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
74934 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
74935 + gr_is_global_nonroot(current_uid())) {
74936 + error = -EPERM;
74937 + goto out;
74938 + }
74939 +
74940 + /* ensure pw and special role name are null terminated */
74941 +
74942 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
74943 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
74944 +
74945 + /* Okay.
74946 + * We have our enough of the argument structure..(we have yet
74947 + * to copy_from_user the tables themselves) . Copy the tables
74948 + * only if we need them, i.e. for loading operations. */
74949 +
74950 + switch (gr_usermode->mode) {
74951 + case GR_STATUS:
74952 + if (gr_acl_is_enabled()) {
74953 + error = 1;
74954 + if (!gr_check_secure_terminal(current))
74955 + error = 3;
74956 + } else
74957 + error = 2;
74958 + goto out;
74959 + case GR_SHUTDOWN:
74960 + if (gr_acl_is_enabled() && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
74961 + stop_machine(gr_rbac_disable, NULL, NULL);
74962 + free_variables(false);
74963 + memset(gr_usermode, 0, sizeof(struct gr_arg));
74964 + memset(gr_system_salt, 0, GR_SALT_LEN);
74965 + memset(gr_system_sum, 0, GR_SHA_LEN);
74966 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
74967 + } else if (gr_acl_is_enabled()) {
74968 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
74969 + error = -EPERM;
74970 + } else {
74971 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
74972 + error = -EAGAIN;
74973 + }
74974 + break;
74975 + case GR_ENABLE:
74976 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(gr_usermode)))
74977 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
74978 + else {
74979 + if (gr_acl_is_enabled())
74980 + error = -EAGAIN;
74981 + else
74982 + error = error2;
74983 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
74984 + }
74985 + break;
74986 + case GR_OLDRELOAD:
74987 + oldmode = 1;
74988 + case GR_RELOAD:
74989 + if (!gr_acl_is_enabled()) {
74990 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
74991 + error = -EAGAIN;
74992 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
74993 + error2 = gracl_reload(gr_usermode, oldmode);
74994 + if (!error2)
74995 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
74996 + else {
74997 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
74998 + error = error2;
74999 + }
75000 + } else {
75001 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75002 + error = -EPERM;
75003 + }
75004 + break;
75005 + case GR_SEGVMOD:
75006 + if (unlikely(!gr_acl_is_enabled())) {
75007 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
75008 + error = -EAGAIN;
75009 + break;
75010 + }
75011 +
75012 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75013 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
75014 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
75015 + struct acl_subject_label *segvacl;
75016 + segvacl =
75017 + lookup_acl_subj_label(gr_usermode->segv_inode,
75018 + gr_usermode->segv_device,
75019 + current->role);
75020 + if (segvacl) {
75021 + segvacl->crashes = 0;
75022 + segvacl->expires = 0;
75023 + }
75024 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
75025 + gr_remove_uid(gr_usermode->segv_uid);
75026 + }
75027 + } else {
75028 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
75029 + error = -EPERM;
75030 + }
75031 + break;
75032 + case GR_SPROLE:
75033 + case GR_SPROLEPAM:
75034 + if (unlikely(!gr_acl_is_enabled())) {
75035 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
75036 + error = -EAGAIN;
75037 + break;
75038 + }
75039 +
75040 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
75041 + current->role->expires = 0;
75042 + current->role->auth_attempts = 0;
75043 + }
75044 +
75045 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75046 + time_after(current->role->expires, get_seconds())) {
75047 + error = -EBUSY;
75048 + goto out;
75049 + }
75050 +
75051 + if (lookup_special_role_auth
75052 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
75053 + && ((!sprole_salt && !sprole_sum)
75054 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
75055 + char *p = "";
75056 + assign_special_role(gr_usermode->sp_role);
75057 + read_lock(&tasklist_lock);
75058 + if (current->real_parent)
75059 + p = current->real_parent->role->rolename;
75060 + read_unlock(&tasklist_lock);
75061 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
75062 + p, acl_sp_role_value);
75063 + } else {
75064 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
75065 + error = -EPERM;
75066 + if(!(current->role->auth_attempts++))
75067 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75068 +
75069 + goto out;
75070 + }
75071 + break;
75072 + case GR_UNSPROLE:
75073 + if (unlikely(!gr_acl_is_enabled())) {
75074 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
75075 + error = -EAGAIN;
75076 + break;
75077 + }
75078 +
75079 + if (current->role->roletype & GR_ROLE_SPECIAL) {
75080 + char *p = "";
75081 + int i = 0;
75082 +
75083 + read_lock(&tasklist_lock);
75084 + if (current->real_parent) {
75085 + p = current->real_parent->role->rolename;
75086 + i = current->real_parent->acl_role_id;
75087 + }
75088 + read_unlock(&tasklist_lock);
75089 +
75090 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
75091 + gr_set_acls(1);
75092 + } else {
75093 + error = -EPERM;
75094 + goto out;
75095 + }
75096 + break;
75097 + default:
75098 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
75099 + error = -EINVAL;
75100 + break;
75101 + }
75102 +
75103 + if (error != -EPERM)
75104 + goto out;
75105 +
75106 + if(!(gr_auth_attempts++))
75107 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75108 +
75109 + out:
75110 + mutex_unlock(&gr_dev_mutex);
75111 +
75112 + if (!error)
75113 + error = req_count;
75114 +
75115 + return error;
75116 +}
75117 +
75118 +int
75119 +gr_set_acls(const int type)
75120 +{
75121 + struct task_struct *task, *task2;
75122 + struct acl_role_label *role = current->role;
75123 + struct acl_subject_label *subj;
75124 + __u16 acl_role_id = current->acl_role_id;
75125 + const struct cred *cred;
75126 + int ret;
75127 +
75128 + rcu_read_lock();
75129 + read_lock(&tasklist_lock);
75130 + read_lock(&grsec_exec_file_lock);
75131 + do_each_thread(task2, task) {
75132 + /* check to see if we're called from the exit handler,
75133 + if so, only replace ACLs that have inherited the admin
75134 + ACL */
75135 +
75136 + if (type && (task->role != role ||
75137 + task->acl_role_id != acl_role_id))
75138 + continue;
75139 +
75140 + task->acl_role_id = 0;
75141 + task->acl_sp_role = 0;
75142 + task->inherited = 0;
75143 +
75144 + if (task->exec_file) {
75145 + cred = __task_cred(task);
75146 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75147 + subj = __gr_get_subject_for_task(polstate, task, NULL);
75148 + if (subj == NULL) {
75149 + ret = -EINVAL;
75150 + read_unlock(&grsec_exec_file_lock);
75151 + read_unlock(&tasklist_lock);
75152 + rcu_read_unlock();
75153 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
75154 + return ret;
75155 + }
75156 + __gr_apply_subject_to_task(polstate, task, subj);
75157 + } else {
75158 + // it's a kernel process
75159 + task->role = polstate->kernel_role;
75160 + task->acl = polstate->kernel_role->root_label;
75161 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
75162 + task->acl->mode &= ~GR_PROCFIND;
75163 +#endif
75164 + }
75165 + } while_each_thread(task2, task);
75166 + read_unlock(&grsec_exec_file_lock);
75167 + read_unlock(&tasklist_lock);
75168 + rcu_read_unlock();
75169 +
75170 + return 0;
75171 +}
75172 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
75173 new file mode 100644
75174 index 0000000..39645c9
75175 --- /dev/null
75176 +++ b/grsecurity/gracl_res.c
75177 @@ -0,0 +1,68 @@
75178 +#include <linux/kernel.h>
75179 +#include <linux/sched.h>
75180 +#include <linux/gracl.h>
75181 +#include <linux/grinternal.h>
75182 +
75183 +static const char *restab_log[] = {
75184 + [RLIMIT_CPU] = "RLIMIT_CPU",
75185 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
75186 + [RLIMIT_DATA] = "RLIMIT_DATA",
75187 + [RLIMIT_STACK] = "RLIMIT_STACK",
75188 + [RLIMIT_CORE] = "RLIMIT_CORE",
75189 + [RLIMIT_RSS] = "RLIMIT_RSS",
75190 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
75191 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
75192 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
75193 + [RLIMIT_AS] = "RLIMIT_AS",
75194 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
75195 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
75196 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
75197 + [RLIMIT_NICE] = "RLIMIT_NICE",
75198 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
75199 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
75200 + [GR_CRASH_RES] = "RLIMIT_CRASH"
75201 +};
75202 +
75203 +void
75204 +gr_log_resource(const struct task_struct *task,
75205 + const int res, const unsigned long wanted, const int gt)
75206 +{
75207 + const struct cred *cred;
75208 + unsigned long rlim;
75209 +
75210 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
75211 + return;
75212 +
75213 + // not yet supported resource
75214 + if (unlikely(!restab_log[res]))
75215 + return;
75216 +
75217 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
75218 + rlim = task_rlimit_max(task, res);
75219 + else
75220 + rlim = task_rlimit(task, res);
75221 +
75222 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
75223 + return;
75224 +
75225 + rcu_read_lock();
75226 + cred = __task_cred(task);
75227 +
75228 + if (res == RLIMIT_NPROC &&
75229 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
75230 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
75231 + goto out_rcu_unlock;
75232 + else if (res == RLIMIT_MEMLOCK &&
75233 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
75234 + goto out_rcu_unlock;
75235 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
75236 + goto out_rcu_unlock;
75237 + rcu_read_unlock();
75238 +
75239 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
75240 +
75241 + return;
75242 +out_rcu_unlock:
75243 + rcu_read_unlock();
75244 + return;
75245 +}
75246 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
75247 new file mode 100644
75248 index 0000000..2040e61
75249 --- /dev/null
75250 +++ b/grsecurity/gracl_segv.c
75251 @@ -0,0 +1,313 @@
75252 +#include <linux/kernel.h>
75253 +#include <linux/mm.h>
75254 +#include <asm/uaccess.h>
75255 +#include <asm/errno.h>
75256 +#include <asm/mman.h>
75257 +#include <net/sock.h>
75258 +#include <linux/file.h>
75259 +#include <linux/fs.h>
75260 +#include <linux/net.h>
75261 +#include <linux/in.h>
75262 +#include <linux/slab.h>
75263 +#include <linux/types.h>
75264 +#include <linux/sched.h>
75265 +#include <linux/timer.h>
75266 +#include <linux/gracl.h>
75267 +#include <linux/grsecurity.h>
75268 +#include <linux/grinternal.h>
75269 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
75270 +#include <linux/magic.h>
75271 +#include <linux/pagemap.h>
75272 +#include "../fs/btrfs/async-thread.h"
75273 +#include "../fs/btrfs/ctree.h"
75274 +#include "../fs/btrfs/btrfs_inode.h"
75275 +#endif
75276 +
75277 +static struct crash_uid *uid_set;
75278 +static unsigned short uid_used;
75279 +static DEFINE_SPINLOCK(gr_uid_lock);
75280 +extern rwlock_t gr_inode_lock;
75281 +extern struct acl_subject_label *
75282 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
75283 + struct acl_role_label *role);
75284 +
75285 +static inline dev_t __get_dev(const struct dentry *dentry)
75286 +{
75287 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
75288 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
75289 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
75290 + else
75291 +#endif
75292 + return dentry->d_sb->s_dev;
75293 +}
75294 +
75295 +int
75296 +gr_init_uidset(void)
75297 +{
75298 + uid_set =
75299 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
75300 + uid_used = 0;
75301 +
75302 + return uid_set ? 1 : 0;
75303 +}
75304 +
75305 +void
75306 +gr_free_uidset(void)
75307 +{
75308 + if (uid_set) {
75309 + struct crash_uid *tmpset;
75310 + spin_lock(&gr_uid_lock);
75311 + tmpset = uid_set;
75312 + uid_set = NULL;
75313 + uid_used = 0;
75314 + spin_unlock(&gr_uid_lock);
75315 + if (tmpset)
75316 + kfree(tmpset);
75317 + }
75318 +
75319 + return;
75320 +}
75321 +
75322 +int
75323 +gr_find_uid(const uid_t uid)
75324 +{
75325 + struct crash_uid *tmp = uid_set;
75326 + uid_t buid;
75327 + int low = 0, high = uid_used - 1, mid;
75328 +
75329 + while (high >= low) {
75330 + mid = (low + high) >> 1;
75331 + buid = tmp[mid].uid;
75332 + if (buid == uid)
75333 + return mid;
75334 + if (buid > uid)
75335 + high = mid - 1;
75336 + if (buid < uid)
75337 + low = mid + 1;
75338 + }
75339 +
75340 + return -1;
75341 +}
75342 +
75343 +static __inline__ void
75344 +gr_insertsort(void)
75345 +{
75346 + unsigned short i, j;
75347 + struct crash_uid index;
75348 +
75349 + for (i = 1; i < uid_used; i++) {
75350 + index = uid_set[i];
75351 + j = i;
75352 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
75353 + uid_set[j] = uid_set[j - 1];
75354 + j--;
75355 + }
75356 + uid_set[j] = index;
75357 + }
75358 +
75359 + return;
75360 +}
75361 +
75362 +static __inline__ void
75363 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
75364 +{
75365 + int loc;
75366 + uid_t uid = GR_GLOBAL_UID(kuid);
75367 +
75368 + if (uid_used == GR_UIDTABLE_MAX)
75369 + return;
75370 +
75371 + loc = gr_find_uid(uid);
75372 +
75373 + if (loc >= 0) {
75374 + uid_set[loc].expires = expires;
75375 + return;
75376 + }
75377 +
75378 + uid_set[uid_used].uid = uid;
75379 + uid_set[uid_used].expires = expires;
75380 + uid_used++;
75381 +
75382 + gr_insertsort();
75383 +
75384 + return;
75385 +}
75386 +
75387 +void
75388 +gr_remove_uid(const unsigned short loc)
75389 +{
75390 + unsigned short i;
75391 +
75392 + for (i = loc + 1; i < uid_used; i++)
75393 + uid_set[i - 1] = uid_set[i];
75394 +
75395 + uid_used--;
75396 +
75397 + return;
75398 +}
75399 +
75400 +int
75401 +gr_check_crash_uid(const kuid_t kuid)
75402 +{
75403 + int loc;
75404 + int ret = 0;
75405 + uid_t uid;
75406 +
75407 + if (unlikely(!gr_acl_is_enabled()))
75408 + return 0;
75409 +
75410 + uid = GR_GLOBAL_UID(kuid);
75411 +
75412 + spin_lock(&gr_uid_lock);
75413 + loc = gr_find_uid(uid);
75414 +
75415 + if (loc < 0)
75416 + goto out_unlock;
75417 +
75418 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
75419 + gr_remove_uid(loc);
75420 + else
75421 + ret = 1;
75422 +
75423 +out_unlock:
75424 + spin_unlock(&gr_uid_lock);
75425 + return ret;
75426 +}
75427 +
75428 +static __inline__ int
75429 +proc_is_setxid(const struct cred *cred)
75430 +{
75431 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
75432 + !uid_eq(cred->uid, cred->fsuid))
75433 + return 1;
75434 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
75435 + !gid_eq(cred->gid, cred->fsgid))
75436 + return 1;
75437 +
75438 + return 0;
75439 +}
75440 +
75441 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
75442 +
75443 +void
75444 +gr_handle_crash(struct task_struct *task, const int sig)
75445 +{
75446 + struct acl_subject_label *curr;
75447 + struct task_struct *tsk, *tsk2;
75448 + const struct cred *cred;
75449 + const struct cred *cred2;
75450 +
75451 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
75452 + return;
75453 +
75454 + if (unlikely(!gr_acl_is_enabled()))
75455 + return;
75456 +
75457 + curr = task->acl;
75458 +
75459 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
75460 + return;
75461 +
75462 + if (time_before_eq(curr->expires, get_seconds())) {
75463 + curr->expires = 0;
75464 + curr->crashes = 0;
75465 + }
75466 +
75467 + curr->crashes++;
75468 +
75469 + if (!curr->expires)
75470 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
75471 +
75472 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
75473 + time_after(curr->expires, get_seconds())) {
75474 + rcu_read_lock();
75475 + cred = __task_cred(task);
75476 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
75477 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
75478 + spin_lock(&gr_uid_lock);
75479 + gr_insert_uid(cred->uid, curr->expires);
75480 + spin_unlock(&gr_uid_lock);
75481 + curr->expires = 0;
75482 + curr->crashes = 0;
75483 + read_lock(&tasklist_lock);
75484 + do_each_thread(tsk2, tsk) {
75485 + cred2 = __task_cred(tsk);
75486 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
75487 + gr_fake_force_sig(SIGKILL, tsk);
75488 + } while_each_thread(tsk2, tsk);
75489 + read_unlock(&tasklist_lock);
75490 + } else {
75491 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
75492 + read_lock(&tasklist_lock);
75493 + read_lock(&grsec_exec_file_lock);
75494 + do_each_thread(tsk2, tsk) {
75495 + if (likely(tsk != task)) {
75496 + // if this thread has the same subject as the one that triggered
75497 + // RES_CRASH and it's the same binary, kill it
75498 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
75499 + gr_fake_force_sig(SIGKILL, tsk);
75500 + }
75501 + } while_each_thread(tsk2, tsk);
75502 + read_unlock(&grsec_exec_file_lock);
75503 + read_unlock(&tasklist_lock);
75504 + }
75505 + rcu_read_unlock();
75506 + }
75507 +
75508 + return;
75509 +}
75510 +
75511 +int
75512 +gr_check_crash_exec(const struct file *filp)
75513 +{
75514 + struct acl_subject_label *curr;
75515 +
75516 + if (unlikely(!gr_acl_is_enabled()))
75517 + return 0;
75518 +
75519 + read_lock(&gr_inode_lock);
75520 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
75521 + __get_dev(filp->f_path.dentry),
75522 + current->role);
75523 + read_unlock(&gr_inode_lock);
75524 +
75525 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
75526 + (!curr->crashes && !curr->expires))
75527 + return 0;
75528 +
75529 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
75530 + time_after(curr->expires, get_seconds()))
75531 + return 1;
75532 + else if (time_before_eq(curr->expires, get_seconds())) {
75533 + curr->crashes = 0;
75534 + curr->expires = 0;
75535 + }
75536 +
75537 + return 0;
75538 +}
75539 +
75540 +void
75541 +gr_handle_alertkill(struct task_struct *task)
75542 +{
75543 + struct acl_subject_label *curracl;
75544 + __u32 curr_ip;
75545 + struct task_struct *p, *p2;
75546 +
75547 + if (unlikely(!gr_acl_is_enabled()))
75548 + return;
75549 +
75550 + curracl = task->acl;
75551 + curr_ip = task->signal->curr_ip;
75552 +
75553 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
75554 + read_lock(&tasklist_lock);
75555 + do_each_thread(p2, p) {
75556 + if (p->signal->curr_ip == curr_ip)
75557 + gr_fake_force_sig(SIGKILL, p);
75558 + } while_each_thread(p2, p);
75559 + read_unlock(&tasklist_lock);
75560 + } else if (curracl->mode & GR_KILLPROC)
75561 + gr_fake_force_sig(SIGKILL, task);
75562 +
75563 + return;
75564 +}
75565 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
75566 new file mode 100644
75567 index 0000000..6b0c9cc
75568 --- /dev/null
75569 +++ b/grsecurity/gracl_shm.c
75570 @@ -0,0 +1,40 @@
75571 +#include <linux/kernel.h>
75572 +#include <linux/mm.h>
75573 +#include <linux/sched.h>
75574 +#include <linux/file.h>
75575 +#include <linux/ipc.h>
75576 +#include <linux/gracl.h>
75577 +#include <linux/grsecurity.h>
75578 +#include <linux/grinternal.h>
75579 +
75580 +int
75581 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
75582 + const u64 shm_createtime, const kuid_t cuid, const int shmid)
75583 +{
75584 + struct task_struct *task;
75585 +
75586 + if (!gr_acl_is_enabled())
75587 + return 1;
75588 +
75589 + rcu_read_lock();
75590 + read_lock(&tasklist_lock);
75591 +
75592 + task = find_task_by_vpid(shm_cprid);
75593 +
75594 + if (unlikely(!task))
75595 + task = find_task_by_vpid(shm_lapid);
75596 +
75597 + if (unlikely(task && (time_before_eq64(task->start_time, shm_createtime) ||
75598 + (task_pid_nr(task) == shm_lapid)) &&
75599 + (task->acl->mode & GR_PROTSHM) &&
75600 + (task->acl != current->acl))) {
75601 + read_unlock(&tasklist_lock);
75602 + rcu_read_unlock();
75603 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
75604 + return 0;
75605 + }
75606 + read_unlock(&tasklist_lock);
75607 + rcu_read_unlock();
75608 +
75609 + return 1;
75610 +}
75611 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
75612 new file mode 100644
75613 index 0000000..bc0be01
75614 --- /dev/null
75615 +++ b/grsecurity/grsec_chdir.c
75616 @@ -0,0 +1,19 @@
75617 +#include <linux/kernel.h>
75618 +#include <linux/sched.h>
75619 +#include <linux/fs.h>
75620 +#include <linux/file.h>
75621 +#include <linux/grsecurity.h>
75622 +#include <linux/grinternal.h>
75623 +
75624 +void
75625 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
75626 +{
75627 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
75628 + if ((grsec_enable_chdir && grsec_enable_group &&
75629 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
75630 + !grsec_enable_group)) {
75631 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
75632 + }
75633 +#endif
75634 + return;
75635 +}
75636 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
75637 new file mode 100644
75638 index 0000000..6d99cec
75639 --- /dev/null
75640 +++ b/grsecurity/grsec_chroot.c
75641 @@ -0,0 +1,385 @@
75642 +#include <linux/kernel.h>
75643 +#include <linux/module.h>
75644 +#include <linux/sched.h>
75645 +#include <linux/file.h>
75646 +#include <linux/fs.h>
75647 +#include <linux/mount.h>
75648 +#include <linux/types.h>
75649 +#include "../fs/mount.h"
75650 +#include <linux/grsecurity.h>
75651 +#include <linux/grinternal.h>
75652 +
75653 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
75654 +int gr_init_ran;
75655 +#endif
75656 +
75657 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
75658 +{
75659 +#ifdef CONFIG_GRKERNSEC
75660 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
75661 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
75662 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
75663 + && gr_init_ran
75664 +#endif
75665 + )
75666 + task->gr_is_chrooted = 1;
75667 + else {
75668 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
75669 + if (task_pid_nr(task) == 1 && !gr_init_ran)
75670 + gr_init_ran = 1;
75671 +#endif
75672 + task->gr_is_chrooted = 0;
75673 + }
75674 +
75675 + task->gr_chroot_dentry = path->dentry;
75676 +#endif
75677 + return;
75678 +}
75679 +
75680 +void gr_clear_chroot_entries(struct task_struct *task)
75681 +{
75682 +#ifdef CONFIG_GRKERNSEC
75683 + task->gr_is_chrooted = 0;
75684 + task->gr_chroot_dentry = NULL;
75685 +#endif
75686 + return;
75687 +}
75688 +
75689 +int
75690 +gr_handle_chroot_unix(const pid_t pid)
75691 +{
75692 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
75693 + struct task_struct *p;
75694 +
75695 + if (unlikely(!grsec_enable_chroot_unix))
75696 + return 1;
75697 +
75698 + if (likely(!proc_is_chrooted(current)))
75699 + return 1;
75700 +
75701 + rcu_read_lock();
75702 + read_lock(&tasklist_lock);
75703 + p = find_task_by_vpid_unrestricted(pid);
75704 + if (unlikely(p && !have_same_root(current, p))) {
75705 + read_unlock(&tasklist_lock);
75706 + rcu_read_unlock();
75707 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
75708 + return 0;
75709 + }
75710 + read_unlock(&tasklist_lock);
75711 + rcu_read_unlock();
75712 +#endif
75713 + return 1;
75714 +}
75715 +
75716 +int
75717 +gr_handle_chroot_nice(void)
75718 +{
75719 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
75720 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
75721 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
75722 + return -EPERM;
75723 + }
75724 +#endif
75725 + return 0;
75726 +}
75727 +
75728 +int
75729 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
75730 +{
75731 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
75732 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
75733 + && proc_is_chrooted(current)) {
75734 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
75735 + return -EACCES;
75736 + }
75737 +#endif
75738 + return 0;
75739 +}
75740 +
75741 +int
75742 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
75743 +{
75744 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
75745 + struct task_struct *p;
75746 + int ret = 0;
75747 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
75748 + return ret;
75749 +
75750 + read_lock(&tasklist_lock);
75751 + do_each_pid_task(pid, type, p) {
75752 + if (!have_same_root(current, p)) {
75753 + ret = 1;
75754 + goto out;
75755 + }
75756 + } while_each_pid_task(pid, type, p);
75757 +out:
75758 + read_unlock(&tasklist_lock);
75759 + return ret;
75760 +#endif
75761 + return 0;
75762 +}
75763 +
75764 +int
75765 +gr_pid_is_chrooted(struct task_struct *p)
75766 +{
75767 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
75768 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
75769 + return 0;
75770 +
75771 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
75772 + !have_same_root(current, p)) {
75773 + return 1;
75774 + }
75775 +#endif
75776 + return 0;
75777 +}
75778 +
75779 +EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
75780 +
75781 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
75782 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
75783 +{
75784 + struct path path, currentroot;
75785 + int ret = 0;
75786 +
75787 + path.dentry = (struct dentry *)u_dentry;
75788 + path.mnt = (struct vfsmount *)u_mnt;
75789 + get_fs_root(current->fs, &currentroot);
75790 + if (path_is_under(&path, &currentroot))
75791 + ret = 1;
75792 + path_put(&currentroot);
75793 +
75794 + return ret;
75795 +}
75796 +#endif
75797 +
75798 +int
75799 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
75800 +{
75801 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
75802 + if (!grsec_enable_chroot_fchdir)
75803 + return 1;
75804 +
75805 + if (!proc_is_chrooted(current))
75806 + return 1;
75807 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
75808 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
75809 + return 0;
75810 + }
75811 +#endif
75812 + return 1;
75813 +}
75814 +
75815 +int
75816 +gr_chroot_fhandle(void)
75817 +{
75818 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
75819 + if (!grsec_enable_chroot_fchdir)
75820 + return 1;
75821 +
75822 + if (!proc_is_chrooted(current))
75823 + return 1;
75824 + else {
75825 + gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
75826 + return 0;
75827 + }
75828 +#endif
75829 + return 1;
75830 +}
75831 +
75832 +int
75833 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
75834 + const u64 shm_createtime)
75835 +{
75836 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
75837 + struct task_struct *p;
75838 +
75839 + if (unlikely(!grsec_enable_chroot_shmat))
75840 + return 1;
75841 +
75842 + if (likely(!proc_is_chrooted(current)))
75843 + return 1;
75844 +
75845 + rcu_read_lock();
75846 + read_lock(&tasklist_lock);
75847 +
75848 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
75849 + if (time_before_eq64(p->start_time, shm_createtime)) {
75850 + if (have_same_root(current, p)) {
75851 + goto allow;
75852 + } else {
75853 + read_unlock(&tasklist_lock);
75854 + rcu_read_unlock();
75855 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
75856 + return 0;
75857 + }
75858 + }
75859 + /* creator exited, pid reuse, fall through to next check */
75860 + }
75861 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
75862 + if (unlikely(!have_same_root(current, p))) {
75863 + read_unlock(&tasklist_lock);
75864 + rcu_read_unlock();
75865 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
75866 + return 0;
75867 + }
75868 + }
75869 +
75870 +allow:
75871 + read_unlock(&tasklist_lock);
75872 + rcu_read_unlock();
75873 +#endif
75874 + return 1;
75875 +}
75876 +
75877 +void
75878 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
75879 +{
75880 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
75881 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
75882 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
75883 +#endif
75884 + return;
75885 +}
75886 +
75887 +int
75888 +gr_handle_chroot_mknod(const struct dentry *dentry,
75889 + const struct vfsmount *mnt, const int mode)
75890 +{
75891 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
75892 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
75893 + proc_is_chrooted(current)) {
75894 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
75895 + return -EPERM;
75896 + }
75897 +#endif
75898 + return 0;
75899 +}
75900 +
75901 +int
75902 +gr_handle_chroot_mount(const struct dentry *dentry,
75903 + const struct vfsmount *mnt, const char *dev_name)
75904 +{
75905 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
75906 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
75907 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
75908 + return -EPERM;
75909 + }
75910 +#endif
75911 + return 0;
75912 +}
75913 +
75914 +int
75915 +gr_handle_chroot_pivot(void)
75916 +{
75917 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
75918 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
75919 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
75920 + return -EPERM;
75921 + }
75922 +#endif
75923 + return 0;
75924 +}
75925 +
75926 +int
75927 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
75928 +{
75929 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
75930 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
75931 + !gr_is_outside_chroot(dentry, mnt)) {
75932 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
75933 + return -EPERM;
75934 + }
75935 +#endif
75936 + return 0;
75937 +}
75938 +
75939 +extern const char *captab_log[];
75940 +extern int captab_log_entries;
75941 +
75942 +int
75943 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
75944 +{
75945 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
75946 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
75947 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
75948 + if (cap_raised(chroot_caps, cap)) {
75949 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
75950 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
75951 + }
75952 + return 0;
75953 + }
75954 + }
75955 +#endif
75956 + return 1;
75957 +}
75958 +
75959 +int
75960 +gr_chroot_is_capable(const int cap)
75961 +{
75962 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
75963 + return gr_task_chroot_is_capable(current, current_cred(), cap);
75964 +#endif
75965 + return 1;
75966 +}
75967 +
75968 +int
75969 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
75970 +{
75971 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
75972 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
75973 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
75974 + if (cap_raised(chroot_caps, cap)) {
75975 + return 0;
75976 + }
75977 + }
75978 +#endif
75979 + return 1;
75980 +}
75981 +
75982 +int
75983 +gr_chroot_is_capable_nolog(const int cap)
75984 +{
75985 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
75986 + return gr_task_chroot_is_capable_nolog(current, cap);
75987 +#endif
75988 + return 1;
75989 +}
75990 +
75991 +int
75992 +gr_handle_chroot_sysctl(const int op)
75993 +{
75994 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
75995 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
75996 + proc_is_chrooted(current))
75997 + return -EACCES;
75998 +#endif
75999 + return 0;
76000 +}
76001 +
76002 +void
76003 +gr_handle_chroot_chdir(const struct path *path)
76004 +{
76005 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76006 + if (grsec_enable_chroot_chdir)
76007 + set_fs_pwd(current->fs, path);
76008 +#endif
76009 + return;
76010 +}
76011 +
76012 +int
76013 +gr_handle_chroot_chmod(const struct dentry *dentry,
76014 + const struct vfsmount *mnt, const int mode)
76015 +{
76016 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76017 + /* allow chmod +s on directories, but not files */
76018 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
76019 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
76020 + proc_is_chrooted(current)) {
76021 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
76022 + return -EPERM;
76023 + }
76024 +#endif
76025 + return 0;
76026 +}
76027 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
76028 new file mode 100644
76029 index 0000000..0f9ac91
76030 --- /dev/null
76031 +++ b/grsecurity/grsec_disabled.c
76032 @@ -0,0 +1,440 @@
76033 +#include <linux/kernel.h>
76034 +#include <linux/module.h>
76035 +#include <linux/sched.h>
76036 +#include <linux/file.h>
76037 +#include <linux/fs.h>
76038 +#include <linux/kdev_t.h>
76039 +#include <linux/net.h>
76040 +#include <linux/in.h>
76041 +#include <linux/ip.h>
76042 +#include <linux/skbuff.h>
76043 +#include <linux/sysctl.h>
76044 +
76045 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
76046 +void
76047 +pax_set_initial_flags(struct linux_binprm *bprm)
76048 +{
76049 + return;
76050 +}
76051 +#endif
76052 +
76053 +#ifdef CONFIG_SYSCTL
76054 +__u32
76055 +gr_handle_sysctl(const struct ctl_table * table, const int op)
76056 +{
76057 + return 0;
76058 +}
76059 +#endif
76060 +
76061 +#ifdef CONFIG_TASKSTATS
76062 +int gr_is_taskstats_denied(int pid)
76063 +{
76064 + return 0;
76065 +}
76066 +#endif
76067 +
76068 +int
76069 +gr_acl_is_enabled(void)
76070 +{
76071 + return 0;
76072 +}
76073 +
76074 +int
76075 +gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
76076 +{
76077 + return 0;
76078 +}
76079 +
76080 +void
76081 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
76082 +{
76083 + return;
76084 +}
76085 +
76086 +int
76087 +gr_handle_rawio(const struct inode *inode)
76088 +{
76089 + return 0;
76090 +}
76091 +
76092 +void
76093 +gr_acl_handle_psacct(struct task_struct *task, const long code)
76094 +{
76095 + return;
76096 +}
76097 +
76098 +int
76099 +gr_handle_ptrace(struct task_struct *task, const long request)
76100 +{
76101 + return 0;
76102 +}
76103 +
76104 +int
76105 +gr_handle_proc_ptrace(struct task_struct *task)
76106 +{
76107 + return 0;
76108 +}
76109 +
76110 +int
76111 +gr_set_acls(const int type)
76112 +{
76113 + return 0;
76114 +}
76115 +
76116 +int
76117 +gr_check_hidden_task(const struct task_struct *tsk)
76118 +{
76119 + return 0;
76120 +}
76121 +
76122 +int
76123 +gr_check_protected_task(const struct task_struct *task)
76124 +{
76125 + return 0;
76126 +}
76127 +
76128 +int
76129 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
76130 +{
76131 + return 0;
76132 +}
76133 +
76134 +void
76135 +gr_copy_label(struct task_struct *tsk)
76136 +{
76137 + return;
76138 +}
76139 +
76140 +void
76141 +gr_set_pax_flags(struct task_struct *task)
76142 +{
76143 + return;
76144 +}
76145 +
76146 +int
76147 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
76148 + const int unsafe_share)
76149 +{
76150 + return 0;
76151 +}
76152 +
76153 +void
76154 +gr_handle_delete(const ino_t ino, const dev_t dev)
76155 +{
76156 + return;
76157 +}
76158 +
76159 +void
76160 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
76161 +{
76162 + return;
76163 +}
76164 +
76165 +void
76166 +gr_handle_crash(struct task_struct *task, const int sig)
76167 +{
76168 + return;
76169 +}
76170 +
76171 +int
76172 +gr_check_crash_exec(const struct file *filp)
76173 +{
76174 + return 0;
76175 +}
76176 +
76177 +int
76178 +gr_check_crash_uid(const kuid_t uid)
76179 +{
76180 + return 0;
76181 +}
76182 +
76183 +void
76184 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
76185 + struct dentry *old_dentry,
76186 + struct dentry *new_dentry,
76187 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
76188 +{
76189 + return;
76190 +}
76191 +
76192 +int
76193 +gr_search_socket(const int family, const int type, const int protocol)
76194 +{
76195 + return 1;
76196 +}
76197 +
76198 +int
76199 +gr_search_connectbind(const int mode, const struct socket *sock,
76200 + const struct sockaddr_in *addr)
76201 +{
76202 + return 0;
76203 +}
76204 +
76205 +void
76206 +gr_handle_alertkill(struct task_struct *task)
76207 +{
76208 + return;
76209 +}
76210 +
76211 +__u32
76212 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
76213 +{
76214 + return 1;
76215 +}
76216 +
76217 +__u32
76218 +gr_acl_handle_hidden_file(const struct dentry * dentry,
76219 + const struct vfsmount * mnt)
76220 +{
76221 + return 1;
76222 +}
76223 +
76224 +__u32
76225 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
76226 + int acc_mode)
76227 +{
76228 + return 1;
76229 +}
76230 +
76231 +__u32
76232 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
76233 +{
76234 + return 1;
76235 +}
76236 +
76237 +__u32
76238 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
76239 +{
76240 + return 1;
76241 +}
76242 +
76243 +int
76244 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
76245 + unsigned int *vm_flags)
76246 +{
76247 + return 1;
76248 +}
76249 +
76250 +__u32
76251 +gr_acl_handle_truncate(const struct dentry * dentry,
76252 + const struct vfsmount * mnt)
76253 +{
76254 + return 1;
76255 +}
76256 +
76257 +__u32
76258 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
76259 +{
76260 + return 1;
76261 +}
76262 +
76263 +__u32
76264 +gr_acl_handle_access(const struct dentry * dentry,
76265 + const struct vfsmount * mnt, const int fmode)
76266 +{
76267 + return 1;
76268 +}
76269 +
76270 +__u32
76271 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
76272 + umode_t *mode)
76273 +{
76274 + return 1;
76275 +}
76276 +
76277 +__u32
76278 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
76279 +{
76280 + return 1;
76281 +}
76282 +
76283 +__u32
76284 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
76285 +{
76286 + return 1;
76287 +}
76288 +
76289 +__u32
76290 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
76291 +{
76292 + return 1;
76293 +}
76294 +
76295 +void
76296 +grsecurity_init(void)
76297 +{
76298 + return;
76299 +}
76300 +
76301 +umode_t gr_acl_umask(void)
76302 +{
76303 + return 0;
76304 +}
76305 +
76306 +__u32
76307 +gr_acl_handle_mknod(const struct dentry * new_dentry,
76308 + const struct dentry * parent_dentry,
76309 + const struct vfsmount * parent_mnt,
76310 + const int mode)
76311 +{
76312 + return 1;
76313 +}
76314 +
76315 +__u32
76316 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
76317 + const struct dentry * parent_dentry,
76318 + const struct vfsmount * parent_mnt)
76319 +{
76320 + return 1;
76321 +}
76322 +
76323 +__u32
76324 +gr_acl_handle_symlink(const struct dentry * new_dentry,
76325 + const struct dentry * parent_dentry,
76326 + const struct vfsmount * parent_mnt, const struct filename *from)
76327 +{
76328 + return 1;
76329 +}
76330 +
76331 +__u32
76332 +gr_acl_handle_link(const struct dentry * new_dentry,
76333 + const struct dentry * parent_dentry,
76334 + const struct vfsmount * parent_mnt,
76335 + const struct dentry * old_dentry,
76336 + const struct vfsmount * old_mnt, const struct filename *to)
76337 +{
76338 + return 1;
76339 +}
76340 +
76341 +int
76342 +gr_acl_handle_rename(const struct dentry *new_dentry,
76343 + const struct dentry *parent_dentry,
76344 + const struct vfsmount *parent_mnt,
76345 + const struct dentry *old_dentry,
76346 + const struct inode *old_parent_inode,
76347 + const struct vfsmount *old_mnt, const struct filename *newname,
76348 + unsigned int flags)
76349 +{
76350 + return 0;
76351 +}
76352 +
76353 +int
76354 +gr_acl_handle_filldir(const struct file *file, const char *name,
76355 + const int namelen, const ino_t ino)
76356 +{
76357 + return 1;
76358 +}
76359 +
76360 +int
76361 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76362 + const u64 shm_createtime, const kuid_t cuid, const int shmid)
76363 +{
76364 + return 1;
76365 +}
76366 +
76367 +int
76368 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
76369 +{
76370 + return 0;
76371 +}
76372 +
76373 +int
76374 +gr_search_accept(const struct socket *sock)
76375 +{
76376 + return 0;
76377 +}
76378 +
76379 +int
76380 +gr_search_listen(const struct socket *sock)
76381 +{
76382 + return 0;
76383 +}
76384 +
76385 +int
76386 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
76387 +{
76388 + return 0;
76389 +}
76390 +
76391 +__u32
76392 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
76393 +{
76394 + return 1;
76395 +}
76396 +
76397 +__u32
76398 +gr_acl_handle_creat(const struct dentry * dentry,
76399 + const struct dentry * p_dentry,
76400 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
76401 + const int imode)
76402 +{
76403 + return 1;
76404 +}
76405 +
76406 +void
76407 +gr_acl_handle_exit(void)
76408 +{
76409 + return;
76410 +}
76411 +
76412 +int
76413 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
76414 +{
76415 + return 1;
76416 +}
76417 +
76418 +void
76419 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
76420 +{
76421 + return;
76422 +}
76423 +
76424 +int
76425 +gr_acl_handle_procpidmem(const struct task_struct *task)
76426 +{
76427 + return 0;
76428 +}
76429 +
76430 +int
76431 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
76432 +{
76433 + return 0;
76434 +}
76435 +
76436 +int
76437 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
76438 +{
76439 + return 0;
76440 +}
76441 +
76442 +int
76443 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
76444 +{
76445 + return 0;
76446 +}
76447 +
76448 +int
76449 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
76450 +{
76451 + return 0;
76452 +}
76453 +
76454 +int gr_acl_enable_at_secure(void)
76455 +{
76456 + return 0;
76457 +}
76458 +
76459 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
76460 +{
76461 + return dentry->d_sb->s_dev;
76462 +}
76463 +
76464 +void gr_put_exec_file(struct task_struct *task)
76465 +{
76466 + return;
76467 +}
76468 +
76469 +#ifdef CONFIG_SECURITY
76470 +EXPORT_SYMBOL_GPL(gr_check_user_change);
76471 +EXPORT_SYMBOL_GPL(gr_check_group_change);
76472 +#endif
76473 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
76474 new file mode 100644
76475 index 0000000..14638ff
76476 --- /dev/null
76477 +++ b/grsecurity/grsec_exec.c
76478 @@ -0,0 +1,188 @@
76479 +#include <linux/kernel.h>
76480 +#include <linux/sched.h>
76481 +#include <linux/file.h>
76482 +#include <linux/binfmts.h>
76483 +#include <linux/fs.h>
76484 +#include <linux/types.h>
76485 +#include <linux/grdefs.h>
76486 +#include <linux/grsecurity.h>
76487 +#include <linux/grinternal.h>
76488 +#include <linux/capability.h>
76489 +#include <linux/module.h>
76490 +#include <linux/compat.h>
76491 +
76492 +#include <asm/uaccess.h>
76493 +
76494 +#ifdef CONFIG_GRKERNSEC_EXECLOG
76495 +static char gr_exec_arg_buf[132];
76496 +static DEFINE_MUTEX(gr_exec_arg_mutex);
76497 +#endif
76498 +
76499 +struct user_arg_ptr {
76500 +#ifdef CONFIG_COMPAT
76501 + bool is_compat;
76502 +#endif
76503 + union {
76504 + const char __user *const __user *native;
76505 +#ifdef CONFIG_COMPAT
76506 + const compat_uptr_t __user *compat;
76507 +#endif
76508 + } ptr;
76509 +};
76510 +
76511 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
76512 +
76513 +void
76514 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
76515 +{
76516 +#ifdef CONFIG_GRKERNSEC_EXECLOG
76517 + char *grarg = gr_exec_arg_buf;
76518 + unsigned int i, x, execlen = 0;
76519 + char c;
76520 +
76521 + if (!((grsec_enable_execlog && grsec_enable_group &&
76522 + in_group_p(grsec_audit_gid))
76523 + || (grsec_enable_execlog && !grsec_enable_group)))
76524 + return;
76525 +
76526 + mutex_lock(&gr_exec_arg_mutex);
76527 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
76528 +
76529 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
76530 + const char __user *p;
76531 + unsigned int len;
76532 +
76533 + p = get_user_arg_ptr(argv, i);
76534 + if (IS_ERR(p))
76535 + goto log;
76536 +
76537 + len = strnlen_user(p, 128 - execlen);
76538 + if (len > 128 - execlen)
76539 + len = 128 - execlen;
76540 + else if (len > 0)
76541 + len--;
76542 + if (copy_from_user(grarg + execlen, p, len))
76543 + goto log;
76544 +
76545 + /* rewrite unprintable characters */
76546 + for (x = 0; x < len; x++) {
76547 + c = *(grarg + execlen + x);
76548 + if (c < 32 || c > 126)
76549 + *(grarg + execlen + x) = ' ';
76550 + }
76551 +
76552 + execlen += len;
76553 + *(grarg + execlen) = ' ';
76554 + *(grarg + execlen + 1) = '\0';
76555 + execlen++;
76556 + }
76557 +
76558 + log:
76559 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
76560 + bprm->file->f_path.mnt, grarg);
76561 + mutex_unlock(&gr_exec_arg_mutex);
76562 +#endif
76563 + return;
76564 +}
76565 +
76566 +#ifdef CONFIG_GRKERNSEC
76567 +extern int gr_acl_is_capable(const int cap);
76568 +extern int gr_acl_is_capable_nolog(const int cap);
76569 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
76570 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
76571 +extern int gr_chroot_is_capable(const int cap);
76572 +extern int gr_chroot_is_capable_nolog(const int cap);
76573 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
76574 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
76575 +#endif
76576 +
76577 +const char *captab_log[] = {
76578 + "CAP_CHOWN",
76579 + "CAP_DAC_OVERRIDE",
76580 + "CAP_DAC_READ_SEARCH",
76581 + "CAP_FOWNER",
76582 + "CAP_FSETID",
76583 + "CAP_KILL",
76584 + "CAP_SETGID",
76585 + "CAP_SETUID",
76586 + "CAP_SETPCAP",
76587 + "CAP_LINUX_IMMUTABLE",
76588 + "CAP_NET_BIND_SERVICE",
76589 + "CAP_NET_BROADCAST",
76590 + "CAP_NET_ADMIN",
76591 + "CAP_NET_RAW",
76592 + "CAP_IPC_LOCK",
76593 + "CAP_IPC_OWNER",
76594 + "CAP_SYS_MODULE",
76595 + "CAP_SYS_RAWIO",
76596 + "CAP_SYS_CHROOT",
76597 + "CAP_SYS_PTRACE",
76598 + "CAP_SYS_PACCT",
76599 + "CAP_SYS_ADMIN",
76600 + "CAP_SYS_BOOT",
76601 + "CAP_SYS_NICE",
76602 + "CAP_SYS_RESOURCE",
76603 + "CAP_SYS_TIME",
76604 + "CAP_SYS_TTY_CONFIG",
76605 + "CAP_MKNOD",
76606 + "CAP_LEASE",
76607 + "CAP_AUDIT_WRITE",
76608 + "CAP_AUDIT_CONTROL",
76609 + "CAP_SETFCAP",
76610 + "CAP_MAC_OVERRIDE",
76611 + "CAP_MAC_ADMIN",
76612 + "CAP_SYSLOG",
76613 + "CAP_WAKE_ALARM",
76614 + "CAP_BLOCK_SUSPEND"
76615 +};
76616 +
76617 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
76618 +
76619 +int gr_is_capable(const int cap)
76620 +{
76621 +#ifdef CONFIG_GRKERNSEC
76622 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
76623 + return 1;
76624 + return 0;
76625 +#else
76626 + return 1;
76627 +#endif
76628 +}
76629 +
76630 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
76631 +{
76632 +#ifdef CONFIG_GRKERNSEC
76633 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
76634 + return 1;
76635 + return 0;
76636 +#else
76637 + return 1;
76638 +#endif
76639 +}
76640 +
76641 +int gr_is_capable_nolog(const int cap)
76642 +{
76643 +#ifdef CONFIG_GRKERNSEC
76644 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
76645 + return 1;
76646 + return 0;
76647 +#else
76648 + return 1;
76649 +#endif
76650 +}
76651 +
76652 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
76653 +{
76654 +#ifdef CONFIG_GRKERNSEC
76655 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
76656 + return 1;
76657 + return 0;
76658 +#else
76659 + return 1;
76660 +#endif
76661 +}
76662 +
76663 +EXPORT_SYMBOL_GPL(gr_is_capable);
76664 +EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
76665 +EXPORT_SYMBOL_GPL(gr_task_is_capable);
76666 +EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
76667 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
76668 new file mode 100644
76669 index 0000000..06cc6ea
76670 --- /dev/null
76671 +++ b/grsecurity/grsec_fifo.c
76672 @@ -0,0 +1,24 @@
76673 +#include <linux/kernel.h>
76674 +#include <linux/sched.h>
76675 +#include <linux/fs.h>
76676 +#include <linux/file.h>
76677 +#include <linux/grinternal.h>
76678 +
76679 +int
76680 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
76681 + const struct dentry *dir, const int flag, const int acc_mode)
76682 +{
76683 +#ifdef CONFIG_GRKERNSEC_FIFO
76684 + const struct cred *cred = current_cred();
76685 +
76686 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
76687 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
76688 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
76689 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
76690 + if (!inode_permission(dentry->d_inode, acc_mode))
76691 + 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));
76692 + return -EACCES;
76693 + }
76694 +#endif
76695 + return 0;
76696 +}
76697 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
76698 new file mode 100644
76699 index 0000000..8ca18bf
76700 --- /dev/null
76701 +++ b/grsecurity/grsec_fork.c
76702 @@ -0,0 +1,23 @@
76703 +#include <linux/kernel.h>
76704 +#include <linux/sched.h>
76705 +#include <linux/grsecurity.h>
76706 +#include <linux/grinternal.h>
76707 +#include <linux/errno.h>
76708 +
76709 +void
76710 +gr_log_forkfail(const int retval)
76711 +{
76712 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
76713 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
76714 + switch (retval) {
76715 + case -EAGAIN:
76716 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
76717 + break;
76718 + case -ENOMEM:
76719 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
76720 + break;
76721 + }
76722 + }
76723 +#endif
76724 + return;
76725 +}
76726 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
76727 new file mode 100644
76728 index 0000000..b7cb191
76729 --- /dev/null
76730 +++ b/grsecurity/grsec_init.c
76731 @@ -0,0 +1,286 @@
76732 +#include <linux/kernel.h>
76733 +#include <linux/sched.h>
76734 +#include <linux/mm.h>
76735 +#include <linux/gracl.h>
76736 +#include <linux/slab.h>
76737 +#include <linux/vmalloc.h>
76738 +#include <linux/percpu.h>
76739 +#include <linux/module.h>
76740 +
76741 +int grsec_enable_ptrace_readexec;
76742 +int grsec_enable_setxid;
76743 +int grsec_enable_symlinkown;
76744 +kgid_t grsec_symlinkown_gid;
76745 +int grsec_enable_brute;
76746 +int grsec_enable_link;
76747 +int grsec_enable_dmesg;
76748 +int grsec_enable_harden_ptrace;
76749 +int grsec_enable_harden_ipc;
76750 +int grsec_enable_fifo;
76751 +int grsec_enable_execlog;
76752 +int grsec_enable_signal;
76753 +int grsec_enable_forkfail;
76754 +int grsec_enable_audit_ptrace;
76755 +int grsec_enable_time;
76756 +int grsec_enable_group;
76757 +kgid_t grsec_audit_gid;
76758 +int grsec_enable_chdir;
76759 +int grsec_enable_mount;
76760 +int grsec_enable_rofs;
76761 +int grsec_deny_new_usb;
76762 +int grsec_enable_chroot_findtask;
76763 +int grsec_enable_chroot_mount;
76764 +int grsec_enable_chroot_shmat;
76765 +int grsec_enable_chroot_fchdir;
76766 +int grsec_enable_chroot_double;
76767 +int grsec_enable_chroot_pivot;
76768 +int grsec_enable_chroot_chdir;
76769 +int grsec_enable_chroot_chmod;
76770 +int grsec_enable_chroot_mknod;
76771 +int grsec_enable_chroot_nice;
76772 +int grsec_enable_chroot_execlog;
76773 +int grsec_enable_chroot_caps;
76774 +int grsec_enable_chroot_sysctl;
76775 +int grsec_enable_chroot_unix;
76776 +int grsec_enable_tpe;
76777 +kgid_t grsec_tpe_gid;
76778 +int grsec_enable_blackhole;
76779 +#ifdef CONFIG_IPV6_MODULE
76780 +EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
76781 +#endif
76782 +int grsec_lastack_retries;
76783 +int grsec_enable_tpe_all;
76784 +int grsec_enable_tpe_invert;
76785 +int grsec_enable_socket_all;
76786 +kgid_t grsec_socket_all_gid;
76787 +int grsec_enable_socket_client;
76788 +kgid_t grsec_socket_client_gid;
76789 +int grsec_enable_socket_server;
76790 +kgid_t grsec_socket_server_gid;
76791 +int grsec_resource_logging;
76792 +int grsec_disable_privio;
76793 +int grsec_enable_log_rwxmaps;
76794 +int grsec_lock;
76795 +
76796 +DEFINE_SPINLOCK(grsec_alert_lock);
76797 +unsigned long grsec_alert_wtime = 0;
76798 +unsigned long grsec_alert_fyet = 0;
76799 +
76800 +DEFINE_SPINLOCK(grsec_audit_lock);
76801 +
76802 +DEFINE_RWLOCK(grsec_exec_file_lock);
76803 +
76804 +char *gr_shared_page[4];
76805 +
76806 +char *gr_alert_log_fmt;
76807 +char *gr_audit_log_fmt;
76808 +char *gr_alert_log_buf;
76809 +char *gr_audit_log_buf;
76810 +
76811 +extern struct gr_arg *gr_usermode;
76812 +extern unsigned char *gr_system_salt;
76813 +extern unsigned char *gr_system_sum;
76814 +
76815 +void __init
76816 +grsecurity_init(void)
76817 +{
76818 + int j;
76819 + /* create the per-cpu shared pages */
76820 +
76821 +#ifdef CONFIG_X86
76822 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
76823 +#endif
76824 +
76825 + for (j = 0; j < 4; j++) {
76826 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
76827 + if (gr_shared_page[j] == NULL) {
76828 + panic("Unable to allocate grsecurity shared page");
76829 + return;
76830 + }
76831 + }
76832 +
76833 + /* allocate log buffers */
76834 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
76835 + if (!gr_alert_log_fmt) {
76836 + panic("Unable to allocate grsecurity alert log format buffer");
76837 + return;
76838 + }
76839 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
76840 + if (!gr_audit_log_fmt) {
76841 + panic("Unable to allocate grsecurity audit log format buffer");
76842 + return;
76843 + }
76844 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
76845 + if (!gr_alert_log_buf) {
76846 + panic("Unable to allocate grsecurity alert log buffer");
76847 + return;
76848 + }
76849 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
76850 + if (!gr_audit_log_buf) {
76851 + panic("Unable to allocate grsecurity audit log buffer");
76852 + return;
76853 + }
76854 +
76855 + /* allocate memory for authentication structure */
76856 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
76857 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
76858 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
76859 +
76860 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
76861 + panic("Unable to allocate grsecurity authentication structure");
76862 + return;
76863 + }
76864 +
76865 +#ifdef CONFIG_GRKERNSEC_IO
76866 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
76867 + grsec_disable_privio = 1;
76868 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
76869 + grsec_disable_privio = 1;
76870 +#else
76871 + grsec_disable_privio = 0;
76872 +#endif
76873 +#endif
76874 +
76875 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76876 + /* for backward compatibility, tpe_invert always defaults to on if
76877 + enabled in the kernel
76878 + */
76879 + grsec_enable_tpe_invert = 1;
76880 +#endif
76881 +
76882 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
76883 +#ifndef CONFIG_GRKERNSEC_SYSCTL
76884 + grsec_lock = 1;
76885 +#endif
76886 +
76887 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
76888 + grsec_enable_log_rwxmaps = 1;
76889 +#endif
76890 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
76891 + grsec_enable_group = 1;
76892 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
76893 +#endif
76894 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
76895 + grsec_enable_ptrace_readexec = 1;
76896 +#endif
76897 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76898 + grsec_enable_chdir = 1;
76899 +#endif
76900 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
76901 + grsec_enable_harden_ptrace = 1;
76902 +#endif
76903 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
76904 + grsec_enable_harden_ipc = 1;
76905 +#endif
76906 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
76907 + grsec_enable_mount = 1;
76908 +#endif
76909 +#ifdef CONFIG_GRKERNSEC_LINK
76910 + grsec_enable_link = 1;
76911 +#endif
76912 +#ifdef CONFIG_GRKERNSEC_BRUTE
76913 + grsec_enable_brute = 1;
76914 +#endif
76915 +#ifdef CONFIG_GRKERNSEC_DMESG
76916 + grsec_enable_dmesg = 1;
76917 +#endif
76918 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76919 + grsec_enable_blackhole = 1;
76920 + grsec_lastack_retries = 4;
76921 +#endif
76922 +#ifdef CONFIG_GRKERNSEC_FIFO
76923 + grsec_enable_fifo = 1;
76924 +#endif
76925 +#ifdef CONFIG_GRKERNSEC_EXECLOG
76926 + grsec_enable_execlog = 1;
76927 +#endif
76928 +#ifdef CONFIG_GRKERNSEC_SETXID
76929 + grsec_enable_setxid = 1;
76930 +#endif
76931 +#ifdef CONFIG_GRKERNSEC_SIGNAL
76932 + grsec_enable_signal = 1;
76933 +#endif
76934 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
76935 + grsec_enable_forkfail = 1;
76936 +#endif
76937 +#ifdef CONFIG_GRKERNSEC_TIME
76938 + grsec_enable_time = 1;
76939 +#endif
76940 +#ifdef CONFIG_GRKERNSEC_RESLOG
76941 + grsec_resource_logging = 1;
76942 +#endif
76943 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76944 + grsec_enable_chroot_findtask = 1;
76945 +#endif
76946 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76947 + grsec_enable_chroot_unix = 1;
76948 +#endif
76949 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76950 + grsec_enable_chroot_mount = 1;
76951 +#endif
76952 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76953 + grsec_enable_chroot_fchdir = 1;
76954 +#endif
76955 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76956 + grsec_enable_chroot_shmat = 1;
76957 +#endif
76958 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
76959 + grsec_enable_audit_ptrace = 1;
76960 +#endif
76961 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76962 + grsec_enable_chroot_double = 1;
76963 +#endif
76964 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76965 + grsec_enable_chroot_pivot = 1;
76966 +#endif
76967 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76968 + grsec_enable_chroot_chdir = 1;
76969 +#endif
76970 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76971 + grsec_enable_chroot_chmod = 1;
76972 +#endif
76973 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76974 + grsec_enable_chroot_mknod = 1;
76975 +#endif
76976 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76977 + grsec_enable_chroot_nice = 1;
76978 +#endif
76979 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76980 + grsec_enable_chroot_execlog = 1;
76981 +#endif
76982 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76983 + grsec_enable_chroot_caps = 1;
76984 +#endif
76985 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76986 + grsec_enable_chroot_sysctl = 1;
76987 +#endif
76988 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
76989 + grsec_enable_symlinkown = 1;
76990 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
76991 +#endif
76992 +#ifdef CONFIG_GRKERNSEC_TPE
76993 + grsec_enable_tpe = 1;
76994 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
76995 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
76996 + grsec_enable_tpe_all = 1;
76997 +#endif
76998 +#endif
76999 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
77000 + grsec_enable_socket_all = 1;
77001 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
77002 +#endif
77003 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
77004 + grsec_enable_socket_client = 1;
77005 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
77006 +#endif
77007 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
77008 + grsec_enable_socket_server = 1;
77009 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
77010 +#endif
77011 +#endif
77012 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
77013 + grsec_deny_new_usb = 1;
77014 +#endif
77015 +
77016 + return;
77017 +}
77018 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
77019 new file mode 100644
77020 index 0000000..1773300
77021 --- /dev/null
77022 +++ b/grsecurity/grsec_ipc.c
77023 @@ -0,0 +1,48 @@
77024 +#include <linux/kernel.h>
77025 +#include <linux/mm.h>
77026 +#include <linux/sched.h>
77027 +#include <linux/file.h>
77028 +#include <linux/ipc.h>
77029 +#include <linux/ipc_namespace.h>
77030 +#include <linux/grsecurity.h>
77031 +#include <linux/grinternal.h>
77032 +
77033 +int
77034 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
77035 +{
77036 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77037 + int write;
77038 + int orig_granted_mode;
77039 + kuid_t euid;
77040 + kgid_t egid;
77041 +
77042 + if (!grsec_enable_harden_ipc)
77043 + return 1;
77044 +
77045 + euid = current_euid();
77046 + egid = current_egid();
77047 +
77048 + write = requested_mode & 00002;
77049 + orig_granted_mode = ipcp->mode;
77050 +
77051 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
77052 + orig_granted_mode >>= 6;
77053 + else {
77054 + /* if likely wrong permissions, lock to user */
77055 + if (orig_granted_mode & 0007)
77056 + orig_granted_mode = 0;
77057 + /* otherwise do a egid-only check */
77058 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
77059 + orig_granted_mode >>= 3;
77060 + /* otherwise, no access */
77061 + else
77062 + orig_granted_mode = 0;
77063 + }
77064 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
77065 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
77066 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
77067 + return 0;
77068 + }
77069 +#endif
77070 + return 1;
77071 +}
77072 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
77073 new file mode 100644
77074 index 0000000..5e05e20
77075 --- /dev/null
77076 +++ b/grsecurity/grsec_link.c
77077 @@ -0,0 +1,58 @@
77078 +#include <linux/kernel.h>
77079 +#include <linux/sched.h>
77080 +#include <linux/fs.h>
77081 +#include <linux/file.h>
77082 +#include <linux/grinternal.h>
77083 +
77084 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
77085 +{
77086 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77087 + const struct inode *link_inode = link->dentry->d_inode;
77088 +
77089 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
77090 + /* ignore root-owned links, e.g. /proc/self */
77091 + gr_is_global_nonroot(link_inode->i_uid) && target &&
77092 + !uid_eq(link_inode->i_uid, target->i_uid)) {
77093 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
77094 + return 1;
77095 + }
77096 +#endif
77097 + return 0;
77098 +}
77099 +
77100 +int
77101 +gr_handle_follow_link(const struct inode *parent,
77102 + const struct inode *inode,
77103 + const struct dentry *dentry, const struct vfsmount *mnt)
77104 +{
77105 +#ifdef CONFIG_GRKERNSEC_LINK
77106 + const struct cred *cred = current_cred();
77107 +
77108 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
77109 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
77110 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
77111 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
77112 + return -EACCES;
77113 + }
77114 +#endif
77115 + return 0;
77116 +}
77117 +
77118 +int
77119 +gr_handle_hardlink(const struct dentry *dentry,
77120 + const struct vfsmount *mnt,
77121 + struct inode *inode, const int mode, const struct filename *to)
77122 +{
77123 +#ifdef CONFIG_GRKERNSEC_LINK
77124 + const struct cred *cred = current_cred();
77125 +
77126 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
77127 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
77128 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
77129 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
77130 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
77131 + return -EPERM;
77132 + }
77133 +#endif
77134 + return 0;
77135 +}
77136 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
77137 new file mode 100644
77138 index 0000000..dbe0a6b
77139 --- /dev/null
77140 +++ b/grsecurity/grsec_log.c
77141 @@ -0,0 +1,341 @@
77142 +#include <linux/kernel.h>
77143 +#include <linux/sched.h>
77144 +#include <linux/file.h>
77145 +#include <linux/tty.h>
77146 +#include <linux/fs.h>
77147 +#include <linux/mm.h>
77148 +#include <linux/grinternal.h>
77149 +
77150 +#ifdef CONFIG_TREE_PREEMPT_RCU
77151 +#define DISABLE_PREEMPT() preempt_disable()
77152 +#define ENABLE_PREEMPT() preempt_enable()
77153 +#else
77154 +#define DISABLE_PREEMPT()
77155 +#define ENABLE_PREEMPT()
77156 +#endif
77157 +
77158 +#define BEGIN_LOCKS(x) \
77159 + DISABLE_PREEMPT(); \
77160 + rcu_read_lock(); \
77161 + read_lock(&tasklist_lock); \
77162 + read_lock(&grsec_exec_file_lock); \
77163 + if (x != GR_DO_AUDIT) \
77164 + spin_lock(&grsec_alert_lock); \
77165 + else \
77166 + spin_lock(&grsec_audit_lock)
77167 +
77168 +#define END_LOCKS(x) \
77169 + if (x != GR_DO_AUDIT) \
77170 + spin_unlock(&grsec_alert_lock); \
77171 + else \
77172 + spin_unlock(&grsec_audit_lock); \
77173 + read_unlock(&grsec_exec_file_lock); \
77174 + read_unlock(&tasklist_lock); \
77175 + rcu_read_unlock(); \
77176 + ENABLE_PREEMPT(); \
77177 + if (x == GR_DONT_AUDIT) \
77178 + gr_handle_alertkill(current)
77179 +
77180 +enum {
77181 + FLOODING,
77182 + NO_FLOODING
77183 +};
77184 +
77185 +extern char *gr_alert_log_fmt;
77186 +extern char *gr_audit_log_fmt;
77187 +extern char *gr_alert_log_buf;
77188 +extern char *gr_audit_log_buf;
77189 +
77190 +static int gr_log_start(int audit)
77191 +{
77192 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
77193 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
77194 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77195 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
77196 + unsigned long curr_secs = get_seconds();
77197 +
77198 + if (audit == GR_DO_AUDIT)
77199 + goto set_fmt;
77200 +
77201 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
77202 + grsec_alert_wtime = curr_secs;
77203 + grsec_alert_fyet = 0;
77204 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
77205 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
77206 + grsec_alert_fyet++;
77207 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
77208 + grsec_alert_wtime = curr_secs;
77209 + grsec_alert_fyet++;
77210 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
77211 + return FLOODING;
77212 + }
77213 + else return FLOODING;
77214 +
77215 +set_fmt:
77216 +#endif
77217 + memset(buf, 0, PAGE_SIZE);
77218 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
77219 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
77220 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
77221 + } else if (current->signal->curr_ip) {
77222 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
77223 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
77224 + } else if (gr_acl_is_enabled()) {
77225 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
77226 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
77227 + } else {
77228 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
77229 + strcpy(buf, fmt);
77230 + }
77231 +
77232 + return NO_FLOODING;
77233 +}
77234 +
77235 +static void gr_log_middle(int audit, const char *msg, va_list ap)
77236 + __attribute__ ((format (printf, 2, 0)));
77237 +
77238 +static void gr_log_middle(int audit, const char *msg, va_list ap)
77239 +{
77240 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77241 + unsigned int len = strlen(buf);
77242 +
77243 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
77244 +
77245 + return;
77246 +}
77247 +
77248 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
77249 + __attribute__ ((format (printf, 2, 3)));
77250 +
77251 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
77252 +{
77253 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77254 + unsigned int len = strlen(buf);
77255 + va_list ap;
77256 +
77257 + va_start(ap, msg);
77258 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
77259 + va_end(ap);
77260 +
77261 + return;
77262 +}
77263 +
77264 +static void gr_log_end(int audit, int append_default)
77265 +{
77266 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77267 + if (append_default) {
77268 + struct task_struct *task = current;
77269 + struct task_struct *parent = task->real_parent;
77270 + const struct cred *cred = __task_cred(task);
77271 + const struct cred *pcred = __task_cred(parent);
77272 + unsigned int len = strlen(buf);
77273 +
77274 + 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));
77275 + }
77276 +
77277 + printk("%s\n", buf);
77278 +
77279 + return;
77280 +}
77281 +
77282 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
77283 +{
77284 + int logtype;
77285 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
77286 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
77287 + void *voidptr = NULL;
77288 + int num1 = 0, num2 = 0;
77289 + unsigned long ulong1 = 0, ulong2 = 0;
77290 + struct dentry *dentry = NULL;
77291 + struct vfsmount *mnt = NULL;
77292 + struct file *file = NULL;
77293 + struct task_struct *task = NULL;
77294 + struct vm_area_struct *vma = NULL;
77295 + const struct cred *cred, *pcred;
77296 + va_list ap;
77297 +
77298 + BEGIN_LOCKS(audit);
77299 + logtype = gr_log_start(audit);
77300 + if (logtype == FLOODING) {
77301 + END_LOCKS(audit);
77302 + return;
77303 + }
77304 + va_start(ap, argtypes);
77305 + switch (argtypes) {
77306 + case GR_TTYSNIFF:
77307 + task = va_arg(ap, struct task_struct *);
77308 + 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));
77309 + break;
77310 + case GR_SYSCTL_HIDDEN:
77311 + str1 = va_arg(ap, char *);
77312 + gr_log_middle_varargs(audit, msg, result, str1);
77313 + break;
77314 + case GR_RBAC:
77315 + dentry = va_arg(ap, struct dentry *);
77316 + mnt = va_arg(ap, struct vfsmount *);
77317 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
77318 + break;
77319 + case GR_RBAC_STR:
77320 + dentry = va_arg(ap, struct dentry *);
77321 + mnt = va_arg(ap, struct vfsmount *);
77322 + str1 = va_arg(ap, char *);
77323 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
77324 + break;
77325 + case GR_STR_RBAC:
77326 + str1 = va_arg(ap, char *);
77327 + dentry = va_arg(ap, struct dentry *);
77328 + mnt = va_arg(ap, struct vfsmount *);
77329 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
77330 + break;
77331 + case GR_RBAC_MODE2:
77332 + dentry = va_arg(ap, struct dentry *);
77333 + mnt = va_arg(ap, struct vfsmount *);
77334 + str1 = va_arg(ap, char *);
77335 + str2 = va_arg(ap, char *);
77336 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
77337 + break;
77338 + case GR_RBAC_MODE3:
77339 + dentry = va_arg(ap, struct dentry *);
77340 + mnt = va_arg(ap, struct vfsmount *);
77341 + str1 = va_arg(ap, char *);
77342 + str2 = va_arg(ap, char *);
77343 + str3 = va_arg(ap, char *);
77344 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
77345 + break;
77346 + case GR_FILENAME:
77347 + dentry = va_arg(ap, struct dentry *);
77348 + mnt = va_arg(ap, struct vfsmount *);
77349 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
77350 + break;
77351 + case GR_STR_FILENAME:
77352 + str1 = va_arg(ap, char *);
77353 + dentry = va_arg(ap, struct dentry *);
77354 + mnt = va_arg(ap, struct vfsmount *);
77355 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
77356 + break;
77357 + case GR_FILENAME_STR:
77358 + dentry = va_arg(ap, struct dentry *);
77359 + mnt = va_arg(ap, struct vfsmount *);
77360 + str1 = va_arg(ap, char *);
77361 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
77362 + break;
77363 + case GR_FILENAME_TWO_INT:
77364 + dentry = va_arg(ap, struct dentry *);
77365 + mnt = va_arg(ap, struct vfsmount *);
77366 + num1 = va_arg(ap, int);
77367 + num2 = va_arg(ap, int);
77368 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
77369 + break;
77370 + case GR_FILENAME_TWO_INT_STR:
77371 + dentry = va_arg(ap, struct dentry *);
77372 + mnt = va_arg(ap, struct vfsmount *);
77373 + num1 = va_arg(ap, int);
77374 + num2 = va_arg(ap, int);
77375 + str1 = va_arg(ap, char *);
77376 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
77377 + break;
77378 + case GR_TEXTREL:
77379 + file = va_arg(ap, struct file *);
77380 + ulong1 = va_arg(ap, unsigned long);
77381 + ulong2 = va_arg(ap, unsigned long);
77382 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
77383 + break;
77384 + case GR_PTRACE:
77385 + task = va_arg(ap, struct task_struct *);
77386 + 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));
77387 + break;
77388 + case GR_RESOURCE:
77389 + task = va_arg(ap, struct task_struct *);
77390 + cred = __task_cred(task);
77391 + pcred = __task_cred(task->real_parent);
77392 + ulong1 = va_arg(ap, unsigned long);
77393 + str1 = va_arg(ap, char *);
77394 + ulong2 = va_arg(ap, unsigned long);
77395 + 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));
77396 + break;
77397 + case GR_CAP:
77398 + task = va_arg(ap, struct task_struct *);
77399 + cred = __task_cred(task);
77400 + pcred = __task_cred(task->real_parent);
77401 + str1 = va_arg(ap, char *);
77402 + 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));
77403 + break;
77404 + case GR_SIG:
77405 + str1 = va_arg(ap, char *);
77406 + voidptr = va_arg(ap, void *);
77407 + gr_log_middle_varargs(audit, msg, str1, voidptr);
77408 + break;
77409 + case GR_SIG2:
77410 + task = va_arg(ap, struct task_struct *);
77411 + cred = __task_cred(task);
77412 + pcred = __task_cred(task->real_parent);
77413 + num1 = va_arg(ap, int);
77414 + 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));
77415 + break;
77416 + case GR_CRASH1:
77417 + task = va_arg(ap, struct task_struct *);
77418 + cred = __task_cred(task);
77419 + pcred = __task_cred(task->real_parent);
77420 + ulong1 = va_arg(ap, unsigned long);
77421 + 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);
77422 + break;
77423 + case GR_CRASH2:
77424 + task = va_arg(ap, struct task_struct *);
77425 + cred = __task_cred(task);
77426 + pcred = __task_cred(task->real_parent);
77427 + ulong1 = va_arg(ap, unsigned long);
77428 + 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);
77429 + break;
77430 + case GR_RWXMAP:
77431 + file = va_arg(ap, struct file *);
77432 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
77433 + break;
77434 + case GR_RWXMAPVMA:
77435 + vma = va_arg(ap, struct vm_area_struct *);
77436 + if (vma->vm_file)
77437 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
77438 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
77439 + str1 = "<stack>";
77440 + else if (vma->vm_start <= current->mm->brk &&
77441 + vma->vm_end >= current->mm->start_brk)
77442 + str1 = "<heap>";
77443 + else
77444 + str1 = "<anonymous mapping>";
77445 + gr_log_middle_varargs(audit, msg, str1);
77446 + break;
77447 + case GR_PSACCT:
77448 + {
77449 + unsigned int wday, cday;
77450 + __u8 whr, chr;
77451 + __u8 wmin, cmin;
77452 + __u8 wsec, csec;
77453 + char cur_tty[64] = { 0 };
77454 + char parent_tty[64] = { 0 };
77455 +
77456 + task = va_arg(ap, struct task_struct *);
77457 + wday = va_arg(ap, unsigned int);
77458 + cday = va_arg(ap, unsigned int);
77459 + whr = va_arg(ap, int);
77460 + chr = va_arg(ap, int);
77461 + wmin = va_arg(ap, int);
77462 + cmin = va_arg(ap, int);
77463 + wsec = va_arg(ap, int);
77464 + csec = va_arg(ap, int);
77465 + ulong1 = va_arg(ap, unsigned long);
77466 + cred = __task_cred(task);
77467 + pcred = __task_cred(task->real_parent);
77468 +
77469 + 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));
77470 + }
77471 + break;
77472 + default:
77473 + gr_log_middle(audit, msg, ap);
77474 + }
77475 + va_end(ap);
77476 + // these don't need DEFAULTSECARGS printed on the end
77477 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
77478 + gr_log_end(audit, 0);
77479 + else
77480 + gr_log_end(audit, 1);
77481 + END_LOCKS(audit);
77482 +}
77483 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
77484 new file mode 100644
77485 index 0000000..0e39d8c
77486 --- /dev/null
77487 +++ b/grsecurity/grsec_mem.c
77488 @@ -0,0 +1,48 @@
77489 +#include <linux/kernel.h>
77490 +#include <linux/sched.h>
77491 +#include <linux/mm.h>
77492 +#include <linux/mman.h>
77493 +#include <linux/module.h>
77494 +#include <linux/grinternal.h>
77495 +
77496 +void gr_handle_msr_write(void)
77497 +{
77498 + gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
77499 + return;
77500 +}
77501 +EXPORT_SYMBOL_GPL(gr_handle_msr_write);
77502 +
77503 +void
77504 +gr_handle_ioperm(void)
77505 +{
77506 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
77507 + return;
77508 +}
77509 +
77510 +void
77511 +gr_handle_iopl(void)
77512 +{
77513 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
77514 + return;
77515 +}
77516 +
77517 +void
77518 +gr_handle_mem_readwrite(u64 from, u64 to)
77519 +{
77520 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
77521 + return;
77522 +}
77523 +
77524 +void
77525 +gr_handle_vm86(void)
77526 +{
77527 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
77528 + return;
77529 +}
77530 +
77531 +void
77532 +gr_log_badprocpid(const char *entry)
77533 +{
77534 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
77535 + return;
77536 +}
77537 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
77538 new file mode 100644
77539 index 0000000..cd9e124
77540 --- /dev/null
77541 +++ b/grsecurity/grsec_mount.c
77542 @@ -0,0 +1,65 @@
77543 +#include <linux/kernel.h>
77544 +#include <linux/sched.h>
77545 +#include <linux/mount.h>
77546 +#include <linux/major.h>
77547 +#include <linux/grsecurity.h>
77548 +#include <linux/grinternal.h>
77549 +
77550 +void
77551 +gr_log_remount(const char *devname, const int retval)
77552 +{
77553 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77554 + if (grsec_enable_mount && (retval >= 0))
77555 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
77556 +#endif
77557 + return;
77558 +}
77559 +
77560 +void
77561 +gr_log_unmount(const char *devname, const int retval)
77562 +{
77563 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77564 + if (grsec_enable_mount && (retval >= 0))
77565 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
77566 +#endif
77567 + return;
77568 +}
77569 +
77570 +void
77571 +gr_log_mount(const char *from, const char *to, const int retval)
77572 +{
77573 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77574 + if (grsec_enable_mount && (retval >= 0))
77575 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
77576 +#endif
77577 + return;
77578 +}
77579 +
77580 +int
77581 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
77582 +{
77583 +#ifdef CONFIG_GRKERNSEC_ROFS
77584 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
77585 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
77586 + return -EPERM;
77587 + } else
77588 + return 0;
77589 +#endif
77590 + return 0;
77591 +}
77592 +
77593 +int
77594 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
77595 +{
77596 +#ifdef CONFIG_GRKERNSEC_ROFS
77597 + struct inode *inode = dentry->d_inode;
77598 +
77599 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
77600 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
77601 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
77602 + return -EPERM;
77603 + } else
77604 + return 0;
77605 +#endif
77606 + return 0;
77607 +}
77608 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
77609 new file mode 100644
77610 index 0000000..6ee9d50
77611 --- /dev/null
77612 +++ b/grsecurity/grsec_pax.c
77613 @@ -0,0 +1,45 @@
77614 +#include <linux/kernel.h>
77615 +#include <linux/sched.h>
77616 +#include <linux/mm.h>
77617 +#include <linux/file.h>
77618 +#include <linux/grinternal.h>
77619 +#include <linux/grsecurity.h>
77620 +
77621 +void
77622 +gr_log_textrel(struct vm_area_struct * vma)
77623 +{
77624 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
77625 + if (grsec_enable_log_rwxmaps)
77626 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
77627 +#endif
77628 + return;
77629 +}
77630 +
77631 +void gr_log_ptgnustack(struct file *file)
77632 +{
77633 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
77634 + if (grsec_enable_log_rwxmaps)
77635 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
77636 +#endif
77637 + return;
77638 +}
77639 +
77640 +void
77641 +gr_log_rwxmmap(struct file *file)
77642 +{
77643 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
77644 + if (grsec_enable_log_rwxmaps)
77645 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
77646 +#endif
77647 + return;
77648 +}
77649 +
77650 +void
77651 +gr_log_rwxmprotect(struct vm_area_struct *vma)
77652 +{
77653 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
77654 + if (grsec_enable_log_rwxmaps)
77655 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
77656 +#endif
77657 + return;
77658 +}
77659 diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
77660 new file mode 100644
77661 index 0000000..2005a3a
77662 --- /dev/null
77663 +++ b/grsecurity/grsec_proc.c
77664 @@ -0,0 +1,20 @@
77665 +#include <linux/kernel.h>
77666 +#include <linux/sched.h>
77667 +#include <linux/grsecurity.h>
77668 +#include <linux/grinternal.h>
77669 +
77670 +int gr_proc_is_restricted(void)
77671 +{
77672 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
77673 + const struct cred *cred = current_cred();
77674 +#endif
77675 +
77676 +#ifdef CONFIG_GRKERNSEC_PROC_USER
77677 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
77678 + return -EACCES;
77679 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
77680 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
77681 + return -EACCES;
77682 +#endif
77683 + return 0;
77684 +}
77685 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
77686 new file mode 100644
77687 index 0000000..f7f29aa
77688 --- /dev/null
77689 +++ b/grsecurity/grsec_ptrace.c
77690 @@ -0,0 +1,30 @@
77691 +#include <linux/kernel.h>
77692 +#include <linux/sched.h>
77693 +#include <linux/grinternal.h>
77694 +#include <linux/security.h>
77695 +
77696 +void
77697 +gr_audit_ptrace(struct task_struct *task)
77698 +{
77699 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
77700 + if (grsec_enable_audit_ptrace)
77701 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
77702 +#endif
77703 + return;
77704 +}
77705 +
77706 +int
77707 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
77708 +{
77709 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
77710 + const struct dentry *dentry = file->f_path.dentry;
77711 + const struct vfsmount *mnt = file->f_path.mnt;
77712 +
77713 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
77714 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
77715 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
77716 + return -EACCES;
77717 + }
77718 +#endif
77719 + return 0;
77720 +}
77721 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
77722 new file mode 100644
77723 index 0000000..3860c7e
77724 --- /dev/null
77725 +++ b/grsecurity/grsec_sig.c
77726 @@ -0,0 +1,236 @@
77727 +#include <linux/kernel.h>
77728 +#include <linux/sched.h>
77729 +#include <linux/fs.h>
77730 +#include <linux/delay.h>
77731 +#include <linux/grsecurity.h>
77732 +#include <linux/grinternal.h>
77733 +#include <linux/hardirq.h>
77734 +
77735 +char *signames[] = {
77736 + [SIGSEGV] = "Segmentation fault",
77737 + [SIGILL] = "Illegal instruction",
77738 + [SIGABRT] = "Abort",
77739 + [SIGBUS] = "Invalid alignment/Bus error"
77740 +};
77741 +
77742 +void
77743 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
77744 +{
77745 +#ifdef CONFIG_GRKERNSEC_SIGNAL
77746 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
77747 + (sig == SIGABRT) || (sig == SIGBUS))) {
77748 + if (task_pid_nr(t) == task_pid_nr(current)) {
77749 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
77750 + } else {
77751 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
77752 + }
77753 + }
77754 +#endif
77755 + return;
77756 +}
77757 +
77758 +int
77759 +gr_handle_signal(const struct task_struct *p, const int sig)
77760 +{
77761 +#ifdef CONFIG_GRKERNSEC
77762 + /* ignore the 0 signal for protected task checks */
77763 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
77764 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
77765 + return -EPERM;
77766 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
77767 + return -EPERM;
77768 + }
77769 +#endif
77770 + return 0;
77771 +}
77772 +
77773 +#ifdef CONFIG_GRKERNSEC
77774 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
77775 +
77776 +int gr_fake_force_sig(int sig, struct task_struct *t)
77777 +{
77778 + unsigned long int flags;
77779 + int ret, blocked, ignored;
77780 + struct k_sigaction *action;
77781 +
77782 + spin_lock_irqsave(&t->sighand->siglock, flags);
77783 + action = &t->sighand->action[sig-1];
77784 + ignored = action->sa.sa_handler == SIG_IGN;
77785 + blocked = sigismember(&t->blocked, sig);
77786 + if (blocked || ignored) {
77787 + action->sa.sa_handler = SIG_DFL;
77788 + if (blocked) {
77789 + sigdelset(&t->blocked, sig);
77790 + recalc_sigpending_and_wake(t);
77791 + }
77792 + }
77793 + if (action->sa.sa_handler == SIG_DFL)
77794 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
77795 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
77796 +
77797 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
77798 +
77799 + return ret;
77800 +}
77801 +#endif
77802 +
77803 +#define GR_USER_BAN_TIME (15 * 60)
77804 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
77805 +
77806 +void gr_handle_brute_attach(int dumpable)
77807 +{
77808 +#ifdef CONFIG_GRKERNSEC_BRUTE
77809 + struct task_struct *p = current;
77810 + kuid_t uid = GLOBAL_ROOT_UID;
77811 + int daemon = 0;
77812 +
77813 + if (!grsec_enable_brute)
77814 + return;
77815 +
77816 + rcu_read_lock();
77817 + read_lock(&tasklist_lock);
77818 + read_lock(&grsec_exec_file_lock);
77819 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
77820 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
77821 + p->real_parent->brute = 1;
77822 + daemon = 1;
77823 + } else {
77824 + const struct cred *cred = __task_cred(p), *cred2;
77825 + struct task_struct *tsk, *tsk2;
77826 +
77827 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
77828 + struct user_struct *user;
77829 +
77830 + uid = cred->uid;
77831 +
77832 + /* this is put upon execution past expiration */
77833 + user = find_user(uid);
77834 + if (user == NULL)
77835 + goto unlock;
77836 + user->suid_banned = 1;
77837 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
77838 + if (user->suid_ban_expires == ~0UL)
77839 + user->suid_ban_expires--;
77840 +
77841 + /* only kill other threads of the same binary, from the same user */
77842 + do_each_thread(tsk2, tsk) {
77843 + cred2 = __task_cred(tsk);
77844 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
77845 + gr_fake_force_sig(SIGKILL, tsk);
77846 + } while_each_thread(tsk2, tsk);
77847 + }
77848 + }
77849 +unlock:
77850 + read_unlock(&grsec_exec_file_lock);
77851 + read_unlock(&tasklist_lock);
77852 + rcu_read_unlock();
77853 +
77854 + if (gr_is_global_nonroot(uid))
77855 + 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);
77856 + else if (daemon)
77857 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
77858 +
77859 +#endif
77860 + return;
77861 +}
77862 +
77863 +void gr_handle_brute_check(void)
77864 +{
77865 +#ifdef CONFIG_GRKERNSEC_BRUTE
77866 + struct task_struct *p = current;
77867 +
77868 + if (unlikely(p->brute)) {
77869 + if (!grsec_enable_brute)
77870 + p->brute = 0;
77871 + else if (time_before(get_seconds(), p->brute_expires))
77872 + msleep(30 * 1000);
77873 + }
77874 +#endif
77875 + return;
77876 +}
77877 +
77878 +void gr_handle_kernel_exploit(void)
77879 +{
77880 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
77881 + const struct cred *cred;
77882 + struct task_struct *tsk, *tsk2;
77883 + struct user_struct *user;
77884 + kuid_t uid;
77885 +
77886 + if (in_irq() || in_serving_softirq() || in_nmi())
77887 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
77888 +
77889 + uid = current_uid();
77890 +
77891 + if (gr_is_global_root(uid))
77892 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
77893 + else {
77894 + /* kill all the processes of this user, hold a reference
77895 + to their creds struct, and prevent them from creating
77896 + another process until system reset
77897 + */
77898 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
77899 + GR_GLOBAL_UID(uid));
77900 + /* we intentionally leak this ref */
77901 + user = get_uid(current->cred->user);
77902 + if (user)
77903 + user->kernel_banned = 1;
77904 +
77905 + /* kill all processes of this user */
77906 + read_lock(&tasklist_lock);
77907 + do_each_thread(tsk2, tsk) {
77908 + cred = __task_cred(tsk);
77909 + if (uid_eq(cred->uid, uid))
77910 + gr_fake_force_sig(SIGKILL, tsk);
77911 + } while_each_thread(tsk2, tsk);
77912 + read_unlock(&tasklist_lock);
77913 + }
77914 +#endif
77915 +}
77916 +
77917 +#ifdef CONFIG_GRKERNSEC_BRUTE
77918 +static bool suid_ban_expired(struct user_struct *user)
77919 +{
77920 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
77921 + user->suid_banned = 0;
77922 + user->suid_ban_expires = 0;
77923 + free_uid(user);
77924 + return true;
77925 + }
77926 +
77927 + return false;
77928 +}
77929 +#endif
77930 +
77931 +int gr_process_kernel_exec_ban(void)
77932 +{
77933 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
77934 + if (unlikely(current->cred->user->kernel_banned))
77935 + return -EPERM;
77936 +#endif
77937 + return 0;
77938 +}
77939 +
77940 +int gr_process_kernel_setuid_ban(struct user_struct *user)
77941 +{
77942 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
77943 + if (unlikely(user->kernel_banned))
77944 + gr_fake_force_sig(SIGKILL, current);
77945 +#endif
77946 + return 0;
77947 +}
77948 +
77949 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
77950 +{
77951 +#ifdef CONFIG_GRKERNSEC_BRUTE
77952 + struct user_struct *user = current->cred->user;
77953 + if (unlikely(user->suid_banned)) {
77954 + if (suid_ban_expired(user))
77955 + return 0;
77956 + /* disallow execution of suid binaries only */
77957 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
77958 + return -EPERM;
77959 + }
77960 +#endif
77961 + return 0;
77962 +}
77963 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
77964 new file mode 100644
77965 index 0000000..e3650b6
77966 --- /dev/null
77967 +++ b/grsecurity/grsec_sock.c
77968 @@ -0,0 +1,244 @@
77969 +#include <linux/kernel.h>
77970 +#include <linux/module.h>
77971 +#include <linux/sched.h>
77972 +#include <linux/file.h>
77973 +#include <linux/net.h>
77974 +#include <linux/in.h>
77975 +#include <linux/ip.h>
77976 +#include <net/sock.h>
77977 +#include <net/inet_sock.h>
77978 +#include <linux/grsecurity.h>
77979 +#include <linux/grinternal.h>
77980 +#include <linux/gracl.h>
77981 +
77982 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
77983 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
77984 +
77985 +EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
77986 +EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
77987 +
77988 +#ifdef CONFIG_UNIX_MODULE
77989 +EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
77990 +EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
77991 +EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
77992 +EXPORT_SYMBOL_GPL(gr_handle_create);
77993 +#endif
77994 +
77995 +#ifdef CONFIG_GRKERNSEC
77996 +#define gr_conn_table_size 32749
77997 +struct conn_table_entry {
77998 + struct conn_table_entry *next;
77999 + struct signal_struct *sig;
78000 +};
78001 +
78002 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
78003 +DEFINE_SPINLOCK(gr_conn_table_lock);
78004 +
78005 +extern const char * gr_socktype_to_name(unsigned char type);
78006 +extern const char * gr_proto_to_name(unsigned char proto);
78007 +extern const char * gr_sockfamily_to_name(unsigned char family);
78008 +
78009 +static __inline__ int
78010 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
78011 +{
78012 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
78013 +}
78014 +
78015 +static __inline__ int
78016 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
78017 + __u16 sport, __u16 dport)
78018 +{
78019 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
78020 + sig->gr_sport == sport && sig->gr_dport == dport))
78021 + return 1;
78022 + else
78023 + return 0;
78024 +}
78025 +
78026 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
78027 +{
78028 + struct conn_table_entry **match;
78029 + unsigned int index;
78030 +
78031 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78032 + sig->gr_sport, sig->gr_dport,
78033 + gr_conn_table_size);
78034 +
78035 + newent->sig = sig;
78036 +
78037 + match = &gr_conn_table[index];
78038 + newent->next = *match;
78039 + *match = newent;
78040 +
78041 + return;
78042 +}
78043 +
78044 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
78045 +{
78046 + struct conn_table_entry *match, *last = NULL;
78047 + unsigned int index;
78048 +
78049 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78050 + sig->gr_sport, sig->gr_dport,
78051 + gr_conn_table_size);
78052 +
78053 + match = gr_conn_table[index];
78054 + while (match && !conn_match(match->sig,
78055 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
78056 + sig->gr_dport)) {
78057 + last = match;
78058 + match = match->next;
78059 + }
78060 +
78061 + if (match) {
78062 + if (last)
78063 + last->next = match->next;
78064 + else
78065 + gr_conn_table[index] = NULL;
78066 + kfree(match);
78067 + }
78068 +
78069 + return;
78070 +}
78071 +
78072 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
78073 + __u16 sport, __u16 dport)
78074 +{
78075 + struct conn_table_entry *match;
78076 + unsigned int index;
78077 +
78078 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
78079 +
78080 + match = gr_conn_table[index];
78081 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
78082 + match = match->next;
78083 +
78084 + if (match)
78085 + return match->sig;
78086 + else
78087 + return NULL;
78088 +}
78089 +
78090 +#endif
78091 +
78092 +void gr_update_task_in_ip_table(const struct inet_sock *inet)
78093 +{
78094 +#ifdef CONFIG_GRKERNSEC
78095 + struct signal_struct *sig = current->signal;
78096 + struct conn_table_entry *newent;
78097 +
78098 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
78099 + if (newent == NULL)
78100 + return;
78101 + /* no bh lock needed since we are called with bh disabled */
78102 + spin_lock(&gr_conn_table_lock);
78103 + gr_del_task_from_ip_table_nolock(sig);
78104 + sig->gr_saddr = inet->inet_rcv_saddr;
78105 + sig->gr_daddr = inet->inet_daddr;
78106 + sig->gr_sport = inet->inet_sport;
78107 + sig->gr_dport = inet->inet_dport;
78108 + gr_add_to_task_ip_table_nolock(sig, newent);
78109 + spin_unlock(&gr_conn_table_lock);
78110 +#endif
78111 + return;
78112 +}
78113 +
78114 +void gr_del_task_from_ip_table(struct task_struct *task)
78115 +{
78116 +#ifdef CONFIG_GRKERNSEC
78117 + spin_lock_bh(&gr_conn_table_lock);
78118 + gr_del_task_from_ip_table_nolock(task->signal);
78119 + spin_unlock_bh(&gr_conn_table_lock);
78120 +#endif
78121 + return;
78122 +}
78123 +
78124 +void
78125 +gr_attach_curr_ip(const struct sock *sk)
78126 +{
78127 +#ifdef CONFIG_GRKERNSEC
78128 + struct signal_struct *p, *set;
78129 + const struct inet_sock *inet = inet_sk(sk);
78130 +
78131 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
78132 + return;
78133 +
78134 + set = current->signal;
78135 +
78136 + spin_lock_bh(&gr_conn_table_lock);
78137 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
78138 + inet->inet_dport, inet->inet_sport);
78139 + if (unlikely(p != NULL)) {
78140 + set->curr_ip = p->curr_ip;
78141 + set->used_accept = 1;
78142 + gr_del_task_from_ip_table_nolock(p);
78143 + spin_unlock_bh(&gr_conn_table_lock);
78144 + return;
78145 + }
78146 + spin_unlock_bh(&gr_conn_table_lock);
78147 +
78148 + set->curr_ip = inet->inet_daddr;
78149 + set->used_accept = 1;
78150 +#endif
78151 + return;
78152 +}
78153 +
78154 +int
78155 +gr_handle_sock_all(const int family, const int type, const int protocol)
78156 +{
78157 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
78158 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
78159 + (family != AF_UNIX)) {
78160 + if (family == AF_INET)
78161 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
78162 + else
78163 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
78164 + return -EACCES;
78165 + }
78166 +#endif
78167 + return 0;
78168 +}
78169 +
78170 +int
78171 +gr_handle_sock_server(const struct sockaddr *sck)
78172 +{
78173 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78174 + if (grsec_enable_socket_server &&
78175 + in_group_p(grsec_socket_server_gid) &&
78176 + sck && (sck->sa_family != AF_UNIX) &&
78177 + (sck->sa_family != AF_LOCAL)) {
78178 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78179 + return -EACCES;
78180 + }
78181 +#endif
78182 + return 0;
78183 +}
78184 +
78185 +int
78186 +gr_handle_sock_server_other(const struct sock *sck)
78187 +{
78188 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78189 + if (grsec_enable_socket_server &&
78190 + in_group_p(grsec_socket_server_gid) &&
78191 + sck && (sck->sk_family != AF_UNIX) &&
78192 + (sck->sk_family != AF_LOCAL)) {
78193 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78194 + return -EACCES;
78195 + }
78196 +#endif
78197 + return 0;
78198 +}
78199 +
78200 +int
78201 +gr_handle_sock_client(const struct sockaddr *sck)
78202 +{
78203 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
78204 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
78205 + sck && (sck->sa_family != AF_UNIX) &&
78206 + (sck->sa_family != AF_LOCAL)) {
78207 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
78208 + return -EACCES;
78209 + }
78210 +#endif
78211 + return 0;
78212 +}
78213 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
78214 new file mode 100644
78215 index 0000000..8159888
78216 --- /dev/null
78217 +++ b/grsecurity/grsec_sysctl.c
78218 @@ -0,0 +1,479 @@
78219 +#include <linux/kernel.h>
78220 +#include <linux/sched.h>
78221 +#include <linux/sysctl.h>
78222 +#include <linux/grsecurity.h>
78223 +#include <linux/grinternal.h>
78224 +
78225 +int
78226 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
78227 +{
78228 +#ifdef CONFIG_GRKERNSEC_SYSCTL
78229 + if (dirname == NULL || name == NULL)
78230 + return 0;
78231 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
78232 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
78233 + return -EACCES;
78234 + }
78235 +#endif
78236 + return 0;
78237 +}
78238 +
78239 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
78240 +static int __maybe_unused __read_only one = 1;
78241 +#endif
78242 +
78243 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
78244 + defined(CONFIG_GRKERNSEC_DENYUSB)
78245 +struct ctl_table grsecurity_table[] = {
78246 +#ifdef CONFIG_GRKERNSEC_SYSCTL
78247 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
78248 +#ifdef CONFIG_GRKERNSEC_IO
78249 + {
78250 + .procname = "disable_priv_io",
78251 + .data = &grsec_disable_privio,
78252 + .maxlen = sizeof(int),
78253 + .mode = 0600,
78254 + .proc_handler = &proc_dointvec,
78255 + },
78256 +#endif
78257 +#endif
78258 +#ifdef CONFIG_GRKERNSEC_LINK
78259 + {
78260 + .procname = "linking_restrictions",
78261 + .data = &grsec_enable_link,
78262 + .maxlen = sizeof(int),
78263 + .mode = 0600,
78264 + .proc_handler = &proc_dointvec,
78265 + },
78266 +#endif
78267 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
78268 + {
78269 + .procname = "enforce_symlinksifowner",
78270 + .data = &grsec_enable_symlinkown,
78271 + .maxlen = sizeof(int),
78272 + .mode = 0600,
78273 + .proc_handler = &proc_dointvec,
78274 + },
78275 + {
78276 + .procname = "symlinkown_gid",
78277 + .data = &grsec_symlinkown_gid,
78278 + .maxlen = sizeof(int),
78279 + .mode = 0600,
78280 + .proc_handler = &proc_dointvec,
78281 + },
78282 +#endif
78283 +#ifdef CONFIG_GRKERNSEC_BRUTE
78284 + {
78285 + .procname = "deter_bruteforce",
78286 + .data = &grsec_enable_brute,
78287 + .maxlen = sizeof(int),
78288 + .mode = 0600,
78289 + .proc_handler = &proc_dointvec,
78290 + },
78291 +#endif
78292 +#ifdef CONFIG_GRKERNSEC_FIFO
78293 + {
78294 + .procname = "fifo_restrictions",
78295 + .data = &grsec_enable_fifo,
78296 + .maxlen = sizeof(int),
78297 + .mode = 0600,
78298 + .proc_handler = &proc_dointvec,
78299 + },
78300 +#endif
78301 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78302 + {
78303 + .procname = "ptrace_readexec",
78304 + .data = &grsec_enable_ptrace_readexec,
78305 + .maxlen = sizeof(int),
78306 + .mode = 0600,
78307 + .proc_handler = &proc_dointvec,
78308 + },
78309 +#endif
78310 +#ifdef CONFIG_GRKERNSEC_SETXID
78311 + {
78312 + .procname = "consistent_setxid",
78313 + .data = &grsec_enable_setxid,
78314 + .maxlen = sizeof(int),
78315 + .mode = 0600,
78316 + .proc_handler = &proc_dointvec,
78317 + },
78318 +#endif
78319 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78320 + {
78321 + .procname = "ip_blackhole",
78322 + .data = &grsec_enable_blackhole,
78323 + .maxlen = sizeof(int),
78324 + .mode = 0600,
78325 + .proc_handler = &proc_dointvec,
78326 + },
78327 + {
78328 + .procname = "lastack_retries",
78329 + .data = &grsec_lastack_retries,
78330 + .maxlen = sizeof(int),
78331 + .mode = 0600,
78332 + .proc_handler = &proc_dointvec,
78333 + },
78334 +#endif
78335 +#ifdef CONFIG_GRKERNSEC_EXECLOG
78336 + {
78337 + .procname = "exec_logging",
78338 + .data = &grsec_enable_execlog,
78339 + .maxlen = sizeof(int),
78340 + .mode = 0600,
78341 + .proc_handler = &proc_dointvec,
78342 + },
78343 +#endif
78344 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78345 + {
78346 + .procname = "rwxmap_logging",
78347 + .data = &grsec_enable_log_rwxmaps,
78348 + .maxlen = sizeof(int),
78349 + .mode = 0600,
78350 + .proc_handler = &proc_dointvec,
78351 + },
78352 +#endif
78353 +#ifdef CONFIG_GRKERNSEC_SIGNAL
78354 + {
78355 + .procname = "signal_logging",
78356 + .data = &grsec_enable_signal,
78357 + .maxlen = sizeof(int),
78358 + .mode = 0600,
78359 + .proc_handler = &proc_dointvec,
78360 + },
78361 +#endif
78362 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
78363 + {
78364 + .procname = "forkfail_logging",
78365 + .data = &grsec_enable_forkfail,
78366 + .maxlen = sizeof(int),
78367 + .mode = 0600,
78368 + .proc_handler = &proc_dointvec,
78369 + },
78370 +#endif
78371 +#ifdef CONFIG_GRKERNSEC_TIME
78372 + {
78373 + .procname = "timechange_logging",
78374 + .data = &grsec_enable_time,
78375 + .maxlen = sizeof(int),
78376 + .mode = 0600,
78377 + .proc_handler = &proc_dointvec,
78378 + },
78379 +#endif
78380 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
78381 + {
78382 + .procname = "chroot_deny_shmat",
78383 + .data = &grsec_enable_chroot_shmat,
78384 + .maxlen = sizeof(int),
78385 + .mode = 0600,
78386 + .proc_handler = &proc_dointvec,
78387 + },
78388 +#endif
78389 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
78390 + {
78391 + .procname = "chroot_deny_unix",
78392 + .data = &grsec_enable_chroot_unix,
78393 + .maxlen = sizeof(int),
78394 + .mode = 0600,
78395 + .proc_handler = &proc_dointvec,
78396 + },
78397 +#endif
78398 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
78399 + {
78400 + .procname = "chroot_deny_mount",
78401 + .data = &grsec_enable_chroot_mount,
78402 + .maxlen = sizeof(int),
78403 + .mode = 0600,
78404 + .proc_handler = &proc_dointvec,
78405 + },
78406 +#endif
78407 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
78408 + {
78409 + .procname = "chroot_deny_fchdir",
78410 + .data = &grsec_enable_chroot_fchdir,
78411 + .maxlen = sizeof(int),
78412 + .mode = 0600,
78413 + .proc_handler = &proc_dointvec,
78414 + },
78415 +#endif
78416 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
78417 + {
78418 + .procname = "chroot_deny_chroot",
78419 + .data = &grsec_enable_chroot_double,
78420 + .maxlen = sizeof(int),
78421 + .mode = 0600,
78422 + .proc_handler = &proc_dointvec,
78423 + },
78424 +#endif
78425 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
78426 + {
78427 + .procname = "chroot_deny_pivot",
78428 + .data = &grsec_enable_chroot_pivot,
78429 + .maxlen = sizeof(int),
78430 + .mode = 0600,
78431 + .proc_handler = &proc_dointvec,
78432 + },
78433 +#endif
78434 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
78435 + {
78436 + .procname = "chroot_enforce_chdir",
78437 + .data = &grsec_enable_chroot_chdir,
78438 + .maxlen = sizeof(int),
78439 + .mode = 0600,
78440 + .proc_handler = &proc_dointvec,
78441 + },
78442 +#endif
78443 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
78444 + {
78445 + .procname = "chroot_deny_chmod",
78446 + .data = &grsec_enable_chroot_chmod,
78447 + .maxlen = sizeof(int),
78448 + .mode = 0600,
78449 + .proc_handler = &proc_dointvec,
78450 + },
78451 +#endif
78452 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
78453 + {
78454 + .procname = "chroot_deny_mknod",
78455 + .data = &grsec_enable_chroot_mknod,
78456 + .maxlen = sizeof(int),
78457 + .mode = 0600,
78458 + .proc_handler = &proc_dointvec,
78459 + },
78460 +#endif
78461 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
78462 + {
78463 + .procname = "chroot_restrict_nice",
78464 + .data = &grsec_enable_chroot_nice,
78465 + .maxlen = sizeof(int),
78466 + .mode = 0600,
78467 + .proc_handler = &proc_dointvec,
78468 + },
78469 +#endif
78470 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
78471 + {
78472 + .procname = "chroot_execlog",
78473 + .data = &grsec_enable_chroot_execlog,
78474 + .maxlen = sizeof(int),
78475 + .mode = 0600,
78476 + .proc_handler = &proc_dointvec,
78477 + },
78478 +#endif
78479 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
78480 + {
78481 + .procname = "chroot_caps",
78482 + .data = &grsec_enable_chroot_caps,
78483 + .maxlen = sizeof(int),
78484 + .mode = 0600,
78485 + .proc_handler = &proc_dointvec,
78486 + },
78487 +#endif
78488 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
78489 + {
78490 + .procname = "chroot_deny_sysctl",
78491 + .data = &grsec_enable_chroot_sysctl,
78492 + .maxlen = sizeof(int),
78493 + .mode = 0600,
78494 + .proc_handler = &proc_dointvec,
78495 + },
78496 +#endif
78497 +#ifdef CONFIG_GRKERNSEC_TPE
78498 + {
78499 + .procname = "tpe",
78500 + .data = &grsec_enable_tpe,
78501 + .maxlen = sizeof(int),
78502 + .mode = 0600,
78503 + .proc_handler = &proc_dointvec,
78504 + },
78505 + {
78506 + .procname = "tpe_gid",
78507 + .data = &grsec_tpe_gid,
78508 + .maxlen = sizeof(int),
78509 + .mode = 0600,
78510 + .proc_handler = &proc_dointvec,
78511 + },
78512 +#endif
78513 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
78514 + {
78515 + .procname = "tpe_invert",
78516 + .data = &grsec_enable_tpe_invert,
78517 + .maxlen = sizeof(int),
78518 + .mode = 0600,
78519 + .proc_handler = &proc_dointvec,
78520 + },
78521 +#endif
78522 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
78523 + {
78524 + .procname = "tpe_restrict_all",
78525 + .data = &grsec_enable_tpe_all,
78526 + .maxlen = sizeof(int),
78527 + .mode = 0600,
78528 + .proc_handler = &proc_dointvec,
78529 + },
78530 +#endif
78531 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
78532 + {
78533 + .procname = "socket_all",
78534 + .data = &grsec_enable_socket_all,
78535 + .maxlen = sizeof(int),
78536 + .mode = 0600,
78537 + .proc_handler = &proc_dointvec,
78538 + },
78539 + {
78540 + .procname = "socket_all_gid",
78541 + .data = &grsec_socket_all_gid,
78542 + .maxlen = sizeof(int),
78543 + .mode = 0600,
78544 + .proc_handler = &proc_dointvec,
78545 + },
78546 +#endif
78547 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
78548 + {
78549 + .procname = "socket_client",
78550 + .data = &grsec_enable_socket_client,
78551 + .maxlen = sizeof(int),
78552 + .mode = 0600,
78553 + .proc_handler = &proc_dointvec,
78554 + },
78555 + {
78556 + .procname = "socket_client_gid",
78557 + .data = &grsec_socket_client_gid,
78558 + .maxlen = sizeof(int),
78559 + .mode = 0600,
78560 + .proc_handler = &proc_dointvec,
78561 + },
78562 +#endif
78563 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78564 + {
78565 + .procname = "socket_server",
78566 + .data = &grsec_enable_socket_server,
78567 + .maxlen = sizeof(int),
78568 + .mode = 0600,
78569 + .proc_handler = &proc_dointvec,
78570 + },
78571 + {
78572 + .procname = "socket_server_gid",
78573 + .data = &grsec_socket_server_gid,
78574 + .maxlen = sizeof(int),
78575 + .mode = 0600,
78576 + .proc_handler = &proc_dointvec,
78577 + },
78578 +#endif
78579 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
78580 + {
78581 + .procname = "audit_group",
78582 + .data = &grsec_enable_group,
78583 + .maxlen = sizeof(int),
78584 + .mode = 0600,
78585 + .proc_handler = &proc_dointvec,
78586 + },
78587 + {
78588 + .procname = "audit_gid",
78589 + .data = &grsec_audit_gid,
78590 + .maxlen = sizeof(int),
78591 + .mode = 0600,
78592 + .proc_handler = &proc_dointvec,
78593 + },
78594 +#endif
78595 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
78596 + {
78597 + .procname = "audit_chdir",
78598 + .data = &grsec_enable_chdir,
78599 + .maxlen = sizeof(int),
78600 + .mode = 0600,
78601 + .proc_handler = &proc_dointvec,
78602 + },
78603 +#endif
78604 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78605 + {
78606 + .procname = "audit_mount",
78607 + .data = &grsec_enable_mount,
78608 + .maxlen = sizeof(int),
78609 + .mode = 0600,
78610 + .proc_handler = &proc_dointvec,
78611 + },
78612 +#endif
78613 +#ifdef CONFIG_GRKERNSEC_DMESG
78614 + {
78615 + .procname = "dmesg",
78616 + .data = &grsec_enable_dmesg,
78617 + .maxlen = sizeof(int),
78618 + .mode = 0600,
78619 + .proc_handler = &proc_dointvec,
78620 + },
78621 +#endif
78622 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
78623 + {
78624 + .procname = "chroot_findtask",
78625 + .data = &grsec_enable_chroot_findtask,
78626 + .maxlen = sizeof(int),
78627 + .mode = 0600,
78628 + .proc_handler = &proc_dointvec,
78629 + },
78630 +#endif
78631 +#ifdef CONFIG_GRKERNSEC_RESLOG
78632 + {
78633 + .procname = "resource_logging",
78634 + .data = &grsec_resource_logging,
78635 + .maxlen = sizeof(int),
78636 + .mode = 0600,
78637 + .proc_handler = &proc_dointvec,
78638 + },
78639 +#endif
78640 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
78641 + {
78642 + .procname = "audit_ptrace",
78643 + .data = &grsec_enable_audit_ptrace,
78644 + .maxlen = sizeof(int),
78645 + .mode = 0600,
78646 + .proc_handler = &proc_dointvec,
78647 + },
78648 +#endif
78649 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
78650 + {
78651 + .procname = "harden_ptrace",
78652 + .data = &grsec_enable_harden_ptrace,
78653 + .maxlen = sizeof(int),
78654 + .mode = 0600,
78655 + .proc_handler = &proc_dointvec,
78656 + },
78657 +#endif
78658 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
78659 + {
78660 + .procname = "harden_ipc",
78661 + .data = &grsec_enable_harden_ipc,
78662 + .maxlen = sizeof(int),
78663 + .mode = 0600,
78664 + .proc_handler = &proc_dointvec,
78665 + },
78666 +#endif
78667 + {
78668 + .procname = "grsec_lock",
78669 + .data = &grsec_lock,
78670 + .maxlen = sizeof(int),
78671 + .mode = 0600,
78672 + .proc_handler = &proc_dointvec,
78673 + },
78674 +#endif
78675 +#ifdef CONFIG_GRKERNSEC_ROFS
78676 + {
78677 + .procname = "romount_protect",
78678 + .data = &grsec_enable_rofs,
78679 + .maxlen = sizeof(int),
78680 + .mode = 0600,
78681 + .proc_handler = &proc_dointvec_minmax,
78682 + .extra1 = &one,
78683 + .extra2 = &one,
78684 + },
78685 +#endif
78686 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
78687 + {
78688 + .procname = "deny_new_usb",
78689 + .data = &grsec_deny_new_usb,
78690 + .maxlen = sizeof(int),
78691 + .mode = 0600,
78692 + .proc_handler = &proc_dointvec,
78693 + },
78694 +#endif
78695 + { }
78696 +};
78697 +#endif
78698 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
78699 new file mode 100644
78700 index 0000000..61b514e
78701 --- /dev/null
78702 +++ b/grsecurity/grsec_time.c
78703 @@ -0,0 +1,16 @@
78704 +#include <linux/kernel.h>
78705 +#include <linux/sched.h>
78706 +#include <linux/grinternal.h>
78707 +#include <linux/module.h>
78708 +
78709 +void
78710 +gr_log_timechange(void)
78711 +{
78712 +#ifdef CONFIG_GRKERNSEC_TIME
78713 + if (grsec_enable_time)
78714 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
78715 +#endif
78716 + return;
78717 +}
78718 +
78719 +EXPORT_SYMBOL_GPL(gr_log_timechange);
78720 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
78721 new file mode 100644
78722 index 0000000..d1953de
78723 --- /dev/null
78724 +++ b/grsecurity/grsec_tpe.c
78725 @@ -0,0 +1,78 @@
78726 +#include <linux/kernel.h>
78727 +#include <linux/sched.h>
78728 +#include <linux/file.h>
78729 +#include <linux/fs.h>
78730 +#include <linux/grinternal.h>
78731 +
78732 +extern int gr_acl_tpe_check(void);
78733 +
78734 +int
78735 +gr_tpe_allow(const struct file *file)
78736 +{
78737 +#ifdef CONFIG_GRKERNSEC
78738 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
78739 + struct inode *file_inode = file->f_path.dentry->d_inode;
78740 + const struct cred *cred = current_cred();
78741 + char *msg = NULL;
78742 + char *msg2 = NULL;
78743 +
78744 + // never restrict root
78745 + if (gr_is_global_root(cred->uid))
78746 + return 1;
78747 +
78748 + if (grsec_enable_tpe) {
78749 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
78750 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
78751 + msg = "not being in trusted group";
78752 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
78753 + msg = "being in untrusted group";
78754 +#else
78755 + if (in_group_p(grsec_tpe_gid))
78756 + msg = "being in untrusted group";
78757 +#endif
78758 + }
78759 + if (!msg && gr_acl_tpe_check())
78760 + msg = "being in untrusted role";
78761 +
78762 + // not in any affected group/role
78763 + if (!msg)
78764 + goto next_check;
78765 +
78766 + if (gr_is_global_nonroot(inode->i_uid))
78767 + msg2 = "file in non-root-owned directory";
78768 + else if (inode->i_mode & S_IWOTH)
78769 + msg2 = "file in world-writable directory";
78770 + else if (inode->i_mode & S_IWGRP)
78771 + msg2 = "file in group-writable directory";
78772 + else if (file_inode->i_mode & S_IWOTH)
78773 + msg2 = "file is world-writable";
78774 +
78775 + if (msg && msg2) {
78776 + char fullmsg[70] = {0};
78777 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
78778 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
78779 + return 0;
78780 + }
78781 + msg = NULL;
78782 +next_check:
78783 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
78784 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
78785 + return 1;
78786 +
78787 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
78788 + msg = "directory not owned by user";
78789 + else if (inode->i_mode & S_IWOTH)
78790 + msg = "file in world-writable directory";
78791 + else if (inode->i_mode & S_IWGRP)
78792 + msg = "file in group-writable directory";
78793 + else if (file_inode->i_mode & S_IWOTH)
78794 + msg = "file is world-writable";
78795 +
78796 + if (msg) {
78797 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
78798 + return 0;
78799 + }
78800 +#endif
78801 +#endif
78802 + return 1;
78803 +}
78804 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
78805 new file mode 100644
78806 index 0000000..ae02d8e
78807 --- /dev/null
78808 +++ b/grsecurity/grsec_usb.c
78809 @@ -0,0 +1,15 @@
78810 +#include <linux/kernel.h>
78811 +#include <linux/grinternal.h>
78812 +#include <linux/module.h>
78813 +
78814 +int gr_handle_new_usb(void)
78815 +{
78816 +#ifdef CONFIG_GRKERNSEC_DENYUSB
78817 + if (grsec_deny_new_usb) {
78818 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
78819 + return 1;
78820 + }
78821 +#endif
78822 + return 0;
78823 +}
78824 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
78825 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
78826 new file mode 100644
78827 index 0000000..158b330
78828 --- /dev/null
78829 +++ b/grsecurity/grsum.c
78830 @@ -0,0 +1,64 @@
78831 +#include <linux/err.h>
78832 +#include <linux/kernel.h>
78833 +#include <linux/sched.h>
78834 +#include <linux/mm.h>
78835 +#include <linux/scatterlist.h>
78836 +#include <linux/crypto.h>
78837 +#include <linux/gracl.h>
78838 +
78839 +
78840 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
78841 +#error "crypto and sha256 must be built into the kernel"
78842 +#endif
78843 +
78844 +int
78845 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
78846 +{
78847 + struct crypto_hash *tfm;
78848 + struct hash_desc desc;
78849 + struct scatterlist sg[2];
78850 + unsigned char temp_sum[GR_SHA_LEN] __attribute__((aligned(__alignof__(unsigned long))));
78851 + unsigned long *tmpsumptr = (unsigned long *)temp_sum;
78852 + unsigned long *sumptr = (unsigned long *)sum;
78853 + int cryptres;
78854 + int retval = 1;
78855 + volatile int mismatched = 0;
78856 + volatile int dummy = 0;
78857 + unsigned int i;
78858 +
78859 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
78860 + if (IS_ERR(tfm)) {
78861 + /* should never happen, since sha256 should be built in */
78862 + memset(entry->pw, 0, GR_PW_LEN);
78863 + return 1;
78864 + }
78865 +
78866 + sg_init_table(sg, 2);
78867 + sg_set_buf(&sg[0], salt, GR_SALT_LEN);
78868 + sg_set_buf(&sg[1], entry->pw, strlen(entry->pw));
78869 +
78870 + desc.tfm = tfm;
78871 + desc.flags = 0;
78872 +
78873 + cryptres = crypto_hash_digest(&desc, sg, GR_SALT_LEN + strlen(entry->pw),
78874 + temp_sum);
78875 +
78876 + memset(entry->pw, 0, GR_PW_LEN);
78877 +
78878 + if (cryptres)
78879 + goto out;
78880 +
78881 + for (i = 0; i < GR_SHA_LEN/sizeof(tmpsumptr[0]); i++)
78882 + if (sumptr[i] != tmpsumptr[i])
78883 + mismatched = 1;
78884 + else
78885 + dummy = 1; // waste a cycle
78886 +
78887 + if (!mismatched)
78888 + retval = dummy - 1;
78889 +
78890 +out:
78891 + crypto_free_hash(tfm);
78892 +
78893 + return retval;
78894 +}
78895 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
78896 index 77ff547..181834f 100644
78897 --- a/include/asm-generic/4level-fixup.h
78898 +++ b/include/asm-generic/4level-fixup.h
78899 @@ -13,8 +13,10 @@
78900 #define pmd_alloc(mm, pud, address) \
78901 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
78902 NULL: pmd_offset(pud, address))
78903 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
78904
78905 #define pud_alloc(mm, pgd, address) (pgd)
78906 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
78907 #define pud_offset(pgd, start) (pgd)
78908 #define pud_none(pud) 0
78909 #define pud_bad(pud) 0
78910 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
78911 index b7babf0..1e4b4f1 100644
78912 --- a/include/asm-generic/atomic-long.h
78913 +++ b/include/asm-generic/atomic-long.h
78914 @@ -22,6 +22,12 @@
78915
78916 typedef atomic64_t atomic_long_t;
78917
78918 +#ifdef CONFIG_PAX_REFCOUNT
78919 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
78920 +#else
78921 +typedef atomic64_t atomic_long_unchecked_t;
78922 +#endif
78923 +
78924 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
78925
78926 static inline long atomic_long_read(atomic_long_t *l)
78927 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
78928 return (long)atomic64_read(v);
78929 }
78930
78931 +#ifdef CONFIG_PAX_REFCOUNT
78932 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
78933 +{
78934 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
78935 +
78936 + return (long)atomic64_read_unchecked(v);
78937 +}
78938 +#endif
78939 +
78940 static inline void atomic_long_set(atomic_long_t *l, long i)
78941 {
78942 atomic64_t *v = (atomic64_t *)l;
78943 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
78944 atomic64_set(v, i);
78945 }
78946
78947 +#ifdef CONFIG_PAX_REFCOUNT
78948 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
78949 +{
78950 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
78951 +
78952 + atomic64_set_unchecked(v, i);
78953 +}
78954 +#endif
78955 +
78956 static inline void atomic_long_inc(atomic_long_t *l)
78957 {
78958 atomic64_t *v = (atomic64_t *)l;
78959 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
78960 atomic64_inc(v);
78961 }
78962
78963 +#ifdef CONFIG_PAX_REFCOUNT
78964 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
78965 +{
78966 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
78967 +
78968 + atomic64_inc_unchecked(v);
78969 +}
78970 +#endif
78971 +
78972 static inline void atomic_long_dec(atomic_long_t *l)
78973 {
78974 atomic64_t *v = (atomic64_t *)l;
78975 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
78976 atomic64_dec(v);
78977 }
78978
78979 +#ifdef CONFIG_PAX_REFCOUNT
78980 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
78981 +{
78982 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
78983 +
78984 + atomic64_dec_unchecked(v);
78985 +}
78986 +#endif
78987 +
78988 static inline void atomic_long_add(long i, atomic_long_t *l)
78989 {
78990 atomic64_t *v = (atomic64_t *)l;
78991 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
78992 atomic64_add(i, v);
78993 }
78994
78995 +#ifdef CONFIG_PAX_REFCOUNT
78996 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
78997 +{
78998 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
78999 +
79000 + atomic64_add_unchecked(i, v);
79001 +}
79002 +#endif
79003 +
79004 static inline void atomic_long_sub(long i, atomic_long_t *l)
79005 {
79006 atomic64_t *v = (atomic64_t *)l;
79007 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79008 atomic64_sub(i, v);
79009 }
79010
79011 +#ifdef CONFIG_PAX_REFCOUNT
79012 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79013 +{
79014 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79015 +
79016 + atomic64_sub_unchecked(i, v);
79017 +}
79018 +#endif
79019 +
79020 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79021 {
79022 atomic64_t *v = (atomic64_t *)l;
79023 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
79024 return atomic64_add_negative(i, v);
79025 }
79026
79027 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
79028 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
79029 {
79030 atomic64_t *v = (atomic64_t *)l;
79031
79032 return (long)atomic64_add_return(i, v);
79033 }
79034
79035 +#ifdef CONFIG_PAX_REFCOUNT
79036 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79037 +{
79038 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79039 +
79040 + return (long)atomic64_add_return_unchecked(i, v);
79041 +}
79042 +#endif
79043 +
79044 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79045 {
79046 atomic64_t *v = (atomic64_t *)l;
79047 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79048 return (long)atomic64_inc_return(v);
79049 }
79050
79051 +#ifdef CONFIG_PAX_REFCOUNT
79052 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79053 +{
79054 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79055 +
79056 + return (long)atomic64_inc_return_unchecked(v);
79057 +}
79058 +#endif
79059 +
79060 static inline long atomic_long_dec_return(atomic_long_t *l)
79061 {
79062 atomic64_t *v = (atomic64_t *)l;
79063 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
79064
79065 typedef atomic_t atomic_long_t;
79066
79067 +#ifdef CONFIG_PAX_REFCOUNT
79068 +typedef atomic_unchecked_t atomic_long_unchecked_t;
79069 +#else
79070 +typedef atomic_t atomic_long_unchecked_t;
79071 +#endif
79072 +
79073 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
79074 static inline long atomic_long_read(atomic_long_t *l)
79075 {
79076 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79077 return (long)atomic_read(v);
79078 }
79079
79080 +#ifdef CONFIG_PAX_REFCOUNT
79081 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79082 +{
79083 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79084 +
79085 + return (long)atomic_read_unchecked(v);
79086 +}
79087 +#endif
79088 +
79089 static inline void atomic_long_set(atomic_long_t *l, long i)
79090 {
79091 atomic_t *v = (atomic_t *)l;
79092 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79093 atomic_set(v, i);
79094 }
79095
79096 +#ifdef CONFIG_PAX_REFCOUNT
79097 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79098 +{
79099 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79100 +
79101 + atomic_set_unchecked(v, i);
79102 +}
79103 +#endif
79104 +
79105 static inline void atomic_long_inc(atomic_long_t *l)
79106 {
79107 atomic_t *v = (atomic_t *)l;
79108 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79109 atomic_inc(v);
79110 }
79111
79112 +#ifdef CONFIG_PAX_REFCOUNT
79113 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79114 +{
79115 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79116 +
79117 + atomic_inc_unchecked(v);
79118 +}
79119 +#endif
79120 +
79121 static inline void atomic_long_dec(atomic_long_t *l)
79122 {
79123 atomic_t *v = (atomic_t *)l;
79124 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79125 atomic_dec(v);
79126 }
79127
79128 +#ifdef CONFIG_PAX_REFCOUNT
79129 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79130 +{
79131 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79132 +
79133 + atomic_dec_unchecked(v);
79134 +}
79135 +#endif
79136 +
79137 static inline void atomic_long_add(long i, atomic_long_t *l)
79138 {
79139 atomic_t *v = (atomic_t *)l;
79140 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79141 atomic_add(i, v);
79142 }
79143
79144 +#ifdef CONFIG_PAX_REFCOUNT
79145 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79146 +{
79147 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79148 +
79149 + atomic_add_unchecked(i, v);
79150 +}
79151 +#endif
79152 +
79153 static inline void atomic_long_sub(long i, atomic_long_t *l)
79154 {
79155 atomic_t *v = (atomic_t *)l;
79156 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79157 atomic_sub(i, v);
79158 }
79159
79160 +#ifdef CONFIG_PAX_REFCOUNT
79161 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79162 +{
79163 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79164 +
79165 + atomic_sub_unchecked(i, v);
79166 +}
79167 +#endif
79168 +
79169 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79170 {
79171 atomic_t *v = (atomic_t *)l;
79172 @@ -211,13 +349,23 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
79173 return atomic_add_negative(i, v);
79174 }
79175
79176 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
79177 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
79178 {
79179 atomic_t *v = (atomic_t *)l;
79180
79181 return (long)atomic_add_return(i, v);
79182 }
79183
79184 +#ifdef CONFIG_PAX_REFCOUNT
79185 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79186 +{
79187 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79188 +
79189 + return (long)atomic_add_return_unchecked(i, v);
79190 +}
79191 +
79192 +#endif
79193 +
79194 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79195 {
79196 atomic_t *v = (atomic_t *)l;
79197 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79198 return (long)atomic_inc_return(v);
79199 }
79200
79201 +#ifdef CONFIG_PAX_REFCOUNT
79202 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79203 +{
79204 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79205 +
79206 + return (long)atomic_inc_return_unchecked(v);
79207 +}
79208 +#endif
79209 +
79210 static inline long atomic_long_dec_return(atomic_long_t *l)
79211 {
79212 atomic_t *v = (atomic_t *)l;
79213 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
79214
79215 #endif /* BITS_PER_LONG == 64 */
79216
79217 +#ifdef CONFIG_PAX_REFCOUNT
79218 +static inline void pax_refcount_needs_these_functions(void)
79219 +{
79220 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
79221 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
79222 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
79223 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
79224 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
79225 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
79226 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
79227 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
79228 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
79229 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
79230 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
79231 +#ifdef CONFIG_X86
79232 + atomic_clear_mask_unchecked(0, NULL);
79233 + atomic_set_mask_unchecked(0, NULL);
79234 +#endif
79235 +
79236 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
79237 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
79238 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
79239 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
79240 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
79241 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
79242 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
79243 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
79244 +}
79245 +#else
79246 +#define atomic_read_unchecked(v) atomic_read(v)
79247 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
79248 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
79249 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
79250 +#define atomic_inc_unchecked(v) atomic_inc(v)
79251 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
79252 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
79253 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
79254 +#define atomic_dec_unchecked(v) atomic_dec(v)
79255 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
79256 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
79257 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
79258 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
79259 +
79260 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
79261 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
79262 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
79263 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
79264 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
79265 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
79266 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
79267 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
79268 +#endif
79269 +
79270 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
79271 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
79272 index 30ad9c8..c70c170 100644
79273 --- a/include/asm-generic/atomic64.h
79274 +++ b/include/asm-generic/atomic64.h
79275 @@ -16,6 +16,8 @@ typedef struct {
79276 long long counter;
79277 } atomic64_t;
79278
79279 +typedef atomic64_t atomic64_unchecked_t;
79280 +
79281 #define ATOMIC64_INIT(i) { (i) }
79282
79283 extern long long atomic64_read(const atomic64_t *v);
79284 @@ -51,4 +53,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
79285 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
79286 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
79287
79288 +#define atomic64_read_unchecked(v) atomic64_read(v)
79289 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
79290 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
79291 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
79292 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
79293 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
79294 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
79295 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
79296 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
79297 +
79298 #endif /* _ASM_GENERIC_ATOMIC64_H */
79299 diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
79300 index 1402fa8..025a736 100644
79301 --- a/include/asm-generic/barrier.h
79302 +++ b/include/asm-generic/barrier.h
79303 @@ -74,7 +74,7 @@
79304 do { \
79305 compiletime_assert_atomic_type(*p); \
79306 smp_mb(); \
79307 - ACCESS_ONCE(*p) = (v); \
79308 + ACCESS_ONCE_RW(*p) = (v); \
79309 } while (0)
79310
79311 #define smp_load_acquire(p) \
79312 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
79313 index a60a7cc..0fe12f2 100644
79314 --- a/include/asm-generic/bitops/__fls.h
79315 +++ b/include/asm-generic/bitops/__fls.h
79316 @@ -9,7 +9,7 @@
79317 *
79318 * Undefined if no set bit exists, so code should check against 0 first.
79319 */
79320 -static __always_inline unsigned long __fls(unsigned long word)
79321 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
79322 {
79323 int num = BITS_PER_LONG - 1;
79324
79325 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
79326 index 0576d1f..dad6c71 100644
79327 --- a/include/asm-generic/bitops/fls.h
79328 +++ b/include/asm-generic/bitops/fls.h
79329 @@ -9,7 +9,7 @@
79330 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
79331 */
79332
79333 -static __always_inline int fls(int x)
79334 +static __always_inline int __intentional_overflow(-1) fls(int x)
79335 {
79336 int r = 32;
79337
79338 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
79339 index b097cf8..3d40e14 100644
79340 --- a/include/asm-generic/bitops/fls64.h
79341 +++ b/include/asm-generic/bitops/fls64.h
79342 @@ -15,7 +15,7 @@
79343 * at position 64.
79344 */
79345 #if BITS_PER_LONG == 32
79346 -static __always_inline int fls64(__u64 x)
79347 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
79348 {
79349 __u32 h = x >> 32;
79350 if (h)
79351 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
79352 return fls(x);
79353 }
79354 #elif BITS_PER_LONG == 64
79355 -static __always_inline int fls64(__u64 x)
79356 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
79357 {
79358 if (x == 0)
79359 return 0;
79360 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
79361 index 1bfcfe5..e04c5c9 100644
79362 --- a/include/asm-generic/cache.h
79363 +++ b/include/asm-generic/cache.h
79364 @@ -6,7 +6,7 @@
79365 * cache lines need to provide their own cache.h.
79366 */
79367
79368 -#define L1_CACHE_SHIFT 5
79369 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
79370 +#define L1_CACHE_SHIFT 5UL
79371 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
79372
79373 #endif /* __ASM_GENERIC_CACHE_H */
79374 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
79375 index 0d68a1e..b74a761 100644
79376 --- a/include/asm-generic/emergency-restart.h
79377 +++ b/include/asm-generic/emergency-restart.h
79378 @@ -1,7 +1,7 @@
79379 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
79380 #define _ASM_GENERIC_EMERGENCY_RESTART_H
79381
79382 -static inline void machine_emergency_restart(void)
79383 +static inline __noreturn void machine_emergency_restart(void)
79384 {
79385 machine_restart(NULL);
79386 }
79387 diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
79388 index b8fdc57..c6d5a5c 100644
79389 --- a/include/asm-generic/io.h
79390 +++ b/include/asm-generic/io.h
79391 @@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
79392 * These are pretty trivial
79393 */
79394 #ifndef virt_to_phys
79395 -static inline unsigned long virt_to_phys(volatile void *address)
79396 +static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
79397 {
79398 return __pa((unsigned long)address);
79399 }
79400 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
79401 index 90f99c7..00ce236 100644
79402 --- a/include/asm-generic/kmap_types.h
79403 +++ b/include/asm-generic/kmap_types.h
79404 @@ -2,9 +2,9 @@
79405 #define _ASM_GENERIC_KMAP_TYPES_H
79406
79407 #ifdef __WITH_KM_FENCE
79408 -# define KM_TYPE_NR 41
79409 +# define KM_TYPE_NR 42
79410 #else
79411 -# define KM_TYPE_NR 20
79412 +# define KM_TYPE_NR 21
79413 #endif
79414
79415 #endif
79416 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
79417 index 9ceb03b..62b0b8f 100644
79418 --- a/include/asm-generic/local.h
79419 +++ b/include/asm-generic/local.h
79420 @@ -23,24 +23,37 @@ typedef struct
79421 atomic_long_t a;
79422 } local_t;
79423
79424 +typedef struct {
79425 + atomic_long_unchecked_t a;
79426 +} local_unchecked_t;
79427 +
79428 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
79429
79430 #define local_read(l) atomic_long_read(&(l)->a)
79431 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
79432 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
79433 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
79434 #define local_inc(l) atomic_long_inc(&(l)->a)
79435 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
79436 #define local_dec(l) atomic_long_dec(&(l)->a)
79437 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
79438 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
79439 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
79440 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
79441 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
79442
79443 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
79444 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
79445 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
79446 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
79447 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
79448 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
79449 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
79450 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
79451 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
79452
79453 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
79454 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
79455 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
79456 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
79457 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
79458 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
79459 index 725612b..9cc513a 100644
79460 --- a/include/asm-generic/pgtable-nopmd.h
79461 +++ b/include/asm-generic/pgtable-nopmd.h
79462 @@ -1,14 +1,19 @@
79463 #ifndef _PGTABLE_NOPMD_H
79464 #define _PGTABLE_NOPMD_H
79465
79466 -#ifndef __ASSEMBLY__
79467 -
79468 #include <asm-generic/pgtable-nopud.h>
79469
79470 -struct mm_struct;
79471 -
79472 #define __PAGETABLE_PMD_FOLDED
79473
79474 +#define PMD_SHIFT PUD_SHIFT
79475 +#define PTRS_PER_PMD 1
79476 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
79477 +#define PMD_MASK (~(PMD_SIZE-1))
79478 +
79479 +#ifndef __ASSEMBLY__
79480 +
79481 +struct mm_struct;
79482 +
79483 /*
79484 * Having the pmd type consist of a pud gets the size right, and allows
79485 * us to conceptually access the pud entry that this pmd is folded into
79486 @@ -16,11 +21,6 @@ struct mm_struct;
79487 */
79488 typedef struct { pud_t pud; } pmd_t;
79489
79490 -#define PMD_SHIFT PUD_SHIFT
79491 -#define PTRS_PER_PMD 1
79492 -#define PMD_SIZE (1UL << PMD_SHIFT)
79493 -#define PMD_MASK (~(PMD_SIZE-1))
79494 -
79495 /*
79496 * The "pud_xxx()" functions here are trivial for a folded two-level
79497 * setup: the pmd is never bad, and a pmd always exists (as it's folded
79498 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
79499 index 810431d..0ec4804f 100644
79500 --- a/include/asm-generic/pgtable-nopud.h
79501 +++ b/include/asm-generic/pgtable-nopud.h
79502 @@ -1,10 +1,15 @@
79503 #ifndef _PGTABLE_NOPUD_H
79504 #define _PGTABLE_NOPUD_H
79505
79506 -#ifndef __ASSEMBLY__
79507 -
79508 #define __PAGETABLE_PUD_FOLDED
79509
79510 +#define PUD_SHIFT PGDIR_SHIFT
79511 +#define PTRS_PER_PUD 1
79512 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
79513 +#define PUD_MASK (~(PUD_SIZE-1))
79514 +
79515 +#ifndef __ASSEMBLY__
79516 +
79517 /*
79518 * Having the pud type consist of a pgd gets the size right, and allows
79519 * us to conceptually access the pgd entry that this pud is folded into
79520 @@ -12,11 +17,6 @@
79521 */
79522 typedef struct { pgd_t pgd; } pud_t;
79523
79524 -#define PUD_SHIFT PGDIR_SHIFT
79525 -#define PTRS_PER_PUD 1
79526 -#define PUD_SIZE (1UL << PUD_SHIFT)
79527 -#define PUD_MASK (~(PUD_SIZE-1))
79528 -
79529 /*
79530 * The "pgd_xxx()" functions here are trivial for a folded two-level
79531 * setup: the pud is never bad, and a pud always exists (as it's folded
79532 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
79533 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
79534
79535 #define pgd_populate(mm, pgd, pud) do { } while (0)
79536 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
79537 /*
79538 * (puds are folded into pgds so this doesn't get actually called,
79539 * but the define is needed for a generic inline function.)
79540 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
79541 index 752e30d..87f172d 100644
79542 --- a/include/asm-generic/pgtable.h
79543 +++ b/include/asm-generic/pgtable.h
79544 @@ -828,6 +828,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
79545 }
79546 #endif /* CONFIG_NUMA_BALANCING */
79547
79548 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
79549 +#ifdef CONFIG_PAX_KERNEXEC
79550 +#error KERNEXEC requires pax_open_kernel
79551 +#else
79552 +static inline unsigned long pax_open_kernel(void) { return 0; }
79553 +#endif
79554 +#endif
79555 +
79556 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
79557 +#ifdef CONFIG_PAX_KERNEXEC
79558 +#error KERNEXEC requires pax_close_kernel
79559 +#else
79560 +static inline unsigned long pax_close_kernel(void) { return 0; }
79561 +#endif
79562 +#endif
79563 +
79564 #endif /* CONFIG_MMU */
79565
79566 #endif /* !__ASSEMBLY__ */
79567 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
79568 index 72d8803..cb9749c 100644
79569 --- a/include/asm-generic/uaccess.h
79570 +++ b/include/asm-generic/uaccess.h
79571 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
79572 return __clear_user(to, n);
79573 }
79574
79575 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
79576 +#ifdef CONFIG_PAX_MEMORY_UDEREF
79577 +#error UDEREF requires pax_open_userland
79578 +#else
79579 +static inline unsigned long pax_open_userland(void) { return 0; }
79580 +#endif
79581 +#endif
79582 +
79583 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
79584 +#ifdef CONFIG_PAX_MEMORY_UDEREF
79585 +#error UDEREF requires pax_close_userland
79586 +#else
79587 +static inline unsigned long pax_close_userland(void) { return 0; }
79588 +#endif
79589 +#endif
79590 +
79591 #endif /* __ASM_GENERIC_UACCESS_H */
79592 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
79593 index aa70cbd..fd72c7a 100644
79594 --- a/include/asm-generic/vmlinux.lds.h
79595 +++ b/include/asm-generic/vmlinux.lds.h
79596 @@ -233,6 +233,7 @@
79597 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
79598 VMLINUX_SYMBOL(__start_rodata) = .; \
79599 *(.rodata) *(.rodata.*) \
79600 + *(.data..read_only) \
79601 *(__vermagic) /* Kernel version magic */ \
79602 . = ALIGN(8); \
79603 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
79604 @@ -724,17 +725,18 @@
79605 * section in the linker script will go there too. @phdr should have
79606 * a leading colon.
79607 *
79608 - * Note that this macros defines __per_cpu_load as an absolute symbol.
79609 + * Note that this macros defines per_cpu_load as an absolute symbol.
79610 * If there is no need to put the percpu section at a predetermined
79611 * address, use PERCPU_SECTION.
79612 */
79613 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
79614 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
79615 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
79616 + per_cpu_load = .; \
79617 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
79618 - LOAD_OFFSET) { \
79619 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
79620 PERCPU_INPUT(cacheline) \
79621 } phdr \
79622 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
79623 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
79624
79625 /**
79626 * PERCPU_SECTION - define output section for percpu area, simple version
79627 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
79628 index 623a59c..1e79ab9 100644
79629 --- a/include/crypto/algapi.h
79630 +++ b/include/crypto/algapi.h
79631 @@ -34,7 +34,7 @@ struct crypto_type {
79632 unsigned int maskclear;
79633 unsigned int maskset;
79634 unsigned int tfmsize;
79635 -};
79636 +} __do_const;
79637
79638 struct crypto_instance {
79639 struct crypto_alg alg;
79640 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
79641 index 53ed876..5bb09be 100644
79642 --- a/include/drm/drmP.h
79643 +++ b/include/drm/drmP.h
79644 @@ -59,6 +59,7 @@
79645
79646 #include <asm/mman.h>
79647 #include <asm/pgalloc.h>
79648 +#include <asm/local.h>
79649 #include <asm/uaccess.h>
79650
79651 #include <uapi/drm/drm.h>
79652 @@ -223,10 +224,12 @@ void drm_err(const char *func, const char *format, ...);
79653 * \param cmd command.
79654 * \param arg argument.
79655 */
79656 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
79657 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
79658 + struct drm_file *file_priv);
79659 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
79660 struct drm_file *file_priv);
79661
79662 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
79663 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
79664 unsigned long arg);
79665
79666 #define DRM_IOCTL_NR(n) _IOC_NR(n)
79667 @@ -242,10 +245,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
79668 struct drm_ioctl_desc {
79669 unsigned int cmd;
79670 int flags;
79671 - drm_ioctl_t *func;
79672 + drm_ioctl_t func;
79673 unsigned int cmd_drv;
79674 const char *name;
79675 -};
79676 +} __do_const;
79677
79678 /**
79679 * Creates a driver or general drm_ioctl_desc array entry for the given
79680 @@ -629,7 +632,8 @@ struct drm_info_list {
79681 int (*show)(struct seq_file*, void*); /** show callback */
79682 u32 driver_features; /**< Required driver features for this entry */
79683 void *data;
79684 -};
79685 +} __do_const;
79686 +typedef struct drm_info_list __no_const drm_info_list_no_const;
79687
79688 /**
79689 * debugfs node structure. This structure represents a debugfs file.
79690 @@ -713,7 +717,7 @@ struct drm_device {
79691
79692 /** \name Usage Counters */
79693 /*@{ */
79694 - int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
79695 + local_t open_count; /**< Outstanding files open, protected by drm_global_mutex. */
79696 spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
79697 int buf_use; /**< Buffers in use -- cannot alloc */
79698 atomic_t buf_alloc; /**< Buffer allocation in progress */
79699 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
79700 index a3d75fe..6802f9c 100644
79701 --- a/include/drm/drm_crtc_helper.h
79702 +++ b/include/drm/drm_crtc_helper.h
79703 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
79704 struct drm_connector *connector);
79705 /* disable encoder when not in use - more explicit than dpms off */
79706 void (*disable)(struct drm_encoder *encoder);
79707 -};
79708 +} __no_const;
79709
79710 /**
79711 * drm_connector_helper_funcs - helper operations for connectors
79712 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
79713 index a70d456..6ea07cd 100644
79714 --- a/include/drm/i915_pciids.h
79715 +++ b/include/drm/i915_pciids.h
79716 @@ -37,7 +37,7 @@
79717 */
79718 #define INTEL_VGA_DEVICE(id, info) { \
79719 0x8086, id, \
79720 - ~0, ~0, \
79721 + PCI_ANY_ID, PCI_ANY_ID, \
79722 0x030000, 0xff0000, \
79723 (unsigned long) info }
79724
79725 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
79726 index 72dcbe8..8db58d7 100644
79727 --- a/include/drm/ttm/ttm_memory.h
79728 +++ b/include/drm/ttm/ttm_memory.h
79729 @@ -48,7 +48,7 @@
79730
79731 struct ttm_mem_shrink {
79732 int (*do_shrink) (struct ttm_mem_shrink *);
79733 -};
79734 +} __no_const;
79735
79736 /**
79737 * struct ttm_mem_global - Global memory accounting structure.
79738 diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
79739 index 49a8284..9643967 100644
79740 --- a/include/drm/ttm/ttm_page_alloc.h
79741 +++ b/include/drm/ttm/ttm_page_alloc.h
79742 @@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
79743 */
79744 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
79745
79746 +struct device;
79747 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
79748 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
79749
79750 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
79751 index 4b840e8..155d235 100644
79752 --- a/include/keys/asymmetric-subtype.h
79753 +++ b/include/keys/asymmetric-subtype.h
79754 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
79755 /* Verify the signature on a key of this subtype (optional) */
79756 int (*verify_signature)(const struct key *key,
79757 const struct public_key_signature *sig);
79758 -};
79759 +} __do_const;
79760
79761 /**
79762 * asymmetric_key_subtype - Get the subtype from an asymmetric key
79763 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
79764 index c1da539..1dcec55 100644
79765 --- a/include/linux/atmdev.h
79766 +++ b/include/linux/atmdev.h
79767 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
79768 #endif
79769
79770 struct k_atm_aal_stats {
79771 -#define __HANDLE_ITEM(i) atomic_t i
79772 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
79773 __AAL_STAT_ITEMS
79774 #undef __HANDLE_ITEM
79775 };
79776 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
79777 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
79778 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
79779 struct module *owner;
79780 -};
79781 +} __do_const ;
79782
79783 struct atmphy_ops {
79784 int (*start)(struct atm_dev *dev);
79785 diff --git a/include/linux/audit.h b/include/linux/audit.h
79786 index e58fe7d..be9f6d8 100644
79787 --- a/include/linux/audit.h
79788 +++ b/include/linux/audit.h
79789 @@ -215,7 +215,7 @@ static inline void audit_ptrace(struct task_struct *t)
79790 extern unsigned int audit_serial(void);
79791 extern int auditsc_get_stamp(struct audit_context *ctx,
79792 struct timespec *t, unsigned int *serial);
79793 -extern int audit_set_loginuid(kuid_t loginuid);
79794 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
79795
79796 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
79797 {
79798 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
79799 index 61f29e5..e67c658 100644
79800 --- a/include/linux/binfmts.h
79801 +++ b/include/linux/binfmts.h
79802 @@ -44,7 +44,7 @@ struct linux_binprm {
79803 unsigned interp_flags;
79804 unsigned interp_data;
79805 unsigned long loader, exec;
79806 -};
79807 +} __randomize_layout;
79808
79809 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
79810 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
79811 @@ -73,8 +73,10 @@ struct linux_binfmt {
79812 int (*load_binary)(struct linux_binprm *);
79813 int (*load_shlib)(struct file *);
79814 int (*core_dump)(struct coredump_params *cprm);
79815 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
79816 + void (*handle_mmap)(struct file *);
79817 unsigned long min_coredump; /* minimal dump size */
79818 -};
79819 +} __do_const __randomize_layout;
79820
79821 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
79822
79823 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
79824 index 5d858e0..336c1d9 100644
79825 --- a/include/linux/bitops.h
79826 +++ b/include/linux/bitops.h
79827 @@ -105,7 +105,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
79828 * @word: value to rotate
79829 * @shift: bits to roll
79830 */
79831 -static inline __u32 rol32(__u32 word, unsigned int shift)
79832 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
79833 {
79834 return (word << shift) | (word >> (32 - shift));
79835 }
79836 @@ -115,7 +115,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
79837 * @word: value to rotate
79838 * @shift: bits to roll
79839 */
79840 -static inline __u32 ror32(__u32 word, unsigned int shift)
79841 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
79842 {
79843 return (word >> shift) | (word << (32 - shift));
79844 }
79845 @@ -171,7 +171,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
79846 return (__s32)(value << shift) >> shift;
79847 }
79848
79849 -static inline unsigned fls_long(unsigned long l)
79850 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
79851 {
79852 if (sizeof(l) == 4)
79853 return fls(l);
79854 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
79855 index aac0f9e..73c9869 100644
79856 --- a/include/linux/blkdev.h
79857 +++ b/include/linux/blkdev.h
79858 @@ -1615,7 +1615,7 @@ struct block_device_operations {
79859 /* this callback is with swap_lock and sometimes page table lock held */
79860 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
79861 struct module *owner;
79862 -};
79863 +} __do_const;
79864
79865 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
79866 unsigned long);
79867 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
79868 index afc1343..9735539 100644
79869 --- a/include/linux/blktrace_api.h
79870 +++ b/include/linux/blktrace_api.h
79871 @@ -25,7 +25,7 @@ struct blk_trace {
79872 struct dentry *dropped_file;
79873 struct dentry *msg_file;
79874 struct list_head running_list;
79875 - atomic_t dropped;
79876 + atomic_unchecked_t dropped;
79877 };
79878
79879 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
79880 diff --git a/include/linux/cache.h b/include/linux/cache.h
79881 index 17e7e82..1d7da26 100644
79882 --- a/include/linux/cache.h
79883 +++ b/include/linux/cache.h
79884 @@ -16,6 +16,14 @@
79885 #define __read_mostly
79886 #endif
79887
79888 +#ifndef __read_only
79889 +#ifdef CONFIG_PAX_KERNEXEC
79890 +#error KERNEXEC requires __read_only
79891 +#else
79892 +#define __read_only __read_mostly
79893 +#endif
79894 +#endif
79895 +
79896 #ifndef ____cacheline_aligned
79897 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
79898 #endif
79899 diff --git a/include/linux/capability.h b/include/linux/capability.h
79900 index aa93e5e..985a1b0 100644
79901 --- a/include/linux/capability.h
79902 +++ b/include/linux/capability.h
79903 @@ -214,9 +214,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
79904 extern bool capable(int cap);
79905 extern bool ns_capable(struct user_namespace *ns, int cap);
79906 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
79907 +extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
79908 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
79909 +extern bool capable_nolog(int cap);
79910 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
79911
79912 /* audit system wants to get cap info from files as well */
79913 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
79914
79915 +extern int is_privileged_binary(const struct dentry *dentry);
79916 +
79917 #endif /* !_LINUX_CAPABILITY_H */
79918 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
79919 index 8609d57..86e4d79 100644
79920 --- a/include/linux/cdrom.h
79921 +++ b/include/linux/cdrom.h
79922 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
79923
79924 /* driver specifications */
79925 const int capability; /* capability flags */
79926 - int n_minors; /* number of active minor devices */
79927 /* handle uniform packets for scsi type devices (scsi,atapi) */
79928 int (*generic_packet) (struct cdrom_device_info *,
79929 struct packet_command *);
79930 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
79931 index 4ce9056..86caac6 100644
79932 --- a/include/linux/cleancache.h
79933 +++ b/include/linux/cleancache.h
79934 @@ -31,7 +31,7 @@ struct cleancache_ops {
79935 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
79936 void (*invalidate_inode)(int, struct cleancache_filekey);
79937 void (*invalidate_fs)(int);
79938 -};
79939 +} __no_const;
79940
79941 extern struct cleancache_ops *
79942 cleancache_register_ops(struct cleancache_ops *ops);
79943 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
79944 index 2839c63..5b06b6b 100644
79945 --- a/include/linux/clk-provider.h
79946 +++ b/include/linux/clk-provider.h
79947 @@ -191,6 +191,7 @@ struct clk_ops {
79948 void (*init)(struct clk_hw *hw);
79949 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
79950 };
79951 +typedef struct clk_ops __no_const clk_ops_no_const;
79952
79953 /**
79954 * struct clk_init_data - holds init data that's common to all clocks and is
79955 diff --git a/include/linux/compat.h b/include/linux/compat.h
79956 index e649426..a74047b 100644
79957 --- a/include/linux/compat.h
79958 +++ b/include/linux/compat.h
79959 @@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
79960 compat_size_t __user *len_ptr);
79961
79962 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
79963 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
79964 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
79965 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
79966 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
79967 compat_ssize_t msgsz, int msgflg);
79968 @@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
79969 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
79970 compat_ulong_t addr, compat_ulong_t data);
79971 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
79972 - compat_long_t addr, compat_long_t data);
79973 + compat_ulong_t addr, compat_ulong_t data);
79974
79975 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
79976 /*
79977 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
79978 index d1a5582..4424efa 100644
79979 --- a/include/linux/compiler-gcc4.h
79980 +++ b/include/linux/compiler-gcc4.h
79981 @@ -39,9 +39,34 @@
79982 # define __compiletime_warning(message) __attribute__((warning(message)))
79983 # define __compiletime_error(message) __attribute__((error(message)))
79984 #endif /* __CHECKER__ */
79985 +
79986 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
79987 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
79988 +#define __bos0(ptr) __bos((ptr), 0)
79989 +#define __bos1(ptr) __bos((ptr), 1)
79990 #endif /* GCC_VERSION >= 40300 */
79991
79992 #if GCC_VERSION >= 40500
79993 +
79994 +#ifdef RANDSTRUCT_PLUGIN
79995 +#define __randomize_layout __attribute__((randomize_layout))
79996 +#define __no_randomize_layout __attribute__((no_randomize_layout))
79997 +#endif
79998 +
79999 +#ifdef CONSTIFY_PLUGIN
80000 +#define __no_const __attribute__((no_const))
80001 +#define __do_const __attribute__((do_const))
80002 +#endif
80003 +
80004 +#ifdef SIZE_OVERFLOW_PLUGIN
80005 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
80006 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
80007 +#endif
80008 +
80009 +#ifdef LATENT_ENTROPY_PLUGIN
80010 +#define __latent_entropy __attribute__((latent_entropy))
80011 +#endif
80012 +
80013 /*
80014 * Mark a position in code as unreachable. This can be used to
80015 * suppress control flow warnings after asm blocks that transfer
80016 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
80017 index d5ad7b1..3b74638 100644
80018 --- a/include/linux/compiler.h
80019 +++ b/include/linux/compiler.h
80020 @@ -5,11 +5,14 @@
80021
80022 #ifdef __CHECKER__
80023 # define __user __attribute__((noderef, address_space(1)))
80024 +# define __force_user __force __user
80025 # define __kernel __attribute__((address_space(0)))
80026 +# define __force_kernel __force __kernel
80027 # define __safe __attribute__((safe))
80028 # define __force __attribute__((force))
80029 # define __nocast __attribute__((nocast))
80030 # define __iomem __attribute__((noderef, address_space(2)))
80031 +# define __force_iomem __force __iomem
80032 # define __must_hold(x) __attribute__((context(x,1,1)))
80033 # define __acquires(x) __attribute__((context(x,0,1)))
80034 # define __releases(x) __attribute__((context(x,1,0)))
80035 @@ -17,20 +20,37 @@
80036 # define __release(x) __context__(x,-1)
80037 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
80038 # define __percpu __attribute__((noderef, address_space(3)))
80039 +# define __force_percpu __force __percpu
80040 #ifdef CONFIG_SPARSE_RCU_POINTER
80041 # define __rcu __attribute__((noderef, address_space(4)))
80042 +# define __force_rcu __force __rcu
80043 #else
80044 # define __rcu
80045 +# define __force_rcu
80046 #endif
80047 extern void __chk_user_ptr(const volatile void __user *);
80048 extern void __chk_io_ptr(const volatile void __iomem *);
80049 #else
80050 -# define __user
80051 -# define __kernel
80052 +# ifdef CHECKER_PLUGIN
80053 +//# define __user
80054 +//# define __force_user
80055 +//# define __kernel
80056 +//# define __force_kernel
80057 +# else
80058 +# ifdef STRUCTLEAK_PLUGIN
80059 +# define __user __attribute__((user))
80060 +# else
80061 +# define __user
80062 +# endif
80063 +# define __force_user
80064 +# define __kernel
80065 +# define __force_kernel
80066 +# endif
80067 # define __safe
80068 # define __force
80069 # define __nocast
80070 # define __iomem
80071 +# define __force_iomem
80072 # define __chk_user_ptr(x) (void)0
80073 # define __chk_io_ptr(x) (void)0
80074 # define __builtin_warning(x, y...) (1)
80075 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
80076 # define __release(x) (void)0
80077 # define __cond_lock(x,c) (c)
80078 # define __percpu
80079 +# define __force_percpu
80080 # define __rcu
80081 +# define __force_rcu
80082 #endif
80083
80084 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
80085 @@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80086 # define __attribute_const__ /* unimplemented */
80087 #endif
80088
80089 +#ifndef __randomize_layout
80090 +# define __randomize_layout
80091 +#endif
80092 +
80093 +#ifndef __no_randomize_layout
80094 +# define __no_randomize_layout
80095 +#endif
80096 +
80097 +#ifndef __no_const
80098 +# define __no_const
80099 +#endif
80100 +
80101 +#ifndef __do_const
80102 +# define __do_const
80103 +#endif
80104 +
80105 +#ifndef __size_overflow
80106 +# define __size_overflow(...)
80107 +#endif
80108 +
80109 +#ifndef __intentional_overflow
80110 +# define __intentional_overflow(...)
80111 +#endif
80112 +
80113 +#ifndef __latent_entropy
80114 +# define __latent_entropy
80115 +#endif
80116 +
80117 /*
80118 * Tell gcc if a function is cold. The compiler will assume any path
80119 * directly leading to the call is unlikely.
80120 @@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80121 #define __cold
80122 #endif
80123
80124 +#ifndef __alloc_size
80125 +#define __alloc_size(...)
80126 +#endif
80127 +
80128 +#ifndef __bos
80129 +#define __bos(ptr, arg)
80130 +#endif
80131 +
80132 +#ifndef __bos0
80133 +#define __bos0(ptr)
80134 +#endif
80135 +
80136 +#ifndef __bos1
80137 +#define __bos1(ptr)
80138 +#endif
80139 +
80140 /* Simple shorthand for a section definition */
80141 #ifndef __section
80142 # define __section(S) __attribute__ ((__section__(#S)))
80143 @@ -378,7 +444,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80144 * use is to mediate communication between process-level code and irq/NMI
80145 * handlers, all running on the same CPU.
80146 */
80147 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
80148 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
80149 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
80150
80151 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
80152 #ifdef CONFIG_KPROBES
80153 diff --git a/include/linux/completion.h b/include/linux/completion.h
80154 index 5d5aaae..0ea9b84 100644
80155 --- a/include/linux/completion.h
80156 +++ b/include/linux/completion.h
80157 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
80158
80159 extern void wait_for_completion(struct completion *);
80160 extern void wait_for_completion_io(struct completion *);
80161 -extern int wait_for_completion_interruptible(struct completion *x);
80162 -extern int wait_for_completion_killable(struct completion *x);
80163 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
80164 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
80165 extern unsigned long wait_for_completion_timeout(struct completion *x,
80166 - unsigned long timeout);
80167 + unsigned long timeout) __intentional_overflow(-1);
80168 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
80169 - unsigned long timeout);
80170 + unsigned long timeout) __intentional_overflow(-1);
80171 extern long wait_for_completion_interruptible_timeout(
80172 - struct completion *x, unsigned long timeout);
80173 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80174 extern long wait_for_completion_killable_timeout(
80175 - struct completion *x, unsigned long timeout);
80176 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80177 extern bool try_wait_for_completion(struct completion *x);
80178 extern bool completion_done(struct completion *x);
80179
80180 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
80181 index 34025df..d94bbbc 100644
80182 --- a/include/linux/configfs.h
80183 +++ b/include/linux/configfs.h
80184 @@ -125,7 +125,7 @@ struct configfs_attribute {
80185 const char *ca_name;
80186 struct module *ca_owner;
80187 umode_t ca_mode;
80188 -};
80189 +} __do_const;
80190
80191 /*
80192 * Users often need to create attribute structures for their configurable
80193 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
80194 index 503b085b..1638c9e 100644
80195 --- a/include/linux/cpufreq.h
80196 +++ b/include/linux/cpufreq.h
80197 @@ -206,6 +206,7 @@ struct global_attr {
80198 ssize_t (*store)(struct kobject *a, struct attribute *b,
80199 const char *c, size_t count);
80200 };
80201 +typedef struct global_attr __no_const global_attr_no_const;
80202
80203 #define define_one_global_ro(_name) \
80204 static struct global_attr _name = \
80205 @@ -273,7 +274,7 @@ struct cpufreq_driver {
80206 bool boost_supported;
80207 bool boost_enabled;
80208 int (*set_boost) (int state);
80209 -};
80210 +} __do_const;
80211
80212 /* flags */
80213 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
80214 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
80215 index 25e0df6..952dffd 100644
80216 --- a/include/linux/cpuidle.h
80217 +++ b/include/linux/cpuidle.h
80218 @@ -50,7 +50,8 @@ struct cpuidle_state {
80219 int index);
80220
80221 int (*enter_dead) (struct cpuidle_device *dev, int index);
80222 -};
80223 +} __do_const;
80224 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
80225
80226 /* Idle State Flags */
80227 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
80228 @@ -209,7 +210,7 @@ struct cpuidle_governor {
80229 void (*reflect) (struct cpuidle_device *dev, int index);
80230
80231 struct module *owner;
80232 -};
80233 +} __do_const;
80234
80235 #ifdef CONFIG_CPU_IDLE
80236 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
80237 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
80238 index 0a9a6da..ea597ca 100644
80239 --- a/include/linux/cpumask.h
80240 +++ b/include/linux/cpumask.h
80241 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
80242 }
80243
80244 /* Valid inputs for n are -1 and 0. */
80245 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80246 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
80247 {
80248 return n+1;
80249 }
80250
80251 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80252 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
80253 {
80254 return n+1;
80255 }
80256
80257 -static inline unsigned int cpumask_next_and(int n,
80258 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
80259 const struct cpumask *srcp,
80260 const struct cpumask *andp)
80261 {
80262 @@ -174,7 +174,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
80263 *
80264 * Returns >= nr_cpu_ids if no further cpus set.
80265 */
80266 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80267 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
80268 {
80269 /* -1 is a legal arg here. */
80270 if (n != -1)
80271 @@ -189,7 +189,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80272 *
80273 * Returns >= nr_cpu_ids if no further cpus unset.
80274 */
80275 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80276 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
80277 {
80278 /* -1 is a legal arg here. */
80279 if (n != -1)
80280 @@ -197,7 +197,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80281 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
80282 }
80283
80284 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
80285 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
80286 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
80287 int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp);
80288
80289 diff --git a/include/linux/cred.h b/include/linux/cred.h
80290 index b2d0820..2ecafd3 100644
80291 --- a/include/linux/cred.h
80292 +++ b/include/linux/cred.h
80293 @@ -35,7 +35,7 @@ struct group_info {
80294 int nblocks;
80295 kgid_t small_block[NGROUPS_SMALL];
80296 kgid_t *blocks[0];
80297 -};
80298 +} __randomize_layout;
80299
80300 /**
80301 * get_group_info - Get a reference to a group info structure
80302 @@ -136,7 +136,7 @@ struct cred {
80303 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
80304 struct group_info *group_info; /* supplementary groups for euid/fsgid */
80305 struct rcu_head rcu; /* RCU deletion hook */
80306 -};
80307 +} __randomize_layout;
80308
80309 extern void __put_cred(struct cred *);
80310 extern void exit_creds(struct task_struct *);
80311 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
80312 static inline void validate_process_creds(void)
80313 {
80314 }
80315 +static inline void validate_task_creds(struct task_struct *task)
80316 +{
80317 +}
80318 #endif
80319
80320 /**
80321 @@ -331,6 +334,7 @@ static inline void put_cred(const struct cred *_cred)
80322
80323 #define task_uid(task) (task_cred_xxx((task), uid))
80324 #define task_euid(task) (task_cred_xxx((task), euid))
80325 +#define task_securebits(task) (task_cred_xxx((task), securebits))
80326
80327 #define current_cred_xxx(xxx) \
80328 ({ \
80329 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
80330 index d45e949..51cf5ea 100644
80331 --- a/include/linux/crypto.h
80332 +++ b/include/linux/crypto.h
80333 @@ -373,7 +373,7 @@ struct cipher_tfm {
80334 const u8 *key, unsigned int keylen);
80335 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
80336 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
80337 -};
80338 +} __no_const;
80339
80340 struct hash_tfm {
80341 int (*init)(struct hash_desc *desc);
80342 @@ -394,13 +394,13 @@ struct compress_tfm {
80343 int (*cot_decompress)(struct crypto_tfm *tfm,
80344 const u8 *src, unsigned int slen,
80345 u8 *dst, unsigned int *dlen);
80346 -};
80347 +} __no_const;
80348
80349 struct rng_tfm {
80350 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
80351 unsigned int dlen);
80352 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
80353 -};
80354 +} __no_const;
80355
80356 #define crt_ablkcipher crt_u.ablkcipher
80357 #define crt_aead crt_u.aead
80358 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
80359 index 653589e..4ef254a 100644
80360 --- a/include/linux/ctype.h
80361 +++ b/include/linux/ctype.h
80362 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
80363 * Fast implementation of tolower() for internal usage. Do not use in your
80364 * code.
80365 */
80366 -static inline char _tolower(const char c)
80367 +static inline unsigned char _tolower(const unsigned char c)
80368 {
80369 return c | 0x20;
80370 }
80371 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
80372 index 1c2f1b8..c67151e 100644
80373 --- a/include/linux/dcache.h
80374 +++ b/include/linux/dcache.h
80375 @@ -133,7 +133,7 @@ struct dentry {
80376 struct hlist_node d_alias; /* inode alias list */
80377 struct rcu_head d_rcu;
80378 } d_u;
80379 -};
80380 +} __randomize_layout;
80381
80382 /*
80383 * dentry->d_lock spinlock nesting subclasses:
80384 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
80385 index 7925bf0..d5143d2 100644
80386 --- a/include/linux/decompress/mm.h
80387 +++ b/include/linux/decompress/mm.h
80388 @@ -77,7 +77,7 @@ static void free(void *where)
80389 * warnings when not needed (indeed large_malloc / large_free are not
80390 * needed by inflate */
80391
80392 -#define malloc(a) kmalloc(a, GFP_KERNEL)
80393 +#define malloc(a) kmalloc((a), GFP_KERNEL)
80394 #define free(a) kfree(a)
80395
80396 #define large_malloc(a) vmalloc(a)
80397 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
80398 index f1863dc..5c26074 100644
80399 --- a/include/linux/devfreq.h
80400 +++ b/include/linux/devfreq.h
80401 @@ -114,7 +114,7 @@ struct devfreq_governor {
80402 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
80403 int (*event_handler)(struct devfreq *devfreq,
80404 unsigned int event, void *data);
80405 -};
80406 +} __do_const;
80407
80408 /**
80409 * struct devfreq - Device devfreq structure
80410 diff --git a/include/linux/device.h b/include/linux/device.h
80411 index ce1f2160..189bc33 100644
80412 --- a/include/linux/device.h
80413 +++ b/include/linux/device.h
80414 @@ -311,7 +311,7 @@ struct subsys_interface {
80415 struct list_head node;
80416 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
80417 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
80418 -};
80419 +} __do_const;
80420
80421 int subsys_interface_register(struct subsys_interface *sif);
80422 void subsys_interface_unregister(struct subsys_interface *sif);
80423 @@ -507,7 +507,7 @@ struct device_type {
80424 void (*release)(struct device *dev);
80425
80426 const struct dev_pm_ops *pm;
80427 -};
80428 +} __do_const;
80429
80430 /* interface for exporting device attributes */
80431 struct device_attribute {
80432 @@ -517,11 +517,12 @@ struct device_attribute {
80433 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
80434 const char *buf, size_t count);
80435 };
80436 +typedef struct device_attribute __no_const device_attribute_no_const;
80437
80438 struct dev_ext_attribute {
80439 struct device_attribute attr;
80440 void *var;
80441 -};
80442 +} __do_const;
80443
80444 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
80445 char *buf);
80446 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
80447 index d5d3881..7ed54af 100644
80448 --- a/include/linux/dma-mapping.h
80449 +++ b/include/linux/dma-mapping.h
80450 @@ -60,7 +60,7 @@ struct dma_map_ops {
80451 u64 (*get_required_mask)(struct device *dev);
80452 #endif
80453 int is_phys;
80454 -};
80455 +} __do_const;
80456
80457 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
80458
80459 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
80460 index 653a1fd..9133cd1 100644
80461 --- a/include/linux/dmaengine.h
80462 +++ b/include/linux/dmaengine.h
80463 @@ -1136,9 +1136,9 @@ struct dma_pinned_list {
80464 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
80465 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
80466
80467 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
80468 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
80469 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
80470 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
80471 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
80472 struct dma_pinned_list *pinned_list, struct page *page,
80473 unsigned int offset, size_t len);
80474
80475 diff --git a/include/linux/efi.h b/include/linux/efi.h
80476 index 0949f9c..04cb9a5 100644
80477 --- a/include/linux/efi.h
80478 +++ b/include/linux/efi.h
80479 @@ -1050,6 +1050,7 @@ struct efivar_operations {
80480 efi_set_variable_nonblocking_t *set_variable_nonblocking;
80481 efi_query_variable_store_t *query_variable_store;
80482 };
80483 +typedef struct efivar_operations __no_const efivar_operations_no_const;
80484
80485 struct efivars {
80486 /*
80487 diff --git a/include/linux/elf.h b/include/linux/elf.h
80488 index 67a5fa7..b817372 100644
80489 --- a/include/linux/elf.h
80490 +++ b/include/linux/elf.h
80491 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
80492 #define elf_note elf32_note
80493 #define elf_addr_t Elf32_Off
80494 #define Elf_Half Elf32_Half
80495 +#define elf_dyn Elf32_Dyn
80496
80497 #else
80498
80499 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
80500 #define elf_note elf64_note
80501 #define elf_addr_t Elf64_Off
80502 #define Elf_Half Elf64_Half
80503 +#define elf_dyn Elf64_Dyn
80504
80505 #endif
80506
80507 diff --git a/include/linux/err.h b/include/linux/err.h
80508 index a729120..6ede2c9 100644
80509 --- a/include/linux/err.h
80510 +++ b/include/linux/err.h
80511 @@ -20,12 +20,12 @@
80512
80513 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
80514
80515 -static inline void * __must_check ERR_PTR(long error)
80516 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
80517 {
80518 return (void *) error;
80519 }
80520
80521 -static inline long __must_check PTR_ERR(__force const void *ptr)
80522 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
80523 {
80524 return (long) ptr;
80525 }
80526 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
80527 index 36f49c4..a2a1f4c 100644
80528 --- a/include/linux/extcon.h
80529 +++ b/include/linux/extcon.h
80530 @@ -135,7 +135,7 @@ struct extcon_dev {
80531 /* /sys/class/extcon/.../mutually_exclusive/... */
80532 struct attribute_group attr_g_muex;
80533 struct attribute **attrs_muex;
80534 - struct device_attribute *d_attrs_muex;
80535 + device_attribute_no_const *d_attrs_muex;
80536 };
80537
80538 /**
80539 diff --git a/include/linux/fb.h b/include/linux/fb.h
80540 index 09bb7a1..d98870a 100644
80541 --- a/include/linux/fb.h
80542 +++ b/include/linux/fb.h
80543 @@ -305,7 +305,7 @@ struct fb_ops {
80544 /* called at KDB enter and leave time to prepare the console */
80545 int (*fb_debug_enter)(struct fb_info *info);
80546 int (*fb_debug_leave)(struct fb_info *info);
80547 -};
80548 +} __do_const;
80549
80550 #ifdef CONFIG_FB_TILEBLITTING
80551 #define FB_TILE_CURSOR_NONE 0
80552 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
80553 index 230f87b..1fd0485 100644
80554 --- a/include/linux/fdtable.h
80555 +++ b/include/linux/fdtable.h
80556 @@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
80557 void put_files_struct(struct files_struct *fs);
80558 void reset_files_struct(struct files_struct *);
80559 int unshare_files(struct files_struct **);
80560 -struct files_struct *dup_fd(struct files_struct *, int *);
80561 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
80562 void do_close_on_exec(struct files_struct *);
80563 int iterate_fd(struct files_struct *, unsigned,
80564 int (*)(const void *, struct file *, unsigned),
80565 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
80566 index 8293262..2b3b8bd 100644
80567 --- a/include/linux/frontswap.h
80568 +++ b/include/linux/frontswap.h
80569 @@ -11,7 +11,7 @@ struct frontswap_ops {
80570 int (*load)(unsigned, pgoff_t, struct page *);
80571 void (*invalidate_page)(unsigned, pgoff_t);
80572 void (*invalidate_area)(unsigned);
80573 -};
80574 +} __no_const;
80575
80576 extern bool frontswap_enabled;
80577 extern struct frontswap_ops *
80578 diff --git a/include/linux/fs.h b/include/linux/fs.h
80579 index 9ab779e..0c636f2 100644
80580 --- a/include/linux/fs.h
80581 +++ b/include/linux/fs.h
80582 @@ -412,7 +412,7 @@ struct address_space {
80583 spinlock_t private_lock; /* for use by the address_space */
80584 struct list_head private_list; /* ditto */
80585 void *private_data; /* ditto */
80586 -} __attribute__((aligned(sizeof(long))));
80587 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
80588 /*
80589 * On most architectures that alignment is already the case; but
80590 * must be enforced here for CRIS, to let the least significant bit
80591 @@ -455,7 +455,7 @@ struct block_device {
80592 int bd_fsfreeze_count;
80593 /* Mutex for freeze */
80594 struct mutex bd_fsfreeze_mutex;
80595 -};
80596 +} __randomize_layout;
80597
80598 /*
80599 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
80600 @@ -624,7 +624,7 @@ struct inode {
80601 #endif
80602
80603 void *i_private; /* fs or device private pointer */
80604 -};
80605 +} __randomize_layout;
80606
80607 static inline int inode_unhashed(struct inode *inode)
80608 {
80609 @@ -820,7 +820,7 @@ struct file {
80610 struct list_head f_tfile_llink;
80611 #endif /* #ifdef CONFIG_EPOLL */
80612 struct address_space *f_mapping;
80613 -} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
80614 +} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
80615
80616 struct file_handle {
80617 __u32 handle_bytes;
80618 @@ -945,7 +945,7 @@ struct file_lock {
80619 int state; /* state of grant or error if -ve */
80620 } afs;
80621 } fl_u;
80622 -};
80623 +} __randomize_layout;
80624
80625 /* The following constant reflects the upper bound of the file/locking space */
80626 #ifndef OFFSET_MAX
80627 @@ -1287,7 +1287,7 @@ struct super_block {
80628 * Indicates how deep in a filesystem stack this SB is
80629 */
80630 int s_stack_depth;
80631 -};
80632 +} __randomize_layout;
80633
80634 extern struct timespec current_fs_time(struct super_block *sb);
80635
80636 @@ -1514,7 +1514,8 @@ struct file_operations {
80637 long (*fallocate)(struct file *file, int mode, loff_t offset,
80638 loff_t len);
80639 int (*show_fdinfo)(struct seq_file *m, struct file *f);
80640 -};
80641 +} __do_const __randomize_layout;
80642 +typedef struct file_operations __no_const file_operations_no_const;
80643
80644 struct inode_operations {
80645 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
80646 @@ -2823,4 +2824,14 @@ static inline bool dir_relax(struct inode *inode)
80647 return !IS_DEADDIR(inode);
80648 }
80649
80650 +static inline bool is_sidechannel_device(const struct inode *inode)
80651 +{
80652 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
80653 + umode_t mode = inode->i_mode;
80654 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
80655 +#else
80656 + return false;
80657 +#endif
80658 +}
80659 +
80660 #endif /* _LINUX_FS_H */
80661 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
80662 index 0efc3e6..fd23610 100644
80663 --- a/include/linux/fs_struct.h
80664 +++ b/include/linux/fs_struct.h
80665 @@ -6,13 +6,13 @@
80666 #include <linux/seqlock.h>
80667
80668 struct fs_struct {
80669 - int users;
80670 + atomic_t users;
80671 spinlock_t lock;
80672 seqcount_t seq;
80673 int umask;
80674 int in_exec;
80675 struct path root, pwd;
80676 -};
80677 +} __randomize_layout;
80678
80679 extern struct kmem_cache *fs_cachep;
80680
80681 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
80682 index 7714849..a4a5c7a 100644
80683 --- a/include/linux/fscache-cache.h
80684 +++ b/include/linux/fscache-cache.h
80685 @@ -113,7 +113,7 @@ struct fscache_operation {
80686 fscache_operation_release_t release;
80687 };
80688
80689 -extern atomic_t fscache_op_debug_id;
80690 +extern atomic_unchecked_t fscache_op_debug_id;
80691 extern void fscache_op_work_func(struct work_struct *work);
80692
80693 extern void fscache_enqueue_operation(struct fscache_operation *);
80694 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
80695 INIT_WORK(&op->work, fscache_op_work_func);
80696 atomic_set(&op->usage, 1);
80697 op->state = FSCACHE_OP_ST_INITIALISED;
80698 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
80699 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
80700 op->processor = processor;
80701 op->release = release;
80702 INIT_LIST_HEAD(&op->pend_link);
80703 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
80704 index 115bb81..e7b812b 100644
80705 --- a/include/linux/fscache.h
80706 +++ b/include/linux/fscache.h
80707 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
80708 * - this is mandatory for any object that may have data
80709 */
80710 void (*now_uncached)(void *cookie_netfs_data);
80711 -};
80712 +} __do_const;
80713
80714 /*
80715 * fscache cached network filesystem type
80716 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
80717 index 1c804b0..1432c2b 100644
80718 --- a/include/linux/fsnotify.h
80719 +++ b/include/linux/fsnotify.h
80720 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
80721 struct inode *inode = file_inode(file);
80722 __u32 mask = FS_ACCESS;
80723
80724 + if (is_sidechannel_device(inode))
80725 + return;
80726 +
80727 if (S_ISDIR(inode->i_mode))
80728 mask |= FS_ISDIR;
80729
80730 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
80731 struct inode *inode = file_inode(file);
80732 __u32 mask = FS_MODIFY;
80733
80734 + if (is_sidechannel_device(inode))
80735 + return;
80736 +
80737 if (S_ISDIR(inode->i_mode))
80738 mask |= FS_ISDIR;
80739
80740 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
80741 */
80742 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
80743 {
80744 - return kstrdup(name, GFP_KERNEL);
80745 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
80746 }
80747
80748 /*
80749 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
80750 index ec274e0..e678159 100644
80751 --- a/include/linux/genhd.h
80752 +++ b/include/linux/genhd.h
80753 @@ -194,7 +194,7 @@ struct gendisk {
80754 struct kobject *slave_dir;
80755
80756 struct timer_rand_state *random;
80757 - atomic_t sync_io; /* RAID */
80758 + atomic_unchecked_t sync_io; /* RAID */
80759 struct disk_events *ev;
80760 #ifdef CONFIG_BLK_DEV_INTEGRITY
80761 struct blk_integrity *integrity;
80762 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
80763 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
80764
80765 /* drivers/char/random.c */
80766 -extern void add_disk_randomness(struct gendisk *disk);
80767 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
80768 extern void rand_initialize_disk(struct gendisk *disk);
80769
80770 static inline sector_t get_start_sect(struct block_device *bdev)
80771 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
80772 index 667c311..abac2a7 100644
80773 --- a/include/linux/genl_magic_func.h
80774 +++ b/include/linux/genl_magic_func.h
80775 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
80776 },
80777
80778 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
80779 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
80780 +static struct genl_ops ZZZ_genl_ops[] = {
80781 #include GENL_MAGIC_INCLUDE_FILE
80782 };
80783
80784 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
80785 index 41b30fd..a3718cf 100644
80786 --- a/include/linux/gfp.h
80787 +++ b/include/linux/gfp.h
80788 @@ -34,6 +34,13 @@ struct vm_area_struct;
80789 #define ___GFP_NO_KSWAPD 0x400000u
80790 #define ___GFP_OTHER_NODE 0x800000u
80791 #define ___GFP_WRITE 0x1000000u
80792 +
80793 +#ifdef CONFIG_PAX_USERCOPY_SLABS
80794 +#define ___GFP_USERCOPY 0x2000000u
80795 +#else
80796 +#define ___GFP_USERCOPY 0
80797 +#endif
80798 +
80799 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
80800
80801 /*
80802 @@ -90,6 +97,7 @@ struct vm_area_struct;
80803 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
80804 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
80805 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
80806 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
80807
80808 /*
80809 * This may seem redundant, but it's a way of annotating false positives vs.
80810 @@ -97,7 +105,7 @@ struct vm_area_struct;
80811 */
80812 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
80813
80814 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
80815 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
80816 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
80817
80818 /* This equals 0, but use constants in case they ever change */
80819 @@ -155,6 +163,8 @@ struct vm_area_struct;
80820 /* 4GB DMA on some platforms */
80821 #define GFP_DMA32 __GFP_DMA32
80822
80823 +#define GFP_USERCOPY __GFP_USERCOPY
80824 +
80825 /* Convert GFP flags to their corresponding migrate type */
80826 static inline int gfpflags_to_migratetype(const gfp_t gfp_flags)
80827 {
80828 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
80829 new file mode 100644
80830 index 0000000..edb2cb6
80831 --- /dev/null
80832 +++ b/include/linux/gracl.h
80833 @@ -0,0 +1,340 @@
80834 +#ifndef GR_ACL_H
80835 +#define GR_ACL_H
80836 +
80837 +#include <linux/grdefs.h>
80838 +#include <linux/resource.h>
80839 +#include <linux/capability.h>
80840 +#include <linux/dcache.h>
80841 +#include <asm/resource.h>
80842 +
80843 +/* Major status information */
80844 +
80845 +#define GR_VERSION "grsecurity 3.0"
80846 +#define GRSECURITY_VERSION 0x3000
80847 +
80848 +enum {
80849 + GR_SHUTDOWN = 0,
80850 + GR_ENABLE = 1,
80851 + GR_SPROLE = 2,
80852 + GR_OLDRELOAD = 3,
80853 + GR_SEGVMOD = 4,
80854 + GR_STATUS = 5,
80855 + GR_UNSPROLE = 6,
80856 + GR_PASSSET = 7,
80857 + GR_SPROLEPAM = 8,
80858 + GR_RELOAD = 9,
80859 +};
80860 +
80861 +/* Password setup definitions
80862 + * kernel/grhash.c */
80863 +enum {
80864 + GR_PW_LEN = 128,
80865 + GR_SALT_LEN = 16,
80866 + GR_SHA_LEN = 32,
80867 +};
80868 +
80869 +enum {
80870 + GR_SPROLE_LEN = 64,
80871 +};
80872 +
80873 +enum {
80874 + GR_NO_GLOB = 0,
80875 + GR_REG_GLOB,
80876 + GR_CREATE_GLOB
80877 +};
80878 +
80879 +#define GR_NLIMITS 32
80880 +
80881 +/* Begin Data Structures */
80882 +
80883 +struct sprole_pw {
80884 + unsigned char *rolename;
80885 + unsigned char salt[GR_SALT_LEN];
80886 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
80887 +};
80888 +
80889 +struct name_entry {
80890 + __u32 key;
80891 + ino_t inode;
80892 + dev_t device;
80893 + char *name;
80894 + __u16 len;
80895 + __u8 deleted;
80896 + struct name_entry *prev;
80897 + struct name_entry *next;
80898 +};
80899 +
80900 +struct inodev_entry {
80901 + struct name_entry *nentry;
80902 + struct inodev_entry *prev;
80903 + struct inodev_entry *next;
80904 +};
80905 +
80906 +struct acl_role_db {
80907 + struct acl_role_label **r_hash;
80908 + __u32 r_size;
80909 +};
80910 +
80911 +struct inodev_db {
80912 + struct inodev_entry **i_hash;
80913 + __u32 i_size;
80914 +};
80915 +
80916 +struct name_db {
80917 + struct name_entry **n_hash;
80918 + __u32 n_size;
80919 +};
80920 +
80921 +struct crash_uid {
80922 + uid_t uid;
80923 + unsigned long expires;
80924 +};
80925 +
80926 +struct gr_hash_struct {
80927 + void **table;
80928 + void **nametable;
80929 + void *first;
80930 + __u32 table_size;
80931 + __u32 used_size;
80932 + int type;
80933 +};
80934 +
80935 +/* Userspace Grsecurity ACL data structures */
80936 +
80937 +struct acl_subject_label {
80938 + char *filename;
80939 + ino_t inode;
80940 + dev_t device;
80941 + __u32 mode;
80942 + kernel_cap_t cap_mask;
80943 + kernel_cap_t cap_lower;
80944 + kernel_cap_t cap_invert_audit;
80945 +
80946 + struct rlimit res[GR_NLIMITS];
80947 + __u32 resmask;
80948 +
80949 + __u8 user_trans_type;
80950 + __u8 group_trans_type;
80951 + uid_t *user_transitions;
80952 + gid_t *group_transitions;
80953 + __u16 user_trans_num;
80954 + __u16 group_trans_num;
80955 +
80956 + __u32 sock_families[2];
80957 + __u32 ip_proto[8];
80958 + __u32 ip_type;
80959 + struct acl_ip_label **ips;
80960 + __u32 ip_num;
80961 + __u32 inaddr_any_override;
80962 +
80963 + __u32 crashes;
80964 + unsigned long expires;
80965 +
80966 + struct acl_subject_label *parent_subject;
80967 + struct gr_hash_struct *hash;
80968 + struct acl_subject_label *prev;
80969 + struct acl_subject_label *next;
80970 +
80971 + struct acl_object_label **obj_hash;
80972 + __u32 obj_hash_size;
80973 + __u16 pax_flags;
80974 +};
80975 +
80976 +struct role_allowed_ip {
80977 + __u32 addr;
80978 + __u32 netmask;
80979 +
80980 + struct role_allowed_ip *prev;
80981 + struct role_allowed_ip *next;
80982 +};
80983 +
80984 +struct role_transition {
80985 + char *rolename;
80986 +
80987 + struct role_transition *prev;
80988 + struct role_transition *next;
80989 +};
80990 +
80991 +struct acl_role_label {
80992 + char *rolename;
80993 + uid_t uidgid;
80994 + __u16 roletype;
80995 +
80996 + __u16 auth_attempts;
80997 + unsigned long expires;
80998 +
80999 + struct acl_subject_label *root_label;
81000 + struct gr_hash_struct *hash;
81001 +
81002 + struct acl_role_label *prev;
81003 + struct acl_role_label *next;
81004 +
81005 + struct role_transition *transitions;
81006 + struct role_allowed_ip *allowed_ips;
81007 + uid_t *domain_children;
81008 + __u16 domain_child_num;
81009 +
81010 + umode_t umask;
81011 +
81012 + struct acl_subject_label **subj_hash;
81013 + __u32 subj_hash_size;
81014 +};
81015 +
81016 +struct user_acl_role_db {
81017 + struct acl_role_label **r_table;
81018 + __u32 num_pointers; /* Number of allocations to track */
81019 + __u32 num_roles; /* Number of roles */
81020 + __u32 num_domain_children; /* Number of domain children */
81021 + __u32 num_subjects; /* Number of subjects */
81022 + __u32 num_objects; /* Number of objects */
81023 +};
81024 +
81025 +struct acl_object_label {
81026 + char *filename;
81027 + ino_t inode;
81028 + dev_t device;
81029 + __u32 mode;
81030 +
81031 + struct acl_subject_label *nested;
81032 + struct acl_object_label *globbed;
81033 +
81034 + /* next two structures not used */
81035 +
81036 + struct acl_object_label *prev;
81037 + struct acl_object_label *next;
81038 +};
81039 +
81040 +struct acl_ip_label {
81041 + char *iface;
81042 + __u32 addr;
81043 + __u32 netmask;
81044 + __u16 low, high;
81045 + __u8 mode;
81046 + __u32 type;
81047 + __u32 proto[8];
81048 +
81049 + /* next two structures not used */
81050 +
81051 + struct acl_ip_label *prev;
81052 + struct acl_ip_label *next;
81053 +};
81054 +
81055 +struct gr_arg {
81056 + struct user_acl_role_db role_db;
81057 + unsigned char pw[GR_PW_LEN];
81058 + unsigned char salt[GR_SALT_LEN];
81059 + unsigned char sum[GR_SHA_LEN];
81060 + unsigned char sp_role[GR_SPROLE_LEN];
81061 + struct sprole_pw *sprole_pws;
81062 + dev_t segv_device;
81063 + ino_t segv_inode;
81064 + uid_t segv_uid;
81065 + __u16 num_sprole_pws;
81066 + __u16 mode;
81067 +};
81068 +
81069 +struct gr_arg_wrapper {
81070 + struct gr_arg *arg;
81071 + __u32 version;
81072 + __u32 size;
81073 +};
81074 +
81075 +struct subject_map {
81076 + struct acl_subject_label *user;
81077 + struct acl_subject_label *kernel;
81078 + struct subject_map *prev;
81079 + struct subject_map *next;
81080 +};
81081 +
81082 +struct acl_subj_map_db {
81083 + struct subject_map **s_hash;
81084 + __u32 s_size;
81085 +};
81086 +
81087 +struct gr_policy_state {
81088 + struct sprole_pw **acl_special_roles;
81089 + __u16 num_sprole_pws;
81090 + struct acl_role_label *kernel_role;
81091 + struct acl_role_label *role_list;
81092 + struct acl_role_label *default_role;
81093 + struct acl_role_db acl_role_set;
81094 + struct acl_subj_map_db subj_map_set;
81095 + struct name_db name_set;
81096 + struct inodev_db inodev_set;
81097 +};
81098 +
81099 +struct gr_alloc_state {
81100 + unsigned long alloc_stack_next;
81101 + unsigned long alloc_stack_size;
81102 + void **alloc_stack;
81103 +};
81104 +
81105 +struct gr_reload_state {
81106 + struct gr_policy_state oldpolicy;
81107 + struct gr_alloc_state oldalloc;
81108 + struct gr_policy_state newpolicy;
81109 + struct gr_alloc_state newalloc;
81110 + struct gr_policy_state *oldpolicy_ptr;
81111 + struct gr_alloc_state *oldalloc_ptr;
81112 + unsigned char oldmode;
81113 +};
81114 +
81115 +/* End Data Structures Section */
81116 +
81117 +/* Hash functions generated by empirical testing by Brad Spengler
81118 + Makes good use of the low bits of the inode. Generally 0-1 times
81119 + in loop for successful match. 0-3 for unsuccessful match.
81120 + Shift/add algorithm with modulus of table size and an XOR*/
81121 +
81122 +static __inline__ unsigned int
81123 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
81124 +{
81125 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
81126 +}
81127 +
81128 + static __inline__ unsigned int
81129 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
81130 +{
81131 + return ((const unsigned long)userp % sz);
81132 +}
81133 +
81134 +static __inline__ unsigned int
81135 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
81136 +{
81137 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
81138 +}
81139 +
81140 +static __inline__ unsigned int
81141 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
81142 +{
81143 + return full_name_hash((const unsigned char *)name, len) % sz;
81144 +}
81145 +
81146 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
81147 + subj = NULL; \
81148 + iter = 0; \
81149 + while (iter < role->subj_hash_size) { \
81150 + if (subj == NULL) \
81151 + subj = role->subj_hash[iter]; \
81152 + if (subj == NULL) { \
81153 + iter++; \
81154 + continue; \
81155 + }
81156 +
81157 +#define FOR_EACH_SUBJECT_END(subj,iter) \
81158 + subj = subj->next; \
81159 + if (subj == NULL) \
81160 + iter++; \
81161 + }
81162 +
81163 +
81164 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
81165 + subj = role->hash->first; \
81166 + while (subj != NULL) {
81167 +
81168 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
81169 + subj = subj->next; \
81170 + }
81171 +
81172 +#endif
81173 +
81174 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
81175 new file mode 100644
81176 index 0000000..33ebd1f
81177 --- /dev/null
81178 +++ b/include/linux/gracl_compat.h
81179 @@ -0,0 +1,156 @@
81180 +#ifndef GR_ACL_COMPAT_H
81181 +#define GR_ACL_COMPAT_H
81182 +
81183 +#include <linux/resource.h>
81184 +#include <asm/resource.h>
81185 +
81186 +struct sprole_pw_compat {
81187 + compat_uptr_t rolename;
81188 + unsigned char salt[GR_SALT_LEN];
81189 + unsigned char sum[GR_SHA_LEN];
81190 +};
81191 +
81192 +struct gr_hash_struct_compat {
81193 + compat_uptr_t table;
81194 + compat_uptr_t nametable;
81195 + compat_uptr_t first;
81196 + __u32 table_size;
81197 + __u32 used_size;
81198 + int type;
81199 +};
81200 +
81201 +struct acl_subject_label_compat {
81202 + compat_uptr_t filename;
81203 + compat_ino_t inode;
81204 + __u32 device;
81205 + __u32 mode;
81206 + kernel_cap_t cap_mask;
81207 + kernel_cap_t cap_lower;
81208 + kernel_cap_t cap_invert_audit;
81209 +
81210 + struct compat_rlimit res[GR_NLIMITS];
81211 + __u32 resmask;
81212 +
81213 + __u8 user_trans_type;
81214 + __u8 group_trans_type;
81215 + compat_uptr_t user_transitions;
81216 + compat_uptr_t group_transitions;
81217 + __u16 user_trans_num;
81218 + __u16 group_trans_num;
81219 +
81220 + __u32 sock_families[2];
81221 + __u32 ip_proto[8];
81222 + __u32 ip_type;
81223 + compat_uptr_t ips;
81224 + __u32 ip_num;
81225 + __u32 inaddr_any_override;
81226 +
81227 + __u32 crashes;
81228 + compat_ulong_t expires;
81229 +
81230 + compat_uptr_t parent_subject;
81231 + compat_uptr_t hash;
81232 + compat_uptr_t prev;
81233 + compat_uptr_t next;
81234 +
81235 + compat_uptr_t obj_hash;
81236 + __u32 obj_hash_size;
81237 + __u16 pax_flags;
81238 +};
81239 +
81240 +struct role_allowed_ip_compat {
81241 + __u32 addr;
81242 + __u32 netmask;
81243 +
81244 + compat_uptr_t prev;
81245 + compat_uptr_t next;
81246 +};
81247 +
81248 +struct role_transition_compat {
81249 + compat_uptr_t rolename;
81250 +
81251 + compat_uptr_t prev;
81252 + compat_uptr_t next;
81253 +};
81254 +
81255 +struct acl_role_label_compat {
81256 + compat_uptr_t rolename;
81257 + uid_t uidgid;
81258 + __u16 roletype;
81259 +
81260 + __u16 auth_attempts;
81261 + compat_ulong_t expires;
81262 +
81263 + compat_uptr_t root_label;
81264 + compat_uptr_t hash;
81265 +
81266 + compat_uptr_t prev;
81267 + compat_uptr_t next;
81268 +
81269 + compat_uptr_t transitions;
81270 + compat_uptr_t allowed_ips;
81271 + compat_uptr_t domain_children;
81272 + __u16 domain_child_num;
81273 +
81274 + umode_t umask;
81275 +
81276 + compat_uptr_t subj_hash;
81277 + __u32 subj_hash_size;
81278 +};
81279 +
81280 +struct user_acl_role_db_compat {
81281 + compat_uptr_t r_table;
81282 + __u32 num_pointers;
81283 + __u32 num_roles;
81284 + __u32 num_domain_children;
81285 + __u32 num_subjects;
81286 + __u32 num_objects;
81287 +};
81288 +
81289 +struct acl_object_label_compat {
81290 + compat_uptr_t filename;
81291 + compat_ino_t inode;
81292 + __u32 device;
81293 + __u32 mode;
81294 +
81295 + compat_uptr_t nested;
81296 + compat_uptr_t globbed;
81297 +
81298 + compat_uptr_t prev;
81299 + compat_uptr_t next;
81300 +};
81301 +
81302 +struct acl_ip_label_compat {
81303 + compat_uptr_t iface;
81304 + __u32 addr;
81305 + __u32 netmask;
81306 + __u16 low, high;
81307 + __u8 mode;
81308 + __u32 type;
81309 + __u32 proto[8];
81310 +
81311 + compat_uptr_t prev;
81312 + compat_uptr_t next;
81313 +};
81314 +
81315 +struct gr_arg_compat {
81316 + struct user_acl_role_db_compat role_db;
81317 + unsigned char pw[GR_PW_LEN];
81318 + unsigned char salt[GR_SALT_LEN];
81319 + unsigned char sum[GR_SHA_LEN];
81320 + unsigned char sp_role[GR_SPROLE_LEN];
81321 + compat_uptr_t sprole_pws;
81322 + __u32 segv_device;
81323 + compat_ino_t segv_inode;
81324 + uid_t segv_uid;
81325 + __u16 num_sprole_pws;
81326 + __u16 mode;
81327 +};
81328 +
81329 +struct gr_arg_wrapper_compat {
81330 + compat_uptr_t arg;
81331 + __u32 version;
81332 + __u32 size;
81333 +};
81334 +
81335 +#endif
81336 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
81337 new file mode 100644
81338 index 0000000..323ecf2
81339 --- /dev/null
81340 +++ b/include/linux/gralloc.h
81341 @@ -0,0 +1,9 @@
81342 +#ifndef __GRALLOC_H
81343 +#define __GRALLOC_H
81344 +
81345 +void acl_free_all(void);
81346 +int acl_alloc_stack_init(unsigned long size);
81347 +void *acl_alloc(unsigned long len);
81348 +void *acl_alloc_num(unsigned long num, unsigned long len);
81349 +
81350 +#endif
81351 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
81352 new file mode 100644
81353 index 0000000..be66033
81354 --- /dev/null
81355 +++ b/include/linux/grdefs.h
81356 @@ -0,0 +1,140 @@
81357 +#ifndef GRDEFS_H
81358 +#define GRDEFS_H
81359 +
81360 +/* Begin grsecurity status declarations */
81361 +
81362 +enum {
81363 + GR_READY = 0x01,
81364 + GR_STATUS_INIT = 0x00 // disabled state
81365 +};
81366 +
81367 +/* Begin ACL declarations */
81368 +
81369 +/* Role flags */
81370 +
81371 +enum {
81372 + GR_ROLE_USER = 0x0001,
81373 + GR_ROLE_GROUP = 0x0002,
81374 + GR_ROLE_DEFAULT = 0x0004,
81375 + GR_ROLE_SPECIAL = 0x0008,
81376 + GR_ROLE_AUTH = 0x0010,
81377 + GR_ROLE_NOPW = 0x0020,
81378 + GR_ROLE_GOD = 0x0040,
81379 + GR_ROLE_LEARN = 0x0080,
81380 + GR_ROLE_TPE = 0x0100,
81381 + GR_ROLE_DOMAIN = 0x0200,
81382 + GR_ROLE_PAM = 0x0400,
81383 + GR_ROLE_PERSIST = 0x0800
81384 +};
81385 +
81386 +/* ACL Subject and Object mode flags */
81387 +enum {
81388 + GR_DELETED = 0x80000000
81389 +};
81390 +
81391 +/* ACL Object-only mode flags */
81392 +enum {
81393 + GR_READ = 0x00000001,
81394 + GR_APPEND = 0x00000002,
81395 + GR_WRITE = 0x00000004,
81396 + GR_EXEC = 0x00000008,
81397 + GR_FIND = 0x00000010,
81398 + GR_INHERIT = 0x00000020,
81399 + GR_SETID = 0x00000040,
81400 + GR_CREATE = 0x00000080,
81401 + GR_DELETE = 0x00000100,
81402 + GR_LINK = 0x00000200,
81403 + GR_AUDIT_READ = 0x00000400,
81404 + GR_AUDIT_APPEND = 0x00000800,
81405 + GR_AUDIT_WRITE = 0x00001000,
81406 + GR_AUDIT_EXEC = 0x00002000,
81407 + GR_AUDIT_FIND = 0x00004000,
81408 + GR_AUDIT_INHERIT= 0x00008000,
81409 + GR_AUDIT_SETID = 0x00010000,
81410 + GR_AUDIT_CREATE = 0x00020000,
81411 + GR_AUDIT_DELETE = 0x00040000,
81412 + GR_AUDIT_LINK = 0x00080000,
81413 + GR_PTRACERD = 0x00100000,
81414 + GR_NOPTRACE = 0x00200000,
81415 + GR_SUPPRESS = 0x00400000,
81416 + GR_NOLEARN = 0x00800000,
81417 + GR_INIT_TRANSFER= 0x01000000
81418 +};
81419 +
81420 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
81421 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
81422 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
81423 +
81424 +/* ACL subject-only mode flags */
81425 +enum {
81426 + GR_KILL = 0x00000001,
81427 + GR_VIEW = 0x00000002,
81428 + GR_PROTECTED = 0x00000004,
81429 + GR_LEARN = 0x00000008,
81430 + GR_OVERRIDE = 0x00000010,
81431 + /* just a placeholder, this mode is only used in userspace */
81432 + GR_DUMMY = 0x00000020,
81433 + GR_PROTSHM = 0x00000040,
81434 + GR_KILLPROC = 0x00000080,
81435 + GR_KILLIPPROC = 0x00000100,
81436 + /* just a placeholder, this mode is only used in userspace */
81437 + GR_NOTROJAN = 0x00000200,
81438 + GR_PROTPROCFD = 0x00000400,
81439 + GR_PROCACCT = 0x00000800,
81440 + GR_RELAXPTRACE = 0x00001000,
81441 + //GR_NESTED = 0x00002000,
81442 + GR_INHERITLEARN = 0x00004000,
81443 + GR_PROCFIND = 0x00008000,
81444 + GR_POVERRIDE = 0x00010000,
81445 + GR_KERNELAUTH = 0x00020000,
81446 + GR_ATSECURE = 0x00040000,
81447 + GR_SHMEXEC = 0x00080000
81448 +};
81449 +
81450 +enum {
81451 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
81452 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
81453 + GR_PAX_ENABLE_MPROTECT = 0x0004,
81454 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
81455 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
81456 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
81457 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
81458 + GR_PAX_DISABLE_MPROTECT = 0x0400,
81459 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
81460 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
81461 +};
81462 +
81463 +enum {
81464 + GR_ID_USER = 0x01,
81465 + GR_ID_GROUP = 0x02,
81466 +};
81467 +
81468 +enum {
81469 + GR_ID_ALLOW = 0x01,
81470 + GR_ID_DENY = 0x02,
81471 +};
81472 +
81473 +#define GR_CRASH_RES 31
81474 +#define GR_UIDTABLE_MAX 500
81475 +
81476 +/* begin resource learning section */
81477 +enum {
81478 + GR_RLIM_CPU_BUMP = 60,
81479 + GR_RLIM_FSIZE_BUMP = 50000,
81480 + GR_RLIM_DATA_BUMP = 10000,
81481 + GR_RLIM_STACK_BUMP = 1000,
81482 + GR_RLIM_CORE_BUMP = 10000,
81483 + GR_RLIM_RSS_BUMP = 500000,
81484 + GR_RLIM_NPROC_BUMP = 1,
81485 + GR_RLIM_NOFILE_BUMP = 5,
81486 + GR_RLIM_MEMLOCK_BUMP = 50000,
81487 + GR_RLIM_AS_BUMP = 500000,
81488 + GR_RLIM_LOCKS_BUMP = 2,
81489 + GR_RLIM_SIGPENDING_BUMP = 5,
81490 + GR_RLIM_MSGQUEUE_BUMP = 10000,
81491 + GR_RLIM_NICE_BUMP = 1,
81492 + GR_RLIM_RTPRIO_BUMP = 1,
81493 + GR_RLIM_RTTIME_BUMP = 1000000
81494 +};
81495 +
81496 +#endif
81497 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
81498 new file mode 100644
81499 index 0000000..d25522e
81500 --- /dev/null
81501 +++ b/include/linux/grinternal.h
81502 @@ -0,0 +1,229 @@
81503 +#ifndef __GRINTERNAL_H
81504 +#define __GRINTERNAL_H
81505 +
81506 +#ifdef CONFIG_GRKERNSEC
81507 +
81508 +#include <linux/fs.h>
81509 +#include <linux/mnt_namespace.h>
81510 +#include <linux/nsproxy.h>
81511 +#include <linux/gracl.h>
81512 +#include <linux/grdefs.h>
81513 +#include <linux/grmsg.h>
81514 +
81515 +void gr_add_learn_entry(const char *fmt, ...)
81516 + __attribute__ ((format (printf, 1, 2)));
81517 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
81518 + const struct vfsmount *mnt);
81519 +__u32 gr_check_create(const struct dentry *new_dentry,
81520 + const struct dentry *parent,
81521 + const struct vfsmount *mnt, const __u32 mode);
81522 +int gr_check_protected_task(const struct task_struct *task);
81523 +__u32 to_gr_audit(const __u32 reqmode);
81524 +int gr_set_acls(const int type);
81525 +int gr_acl_is_enabled(void);
81526 +char gr_roletype_to_char(void);
81527 +
81528 +void gr_handle_alertkill(struct task_struct *task);
81529 +char *gr_to_filename(const struct dentry *dentry,
81530 + const struct vfsmount *mnt);
81531 +char *gr_to_filename1(const struct dentry *dentry,
81532 + const struct vfsmount *mnt);
81533 +char *gr_to_filename2(const struct dentry *dentry,
81534 + const struct vfsmount *mnt);
81535 +char *gr_to_filename3(const struct dentry *dentry,
81536 + const struct vfsmount *mnt);
81537 +
81538 +extern int grsec_enable_ptrace_readexec;
81539 +extern int grsec_enable_harden_ptrace;
81540 +extern int grsec_enable_link;
81541 +extern int grsec_enable_fifo;
81542 +extern int grsec_enable_execve;
81543 +extern int grsec_enable_shm;
81544 +extern int grsec_enable_execlog;
81545 +extern int grsec_enable_signal;
81546 +extern int grsec_enable_audit_ptrace;
81547 +extern int grsec_enable_forkfail;
81548 +extern int grsec_enable_time;
81549 +extern int grsec_enable_rofs;
81550 +extern int grsec_deny_new_usb;
81551 +extern int grsec_enable_chroot_shmat;
81552 +extern int grsec_enable_chroot_mount;
81553 +extern int grsec_enable_chroot_double;
81554 +extern int grsec_enable_chroot_pivot;
81555 +extern int grsec_enable_chroot_chdir;
81556 +extern int grsec_enable_chroot_chmod;
81557 +extern int grsec_enable_chroot_mknod;
81558 +extern int grsec_enable_chroot_fchdir;
81559 +extern int grsec_enable_chroot_nice;
81560 +extern int grsec_enable_chroot_execlog;
81561 +extern int grsec_enable_chroot_caps;
81562 +extern int grsec_enable_chroot_sysctl;
81563 +extern int grsec_enable_chroot_unix;
81564 +extern int grsec_enable_symlinkown;
81565 +extern kgid_t grsec_symlinkown_gid;
81566 +extern int grsec_enable_tpe;
81567 +extern kgid_t grsec_tpe_gid;
81568 +extern int grsec_enable_tpe_all;
81569 +extern int grsec_enable_tpe_invert;
81570 +extern int grsec_enable_socket_all;
81571 +extern kgid_t grsec_socket_all_gid;
81572 +extern int grsec_enable_socket_client;
81573 +extern kgid_t grsec_socket_client_gid;
81574 +extern int grsec_enable_socket_server;
81575 +extern kgid_t grsec_socket_server_gid;
81576 +extern kgid_t grsec_audit_gid;
81577 +extern int grsec_enable_group;
81578 +extern int grsec_enable_log_rwxmaps;
81579 +extern int grsec_enable_mount;
81580 +extern int grsec_enable_chdir;
81581 +extern int grsec_resource_logging;
81582 +extern int grsec_enable_blackhole;
81583 +extern int grsec_lastack_retries;
81584 +extern int grsec_enable_brute;
81585 +extern int grsec_enable_harden_ipc;
81586 +extern int grsec_lock;
81587 +
81588 +extern spinlock_t grsec_alert_lock;
81589 +extern unsigned long grsec_alert_wtime;
81590 +extern unsigned long grsec_alert_fyet;
81591 +
81592 +extern spinlock_t grsec_audit_lock;
81593 +
81594 +extern rwlock_t grsec_exec_file_lock;
81595 +
81596 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
81597 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
81598 + (tsk)->exec_file->f_path.mnt) : "/")
81599 +
81600 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
81601 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
81602 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
81603 +
81604 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
81605 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
81606 + (tsk)->exec_file->f_path.mnt) : "/")
81607 +
81608 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
81609 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
81610 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
81611 +
81612 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
81613 +
81614 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
81615 +
81616 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
81617 +{
81618 + if (file1 && file2) {
81619 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
81620 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
81621 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
81622 + return true;
81623 + }
81624 +
81625 + return false;
81626 +}
81627 +
81628 +#define GR_CHROOT_CAPS {{ \
81629 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
81630 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
81631 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
81632 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
81633 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
81634 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
81635 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
81636 +
81637 +#define security_learn(normal_msg,args...) \
81638 +({ \
81639 + read_lock(&grsec_exec_file_lock); \
81640 + gr_add_learn_entry(normal_msg "\n", ## args); \
81641 + read_unlock(&grsec_exec_file_lock); \
81642 +})
81643 +
81644 +enum {
81645 + GR_DO_AUDIT,
81646 + GR_DONT_AUDIT,
81647 + /* used for non-audit messages that we shouldn't kill the task on */
81648 + GR_DONT_AUDIT_GOOD
81649 +};
81650 +
81651 +enum {
81652 + GR_TTYSNIFF,
81653 + GR_RBAC,
81654 + GR_RBAC_STR,
81655 + GR_STR_RBAC,
81656 + GR_RBAC_MODE2,
81657 + GR_RBAC_MODE3,
81658 + GR_FILENAME,
81659 + GR_SYSCTL_HIDDEN,
81660 + GR_NOARGS,
81661 + GR_ONE_INT,
81662 + GR_ONE_INT_TWO_STR,
81663 + GR_ONE_STR,
81664 + GR_STR_INT,
81665 + GR_TWO_STR_INT,
81666 + GR_TWO_INT,
81667 + GR_TWO_U64,
81668 + GR_THREE_INT,
81669 + GR_FIVE_INT_TWO_STR,
81670 + GR_TWO_STR,
81671 + GR_THREE_STR,
81672 + GR_FOUR_STR,
81673 + GR_STR_FILENAME,
81674 + GR_FILENAME_STR,
81675 + GR_FILENAME_TWO_INT,
81676 + GR_FILENAME_TWO_INT_STR,
81677 + GR_TEXTREL,
81678 + GR_PTRACE,
81679 + GR_RESOURCE,
81680 + GR_CAP,
81681 + GR_SIG,
81682 + GR_SIG2,
81683 + GR_CRASH1,
81684 + GR_CRASH2,
81685 + GR_PSACCT,
81686 + GR_RWXMAP,
81687 + GR_RWXMAPVMA
81688 +};
81689 +
81690 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
81691 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
81692 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
81693 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
81694 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
81695 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
81696 +#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)
81697 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
81698 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
81699 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
81700 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
81701 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
81702 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
81703 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
81704 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
81705 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
81706 +#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)
81707 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
81708 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
81709 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
81710 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
81711 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
81712 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
81713 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
81714 +#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)
81715 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
81716 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
81717 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
81718 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
81719 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
81720 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
81721 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
81722 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
81723 +#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)
81724 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
81725 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
81726 +
81727 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
81728 +
81729 +#endif
81730 +
81731 +#endif
81732 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
81733 new file mode 100644
81734 index 0000000..b02ba9d
81735 --- /dev/null
81736 +++ b/include/linux/grmsg.h
81737 @@ -0,0 +1,117 @@
81738 +#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"
81739 +#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"
81740 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
81741 +#define GR_STOPMOD_MSG "denied modification of module state by "
81742 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
81743 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
81744 +#define GR_IOPERM_MSG "denied use of ioperm() by "
81745 +#define GR_IOPL_MSG "denied use of iopl() by "
81746 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
81747 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
81748 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
81749 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
81750 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
81751 +#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"
81752 +#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"
81753 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
81754 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
81755 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
81756 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
81757 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
81758 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
81759 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
81760 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
81761 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
81762 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
81763 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
81764 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
81765 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
81766 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
81767 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
81768 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
81769 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
81770 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
81771 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
81772 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
81773 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
81774 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
81775 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
81776 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
81777 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
81778 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
81779 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
81780 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
81781 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
81782 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
81783 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
81784 +#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
81785 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
81786 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
81787 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
81788 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
81789 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
81790 +#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"
81791 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
81792 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
81793 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
81794 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
81795 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
81796 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
81797 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
81798 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
81799 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
81800 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
81801 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
81802 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
81803 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
81804 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
81805 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
81806 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
81807 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
81808 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
81809 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
81810 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
81811 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
81812 +#define GR_NICE_CHROOT_MSG "denied priority change by "
81813 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
81814 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
81815 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
81816 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
81817 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
81818 +#define GR_TIME_MSG "time set by "
81819 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
81820 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
81821 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
81822 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
81823 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
81824 +#define GR_BIND_MSG "denied bind() by "
81825 +#define GR_CONNECT_MSG "denied connect() by "
81826 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
81827 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
81828 +#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"
81829 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
81830 +#define GR_CAP_ACL_MSG "use of %s denied for "
81831 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
81832 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
81833 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
81834 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
81835 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
81836 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
81837 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
81838 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
81839 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
81840 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
81841 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
81842 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
81843 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
81844 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
81845 +#define GR_VM86_MSG "denied use of vm86 by "
81846 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
81847 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
81848 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
81849 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
81850 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
81851 +#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 "
81852 +#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 "
81853 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
81854 +#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
81855 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
81856 new file mode 100644
81857 index 0000000..bb53817
81858 --- /dev/null
81859 +++ b/include/linux/grsecurity.h
81860 @@ -0,0 +1,244 @@
81861 +#ifndef GR_SECURITY_H
81862 +#define GR_SECURITY_H
81863 +#include <linux/fs.h>
81864 +#include <linux/fs_struct.h>
81865 +#include <linux/binfmts.h>
81866 +#include <linux/gracl.h>
81867 +
81868 +/* notify of brain-dead configs */
81869 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81870 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
81871 +#endif
81872 +#if defined(CONFIG_GRKERNSEC_PROC) && !defined(CONFIG_GRKERNSEC_PROC_USER) && !defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81873 +#error "CONFIG_GRKERNSEC_PROC enabled, but neither CONFIG_GRKERNSEC_PROC_USER nor CONFIG_GRKERNSEC_PROC_USERGROUP enabled"
81874 +#endif
81875 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
81876 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
81877 +#endif
81878 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
81879 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
81880 +#endif
81881 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
81882 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
81883 +#endif
81884 +
81885 +int gr_handle_new_usb(void);
81886 +
81887 +void gr_handle_brute_attach(int dumpable);
81888 +void gr_handle_brute_check(void);
81889 +void gr_handle_kernel_exploit(void);
81890 +
81891 +char gr_roletype_to_char(void);
81892 +
81893 +int gr_proc_is_restricted(void);
81894 +
81895 +int gr_acl_enable_at_secure(void);
81896 +
81897 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
81898 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
81899 +
81900 +int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap);
81901 +
81902 +void gr_del_task_from_ip_table(struct task_struct *p);
81903 +
81904 +int gr_pid_is_chrooted(struct task_struct *p);
81905 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
81906 +int gr_handle_chroot_nice(void);
81907 +int gr_handle_chroot_sysctl(const int op);
81908 +int gr_handle_chroot_setpriority(struct task_struct *p,
81909 + const int niceval);
81910 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
81911 +int gr_chroot_fhandle(void);
81912 +int gr_handle_chroot_chroot(const struct dentry *dentry,
81913 + const struct vfsmount *mnt);
81914 +void gr_handle_chroot_chdir(const struct path *path);
81915 +int gr_handle_chroot_chmod(const struct dentry *dentry,
81916 + const struct vfsmount *mnt, const int mode);
81917 +int gr_handle_chroot_mknod(const struct dentry *dentry,
81918 + const struct vfsmount *mnt, const int mode);
81919 +int gr_handle_chroot_mount(const struct dentry *dentry,
81920 + const struct vfsmount *mnt,
81921 + const char *dev_name);
81922 +int gr_handle_chroot_pivot(void);
81923 +int gr_handle_chroot_unix(const pid_t pid);
81924 +
81925 +int gr_handle_rawio(const struct inode *inode);
81926 +
81927 +void gr_handle_ioperm(void);
81928 +void gr_handle_iopl(void);
81929 +void gr_handle_msr_write(void);
81930 +
81931 +umode_t gr_acl_umask(void);
81932 +
81933 +int gr_tpe_allow(const struct file *file);
81934 +
81935 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
81936 +void gr_clear_chroot_entries(struct task_struct *task);
81937 +
81938 +void gr_log_forkfail(const int retval);
81939 +void gr_log_timechange(void);
81940 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
81941 +void gr_log_chdir(const struct dentry *dentry,
81942 + const struct vfsmount *mnt);
81943 +void gr_log_chroot_exec(const struct dentry *dentry,
81944 + const struct vfsmount *mnt);
81945 +void gr_log_remount(const char *devname, const int retval);
81946 +void gr_log_unmount(const char *devname, const int retval);
81947 +void gr_log_mount(const char *from, const char *to, const int retval);
81948 +void gr_log_textrel(struct vm_area_struct *vma);
81949 +void gr_log_ptgnustack(struct file *file);
81950 +void gr_log_rwxmmap(struct file *file);
81951 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
81952 +
81953 +int gr_handle_follow_link(const struct inode *parent,
81954 + const struct inode *inode,
81955 + const struct dentry *dentry,
81956 + const struct vfsmount *mnt);
81957 +int gr_handle_fifo(const struct dentry *dentry,
81958 + const struct vfsmount *mnt,
81959 + const struct dentry *dir, const int flag,
81960 + const int acc_mode);
81961 +int gr_handle_hardlink(const struct dentry *dentry,
81962 + const struct vfsmount *mnt,
81963 + struct inode *inode,
81964 + const int mode, const struct filename *to);
81965 +
81966 +int gr_is_capable(const int cap);
81967 +int gr_is_capable_nolog(const int cap);
81968 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
81969 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
81970 +
81971 +void gr_copy_label(struct task_struct *tsk);
81972 +void gr_handle_crash(struct task_struct *task, const int sig);
81973 +int gr_handle_signal(const struct task_struct *p, const int sig);
81974 +int gr_check_crash_uid(const kuid_t uid);
81975 +int gr_check_protected_task(const struct task_struct *task);
81976 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
81977 +int gr_acl_handle_mmap(const struct file *file,
81978 + const unsigned long prot);
81979 +int gr_acl_handle_mprotect(const struct file *file,
81980 + const unsigned long prot);
81981 +int gr_check_hidden_task(const struct task_struct *tsk);
81982 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
81983 + const struct vfsmount *mnt);
81984 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
81985 + const struct vfsmount *mnt);
81986 +__u32 gr_acl_handle_access(const struct dentry *dentry,
81987 + const struct vfsmount *mnt, const int fmode);
81988 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
81989 + const struct vfsmount *mnt, umode_t *mode);
81990 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
81991 + const struct vfsmount *mnt);
81992 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
81993 + const struct vfsmount *mnt);
81994 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
81995 + const struct vfsmount *mnt);
81996 +int gr_handle_ptrace(struct task_struct *task, const long request);
81997 +int gr_handle_proc_ptrace(struct task_struct *task);
81998 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
81999 + const struct vfsmount *mnt);
82000 +int gr_check_crash_exec(const struct file *filp);
82001 +int gr_acl_is_enabled(void);
82002 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
82003 + const kgid_t gid);
82004 +int gr_set_proc_label(const struct dentry *dentry,
82005 + const struct vfsmount *mnt,
82006 + const int unsafe_flags);
82007 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
82008 + const struct vfsmount *mnt);
82009 +__u32 gr_acl_handle_open(const struct dentry *dentry,
82010 + const struct vfsmount *mnt, int acc_mode);
82011 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
82012 + const struct dentry *p_dentry,
82013 + const struct vfsmount *p_mnt,
82014 + int open_flags, int acc_mode, const int imode);
82015 +void gr_handle_create(const struct dentry *dentry,
82016 + const struct vfsmount *mnt);
82017 +void gr_handle_proc_create(const struct dentry *dentry,
82018 + const struct inode *inode);
82019 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
82020 + const struct dentry *parent_dentry,
82021 + const struct vfsmount *parent_mnt,
82022 + const int mode);
82023 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
82024 + const struct dentry *parent_dentry,
82025 + const struct vfsmount *parent_mnt);
82026 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
82027 + const struct vfsmount *mnt);
82028 +void gr_handle_delete(const ino_t ino, const dev_t dev);
82029 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
82030 + const struct vfsmount *mnt);
82031 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
82032 + const struct dentry *parent_dentry,
82033 + const struct vfsmount *parent_mnt,
82034 + const struct filename *from);
82035 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
82036 + const struct dentry *parent_dentry,
82037 + const struct vfsmount *parent_mnt,
82038 + const struct dentry *old_dentry,
82039 + const struct vfsmount *old_mnt, const struct filename *to);
82040 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
82041 +int gr_acl_handle_rename(struct dentry *new_dentry,
82042 + struct dentry *parent_dentry,
82043 + const struct vfsmount *parent_mnt,
82044 + struct dentry *old_dentry,
82045 + struct inode *old_parent_inode,
82046 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
82047 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
82048 + struct dentry *old_dentry,
82049 + struct dentry *new_dentry,
82050 + struct vfsmount *mnt, const __u8 replace, unsigned int flags);
82051 +__u32 gr_check_link(const struct dentry *new_dentry,
82052 + const struct dentry *parent_dentry,
82053 + const struct vfsmount *parent_mnt,
82054 + const struct dentry *old_dentry,
82055 + const struct vfsmount *old_mnt);
82056 +int gr_acl_handle_filldir(const struct file *file, const char *name,
82057 + const unsigned int namelen, const ino_t ino);
82058 +
82059 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
82060 + const struct vfsmount *mnt);
82061 +void gr_acl_handle_exit(void);
82062 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
82063 +int gr_acl_handle_procpidmem(const struct task_struct *task);
82064 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
82065 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
82066 +void gr_audit_ptrace(struct task_struct *task);
82067 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
82068 +void gr_put_exec_file(struct task_struct *task);
82069 +
82070 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
82071 +
82072 +#ifdef CONFIG_GRKERNSEC_RESLOG
82073 +extern void gr_log_resource(const struct task_struct *task, const int res,
82074 + const unsigned long wanted, const int gt);
82075 +#else
82076 +static inline void gr_log_resource(const struct task_struct *task, const int res,
82077 + const unsigned long wanted, const int gt)
82078 +{
82079 +}
82080 +#endif
82081 +
82082 +#ifdef CONFIG_GRKERNSEC
82083 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
82084 +void gr_handle_vm86(void);
82085 +void gr_handle_mem_readwrite(u64 from, u64 to);
82086 +
82087 +void gr_log_badprocpid(const char *entry);
82088 +
82089 +extern int grsec_enable_dmesg;
82090 +extern int grsec_disable_privio;
82091 +
82092 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
82093 +extern kgid_t grsec_proc_gid;
82094 +#endif
82095 +
82096 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
82097 +extern int grsec_enable_chroot_findtask;
82098 +#endif
82099 +#ifdef CONFIG_GRKERNSEC_SETXID
82100 +extern int grsec_enable_setxid;
82101 +#endif
82102 +#endif
82103 +
82104 +#endif
82105 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
82106 new file mode 100644
82107 index 0000000..e7ffaaf
82108 --- /dev/null
82109 +++ b/include/linux/grsock.h
82110 @@ -0,0 +1,19 @@
82111 +#ifndef __GRSOCK_H
82112 +#define __GRSOCK_H
82113 +
82114 +extern void gr_attach_curr_ip(const struct sock *sk);
82115 +extern int gr_handle_sock_all(const int family, const int type,
82116 + const int protocol);
82117 +extern int gr_handle_sock_server(const struct sockaddr *sck);
82118 +extern int gr_handle_sock_server_other(const struct sock *sck);
82119 +extern int gr_handle_sock_client(const struct sockaddr *sck);
82120 +extern int gr_search_connect(struct socket * sock,
82121 + struct sockaddr_in * addr);
82122 +extern int gr_search_bind(struct socket * sock,
82123 + struct sockaddr_in * addr);
82124 +extern int gr_search_listen(struct socket * sock);
82125 +extern int gr_search_accept(struct socket * sock);
82126 +extern int gr_search_socket(const int domain, const int type,
82127 + const int protocol);
82128 +
82129 +#endif
82130 diff --git a/include/linux/hash.h b/include/linux/hash.h
82131 index d0494c3..69b7715 100644
82132 --- a/include/linux/hash.h
82133 +++ b/include/linux/hash.h
82134 @@ -87,7 +87,7 @@ static inline u32 hash32_ptr(const void *ptr)
82135 struct fast_hash_ops {
82136 u32 (*hash)(const void *data, u32 len, u32 seed);
82137 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
82138 -};
82139 +} __no_const;
82140
82141 /**
82142 * arch_fast_hash - Caclulates a hash over a given buffer that can have
82143 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
82144 index 9286a46..373f27f 100644
82145 --- a/include/linux/highmem.h
82146 +++ b/include/linux/highmem.h
82147 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
82148 kunmap_atomic(kaddr);
82149 }
82150
82151 +static inline void sanitize_highpage(struct page *page)
82152 +{
82153 + void *kaddr;
82154 + unsigned long flags;
82155 +
82156 + local_irq_save(flags);
82157 + kaddr = kmap_atomic(page);
82158 + clear_page(kaddr);
82159 + kunmap_atomic(kaddr);
82160 + local_irq_restore(flags);
82161 +}
82162 +
82163 static inline void zero_user_segments(struct page *page,
82164 unsigned start1, unsigned end1,
82165 unsigned start2, unsigned end2)
82166 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
82167 index 1c7b89a..7dda400 100644
82168 --- a/include/linux/hwmon-sysfs.h
82169 +++ b/include/linux/hwmon-sysfs.h
82170 @@ -25,7 +25,8 @@
82171 struct sensor_device_attribute{
82172 struct device_attribute dev_attr;
82173 int index;
82174 -};
82175 +} __do_const;
82176 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
82177 #define to_sensor_dev_attr(_dev_attr) \
82178 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
82179
82180 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
82181 struct device_attribute dev_attr;
82182 u8 index;
82183 u8 nr;
82184 -};
82185 +} __do_const;
82186 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
82187 #define to_sensor_dev_attr_2(_dev_attr) \
82188 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
82189
82190 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
82191 index b556e0a..c10a515 100644
82192 --- a/include/linux/i2c.h
82193 +++ b/include/linux/i2c.h
82194 @@ -378,6 +378,7 @@ struct i2c_algorithm {
82195 /* To determine what the adapter supports */
82196 u32 (*functionality) (struct i2c_adapter *);
82197 };
82198 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
82199
82200 /**
82201 * struct i2c_bus_recovery_info - I2C bus recovery information
82202 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
82203 index d23c3c2..eb63c81 100644
82204 --- a/include/linux/i2o.h
82205 +++ b/include/linux/i2o.h
82206 @@ -565,7 +565,7 @@ struct i2o_controller {
82207 struct i2o_device *exec; /* Executive */
82208 #if BITS_PER_LONG == 64
82209 spinlock_t context_list_lock; /* lock for context_list */
82210 - atomic_t context_list_counter; /* needed for unique contexts */
82211 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
82212 struct list_head context_list; /* list of context id's
82213 and pointers */
82214 #endif
82215 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
82216 index aff7ad8..3942bbd 100644
82217 --- a/include/linux/if_pppox.h
82218 +++ b/include/linux/if_pppox.h
82219 @@ -76,7 +76,7 @@ struct pppox_proto {
82220 int (*ioctl)(struct socket *sock, unsigned int cmd,
82221 unsigned long arg);
82222 struct module *owner;
82223 -};
82224 +} __do_const;
82225
82226 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
82227 extern void unregister_pppox_proto(int proto_num);
82228 diff --git a/include/linux/init.h b/include/linux/init.h
82229 index 2df8e8d..3e1280d 100644
82230 --- a/include/linux/init.h
82231 +++ b/include/linux/init.h
82232 @@ -37,9 +37,17 @@
82233 * section.
82234 */
82235
82236 +#define add_init_latent_entropy __latent_entropy
82237 +
82238 +#ifdef CONFIG_MEMORY_HOTPLUG
82239 +#define add_meminit_latent_entropy
82240 +#else
82241 +#define add_meminit_latent_entropy __latent_entropy
82242 +#endif
82243 +
82244 /* These are for everybody (although not all archs will actually
82245 discard it in modules) */
82246 -#define __init __section(.init.text) __cold notrace
82247 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
82248 #define __initdata __section(.init.data)
82249 #define __initconst __constsection(.init.rodata)
82250 #define __exitdata __section(.exit.data)
82251 @@ -100,7 +108,7 @@
82252 #define __cpuexitconst
82253
82254 /* Used for MEMORY_HOTPLUG */
82255 -#define __meminit __section(.meminit.text) __cold notrace
82256 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
82257 #define __meminitdata __section(.meminit.data)
82258 #define __meminitconst __constsection(.meminit.rodata)
82259 #define __memexit __section(.memexit.text) __exitused __cold notrace
82260 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
82261 index 77fc43f..73caf92 100644
82262 --- a/include/linux/init_task.h
82263 +++ b/include/linux/init_task.h
82264 @@ -158,6 +158,12 @@ extern struct task_group root_task_group;
82265
82266 #define INIT_TASK_COMM "swapper"
82267
82268 +#ifdef CONFIG_X86
82269 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
82270 +#else
82271 +#define INIT_TASK_THREAD_INFO
82272 +#endif
82273 +
82274 #ifdef CONFIG_RT_MUTEXES
82275 # define INIT_RT_MUTEXES(tsk) \
82276 .pi_waiters = RB_ROOT, \
82277 @@ -205,6 +211,7 @@ extern struct task_group root_task_group;
82278 RCU_POINTER_INITIALIZER(cred, &init_cred), \
82279 .comm = INIT_TASK_COMM, \
82280 .thread = INIT_THREAD, \
82281 + INIT_TASK_THREAD_INFO \
82282 .fs = &init_fs, \
82283 .files = &init_files, \
82284 .signal = &init_signals, \
82285 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
82286 index 69517a2..6b12d37 100644
82287 --- a/include/linux/interrupt.h
82288 +++ b/include/linux/interrupt.h
82289 @@ -413,8 +413,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
82290
82291 struct softirq_action
82292 {
82293 - void (*action)(struct softirq_action *);
82294 -};
82295 + void (*action)(void);
82296 +} __no_const;
82297
82298 asmlinkage void do_softirq(void);
82299 asmlinkage void __do_softirq(void);
82300 @@ -428,7 +428,7 @@ static inline void do_softirq_own_stack(void)
82301 }
82302 #endif
82303
82304 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
82305 +extern void open_softirq(int nr, void (*action)(void));
82306 extern void softirq_init(void);
82307 extern void __raise_softirq_irqoff(unsigned int nr);
82308
82309 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
82310 index e6a7c9f..5804745 100644
82311 --- a/include/linux/iommu.h
82312 +++ b/include/linux/iommu.h
82313 @@ -133,7 +133,7 @@ struct iommu_ops {
82314 u32 (*domain_get_windows)(struct iommu_domain *domain);
82315
82316 unsigned long pgsize_bitmap;
82317 -};
82318 +} __do_const;
82319
82320 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
82321 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
82322 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
82323 index 2c525022..345b106 100644
82324 --- a/include/linux/ioport.h
82325 +++ b/include/linux/ioport.h
82326 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
82327 int adjust_resource(struct resource *res, resource_size_t start,
82328 resource_size_t size);
82329 resource_size_t resource_alignment(struct resource *res);
82330 -static inline resource_size_t resource_size(const struct resource *res)
82331 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
82332 {
82333 return res->end - res->start + 1;
82334 }
82335 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
82336 index 35e7eca..6afb7ad 100644
82337 --- a/include/linux/ipc_namespace.h
82338 +++ b/include/linux/ipc_namespace.h
82339 @@ -69,7 +69,7 @@ struct ipc_namespace {
82340 struct user_namespace *user_ns;
82341
82342 unsigned int proc_inum;
82343 -};
82344 +} __randomize_layout;
82345
82346 extern struct ipc_namespace init_ipc_ns;
82347 extern atomic_t nr_ipc_ns;
82348 diff --git a/include/linux/irq.h b/include/linux/irq.h
82349 index 03f48d9..e86af0c 100644
82350 --- a/include/linux/irq.h
82351 +++ b/include/linux/irq.h
82352 @@ -352,7 +352,8 @@ struct irq_chip {
82353 void (*irq_release_resources)(struct irq_data *data);
82354
82355 unsigned long flags;
82356 -};
82357 +} __do_const;
82358 +typedef struct irq_chip __no_const irq_chip_no_const;
82359
82360 /*
82361 * irq_chip specific flags
82362 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
82363 index 13eed92..3261c86 100644
82364 --- a/include/linux/irqchip/arm-gic.h
82365 +++ b/include/linux/irqchip/arm-gic.h
82366 @@ -91,9 +91,11 @@
82367
82368 #ifndef __ASSEMBLY__
82369
82370 +#include <linux/irq.h>
82371 +
82372 struct device_node;
82373
82374 -extern struct irq_chip gic_arch_extn;
82375 +extern irq_chip_no_const gic_arch_extn;
82376
82377 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
82378 u32 offset, struct device_node *);
82379 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
82380 index c367cbd..c9b79e6 100644
82381 --- a/include/linux/jiffies.h
82382 +++ b/include/linux/jiffies.h
82383 @@ -280,20 +280,20 @@ extern unsigned long preset_lpj;
82384 /*
82385 * Convert various time units to each other:
82386 */
82387 -extern unsigned int jiffies_to_msecs(const unsigned long j);
82388 -extern unsigned int jiffies_to_usecs(const unsigned long j);
82389 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
82390 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
82391
82392 -static inline u64 jiffies_to_nsecs(const unsigned long j)
82393 +static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
82394 {
82395 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
82396 }
82397
82398 -extern unsigned long msecs_to_jiffies(const unsigned int m);
82399 -extern unsigned long usecs_to_jiffies(const unsigned int u);
82400 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
82401 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
82402 extern unsigned long timespec_to_jiffies(const struct timespec *value);
82403 extern void jiffies_to_timespec(const unsigned long jiffies,
82404 - struct timespec *value);
82405 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
82406 + struct timespec *value) __intentional_overflow(-1);
82407 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
82408 extern void jiffies_to_timeval(const unsigned long jiffies,
82409 struct timeval *value);
82410
82411 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
82412 index 6883e19..e854fcb 100644
82413 --- a/include/linux/kallsyms.h
82414 +++ b/include/linux/kallsyms.h
82415 @@ -15,7 +15,8 @@
82416
82417 struct module;
82418
82419 -#ifdef CONFIG_KALLSYMS
82420 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
82421 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
82422 /* Lookup the address for a symbol. Returns 0 if not found. */
82423 unsigned long kallsyms_lookup_name(const char *name);
82424
82425 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
82426 /* Stupid that this does nothing, but I didn't create this mess. */
82427 #define __print_symbol(fmt, addr)
82428 #endif /*CONFIG_KALLSYMS*/
82429 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
82430 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
82431 +extern unsigned long kallsyms_lookup_name(const char *name);
82432 +extern void __print_symbol(const char *fmt, unsigned long address);
82433 +extern int sprint_backtrace(char *buffer, unsigned long address);
82434 +extern int sprint_symbol(char *buffer, unsigned long address);
82435 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
82436 +const char *kallsyms_lookup(unsigned long addr,
82437 + unsigned long *symbolsize,
82438 + unsigned long *offset,
82439 + char **modname, char *namebuf);
82440 +extern int kallsyms_lookup_size_offset(unsigned long addr,
82441 + unsigned long *symbolsize,
82442 + unsigned long *offset);
82443 +#endif
82444
82445 /* This macro allows us to keep printk typechecking */
82446 static __printf(1, 2)
82447 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
82448 index ff9f1d3..6712be5 100644
82449 --- a/include/linux/key-type.h
82450 +++ b/include/linux/key-type.h
82451 @@ -152,7 +152,7 @@ struct key_type {
82452 /* internal fields */
82453 struct list_head link; /* link in types list */
82454 struct lock_class_key lock_class; /* key->sem lock class */
82455 -};
82456 +} __do_const;
82457
82458 extern struct key_type key_type_keyring;
82459
82460 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
82461 index e465bb1..19f605f 100644
82462 --- a/include/linux/kgdb.h
82463 +++ b/include/linux/kgdb.h
82464 @@ -52,7 +52,7 @@ extern int kgdb_connected;
82465 extern int kgdb_io_module_registered;
82466
82467 extern atomic_t kgdb_setting_breakpoint;
82468 -extern atomic_t kgdb_cpu_doing_single_step;
82469 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
82470
82471 extern struct task_struct *kgdb_usethread;
82472 extern struct task_struct *kgdb_contthread;
82473 @@ -254,7 +254,7 @@ struct kgdb_arch {
82474 void (*correct_hw_break)(void);
82475
82476 void (*enable_nmi)(bool on);
82477 -};
82478 +} __do_const;
82479
82480 /**
82481 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
82482 @@ -279,7 +279,7 @@ struct kgdb_io {
82483 void (*pre_exception) (void);
82484 void (*post_exception) (void);
82485 int is_console;
82486 -};
82487 +} __do_const;
82488
82489 extern struct kgdb_arch arch_kgdb_ops;
82490
82491 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
82492 index 0555cc6..40116ce 100644
82493 --- a/include/linux/kmod.h
82494 +++ b/include/linux/kmod.h
82495 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
82496 * usually useless though. */
82497 extern __printf(2, 3)
82498 int __request_module(bool wait, const char *name, ...);
82499 +extern __printf(3, 4)
82500 +int ___request_module(bool wait, char *param_name, const char *name, ...);
82501 #define request_module(mod...) __request_module(true, mod)
82502 #define request_module_nowait(mod...) __request_module(false, mod)
82503 #define try_then_request_module(x, mod...) \
82504 @@ -57,6 +59,9 @@ struct subprocess_info {
82505 struct work_struct work;
82506 struct completion *complete;
82507 char *path;
82508 +#ifdef CONFIG_GRKERNSEC
82509 + char *origpath;
82510 +#endif
82511 char **argv;
82512 char **envp;
82513 int wait;
82514 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
82515 index 2d61b90..a1d0a13 100644
82516 --- a/include/linux/kobject.h
82517 +++ b/include/linux/kobject.h
82518 @@ -118,7 +118,7 @@ struct kobj_type {
82519 struct attribute **default_attrs;
82520 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
82521 const void *(*namespace)(struct kobject *kobj);
82522 -};
82523 +} __do_const;
82524
82525 struct kobj_uevent_env {
82526 char *argv[3];
82527 @@ -142,6 +142,7 @@ struct kobj_attribute {
82528 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
82529 const char *buf, size_t count);
82530 };
82531 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
82532
82533 extern const struct sysfs_ops kobj_sysfs_ops;
82534
82535 @@ -169,7 +170,7 @@ struct kset {
82536 spinlock_t list_lock;
82537 struct kobject kobj;
82538 const struct kset_uevent_ops *uevent_ops;
82539 -};
82540 +} __randomize_layout;
82541
82542 extern void kset_init(struct kset *kset);
82543 extern int __must_check kset_register(struct kset *kset);
82544 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
82545 index df32d25..fb52e27 100644
82546 --- a/include/linux/kobject_ns.h
82547 +++ b/include/linux/kobject_ns.h
82548 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
82549 const void *(*netlink_ns)(struct sock *sk);
82550 const void *(*initial_ns)(void);
82551 void (*drop_ns)(void *);
82552 -};
82553 +} __do_const;
82554
82555 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
82556 int kobj_ns_type_registered(enum kobj_ns_type type);
82557 diff --git a/include/linux/kref.h b/include/linux/kref.h
82558 index 484604d..0f6c5b6 100644
82559 --- a/include/linux/kref.h
82560 +++ b/include/linux/kref.h
82561 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
82562 static inline int kref_sub(struct kref *kref, unsigned int count,
82563 void (*release)(struct kref *kref))
82564 {
82565 - WARN_ON(release == NULL);
82566 + BUG_ON(release == NULL);
82567
82568 if (atomic_sub_and_test((int) count, &kref->refcount)) {
82569 release(kref);
82570 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
82571 index a6059bd..8126d5c 100644
82572 --- a/include/linux/kvm_host.h
82573 +++ b/include/linux/kvm_host.h
82574 @@ -460,7 +460,7 @@ static inline void kvm_irqfd_exit(void)
82575 {
82576 }
82577 #endif
82578 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
82579 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
82580 struct module *module);
82581 void kvm_exit(void);
82582
82583 @@ -629,7 +629,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
82584 struct kvm_guest_debug *dbg);
82585 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
82586
82587 -int kvm_arch_init(void *opaque);
82588 +int kvm_arch_init(const void *opaque);
82589 void kvm_arch_exit(void);
82590
82591 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
82592 diff --git a/include/linux/libata.h b/include/linux/libata.h
82593 index bd5fefe..2a8a8d2 100644
82594 --- a/include/linux/libata.h
82595 +++ b/include/linux/libata.h
82596 @@ -976,7 +976,7 @@ struct ata_port_operations {
82597 * fields must be pointers.
82598 */
82599 const struct ata_port_operations *inherits;
82600 -};
82601 +} __do_const;
82602
82603 struct ata_port_info {
82604 unsigned long flags;
82605 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
82606 index a6a42dd..6c5ebce 100644
82607 --- a/include/linux/linkage.h
82608 +++ b/include/linux/linkage.h
82609 @@ -36,6 +36,7 @@
82610 #endif
82611
82612 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
82613 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
82614 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
82615
82616 /*
82617 diff --git a/include/linux/list.h b/include/linux/list.h
82618 index f33f831..1ffe5e2 100644
82619 --- a/include/linux/list.h
82620 +++ b/include/linux/list.h
82621 @@ -113,6 +113,19 @@ extern void __list_del_entry(struct list_head *entry);
82622 extern void list_del(struct list_head *entry);
82623 #endif
82624
82625 +extern void __pax_list_add(struct list_head *new,
82626 + struct list_head *prev,
82627 + struct list_head *next);
82628 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
82629 +{
82630 + __pax_list_add(new, head, head->next);
82631 +}
82632 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
82633 +{
82634 + __pax_list_add(new, head->prev, head);
82635 +}
82636 +extern void pax_list_del(struct list_head *entry);
82637 +
82638 /**
82639 * list_replace - replace old entry by new one
82640 * @old : the element to be replaced
82641 @@ -146,6 +159,8 @@ static inline void list_del_init(struct list_head *entry)
82642 INIT_LIST_HEAD(entry);
82643 }
82644
82645 +extern void pax_list_del_init(struct list_head *entry);
82646 +
82647 /**
82648 * list_move - delete from one list and add as another's head
82649 * @list: the entry to move
82650 diff --git a/include/linux/lockref.h b/include/linux/lockref.h
82651 index 4bfde0e..d6e2e09 100644
82652 --- a/include/linux/lockref.h
82653 +++ b/include/linux/lockref.h
82654 @@ -47,4 +47,36 @@ static inline int __lockref_is_dead(const struct lockref *l)
82655 return ((int)l->count < 0);
82656 }
82657
82658 +static inline unsigned int __lockref_read(struct lockref *lockref)
82659 +{
82660 + return lockref->count;
82661 +}
82662 +
82663 +static inline void __lockref_set(struct lockref *lockref, unsigned int count)
82664 +{
82665 + lockref->count = count;
82666 +}
82667 +
82668 +static inline void __lockref_inc(struct lockref *lockref)
82669 +{
82670 +
82671 +#ifdef CONFIG_PAX_REFCOUNT
82672 + atomic_inc((atomic_t *)&lockref->count);
82673 +#else
82674 + lockref->count++;
82675 +#endif
82676 +
82677 +}
82678 +
82679 +static inline void __lockref_dec(struct lockref *lockref)
82680 +{
82681 +
82682 +#ifdef CONFIG_PAX_REFCOUNT
82683 + atomic_dec((atomic_t *)&lockref->count);
82684 +#else
82685 + lockref->count--;
82686 +#endif
82687 +
82688 +}
82689 +
82690 #endif /* __LINUX_LOCKREF_H */
82691 diff --git a/include/linux/math64.h b/include/linux/math64.h
82692 index c45c089..298841c 100644
82693 --- a/include/linux/math64.h
82694 +++ b/include/linux/math64.h
82695 @@ -15,7 +15,7 @@
82696 * This is commonly provided by 32bit archs to provide an optimized 64bit
82697 * divide.
82698 */
82699 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
82700 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
82701 {
82702 *remainder = dividend % divisor;
82703 return dividend / divisor;
82704 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
82705 /**
82706 * div64_u64 - unsigned 64bit divide with 64bit divisor
82707 */
82708 -static inline u64 div64_u64(u64 dividend, u64 divisor)
82709 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
82710 {
82711 return dividend / divisor;
82712 }
82713 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
82714 #define div64_ul(x, y) div_u64((x), (y))
82715
82716 #ifndef div_u64_rem
82717 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
82718 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
82719 {
82720 *remainder = do_div(dividend, divisor);
82721 return dividend;
82722 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
82723 #endif
82724
82725 #ifndef div64_u64
82726 -extern u64 div64_u64(u64 dividend, u64 divisor);
82727 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
82728 #endif
82729
82730 #ifndef div64_s64
82731 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
82732 * divide.
82733 */
82734 #ifndef div_u64
82735 -static inline u64 div_u64(u64 dividend, u32 divisor)
82736 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
82737 {
82738 u32 remainder;
82739 return div_u64_rem(dividend, divisor, &remainder);
82740 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
82741 index 3d385c8..deacb6a 100644
82742 --- a/include/linux/mempolicy.h
82743 +++ b/include/linux/mempolicy.h
82744 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
82745 }
82746
82747 #define vma_policy(vma) ((vma)->vm_policy)
82748 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
82749 +{
82750 + vma->vm_policy = pol;
82751 +}
82752
82753 static inline void mpol_get(struct mempolicy *pol)
82754 {
82755 @@ -229,6 +233,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
82756 }
82757
82758 #define vma_policy(vma) NULL
82759 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
82760 +{
82761 +}
82762
82763 static inline int
82764 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
82765 diff --git a/include/linux/mm.h b/include/linux/mm.h
82766 index b464611..77cbfc1 100644
82767 --- a/include/linux/mm.h
82768 +++ b/include/linux/mm.h
82769 @@ -128,6 +128,11 @@ extern unsigned int kobjsize(const void *objp);
82770 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
82771 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
82772 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
82773 +
82774 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82775 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
82776 +#endif
82777 +
82778 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
82779
82780 #ifdef CONFIG_MEM_SOFT_DIRTY
82781 @@ -238,8 +243,8 @@ struct vm_operations_struct {
82782 /* called by access_process_vm when get_user_pages() fails, typically
82783 * for use by special VMAs that can switch between memory and hardware
82784 */
82785 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
82786 - void *buf, int len, int write);
82787 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
82788 + void *buf, size_t len, int write);
82789
82790 /* Called by the /proc/PID/maps code to ask the vma whether it
82791 * has a special name. Returning non-NULL will also cause this
82792 @@ -275,6 +280,7 @@ struct vm_operations_struct {
82793 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
82794 unsigned long size, pgoff_t pgoff);
82795 };
82796 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
82797
82798 struct mmu_gather;
82799 struct inode;
82800 @@ -1165,8 +1171,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
82801 unsigned long *pfn);
82802 int follow_phys(struct vm_area_struct *vma, unsigned long address,
82803 unsigned int flags, unsigned long *prot, resource_size_t *phys);
82804 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
82805 - void *buf, int len, int write);
82806 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
82807 + void *buf, size_t len, int write);
82808
82809 static inline void unmap_shared_mapping_range(struct address_space *mapping,
82810 loff_t const holebegin, loff_t const holelen)
82811 @@ -1206,9 +1212,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
82812 }
82813 #endif
82814
82815 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
82816 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
82817 - void *buf, int len, int write);
82818 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
82819 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
82820 + void *buf, size_t len, int write);
82821
82822 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
82823 unsigned long start, unsigned long nr_pages,
82824 @@ -1240,34 +1246,6 @@ int set_page_dirty_lock(struct page *page);
82825 int clear_page_dirty_for_io(struct page *page);
82826 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
82827
82828 -/* Is the vma a continuation of the stack vma above it? */
82829 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
82830 -{
82831 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
82832 -}
82833 -
82834 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
82835 - unsigned long addr)
82836 -{
82837 - return (vma->vm_flags & VM_GROWSDOWN) &&
82838 - (vma->vm_start == addr) &&
82839 - !vma_growsdown(vma->vm_prev, addr);
82840 -}
82841 -
82842 -/* Is the vma a continuation of the stack vma below it? */
82843 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
82844 -{
82845 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
82846 -}
82847 -
82848 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
82849 - unsigned long addr)
82850 -{
82851 - return (vma->vm_flags & VM_GROWSUP) &&
82852 - (vma->vm_end == addr) &&
82853 - !vma_growsup(vma->vm_next, addr);
82854 -}
82855 -
82856 extern struct task_struct *task_of_stack(struct task_struct *task,
82857 struct vm_area_struct *vma, bool in_group);
82858
82859 @@ -1385,8 +1363,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
82860 {
82861 return 0;
82862 }
82863 +
82864 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
82865 + unsigned long address)
82866 +{
82867 + return 0;
82868 +}
82869 #else
82870 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
82871 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
82872 #endif
82873
82874 #ifdef __PAGETABLE_PMD_FOLDED
82875 @@ -1395,8 +1380,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
82876 {
82877 return 0;
82878 }
82879 +
82880 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
82881 + unsigned long address)
82882 +{
82883 + return 0;
82884 +}
82885 #else
82886 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
82887 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
82888 #endif
82889
82890 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
82891 @@ -1414,11 +1406,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
82892 NULL: pud_offset(pgd, address);
82893 }
82894
82895 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
82896 +{
82897 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
82898 + NULL: pud_offset(pgd, address);
82899 +}
82900 +
82901 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
82902 {
82903 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
82904 NULL: pmd_offset(pud, address);
82905 }
82906 +
82907 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
82908 +{
82909 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
82910 + NULL: pmd_offset(pud, address);
82911 +}
82912 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
82913
82914 #if USE_SPLIT_PTE_PTLOCKS
82915 @@ -1801,12 +1805,23 @@ extern struct vm_area_struct *copy_vma(struct vm_area_struct **,
82916 bool *need_rmap_locks);
82917 extern void exit_mmap(struct mm_struct *);
82918
82919 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
82920 +extern void gr_learn_resource(const struct task_struct *task, const int res,
82921 + const unsigned long wanted, const int gt);
82922 +#else
82923 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
82924 + const unsigned long wanted, const int gt)
82925 +{
82926 +}
82927 +#endif
82928 +
82929 static inline int check_data_rlimit(unsigned long rlim,
82930 unsigned long new,
82931 unsigned long start,
82932 unsigned long end_data,
82933 unsigned long start_data)
82934 {
82935 + gr_learn_resource(current, RLIMIT_DATA, (new - start) + (end_data - start_data), 1);
82936 if (rlim < RLIM_INFINITY) {
82937 if (((new - start) + (end_data - start_data)) > rlim)
82938 return -ENOSPC;
82939 @@ -1831,7 +1846,7 @@ extern int install_special_mapping(struct mm_struct *mm,
82940 unsigned long addr, unsigned long len,
82941 unsigned long flags, struct page **pages);
82942
82943 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
82944 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
82945
82946 extern unsigned long mmap_region(struct file *file, unsigned long addr,
82947 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
82948 @@ -1839,6 +1854,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82949 unsigned long len, unsigned long prot, unsigned long flags,
82950 unsigned long pgoff, unsigned long *populate);
82951 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
82952 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
82953
82954 #ifdef CONFIG_MMU
82955 extern int __mm_populate(unsigned long addr, unsigned long len,
82956 @@ -1867,10 +1883,11 @@ struct vm_unmapped_area_info {
82957 unsigned long high_limit;
82958 unsigned long align_mask;
82959 unsigned long align_offset;
82960 + unsigned long threadstack_offset;
82961 };
82962
82963 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
82964 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
82965 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
82966 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
82967
82968 /*
82969 * Search for an unmapped address range.
82970 @@ -1882,7 +1899,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
82971 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
82972 */
82973 static inline unsigned long
82974 -vm_unmapped_area(struct vm_unmapped_area_info *info)
82975 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
82976 {
82977 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
82978 return unmapped_area(info);
82979 @@ -1944,6 +1961,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
82980 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
82981 struct vm_area_struct **pprev);
82982
82983 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
82984 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
82985 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
82986 +
82987 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
82988 NULL if none. Assume start_addr < end_addr. */
82989 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
82990 @@ -1973,10 +1994,10 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
82991 }
82992
82993 #ifdef CONFIG_MMU
82994 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
82995 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
82996 void vma_set_page_prot(struct vm_area_struct *vma);
82997 #else
82998 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
82999 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
83000 {
83001 return __pgprot(0);
83002 }
83003 @@ -2038,6 +2059,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
83004 static inline void vm_stat_account(struct mm_struct *mm,
83005 unsigned long flags, struct file *file, long pages)
83006 {
83007 +
83008 +#ifdef CONFIG_PAX_RANDMMAP
83009 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
83010 +#endif
83011 +
83012 mm->total_vm += pages;
83013 }
83014 #endif /* CONFIG_PROC_FS */
83015 @@ -2126,7 +2152,7 @@ extern int unpoison_memory(unsigned long pfn);
83016 extern int sysctl_memory_failure_early_kill;
83017 extern int sysctl_memory_failure_recovery;
83018 extern void shake_page(struct page *p, int access);
83019 -extern atomic_long_t num_poisoned_pages;
83020 +extern atomic_long_unchecked_t num_poisoned_pages;
83021 extern int soft_offline_page(struct page *page, int flags);
83022
83023 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
83024 @@ -2161,5 +2187,11 @@ void __init setup_nr_node_ids(void);
83025 static inline void setup_nr_node_ids(void) {}
83026 #endif
83027
83028 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83029 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
83030 +#else
83031 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
83032 +#endif
83033 +
83034 #endif /* __KERNEL__ */
83035 #endif /* _LINUX_MM_H */
83036 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
83037 index 6e0b286..90d9c0d 100644
83038 --- a/include/linux/mm_types.h
83039 +++ b/include/linux/mm_types.h
83040 @@ -308,7 +308,9 @@ struct vm_area_struct {
83041 #ifdef CONFIG_NUMA
83042 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
83043 #endif
83044 -};
83045 +
83046 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
83047 +} __randomize_layout;
83048
83049 struct core_thread {
83050 struct task_struct *task;
83051 @@ -454,7 +456,25 @@ struct mm_struct {
83052 bool tlb_flush_pending;
83053 #endif
83054 struct uprobes_state uprobes_state;
83055 -};
83056 +
83057 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
83058 + unsigned long pax_flags;
83059 +#endif
83060 +
83061 +#ifdef CONFIG_PAX_DLRESOLVE
83062 + unsigned long call_dl_resolve;
83063 +#endif
83064 +
83065 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
83066 + unsigned long call_syscall;
83067 +#endif
83068 +
83069 +#ifdef CONFIG_PAX_ASLR
83070 + unsigned long delta_mmap; /* randomized offset */
83071 + unsigned long delta_stack; /* randomized offset */
83072 +#endif
83073 +
83074 +} __randomize_layout;
83075
83076 static inline void mm_init_cpumask(struct mm_struct *mm)
83077 {
83078 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
83079 index c5d5278..f0b68c8 100644
83080 --- a/include/linux/mmiotrace.h
83081 +++ b/include/linux/mmiotrace.h
83082 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
83083 /* Called from ioremap.c */
83084 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
83085 void __iomem *addr);
83086 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
83087 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
83088
83089 /* For anyone to insert markers. Remember trailing newline. */
83090 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
83091 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
83092 {
83093 }
83094
83095 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
83096 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
83097 {
83098 }
83099
83100 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
83101 index ffe66e3..b310722 100644
83102 --- a/include/linux/mmzone.h
83103 +++ b/include/linux/mmzone.h
83104 @@ -527,7 +527,7 @@ struct zone {
83105
83106 ZONE_PADDING(_pad3_)
83107 /* Zone statistics */
83108 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83109 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83110 } ____cacheline_internodealigned_in_smp;
83111
83112 enum zone_flags {
83113 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
83114 index 44eeef0..a92d3f9 100644
83115 --- a/include/linux/mod_devicetable.h
83116 +++ b/include/linux/mod_devicetable.h
83117 @@ -139,7 +139,7 @@ struct usb_device_id {
83118 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
83119 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
83120
83121 -#define HID_ANY_ID (~0)
83122 +#define HID_ANY_ID (~0U)
83123 #define HID_BUS_ANY 0xffff
83124 #define HID_GROUP_ANY 0x0000
83125
83126 @@ -475,7 +475,7 @@ struct dmi_system_id {
83127 const char *ident;
83128 struct dmi_strmatch matches[4];
83129 void *driver_data;
83130 -};
83131 +} __do_const;
83132 /*
83133 * struct dmi_device_id appears during expansion of
83134 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
83135 diff --git a/include/linux/module.h b/include/linux/module.h
83136 index 71f282a..b2387e2 100644
83137 --- a/include/linux/module.h
83138 +++ b/include/linux/module.h
83139 @@ -17,9 +17,11 @@
83140 #include <linux/moduleparam.h>
83141 #include <linux/jump_label.h>
83142 #include <linux/export.h>
83143 +#include <linux/fs.h>
83144
83145 #include <linux/percpu.h>
83146 #include <asm/module.h>
83147 +#include <asm/pgtable.h>
83148
83149 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
83150 #define MODULE_SIG_STRING "~Module signature appended~\n"
83151 @@ -42,7 +44,7 @@ struct module_kobject {
83152 struct kobject *drivers_dir;
83153 struct module_param_attrs *mp;
83154 struct completion *kobj_completion;
83155 -};
83156 +} __randomize_layout;
83157
83158 struct module_attribute {
83159 struct attribute attr;
83160 @@ -54,12 +56,13 @@ struct module_attribute {
83161 int (*test)(struct module *);
83162 void (*free)(struct module *);
83163 };
83164 +typedef struct module_attribute __no_const module_attribute_no_const;
83165
83166 struct module_version_attribute {
83167 struct module_attribute mattr;
83168 const char *module_name;
83169 const char *version;
83170 -} __attribute__ ((__aligned__(sizeof(void *))));
83171 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
83172
83173 extern ssize_t __modver_version_show(struct module_attribute *,
83174 struct module_kobject *, char *);
83175 @@ -235,7 +238,7 @@ struct module {
83176
83177 /* Sysfs stuff. */
83178 struct module_kobject mkobj;
83179 - struct module_attribute *modinfo_attrs;
83180 + module_attribute_no_const *modinfo_attrs;
83181 const char *version;
83182 const char *srcversion;
83183 struct kobject *holders_dir;
83184 @@ -284,19 +287,16 @@ struct module {
83185 int (*init)(void);
83186
83187 /* If this is non-NULL, vfree after init() returns */
83188 - void *module_init;
83189 + void *module_init_rx, *module_init_rw;
83190
83191 /* Here is the actual code + data, vfree'd on unload. */
83192 - void *module_core;
83193 + void *module_core_rx, *module_core_rw;
83194
83195 /* Here are the sizes of the init and core sections */
83196 - unsigned int init_size, core_size;
83197 + unsigned int init_size_rw, core_size_rw;
83198
83199 /* The size of the executable code in each section. */
83200 - unsigned int init_text_size, core_text_size;
83201 -
83202 - /* Size of RO sections of the module (text+rodata) */
83203 - unsigned int init_ro_size, core_ro_size;
83204 + unsigned int init_size_rx, core_size_rx;
83205
83206 /* Arch-specific module values */
83207 struct mod_arch_specific arch;
83208 @@ -352,6 +352,10 @@ struct module {
83209 #ifdef CONFIG_EVENT_TRACING
83210 struct ftrace_event_call **trace_events;
83211 unsigned int num_trace_events;
83212 + struct file_operations trace_id;
83213 + struct file_operations trace_enable;
83214 + struct file_operations trace_format;
83215 + struct file_operations trace_filter;
83216 #endif
83217 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
83218 unsigned int num_ftrace_callsites;
83219 @@ -375,7 +379,7 @@ struct module {
83220 ctor_fn_t *ctors;
83221 unsigned int num_ctors;
83222 #endif
83223 -};
83224 +} __randomize_layout;
83225 #ifndef MODULE_ARCH_INIT
83226 #define MODULE_ARCH_INIT {}
83227 #endif
83228 @@ -396,18 +400,48 @@ bool is_module_address(unsigned long addr);
83229 bool is_module_percpu_address(unsigned long addr);
83230 bool is_module_text_address(unsigned long addr);
83231
83232 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
83233 +{
83234 +
83235 +#ifdef CONFIG_PAX_KERNEXEC
83236 + if (ktla_ktva(addr) >= (unsigned long)start &&
83237 + ktla_ktva(addr) < (unsigned long)start + size)
83238 + return 1;
83239 +#endif
83240 +
83241 + return ((void *)addr >= start && (void *)addr < start + size);
83242 +}
83243 +
83244 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
83245 +{
83246 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
83247 +}
83248 +
83249 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
83250 +{
83251 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
83252 +}
83253 +
83254 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
83255 +{
83256 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
83257 +}
83258 +
83259 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
83260 +{
83261 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
83262 +}
83263 +
83264 static inline bool within_module_core(unsigned long addr,
83265 const struct module *mod)
83266 {
83267 - return (unsigned long)mod->module_core <= addr &&
83268 - addr < (unsigned long)mod->module_core + mod->core_size;
83269 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
83270 }
83271
83272 static inline bool within_module_init(unsigned long addr,
83273 const struct module *mod)
83274 {
83275 - return (unsigned long)mod->module_init <= addr &&
83276 - addr < (unsigned long)mod->module_init + mod->init_size;
83277 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
83278 }
83279
83280 static inline bool within_module(unsigned long addr, const struct module *mod)
83281 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
83282 index 7eeb9bb..68f37e0 100644
83283 --- a/include/linux/moduleloader.h
83284 +++ b/include/linux/moduleloader.h
83285 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
83286 sections. Returns NULL on failure. */
83287 void *module_alloc(unsigned long size);
83288
83289 +#ifdef CONFIG_PAX_KERNEXEC
83290 +void *module_alloc_exec(unsigned long size);
83291 +#else
83292 +#define module_alloc_exec(x) module_alloc(x)
83293 +#endif
83294 +
83295 /* Free memory returned from module_alloc. */
83296 void module_free(struct module *mod, void *module_region);
83297
83298 +#ifdef CONFIG_PAX_KERNEXEC
83299 +void module_free_exec(struct module *mod, void *module_region);
83300 +#else
83301 +#define module_free_exec(x, y) module_free((x), (y))
83302 +#endif
83303 +
83304 /*
83305 * Apply the given relocation to the (simplified) ELF. Return -error
83306 * or 0.
83307 @@ -45,8 +57,10 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
83308 unsigned int relsec,
83309 struct module *me)
83310 {
83311 +#ifdef CONFIG_MODULES
83312 printk(KERN_ERR "module %s: REL relocation unsupported\n",
83313 module_name(me));
83314 +#endif
83315 return -ENOEXEC;
83316 }
83317 #endif
83318 @@ -68,8 +82,10 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
83319 unsigned int relsec,
83320 struct module *me)
83321 {
83322 +#ifdef CONFIG_MODULES
83323 printk(KERN_ERR "module %s: REL relocation unsupported\n",
83324 module_name(me));
83325 +#endif
83326 return -ENOEXEC;
83327 }
83328 #endif
83329 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
83330 index 1c9effa..1160bdd 100644
83331 --- a/include/linux/moduleparam.h
83332 +++ b/include/linux/moduleparam.h
83333 @@ -323,7 +323,7 @@ static inline void __kernel_param_unlock(void)
83334 * @len is usually just sizeof(string).
83335 */
83336 #define module_param_string(name, string, len, perm) \
83337 - static const struct kparam_string __param_string_##name \
83338 + static const struct kparam_string __param_string_##name __used \
83339 = { len, string }; \
83340 __module_param_call(MODULE_PARAM_PREFIX, name, \
83341 &param_ops_string, \
83342 @@ -467,7 +467,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
83343 */
83344 #define module_param_array_named(name, array, type, nump, perm) \
83345 param_check_##type(name, &(array)[0]); \
83346 - static const struct kparam_array __param_arr_##name \
83347 + static const struct kparam_array __param_arr_##name __used \
83348 = { .max = ARRAY_SIZE(array), .num = nump, \
83349 .ops = &param_ops_##type, \
83350 .elemsize = sizeof(array[0]), .elem = array }; \
83351 diff --git a/include/linux/mount.h b/include/linux/mount.h
83352 index c2c561d..a5f2a8c 100644
83353 --- a/include/linux/mount.h
83354 +++ b/include/linux/mount.h
83355 @@ -66,7 +66,7 @@ struct vfsmount {
83356 struct dentry *mnt_root; /* root of the mounted tree */
83357 struct super_block *mnt_sb; /* pointer to superblock */
83358 int mnt_flags;
83359 -};
83360 +} __randomize_layout;
83361
83362 struct file; /* forward dec */
83363 struct path;
83364 diff --git a/include/linux/namei.h b/include/linux/namei.h
83365 index 492de72..1bddcd4 100644
83366 --- a/include/linux/namei.h
83367 +++ b/include/linux/namei.h
83368 @@ -19,7 +19,7 @@ struct nameidata {
83369 unsigned seq, m_seq;
83370 int last_type;
83371 unsigned depth;
83372 - char *saved_names[MAX_NESTED_LINKS + 1];
83373 + const char *saved_names[MAX_NESTED_LINKS + 1];
83374 };
83375
83376 /*
83377 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
83378
83379 extern void nd_jump_link(struct nameidata *nd, struct path *path);
83380
83381 -static inline void nd_set_link(struct nameidata *nd, char *path)
83382 +static inline void nd_set_link(struct nameidata *nd, const char *path)
83383 {
83384 nd->saved_names[nd->depth] = path;
83385 }
83386
83387 -static inline char *nd_get_link(struct nameidata *nd)
83388 +static inline const char *nd_get_link(const struct nameidata *nd)
83389 {
83390 return nd->saved_names[nd->depth];
83391 }
83392 diff --git a/include/linux/net.h b/include/linux/net.h
83393 index 17d8339..81656c0 100644
83394 --- a/include/linux/net.h
83395 +++ b/include/linux/net.h
83396 @@ -192,7 +192,7 @@ struct net_proto_family {
83397 int (*create)(struct net *net, struct socket *sock,
83398 int protocol, int kern);
83399 struct module *owner;
83400 -};
83401 +} __do_const;
83402
83403 struct iovec;
83404 struct kvec;
83405 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
83406 index 74fd5d3..86a1e4f 100644
83407 --- a/include/linux/netdevice.h
83408 +++ b/include/linux/netdevice.h
83409 @@ -1156,6 +1156,7 @@ struct net_device_ops {
83410 bool (*ndo_gso_check) (struct sk_buff *skb,
83411 struct net_device *dev);
83412 };
83413 +typedef struct net_device_ops __no_const net_device_ops_no_const;
83414
83415 /**
83416 * enum net_device_priv_flags - &struct net_device priv_flags
83417 @@ -1498,10 +1499,10 @@ struct net_device {
83418
83419 struct net_device_stats stats;
83420
83421 - atomic_long_t rx_dropped;
83422 - atomic_long_t tx_dropped;
83423 + atomic_long_unchecked_t rx_dropped;
83424 + atomic_long_unchecked_t tx_dropped;
83425
83426 - atomic_t carrier_changes;
83427 + atomic_unchecked_t carrier_changes;
83428
83429 #ifdef CONFIG_WIRELESS_EXT
83430 const struct iw_handler_def * wireless_handlers;
83431 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
83432 index 2517ece..0bbfcfb 100644
83433 --- a/include/linux/netfilter.h
83434 +++ b/include/linux/netfilter.h
83435 @@ -85,7 +85,7 @@ struct nf_sockopt_ops {
83436 #endif
83437 /* Use the module struct to lock set/get code in place */
83438 struct module *owner;
83439 -};
83440 +} __do_const;
83441
83442 /* Function to register/unregister hook points. */
83443 int nf_register_hook(struct nf_hook_ops *reg);
83444 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
83445 index e955d47..04a5338 100644
83446 --- a/include/linux/netfilter/nfnetlink.h
83447 +++ b/include/linux/netfilter/nfnetlink.h
83448 @@ -19,7 +19,7 @@ struct nfnl_callback {
83449 const struct nlattr * const cda[]);
83450 const struct nla_policy *policy; /* netlink attribute policy */
83451 const u_int16_t attr_count; /* number of nlattr's */
83452 -};
83453 +} __do_const;
83454
83455 struct nfnetlink_subsystem {
83456 const char *name;
83457 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
83458 new file mode 100644
83459 index 0000000..33f4af8
83460 --- /dev/null
83461 +++ b/include/linux/netfilter/xt_gradm.h
83462 @@ -0,0 +1,9 @@
83463 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
83464 +#define _LINUX_NETFILTER_XT_GRADM_H 1
83465 +
83466 +struct xt_gradm_mtinfo {
83467 + __u16 flags;
83468 + __u16 invflags;
83469 +};
83470 +
83471 +#endif
83472 diff --git a/include/linux/nls.h b/include/linux/nls.h
83473 index 520681b..2b7fabb 100644
83474 --- a/include/linux/nls.h
83475 +++ b/include/linux/nls.h
83476 @@ -31,7 +31,7 @@ struct nls_table {
83477 const unsigned char *charset2upper;
83478 struct module *owner;
83479 struct nls_table *next;
83480 -};
83481 +} __do_const;
83482
83483 /* this value hold the maximum octet of charset */
83484 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
83485 @@ -46,7 +46,7 @@ enum utf16_endian {
83486 /* nls_base.c */
83487 extern int __register_nls(struct nls_table *, struct module *);
83488 extern int unregister_nls(struct nls_table *);
83489 -extern struct nls_table *load_nls(char *);
83490 +extern struct nls_table *load_nls(const char *);
83491 extern void unload_nls(struct nls_table *);
83492 extern struct nls_table *load_nls_default(void);
83493 #define register_nls(nls) __register_nls((nls), THIS_MODULE)
83494 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
83495 index d14a4c3..a078786 100644
83496 --- a/include/linux/notifier.h
83497 +++ b/include/linux/notifier.h
83498 @@ -54,7 +54,8 @@ struct notifier_block {
83499 notifier_fn_t notifier_call;
83500 struct notifier_block __rcu *next;
83501 int priority;
83502 -};
83503 +} __do_const;
83504 +typedef struct notifier_block __no_const notifier_block_no_const;
83505
83506 struct atomic_notifier_head {
83507 spinlock_t lock;
83508 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
83509 index b2a0f15..4d7da32 100644
83510 --- a/include/linux/oprofile.h
83511 +++ b/include/linux/oprofile.h
83512 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
83513 int oprofilefs_create_ro_ulong(struct dentry * root,
83514 char const * name, ulong * val);
83515
83516 -/** Create a file for read-only access to an atomic_t. */
83517 +/** Create a file for read-only access to an atomic_unchecked_t. */
83518 int oprofilefs_create_ro_atomic(struct dentry * root,
83519 - char const * name, atomic_t * val);
83520 + char const * name, atomic_unchecked_t * val);
83521
83522 /** create a directory */
83523 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
83524 diff --git a/include/linux/padata.h b/include/linux/padata.h
83525 index 4386946..f50c615 100644
83526 --- a/include/linux/padata.h
83527 +++ b/include/linux/padata.h
83528 @@ -129,7 +129,7 @@ struct parallel_data {
83529 struct padata_serial_queue __percpu *squeue;
83530 atomic_t reorder_objects;
83531 atomic_t refcnt;
83532 - atomic_t seq_nr;
83533 + atomic_unchecked_t seq_nr;
83534 struct padata_cpumask cpumask;
83535 spinlock_t lock ____cacheline_aligned;
83536 unsigned int processed;
83537 diff --git a/include/linux/path.h b/include/linux/path.h
83538 index d137218..be0c176 100644
83539 --- a/include/linux/path.h
83540 +++ b/include/linux/path.h
83541 @@ -1,13 +1,15 @@
83542 #ifndef _LINUX_PATH_H
83543 #define _LINUX_PATH_H
83544
83545 +#include <linux/compiler.h>
83546 +
83547 struct dentry;
83548 struct vfsmount;
83549
83550 struct path {
83551 struct vfsmount *mnt;
83552 struct dentry *dentry;
83553 -};
83554 +} __randomize_layout;
83555
83556 extern void path_get(const struct path *);
83557 extern void path_put(const struct path *);
83558 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
83559 index 2706ee9..e691f7c 100644
83560 --- a/include/linux/pci_hotplug.h
83561 +++ b/include/linux/pci_hotplug.h
83562 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
83563 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
83564 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
83565 int (*reset_slot) (struct hotplug_slot *slot, int probe);
83566 -};
83567 +} __do_const;
83568 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
83569
83570 /**
83571 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
83572 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
83573 index 893a0d0..d5f996e 100644
83574 --- a/include/linux/perf_event.h
83575 +++ b/include/linux/perf_event.h
83576 @@ -341,8 +341,8 @@ struct perf_event {
83577
83578 enum perf_event_active_state state;
83579 unsigned int attach_state;
83580 - local64_t count;
83581 - atomic64_t child_count;
83582 + local64_t count; /* PaX: fix it one day */
83583 + atomic64_unchecked_t child_count;
83584
83585 /*
83586 * These are the total time in nanoseconds that the event
83587 @@ -393,8 +393,8 @@ struct perf_event {
83588 * These accumulate total time (in nanoseconds) that children
83589 * events have been enabled and running, respectively.
83590 */
83591 - atomic64_t child_total_time_enabled;
83592 - atomic64_t child_total_time_running;
83593 + atomic64_unchecked_t child_total_time_enabled;
83594 + atomic64_unchecked_t child_total_time_running;
83595
83596 /*
83597 * Protect attach/detach and child_list:
83598 @@ -734,7 +734,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
83599 entry->ip[entry->nr++] = ip;
83600 }
83601
83602 -extern int sysctl_perf_event_paranoid;
83603 +extern int sysctl_perf_event_legitimately_concerned;
83604 extern int sysctl_perf_event_mlock;
83605 extern int sysctl_perf_event_sample_rate;
83606 extern int sysctl_perf_cpu_time_max_percent;
83607 @@ -749,19 +749,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
83608 loff_t *ppos);
83609
83610
83611 +static inline bool perf_paranoid_any(void)
83612 +{
83613 + return sysctl_perf_event_legitimately_concerned > 2;
83614 +}
83615 +
83616 static inline bool perf_paranoid_tracepoint_raw(void)
83617 {
83618 - return sysctl_perf_event_paranoid > -1;
83619 + return sysctl_perf_event_legitimately_concerned > -1;
83620 }
83621
83622 static inline bool perf_paranoid_cpu(void)
83623 {
83624 - return sysctl_perf_event_paranoid > 0;
83625 + return sysctl_perf_event_legitimately_concerned > 0;
83626 }
83627
83628 static inline bool perf_paranoid_kernel(void)
83629 {
83630 - return sysctl_perf_event_paranoid > 1;
83631 + return sysctl_perf_event_legitimately_concerned > 1;
83632 }
83633
83634 extern void perf_event_init(void);
83635 @@ -892,7 +897,7 @@ struct perf_pmu_events_attr {
83636 struct device_attribute attr;
83637 u64 id;
83638 const char *event_str;
83639 -};
83640 +} __do_const;
83641
83642 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
83643 static struct perf_pmu_events_attr _var = { \
83644 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
83645 index 1997ffc..4f1f44d 100644
83646 --- a/include/linux/pid_namespace.h
83647 +++ b/include/linux/pid_namespace.h
83648 @@ -44,7 +44,7 @@ struct pid_namespace {
83649 int hide_pid;
83650 int reboot; /* group exit code if this pidns was rebooted */
83651 unsigned int proc_inum;
83652 -};
83653 +} __randomize_layout;
83654
83655 extern struct pid_namespace init_pid_ns;
83656
83657 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
83658 index eb8b8ac..62649e1 100644
83659 --- a/include/linux/pipe_fs_i.h
83660 +++ b/include/linux/pipe_fs_i.h
83661 @@ -47,10 +47,10 @@ struct pipe_inode_info {
83662 struct mutex mutex;
83663 wait_queue_head_t wait;
83664 unsigned int nrbufs, curbuf, buffers;
83665 - unsigned int readers;
83666 - unsigned int writers;
83667 - unsigned int files;
83668 - unsigned int waiting_writers;
83669 + atomic_t readers;
83670 + atomic_t writers;
83671 + atomic_t files;
83672 + atomic_t waiting_writers;
83673 unsigned int r_counter;
83674 unsigned int w_counter;
83675 struct page *tmp_page;
83676 diff --git a/include/linux/pm.h b/include/linux/pm.h
83677 index 383fd68..7a11504 100644
83678 --- a/include/linux/pm.h
83679 +++ b/include/linux/pm.h
83680 @@ -621,6 +621,7 @@ struct dev_pm_domain {
83681 struct dev_pm_ops ops;
83682 void (*detach)(struct device *dev, bool power_off);
83683 };
83684 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
83685
83686 /*
83687 * The PM_EVENT_ messages are also used by drivers implementing the legacy
83688 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
83689 index 2e0e06d..824cc9b 100644
83690 --- a/include/linux/pm_domain.h
83691 +++ b/include/linux/pm_domain.h
83692 @@ -36,11 +36,11 @@ struct gpd_dev_ops {
83693 int (*save_state)(struct device *dev);
83694 int (*restore_state)(struct device *dev);
83695 bool (*active_wakeup)(struct device *dev);
83696 -};
83697 +} __no_const;
83698
83699 struct gpd_cpuidle_data {
83700 unsigned int saved_exit_latency;
83701 - struct cpuidle_state *idle_state;
83702 + cpuidle_state_no_const *idle_state;
83703 };
83704
83705 struct generic_pm_domain {
83706 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
83707 index 367f49b..d2f5a14 100644
83708 --- a/include/linux/pm_runtime.h
83709 +++ b/include/linux/pm_runtime.h
83710 @@ -125,7 +125,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
83711
83712 static inline void pm_runtime_mark_last_busy(struct device *dev)
83713 {
83714 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
83715 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
83716 }
83717
83718 #else /* !CONFIG_PM_RUNTIME */
83719 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
83720 index 195aafc..49a7bc2 100644
83721 --- a/include/linux/pnp.h
83722 +++ b/include/linux/pnp.h
83723 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
83724 struct pnp_fixup {
83725 char id[7];
83726 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
83727 -};
83728 +} __do_const;
83729
83730 /* config parameters */
83731 #define PNP_CONFIG_NORMAL 0x0001
83732 diff --git a/include/linux/poison.h b/include/linux/poison.h
83733 index 2110a81..13a11bb 100644
83734 --- a/include/linux/poison.h
83735 +++ b/include/linux/poison.h
83736 @@ -19,8 +19,8 @@
83737 * under normal circumstances, used to verify that nobody uses
83738 * non-initialized list entries.
83739 */
83740 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
83741 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
83742 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
83743 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
83744
83745 /********** include/linux/timer.h **********/
83746 /*
83747 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
83748 index d8b187c3..9a9257a 100644
83749 --- a/include/linux/power/smartreflex.h
83750 +++ b/include/linux/power/smartreflex.h
83751 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
83752 int (*notify)(struct omap_sr *sr, u32 status);
83753 u8 notify_flags;
83754 u8 class_type;
83755 -};
83756 +} __do_const;
83757
83758 /**
83759 * struct omap_sr_nvalue_table - Smartreflex n-target value info
83760 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
83761 index 4ea1d37..80f4b33 100644
83762 --- a/include/linux/ppp-comp.h
83763 +++ b/include/linux/ppp-comp.h
83764 @@ -84,7 +84,7 @@ struct compressor {
83765 struct module *owner;
83766 /* Extra skb space needed by the compressor algorithm */
83767 unsigned int comp_extra;
83768 -};
83769 +} __do_const;
83770
83771 /*
83772 * The return value from decompress routine is the length of the
83773 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
83774 index de83b4e..c4b997d 100644
83775 --- a/include/linux/preempt.h
83776 +++ b/include/linux/preempt.h
83777 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
83778 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
83779 #endif
83780
83781 +#define raw_preempt_count_add(val) __preempt_count_add(val)
83782 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
83783 +
83784 #define __preempt_count_inc() __preempt_count_add(1)
83785 #define __preempt_count_dec() __preempt_count_sub(1)
83786
83787 #define preempt_count_inc() preempt_count_add(1)
83788 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
83789 #define preempt_count_dec() preempt_count_sub(1)
83790 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
83791
83792 #ifdef CONFIG_PREEMPT_COUNT
83793
83794 @@ -41,6 +46,12 @@ do { \
83795 barrier(); \
83796 } while (0)
83797
83798 +#define raw_preempt_disable() \
83799 +do { \
83800 + raw_preempt_count_inc(); \
83801 + barrier(); \
83802 +} while (0)
83803 +
83804 #define sched_preempt_enable_no_resched() \
83805 do { \
83806 barrier(); \
83807 @@ -49,6 +60,12 @@ do { \
83808
83809 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
83810
83811 +#define raw_preempt_enable_no_resched() \
83812 +do { \
83813 + barrier(); \
83814 + raw_preempt_count_dec(); \
83815 +} while (0)
83816 +
83817 #ifdef CONFIG_PREEMPT
83818 #define preempt_enable() \
83819 do { \
83820 @@ -113,8 +130,10 @@ do { \
83821 * region.
83822 */
83823 #define preempt_disable() barrier()
83824 +#define raw_preempt_disable() barrier()
83825 #define sched_preempt_enable_no_resched() barrier()
83826 #define preempt_enable_no_resched() barrier()
83827 +#define raw_preempt_enable_no_resched() barrier()
83828 #define preempt_enable() barrier()
83829 #define preempt_check_resched() do { } while (0)
83830
83831 @@ -128,11 +147,13 @@ do { \
83832 /*
83833 * Modules have no business playing preemption tricks.
83834 */
83835 +#ifndef CONFIG_PAX_KERNEXEC
83836 #undef sched_preempt_enable_no_resched
83837 #undef preempt_enable_no_resched
83838 #undef preempt_enable_no_resched_notrace
83839 #undef preempt_check_resched
83840 #endif
83841 +#endif
83842
83843 #define preempt_set_need_resched() \
83844 do { \
83845 diff --git a/include/linux/printk.h b/include/linux/printk.h
83846 index d78125f..7f36596 100644
83847 --- a/include/linux/printk.h
83848 +++ b/include/linux/printk.h
83849 @@ -124,6 +124,8 @@ static inline __printf(1, 2) __cold
83850 void early_printk(const char *s, ...) { }
83851 #endif
83852
83853 +extern int kptr_restrict;
83854 +
83855 #ifdef CONFIG_PRINTK
83856 asmlinkage __printf(5, 0)
83857 int vprintk_emit(int facility, int level,
83858 @@ -158,7 +160,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
83859
83860 extern int printk_delay_msec;
83861 extern int dmesg_restrict;
83862 -extern int kptr_restrict;
83863
83864 extern void wake_up_klogd(void);
83865
83866 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
83867 index b97bf2e..f14c92d4 100644
83868 --- a/include/linux/proc_fs.h
83869 +++ b/include/linux/proc_fs.h
83870 @@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
83871 extern struct proc_dir_entry *proc_symlink(const char *,
83872 struct proc_dir_entry *, const char *);
83873 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
83874 +extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
83875 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
83876 struct proc_dir_entry *, void *);
83877 +extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
83878 + struct proc_dir_entry *, void *);
83879 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
83880 struct proc_dir_entry *);
83881
83882 @@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
83883 return proc_create_data(name, mode, parent, proc_fops, NULL);
83884 }
83885
83886 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
83887 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
83888 +{
83889 +#ifdef CONFIG_GRKERNSEC_PROC_USER
83890 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
83891 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83892 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
83893 +#else
83894 + return proc_create_data(name, mode, parent, proc_fops, NULL);
83895 +#endif
83896 +}
83897 +
83898 +
83899 extern void proc_set_size(struct proc_dir_entry *, loff_t);
83900 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
83901 extern void *PDE_DATA(const struct inode *);
83902 @@ -56,8 +72,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
83903 struct proc_dir_entry *parent,const char *dest) { return NULL;}
83904 static inline struct proc_dir_entry *proc_mkdir(const char *name,
83905 struct proc_dir_entry *parent) {return NULL;}
83906 +static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
83907 + struct proc_dir_entry *parent) { return NULL; }
83908 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
83909 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
83910 +static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
83911 + umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
83912 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
83913 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
83914 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
83915 @@ -79,7 +99,7 @@ struct net;
83916 static inline struct proc_dir_entry *proc_net_mkdir(
83917 struct net *net, const char *name, struct proc_dir_entry *parent)
83918 {
83919 - return proc_mkdir_data(name, 0, parent, net);
83920 + return proc_mkdir_data_restrict(name, 0, parent, net);
83921 }
83922
83923 #endif /* _LINUX_PROC_FS_H */
83924 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
83925 index 34a1e10..70f6bde 100644
83926 --- a/include/linux/proc_ns.h
83927 +++ b/include/linux/proc_ns.h
83928 @@ -14,7 +14,7 @@ struct proc_ns_operations {
83929 void (*put)(void *ns);
83930 int (*install)(struct nsproxy *nsproxy, void *ns);
83931 unsigned int (*inum)(void *ns);
83932 -};
83933 +} __do_const __randomize_layout;
83934
83935 struct proc_ns {
83936 void *ns;
83937 diff --git a/include/linux/quota.h b/include/linux/quota.h
83938 index 80d345a..9e89a9a 100644
83939 --- a/include/linux/quota.h
83940 +++ b/include/linux/quota.h
83941 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
83942
83943 extern bool qid_eq(struct kqid left, struct kqid right);
83944 extern bool qid_lt(struct kqid left, struct kqid right);
83945 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
83946 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
83947 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
83948 extern bool qid_valid(struct kqid qid);
83949
83950 diff --git a/include/linux/random.h b/include/linux/random.h
83951 index b05856e..0a9f14e 100644
83952 --- a/include/linux/random.h
83953 +++ b/include/linux/random.h
83954 @@ -9,9 +9,19 @@
83955 #include <uapi/linux/random.h>
83956
83957 extern void add_device_randomness(const void *, unsigned int);
83958 +
83959 +static inline void add_latent_entropy(void)
83960 +{
83961 +
83962 +#ifdef LATENT_ENTROPY_PLUGIN
83963 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
83964 +#endif
83965 +
83966 +}
83967 +
83968 extern void add_input_randomness(unsigned int type, unsigned int code,
83969 - unsigned int value);
83970 -extern void add_interrupt_randomness(int irq, int irq_flags);
83971 + unsigned int value) __latent_entropy;
83972 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
83973
83974 extern void get_random_bytes(void *buf, int nbytes);
83975 extern void get_random_bytes_arch(void *buf, int nbytes);
83976 @@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
83977 extern const struct file_operations random_fops, urandom_fops;
83978 #endif
83979
83980 -unsigned int get_random_int(void);
83981 +unsigned int __intentional_overflow(-1) get_random_int(void);
83982 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
83983
83984 -u32 prandom_u32(void);
83985 +u32 prandom_u32(void) __intentional_overflow(-1);
83986 void prandom_bytes(void *buf, size_t nbytes);
83987 void prandom_seed(u32 seed);
83988 void prandom_reseed_late(void);
83989 @@ -37,6 +47,11 @@ struct rnd_state {
83990 u32 prandom_u32_state(struct rnd_state *state);
83991 void prandom_bytes_state(struct rnd_state *state, void *buf, size_t nbytes);
83992
83993 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
83994 +{
83995 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
83996 +}
83997 +
83998 /**
83999 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
84000 * @ep_ro: right open interval endpoint
84001 @@ -49,7 +64,7 @@ void prandom_bytes_state(struct rnd_state *state, void *buf, size_t nbytes);
84002 *
84003 * Returns: pseudo-random number in interval [0, ep_ro)
84004 */
84005 -static inline u32 prandom_u32_max(u32 ep_ro)
84006 +static inline u32 __intentional_overflow(-1) prandom_u32_max(u32 ep_ro)
84007 {
84008 return (u32)(((u64) prandom_u32() * ep_ro) >> 32);
84009 }
84010 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
84011 index 378c5ee..aa84a47 100644
84012 --- a/include/linux/rbtree_augmented.h
84013 +++ b/include/linux/rbtree_augmented.h
84014 @@ -90,7 +90,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
84015 old->rbaugmented = rbcompute(old); \
84016 } \
84017 rbstatic const struct rb_augment_callbacks rbname = { \
84018 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
84019 + .propagate = rbname ## _propagate, \
84020 + .copy = rbname ## _copy, \
84021 + .rotate = rbname ## _rotate \
84022 };
84023
84024
84025 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
84026 index 372ad5e..d4373f8 100644
84027 --- a/include/linux/rculist.h
84028 +++ b/include/linux/rculist.h
84029 @@ -29,8 +29,8 @@
84030 */
84031 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
84032 {
84033 - ACCESS_ONCE(list->next) = list;
84034 - ACCESS_ONCE(list->prev) = list;
84035 + ACCESS_ONCE_RW(list->next) = list;
84036 + ACCESS_ONCE_RW(list->prev) = list;
84037 }
84038
84039 /*
84040 @@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
84041 struct list_head *prev, struct list_head *next);
84042 #endif
84043
84044 +void __pax_list_add_rcu(struct list_head *new,
84045 + struct list_head *prev, struct list_head *next);
84046 +
84047 /**
84048 * list_add_rcu - add a new entry to rcu-protected list
84049 * @new: new entry to be added
84050 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
84051 __list_add_rcu(new, head, head->next);
84052 }
84053
84054 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
84055 +{
84056 + __pax_list_add_rcu(new, head, head->next);
84057 +}
84058 +
84059 /**
84060 * list_add_tail_rcu - add a new entry to rcu-protected list
84061 * @new: new entry to be added
84062 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
84063 __list_add_rcu(new, head->prev, head);
84064 }
84065
84066 +static inline void pax_list_add_tail_rcu(struct list_head *new,
84067 + struct list_head *head)
84068 +{
84069 + __pax_list_add_rcu(new, head->prev, head);
84070 +}
84071 +
84072 /**
84073 * list_del_rcu - deletes entry from list without re-initialization
84074 * @entry: the element to delete from the list.
84075 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
84076 entry->prev = LIST_POISON2;
84077 }
84078
84079 +extern void pax_list_del_rcu(struct list_head *entry);
84080 +
84081 /**
84082 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
84083 * @n: the element to delete from the hash list.
84084 diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
84085 index 53ff1a7..c40f0ab 100644
84086 --- a/include/linux/rcupdate.h
84087 +++ b/include/linux/rcupdate.h
84088 @@ -332,7 +332,7 @@ extern struct srcu_struct tasks_rcu_exit_srcu;
84089 #define rcu_note_voluntary_context_switch(t) \
84090 do { \
84091 if (ACCESS_ONCE((t)->rcu_tasks_holdout)) \
84092 - ACCESS_ONCE((t)->rcu_tasks_holdout) = false; \
84093 + ACCESS_ONCE_RW((t)->rcu_tasks_holdout) = false; \
84094 } while (0)
84095 #else /* #ifdef CONFIG_TASKS_RCU */
84096 #define TASKS_RCU(x) do { } while (0)
84097 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
84098 index 67fc8fc..a90f7d8 100644
84099 --- a/include/linux/reboot.h
84100 +++ b/include/linux/reboot.h
84101 @@ -47,9 +47,9 @@ extern void do_kernel_restart(char *cmd);
84102 */
84103
84104 extern void migrate_to_reboot_cpu(void);
84105 -extern void machine_restart(char *cmd);
84106 -extern void machine_halt(void);
84107 -extern void machine_power_off(void);
84108 +extern void machine_restart(char *cmd) __noreturn;
84109 +extern void machine_halt(void) __noreturn;
84110 +extern void machine_power_off(void) __noreturn;
84111
84112 extern void machine_shutdown(void);
84113 struct pt_regs;
84114 @@ -60,9 +60,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
84115 */
84116
84117 extern void kernel_restart_prepare(char *cmd);
84118 -extern void kernel_restart(char *cmd);
84119 -extern void kernel_halt(void);
84120 -extern void kernel_power_off(void);
84121 +extern void kernel_restart(char *cmd) __noreturn;
84122 +extern void kernel_halt(void) __noreturn;
84123 +extern void kernel_power_off(void) __noreturn;
84124
84125 extern int C_A_D; /* for sysctl */
84126 void ctrl_alt_del(void);
84127 @@ -76,7 +76,7 @@ extern int orderly_poweroff(bool force);
84128 * Emergency restart, callable from an interrupt handler.
84129 */
84130
84131 -extern void emergency_restart(void);
84132 +extern void emergency_restart(void) __noreturn;
84133 #include <asm/emergency-restart.h>
84134
84135 #endif /* _LINUX_REBOOT_H */
84136 diff --git a/include/linux/regset.h b/include/linux/regset.h
84137 index 8e0c9fe..ac4d221 100644
84138 --- a/include/linux/regset.h
84139 +++ b/include/linux/regset.h
84140 @@ -161,7 +161,8 @@ struct user_regset {
84141 unsigned int align;
84142 unsigned int bias;
84143 unsigned int core_note_type;
84144 -};
84145 +} __do_const;
84146 +typedef struct user_regset __no_const user_regset_no_const;
84147
84148 /**
84149 * struct user_regset_view - available regsets
84150 diff --git a/include/linux/relay.h b/include/linux/relay.h
84151 index d7c8359..818daf5 100644
84152 --- a/include/linux/relay.h
84153 +++ b/include/linux/relay.h
84154 @@ -157,7 +157,7 @@ struct rchan_callbacks
84155 * The callback should return 0 if successful, negative if not.
84156 */
84157 int (*remove_buf_file)(struct dentry *dentry);
84158 -};
84159 +} __no_const;
84160
84161 /*
84162 * CONFIG_RELAY kernel API, kernel/relay.c
84163 diff --git a/include/linux/rio.h b/include/linux/rio.h
84164 index 6bda06f..bf39a9b 100644
84165 --- a/include/linux/rio.h
84166 +++ b/include/linux/rio.h
84167 @@ -358,7 +358,7 @@ struct rio_ops {
84168 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
84169 u64 rstart, u32 size, u32 flags);
84170 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
84171 -};
84172 +} __no_const;
84173
84174 #define RIO_RESOURCE_MEM 0x00000100
84175 #define RIO_RESOURCE_DOORBELL 0x00000200
84176 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
84177 index c0c2bce..4813524 100644
84178 --- a/include/linux/rmap.h
84179 +++ b/include/linux/rmap.h
84180 @@ -144,8 +144,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
84181 void anon_vma_init(void); /* create anon_vma_cachep */
84182 int anon_vma_prepare(struct vm_area_struct *);
84183 void unlink_anon_vmas(struct vm_area_struct *);
84184 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
84185 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
84186 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
84187 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
84188
84189 static inline void anon_vma_merge(struct vm_area_struct *vma,
84190 struct vm_area_struct *next)
84191 diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
84192 index ed8f9e7..999bc96 100644
84193 --- a/include/linux/scatterlist.h
84194 +++ b/include/linux/scatterlist.h
84195 @@ -1,6 +1,7 @@
84196 #ifndef _LINUX_SCATTERLIST_H
84197 #define _LINUX_SCATTERLIST_H
84198
84199 +#include <linux/sched.h>
84200 #include <linux/string.h>
84201 #include <linux/bug.h>
84202 #include <linux/mm.h>
84203 @@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
84204 #ifdef CONFIG_DEBUG_SG
84205 BUG_ON(!virt_addr_valid(buf));
84206 #endif
84207 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
84208 + if (object_starts_on_stack(buf)) {
84209 + void *adjbuf = buf - current->stack + current->lowmem_stack;
84210 + sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
84211 + } else
84212 +#endif
84213 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
84214 }
84215
84216 diff --git a/include/linux/sched.h b/include/linux/sched.h
84217 index 5e344bb..0743255 100644
84218 --- a/include/linux/sched.h
84219 +++ b/include/linux/sched.h
84220 @@ -133,6 +133,7 @@ struct fs_struct;
84221 struct perf_event_context;
84222 struct blk_plug;
84223 struct filename;
84224 +struct linux_binprm;
84225
84226 #define VMACACHE_BITS 2
84227 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
84228 @@ -376,7 +377,7 @@ extern char __sched_text_start[], __sched_text_end[];
84229 extern int in_sched_functions(unsigned long addr);
84230
84231 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
84232 -extern signed long schedule_timeout(signed long timeout);
84233 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
84234 extern signed long schedule_timeout_interruptible(signed long timeout);
84235 extern signed long schedule_timeout_killable(signed long timeout);
84236 extern signed long schedule_timeout_uninterruptible(signed long timeout);
84237 @@ -387,6 +388,19 @@ struct nsproxy;
84238 struct user_namespace;
84239
84240 #ifdef CONFIG_MMU
84241 +
84242 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
84243 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
84244 +#else
84245 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
84246 +{
84247 + return 0;
84248 +}
84249 +#endif
84250 +
84251 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
84252 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
84253 +
84254 extern void arch_pick_mmap_layout(struct mm_struct *mm);
84255 extern unsigned long
84256 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
84257 @@ -685,6 +699,17 @@ struct signal_struct {
84258 #ifdef CONFIG_TASKSTATS
84259 struct taskstats *stats;
84260 #endif
84261 +
84262 +#ifdef CONFIG_GRKERNSEC
84263 + u32 curr_ip;
84264 + u32 saved_ip;
84265 + u32 gr_saddr;
84266 + u32 gr_daddr;
84267 + u16 gr_sport;
84268 + u16 gr_dport;
84269 + u8 used_accept:1;
84270 +#endif
84271 +
84272 #ifdef CONFIG_AUDIT
84273 unsigned audit_tty;
84274 unsigned audit_tty_log_passwd;
84275 @@ -711,7 +736,7 @@ struct signal_struct {
84276 struct mutex cred_guard_mutex; /* guard against foreign influences on
84277 * credential calculations
84278 * (notably. ptrace) */
84279 -};
84280 +} __randomize_layout;
84281
84282 /*
84283 * Bits in flags field of signal_struct.
84284 @@ -764,6 +789,14 @@ struct user_struct {
84285 struct key *session_keyring; /* UID's default session keyring */
84286 #endif
84287
84288 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
84289 + unsigned char kernel_banned;
84290 +#endif
84291 +#ifdef CONFIG_GRKERNSEC_BRUTE
84292 + unsigned char suid_banned;
84293 + unsigned long suid_ban_expires;
84294 +#endif
84295 +
84296 /* Hash table maintenance information */
84297 struct hlist_node uidhash_node;
84298 kuid_t uid;
84299 @@ -771,7 +804,7 @@ struct user_struct {
84300 #ifdef CONFIG_PERF_EVENTS
84301 atomic_long_t locked_vm;
84302 #endif
84303 -};
84304 +} __randomize_layout;
84305
84306 extern int uids_sysfs_init(void);
84307
84308 @@ -1235,6 +1268,9 @@ enum perf_event_task_context {
84309 struct task_struct {
84310 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
84311 void *stack;
84312 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
84313 + void *lowmem_stack;
84314 +#endif
84315 atomic_t usage;
84316 unsigned int flags; /* per process flags, defined below */
84317 unsigned int ptrace;
84318 @@ -1362,8 +1398,8 @@ struct task_struct {
84319 struct list_head thread_node;
84320
84321 struct completion *vfork_done; /* for vfork() */
84322 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
84323 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
84324 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
84325 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
84326
84327 cputime_t utime, stime, utimescaled, stimescaled;
84328 cputime_t gtime;
84329 @@ -1388,11 +1424,6 @@ struct task_struct {
84330 struct task_cputime cputime_expires;
84331 struct list_head cpu_timers[3];
84332
84333 -/* process credentials */
84334 - const struct cred __rcu *real_cred; /* objective and real subjective task
84335 - * credentials (COW) */
84336 - const struct cred __rcu *cred; /* effective (overridable) subjective task
84337 - * credentials (COW) */
84338 char comm[TASK_COMM_LEN]; /* executable name excluding path
84339 - access with [gs]et_task_comm (which lock
84340 it with task_lock())
84341 @@ -1410,6 +1441,10 @@ struct task_struct {
84342 #endif
84343 /* CPU-specific state of this task */
84344 struct thread_struct thread;
84345 +/* thread_info moved to task_struct */
84346 +#ifdef CONFIG_X86
84347 + struct thread_info tinfo;
84348 +#endif
84349 /* filesystem information */
84350 struct fs_struct *fs;
84351 /* open file information */
84352 @@ -1484,6 +1519,10 @@ struct task_struct {
84353 gfp_t lockdep_reclaim_gfp;
84354 #endif
84355
84356 +/* process credentials */
84357 + const struct cred __rcu *real_cred; /* objective and real subjective task
84358 + * credentials (COW) */
84359 +
84360 /* journalling filesystem info */
84361 void *journal_info;
84362
84363 @@ -1522,6 +1561,10 @@ struct task_struct {
84364 /* cg_list protected by css_set_lock and tsk->alloc_lock */
84365 struct list_head cg_list;
84366 #endif
84367 +
84368 + const struct cred __rcu *cred; /* effective (overridable) subjective task
84369 + * credentials (COW) */
84370 +
84371 #ifdef CONFIG_FUTEX
84372 struct robust_list_head __user *robust_list;
84373 #ifdef CONFIG_COMPAT
84374 @@ -1635,7 +1678,7 @@ struct task_struct {
84375 * Number of functions that haven't been traced
84376 * because of depth overrun.
84377 */
84378 - atomic_t trace_overrun;
84379 + atomic_unchecked_t trace_overrun;
84380 /* Pause for the tracing */
84381 atomic_t tracing_graph_pause;
84382 #endif
84383 @@ -1661,7 +1704,78 @@ struct task_struct {
84384 unsigned int sequential_io;
84385 unsigned int sequential_io_avg;
84386 #endif
84387 -};
84388 +
84389 +#ifdef CONFIG_GRKERNSEC
84390 + /* grsecurity */
84391 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
84392 + u64 exec_id;
84393 +#endif
84394 +#ifdef CONFIG_GRKERNSEC_SETXID
84395 + const struct cred *delayed_cred;
84396 +#endif
84397 + struct dentry *gr_chroot_dentry;
84398 + struct acl_subject_label *acl;
84399 + struct acl_subject_label *tmpacl;
84400 + struct acl_role_label *role;
84401 + struct file *exec_file;
84402 + unsigned long brute_expires;
84403 + u16 acl_role_id;
84404 + u8 inherited;
84405 + /* is this the task that authenticated to the special role */
84406 + u8 acl_sp_role;
84407 + u8 is_writable;
84408 + u8 brute;
84409 + u8 gr_is_chrooted;
84410 +#endif
84411 +
84412 +} __randomize_layout;
84413 +
84414 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
84415 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
84416 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
84417 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
84418 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
84419 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
84420 +
84421 +#ifdef CONFIG_PAX_SOFTMODE
84422 +extern int pax_softmode;
84423 +#endif
84424 +
84425 +extern int pax_check_flags(unsigned long *);
84426 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
84427 +
84428 +/* if tsk != current then task_lock must be held on it */
84429 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
84430 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
84431 +{
84432 + if (likely(tsk->mm))
84433 + return tsk->mm->pax_flags;
84434 + else
84435 + return 0UL;
84436 +}
84437 +
84438 +/* if tsk != current then task_lock must be held on it */
84439 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
84440 +{
84441 + if (likely(tsk->mm)) {
84442 + tsk->mm->pax_flags = flags;
84443 + return 0;
84444 + }
84445 + return -EINVAL;
84446 +}
84447 +#endif
84448 +
84449 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
84450 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
84451 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
84452 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
84453 +#endif
84454 +
84455 +struct path;
84456 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
84457 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
84458 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
84459 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
84460
84461 /* Future-safe accessor for struct task_struct's cpus_allowed. */
84462 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
84463 @@ -1743,7 +1857,7 @@ struct pid_namespace;
84464 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
84465 struct pid_namespace *ns);
84466
84467 -static inline pid_t task_pid_nr(struct task_struct *tsk)
84468 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
84469 {
84470 return tsk->pid;
84471 }
84472 @@ -2106,6 +2220,25 @@ extern u64 sched_clock_cpu(int cpu);
84473
84474 extern void sched_clock_init(void);
84475
84476 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
84477 +static inline void populate_stack(void)
84478 +{
84479 + struct task_struct *curtask = current;
84480 + int c;
84481 + int *ptr = curtask->stack;
84482 + int *end = curtask->stack + THREAD_SIZE;
84483 +
84484 + while (ptr < end) {
84485 + c = *(volatile int *)ptr;
84486 + ptr += PAGE_SIZE/sizeof(int);
84487 + }
84488 +}
84489 +#else
84490 +static inline void populate_stack(void)
84491 +{
84492 +}
84493 +#endif
84494 +
84495 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
84496 static inline void sched_clock_tick(void)
84497 {
84498 @@ -2239,7 +2372,9 @@ void yield(void);
84499 extern struct exec_domain default_exec_domain;
84500
84501 union thread_union {
84502 +#ifndef CONFIG_X86
84503 struct thread_info thread_info;
84504 +#endif
84505 unsigned long stack[THREAD_SIZE/sizeof(long)];
84506 };
84507
84508 @@ -2272,6 +2407,7 @@ extern struct pid_namespace init_pid_ns;
84509 */
84510
84511 extern struct task_struct *find_task_by_vpid(pid_t nr);
84512 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
84513 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
84514 struct pid_namespace *ns);
84515
84516 @@ -2436,7 +2572,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
84517 extern void exit_itimers(struct signal_struct *);
84518 extern void flush_itimer_signals(void);
84519
84520 -extern void do_group_exit(int);
84521 +extern __noreturn void do_group_exit(int);
84522
84523 extern int do_execve(struct filename *,
84524 const char __user * const __user *,
84525 @@ -2653,9 +2789,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
84526 #define task_stack_end_corrupted(task) \
84527 (*(end_of_stack(task)) != STACK_END_MAGIC)
84528
84529 -static inline int object_is_on_stack(void *obj)
84530 +static inline int object_starts_on_stack(const void *obj)
84531 {
84532 - void *stack = task_stack_page(current);
84533 + const void *stack = task_stack_page(current);
84534
84535 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
84536 }
84537 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
84538 index 596a0e0..bea77ec 100644
84539 --- a/include/linux/sched/sysctl.h
84540 +++ b/include/linux/sched/sysctl.h
84541 @@ -34,6 +34,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
84542 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
84543
84544 extern int sysctl_max_map_count;
84545 +extern unsigned long sysctl_heap_stack_gap;
84546
84547 extern unsigned int sysctl_sched_latency;
84548 extern unsigned int sysctl_sched_min_granularity;
84549 diff --git a/include/linux/security.h b/include/linux/security.h
84550 index ba96471..74fb3f6 100644
84551 --- a/include/linux/security.h
84552 +++ b/include/linux/security.h
84553 @@ -27,6 +27,7 @@
84554 #include <linux/slab.h>
84555 #include <linux/err.h>
84556 #include <linux/string.h>
84557 +#include <linux/grsecurity.h>
84558
84559 struct linux_binprm;
84560 struct cred;
84561 @@ -116,8 +117,6 @@ struct seq_file;
84562
84563 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
84564
84565 -void reset_security_ops(void);
84566 -
84567 #ifdef CONFIG_MMU
84568 extern unsigned long mmap_min_addr;
84569 extern unsigned long dac_mmap_min_addr;
84570 @@ -1729,7 +1728,7 @@ struct security_operations {
84571 struct audit_context *actx);
84572 void (*audit_rule_free) (void *lsmrule);
84573 #endif /* CONFIG_AUDIT */
84574 -};
84575 +} __randomize_layout;
84576
84577 /* prototypes */
84578 extern int security_init(void);
84579 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
84580 index dc368b8..e895209 100644
84581 --- a/include/linux/semaphore.h
84582 +++ b/include/linux/semaphore.h
84583 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
84584 }
84585
84586 extern void down(struct semaphore *sem);
84587 -extern int __must_check down_interruptible(struct semaphore *sem);
84588 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
84589 extern int __must_check down_killable(struct semaphore *sem);
84590 extern int __must_check down_trylock(struct semaphore *sem);
84591 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
84592 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
84593 index 52e0097..383f21d 100644
84594 --- a/include/linux/seq_file.h
84595 +++ b/include/linux/seq_file.h
84596 @@ -27,6 +27,9 @@ struct seq_file {
84597 struct mutex lock;
84598 const struct seq_operations *op;
84599 int poll_event;
84600 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
84601 + u64 exec_id;
84602 +#endif
84603 #ifdef CONFIG_USER_NS
84604 struct user_namespace *user_ns;
84605 #endif
84606 @@ -39,6 +42,7 @@ struct seq_operations {
84607 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
84608 int (*show) (struct seq_file *m, void *v);
84609 };
84610 +typedef struct seq_operations __no_const seq_operations_no_const;
84611
84612 #define SEQ_SKIP 1
84613
84614 @@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
84615
84616 char *mangle_path(char *s, const char *p, const char *esc);
84617 int seq_open(struct file *, const struct seq_operations *);
84618 +int seq_open_restrict(struct file *, const struct seq_operations *);
84619 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
84620 loff_t seq_lseek(struct file *, loff_t, int);
84621 int seq_release(struct inode *, struct file *);
84622 @@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
84623 }
84624
84625 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
84626 +int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
84627 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
84628 int single_release(struct inode *, struct file *);
84629 void *__seq_open_private(struct file *, const struct seq_operations *, int);
84630 diff --git a/include/linux/shm.h b/include/linux/shm.h
84631 index 6fb8016..ab4465e 100644
84632 --- a/include/linux/shm.h
84633 +++ b/include/linux/shm.h
84634 @@ -22,6 +22,10 @@ struct shmid_kernel /* private to the kernel */
84635 /* The task created the shm object. NULL if the task is dead. */
84636 struct task_struct *shm_creator;
84637 struct list_head shm_clist; /* list by creator */
84638 +#ifdef CONFIG_GRKERNSEC
84639 + u64 shm_createtime;
84640 + pid_t shm_lapid;
84641 +#endif
84642 };
84643
84644 /* shm_mode upper byte flags */
84645 diff --git a/include/linux/signal.h b/include/linux/signal.h
84646 index ab1e039..ad4229e 100644
84647 --- a/include/linux/signal.h
84648 +++ b/include/linux/signal.h
84649 @@ -289,7 +289,7 @@ static inline void allow_signal(int sig)
84650 * know it'll be handled, so that they don't get converted to
84651 * SIGKILL or just silently dropped.
84652 */
84653 - kernel_sigaction(sig, (__force __sighandler_t)2);
84654 + kernel_sigaction(sig, (__force_user __sighandler_t)2);
84655 }
84656
84657 static inline void disallow_signal(int sig)
84658 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
84659 index 6c8b6f6..5a0f4bd 100644
84660 --- a/include/linux/skbuff.h
84661 +++ b/include/linux/skbuff.h
84662 @@ -773,7 +773,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
84663 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
84664 int node);
84665 struct sk_buff *build_skb(void *data, unsigned int frag_size);
84666 -static inline struct sk_buff *alloc_skb(unsigned int size,
84667 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
84668 gfp_t priority)
84669 {
84670 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
84671 @@ -1962,7 +1962,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
84672 return skb->inner_transport_header - skb->inner_network_header;
84673 }
84674
84675 -static inline int skb_network_offset(const struct sk_buff *skb)
84676 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
84677 {
84678 return skb_network_header(skb) - skb->data;
84679 }
84680 @@ -2022,7 +2022,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
84681 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
84682 */
84683 #ifndef NET_SKB_PAD
84684 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
84685 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
84686 #endif
84687
84688 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
84689 @@ -2629,7 +2629,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
84690 int *err);
84691 unsigned int datagram_poll(struct file *file, struct socket *sock,
84692 struct poll_table_struct *wait);
84693 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
84694 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
84695 struct iovec *to, int size);
84696 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
84697 struct iovec *iov);
84698 @@ -3091,6 +3091,9 @@ static inline void nf_reset(struct sk_buff *skb)
84699 nf_bridge_put(skb->nf_bridge);
84700 skb->nf_bridge = NULL;
84701 #endif
84702 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
84703 + skb->nf_trace = 0;
84704 +#endif
84705 }
84706
84707 static inline void nf_reset_trace(struct sk_buff *skb)
84708 diff --git a/include/linux/slab.h b/include/linux/slab.h
84709 index c265bec..4867d28 100644
84710 --- a/include/linux/slab.h
84711 +++ b/include/linux/slab.h
84712 @@ -14,15 +14,29 @@
84713 #include <linux/gfp.h>
84714 #include <linux/types.h>
84715 #include <linux/workqueue.h>
84716 -
84717 +#include <linux/err.h>
84718
84719 /*
84720 * Flags to pass to kmem_cache_create().
84721 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
84722 */
84723 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
84724 +
84725 +#ifdef CONFIG_PAX_USERCOPY_SLABS
84726 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
84727 +#else
84728 +#define SLAB_USERCOPY 0x00000000UL
84729 +#endif
84730 +
84731 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
84732 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
84733 +
84734 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
84735 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
84736 +#else
84737 +#define SLAB_NO_SANITIZE 0x00000000UL
84738 +#endif
84739 +
84740 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
84741 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
84742 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
84743 @@ -98,10 +112,13 @@
84744 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
84745 * Both make kfree a no-op.
84746 */
84747 -#define ZERO_SIZE_PTR ((void *)16)
84748 +#define ZERO_SIZE_PTR \
84749 +({ \
84750 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
84751 + (void *)(-MAX_ERRNO-1L); \
84752 +})
84753
84754 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
84755 - (unsigned long)ZERO_SIZE_PTR)
84756 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
84757
84758 #include <linux/kmemleak.h>
84759
84760 @@ -144,6 +161,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
84761 void kfree(const void *);
84762 void kzfree(const void *);
84763 size_t ksize(const void *);
84764 +const char *check_heap_object(const void *ptr, unsigned long n);
84765 +bool is_usercopy_object(const void *ptr);
84766
84767 /*
84768 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
84769 @@ -236,6 +255,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
84770 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
84771 #endif
84772
84773 +#ifdef CONFIG_PAX_USERCOPY_SLABS
84774 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
84775 +#endif
84776 +
84777 /*
84778 * Figure out which kmalloc slab an allocation of a certain size
84779 * belongs to.
84780 @@ -244,7 +267,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
84781 * 2 = 120 .. 192 bytes
84782 * n = 2^(n-1) .. 2^n -1
84783 */
84784 -static __always_inline int kmalloc_index(size_t size)
84785 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
84786 {
84787 if (!size)
84788 return 0;
84789 @@ -287,11 +310,11 @@ static __always_inline int kmalloc_index(size_t size)
84790 }
84791 #endif /* !CONFIG_SLOB */
84792
84793 -void *__kmalloc(size_t size, gfp_t flags);
84794 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
84795 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
84796
84797 #ifdef CONFIG_NUMA
84798 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
84799 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
84800 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
84801 #else
84802 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
84803 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
84804 index b869d16..1453c73 100644
84805 --- a/include/linux/slab_def.h
84806 +++ b/include/linux/slab_def.h
84807 @@ -40,7 +40,7 @@ struct kmem_cache {
84808 /* 4) cache creation/removal */
84809 const char *name;
84810 struct list_head list;
84811 - int refcount;
84812 + atomic_t refcount;
84813 int object_size;
84814 int align;
84815
84816 @@ -56,10 +56,14 @@ struct kmem_cache {
84817 unsigned long node_allocs;
84818 unsigned long node_frees;
84819 unsigned long node_overflow;
84820 - atomic_t allochit;
84821 - atomic_t allocmiss;
84822 - atomic_t freehit;
84823 - atomic_t freemiss;
84824 + atomic_unchecked_t allochit;
84825 + atomic_unchecked_t allocmiss;
84826 + atomic_unchecked_t freehit;
84827 + atomic_unchecked_t freemiss;
84828 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
84829 + atomic_unchecked_t sanitized;
84830 + atomic_unchecked_t not_sanitized;
84831 +#endif
84832
84833 /*
84834 * If debugging is enabled, then the allocator can add additional
84835 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
84836 index d82abd4..408c3a0 100644
84837 --- a/include/linux/slub_def.h
84838 +++ b/include/linux/slub_def.h
84839 @@ -74,7 +74,7 @@ struct kmem_cache {
84840 struct kmem_cache_order_objects max;
84841 struct kmem_cache_order_objects min;
84842 gfp_t allocflags; /* gfp flags to use on each alloc */
84843 - int refcount; /* Refcount for slab cache destroy */
84844 + atomic_t refcount; /* Refcount for slab cache destroy */
84845 void (*ctor)(void *);
84846 int inuse; /* Offset to metadata */
84847 int align; /* Alignment */
84848 diff --git a/include/linux/smp.h b/include/linux/smp.h
84849 index 93dff5f..933c561 100644
84850 --- a/include/linux/smp.h
84851 +++ b/include/linux/smp.h
84852 @@ -176,7 +176,9 @@ static inline void wake_up_all_idle_cpus(void) { }
84853 #endif
84854
84855 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
84856 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
84857 #define put_cpu() preempt_enable()
84858 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
84859
84860 /*
84861 * Callback to arch code if there's nosmp or maxcpus=0 on the
84862 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
84863 index 46cca4c..3323536 100644
84864 --- a/include/linux/sock_diag.h
84865 +++ b/include/linux/sock_diag.h
84866 @@ -11,7 +11,7 @@ struct sock;
84867 struct sock_diag_handler {
84868 __u8 family;
84869 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
84870 -};
84871 +} __do_const;
84872
84873 int sock_diag_register(const struct sock_diag_handler *h);
84874 void sock_diag_unregister(const struct sock_diag_handler *h);
84875 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
84876 index 680f9a3..f13aeb0 100644
84877 --- a/include/linux/sonet.h
84878 +++ b/include/linux/sonet.h
84879 @@ -7,7 +7,7 @@
84880 #include <uapi/linux/sonet.h>
84881
84882 struct k_sonet_stats {
84883 -#define __HANDLE_ITEM(i) atomic_t i
84884 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
84885 __SONET_ITEMS
84886 #undef __HANDLE_ITEM
84887 };
84888 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
84889 index 07d8e53..dc934c9 100644
84890 --- a/include/linux/sunrpc/addr.h
84891 +++ b/include/linux/sunrpc/addr.h
84892 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
84893 {
84894 switch (sap->sa_family) {
84895 case AF_INET:
84896 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
84897 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
84898 case AF_INET6:
84899 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
84900 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
84901 }
84902 return 0;
84903 }
84904 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
84905 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
84906 const struct sockaddr *src)
84907 {
84908 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
84909 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
84910 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
84911
84912 dsin->sin_family = ssin->sin_family;
84913 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
84914 if (sa->sa_family != AF_INET6)
84915 return 0;
84916
84917 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
84918 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
84919 }
84920
84921 #endif /* _LINUX_SUNRPC_ADDR_H */
84922 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
84923 index 70736b9..37f33db 100644
84924 --- a/include/linux/sunrpc/clnt.h
84925 +++ b/include/linux/sunrpc/clnt.h
84926 @@ -97,7 +97,7 @@ struct rpc_procinfo {
84927 unsigned int p_timer; /* Which RTT timer to use */
84928 u32 p_statidx; /* Which procedure to account */
84929 const char * p_name; /* name of procedure */
84930 -};
84931 +} __do_const;
84932
84933 #ifdef __KERNEL__
84934
84935 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
84936 index 2167846..0648fc3 100644
84937 --- a/include/linux/sunrpc/svc.h
84938 +++ b/include/linux/sunrpc/svc.h
84939 @@ -416,7 +416,7 @@ struct svc_procedure {
84940 unsigned int pc_count; /* call count */
84941 unsigned int pc_cachetype; /* cache info (NFS) */
84942 unsigned int pc_xdrressize; /* maximum size of XDR reply */
84943 -};
84944 +} __do_const;
84945
84946 /*
84947 * Function prototypes.
84948 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
84949 index 975da75..318c083 100644
84950 --- a/include/linux/sunrpc/svc_rdma.h
84951 +++ b/include/linux/sunrpc/svc_rdma.h
84952 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
84953 extern unsigned int svcrdma_max_requests;
84954 extern unsigned int svcrdma_max_req_size;
84955
84956 -extern atomic_t rdma_stat_recv;
84957 -extern atomic_t rdma_stat_read;
84958 -extern atomic_t rdma_stat_write;
84959 -extern atomic_t rdma_stat_sq_starve;
84960 -extern atomic_t rdma_stat_rq_starve;
84961 -extern atomic_t rdma_stat_rq_poll;
84962 -extern atomic_t rdma_stat_rq_prod;
84963 -extern atomic_t rdma_stat_sq_poll;
84964 -extern atomic_t rdma_stat_sq_prod;
84965 +extern atomic_unchecked_t rdma_stat_recv;
84966 +extern atomic_unchecked_t rdma_stat_read;
84967 +extern atomic_unchecked_t rdma_stat_write;
84968 +extern atomic_unchecked_t rdma_stat_sq_starve;
84969 +extern atomic_unchecked_t rdma_stat_rq_starve;
84970 +extern atomic_unchecked_t rdma_stat_rq_poll;
84971 +extern atomic_unchecked_t rdma_stat_rq_prod;
84972 +extern atomic_unchecked_t rdma_stat_sq_poll;
84973 +extern atomic_unchecked_t rdma_stat_sq_prod;
84974
84975 #define RPCRDMA_VERSION 1
84976
84977 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
84978 index 8d71d65..f79586e 100644
84979 --- a/include/linux/sunrpc/svcauth.h
84980 +++ b/include/linux/sunrpc/svcauth.h
84981 @@ -120,7 +120,7 @@ struct auth_ops {
84982 int (*release)(struct svc_rqst *rq);
84983 void (*domain_release)(struct auth_domain *);
84984 int (*set_client)(struct svc_rqst *rq);
84985 -};
84986 +} __do_const;
84987
84988 #define SVC_GARBAGE 1
84989 #define SVC_SYSERR 2
84990 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
84991 index e7a018e..49f8b17 100644
84992 --- a/include/linux/swiotlb.h
84993 +++ b/include/linux/swiotlb.h
84994 @@ -60,7 +60,8 @@ extern void
84995
84996 extern void
84997 swiotlb_free_coherent(struct device *hwdev, size_t size,
84998 - void *vaddr, dma_addr_t dma_handle);
84999 + void *vaddr, dma_addr_t dma_handle,
85000 + struct dma_attrs *attrs);
85001
85002 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
85003 unsigned long offset, size_t size,
85004 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
85005 index bda9b81..629e06e 100644
85006 --- a/include/linux/syscalls.h
85007 +++ b/include/linux/syscalls.h
85008 @@ -99,10 +99,16 @@ union bpf_attr;
85009 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
85010
85011 #define __SC_DECL(t, a) t a
85012 +#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))
85013 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
85014 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
85015 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
85016 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
85017 +#define __SC_LONG(t, a) __typeof( \
85018 + __builtin_choose_expr( \
85019 + sizeof(t) > sizeof(int), \
85020 + (t) 0, \
85021 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
85022 + )) a
85023 #define __SC_CAST(t, a) (t) a
85024 #define __SC_ARGS(t, a) a
85025 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
85026 @@ -384,11 +390,11 @@ asmlinkage long sys_sync(void);
85027 asmlinkage long sys_fsync(unsigned int fd);
85028 asmlinkage long sys_fdatasync(unsigned int fd);
85029 asmlinkage long sys_bdflush(int func, long data);
85030 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
85031 - char __user *type, unsigned long flags,
85032 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
85033 + const char __user *type, unsigned long flags,
85034 void __user *data);
85035 -asmlinkage long sys_umount(char __user *name, int flags);
85036 -asmlinkage long sys_oldumount(char __user *name);
85037 +asmlinkage long sys_umount(const char __user *name, int flags);
85038 +asmlinkage long sys_oldumount(const char __user *name);
85039 asmlinkage long sys_truncate(const char __user *path, long length);
85040 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
85041 asmlinkage long sys_stat(const char __user *filename,
85042 @@ -600,7 +606,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
85043 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
85044 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
85045 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
85046 - struct sockaddr __user *, int);
85047 + struct sockaddr __user *, int) __intentional_overflow(0);
85048 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
85049 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
85050 unsigned int vlen, unsigned flags);
85051 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
85052 index 27b3b0b..e093dd9 100644
85053 --- a/include/linux/syscore_ops.h
85054 +++ b/include/linux/syscore_ops.h
85055 @@ -16,7 +16,7 @@ struct syscore_ops {
85056 int (*suspend)(void);
85057 void (*resume)(void);
85058 void (*shutdown)(void);
85059 -};
85060 +} __do_const;
85061
85062 extern void register_syscore_ops(struct syscore_ops *ops);
85063 extern void unregister_syscore_ops(struct syscore_ops *ops);
85064 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
85065 index b7361f8..341a15a 100644
85066 --- a/include/linux/sysctl.h
85067 +++ b/include/linux/sysctl.h
85068 @@ -39,6 +39,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
85069
85070 extern int proc_dostring(struct ctl_table *, int,
85071 void __user *, size_t *, loff_t *);
85072 +extern int proc_dostring_modpriv(struct ctl_table *, int,
85073 + void __user *, size_t *, loff_t *);
85074 extern int proc_dointvec(struct ctl_table *, int,
85075 void __user *, size_t *, loff_t *);
85076 extern int proc_dointvec_minmax(struct ctl_table *, int,
85077 @@ -113,7 +115,8 @@ struct ctl_table
85078 struct ctl_table_poll *poll;
85079 void *extra1;
85080 void *extra2;
85081 -};
85082 +} __do_const __randomize_layout;
85083 +typedef struct ctl_table __no_const ctl_table_no_const;
85084
85085 struct ctl_node {
85086 struct rb_node node;
85087 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
85088 index f97d0db..c1187dc 100644
85089 --- a/include/linux/sysfs.h
85090 +++ b/include/linux/sysfs.h
85091 @@ -34,7 +34,8 @@ struct attribute {
85092 struct lock_class_key *key;
85093 struct lock_class_key skey;
85094 #endif
85095 -};
85096 +} __do_const;
85097 +typedef struct attribute __no_const attribute_no_const;
85098
85099 /**
85100 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
85101 @@ -63,7 +64,8 @@ struct attribute_group {
85102 struct attribute *, int);
85103 struct attribute **attrs;
85104 struct bin_attribute **bin_attrs;
85105 -};
85106 +} __do_const;
85107 +typedef struct attribute_group __no_const attribute_group_no_const;
85108
85109 /**
85110 * Use these macros to make defining attributes easier. See include/linux/device.h
85111 @@ -128,7 +130,8 @@ struct bin_attribute {
85112 char *, loff_t, size_t);
85113 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
85114 struct vm_area_struct *vma);
85115 -};
85116 +} __do_const;
85117 +typedef struct bin_attribute __no_const bin_attribute_no_const;
85118
85119 /**
85120 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
85121 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
85122 index 387fa7d..3fcde6b 100644
85123 --- a/include/linux/sysrq.h
85124 +++ b/include/linux/sysrq.h
85125 @@ -16,6 +16,7 @@
85126
85127 #include <linux/errno.h>
85128 #include <linux/types.h>
85129 +#include <linux/compiler.h>
85130
85131 /* Possible values of bitmask for enabling sysrq functions */
85132 /* 0x0001 is reserved for enable everything */
85133 @@ -33,7 +34,7 @@ struct sysrq_key_op {
85134 char *help_msg;
85135 char *action_msg;
85136 int enable_mask;
85137 -};
85138 +} __do_const;
85139
85140 #ifdef CONFIG_MAGIC_SYSRQ
85141
85142 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
85143 index ff307b5..f1a4468 100644
85144 --- a/include/linux/thread_info.h
85145 +++ b/include/linux/thread_info.h
85146 @@ -145,6 +145,13 @@ static inline bool test_and_clear_restore_sigmask(void)
85147 #error "no set_restore_sigmask() provided and default one won't work"
85148 #endif
85149
85150 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
85151 +
85152 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
85153 +{
85154 + __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
85155 +}
85156 +
85157 #endif /* __KERNEL__ */
85158
85159 #endif /* _LINUX_THREAD_INFO_H */
85160 diff --git a/include/linux/tty.h b/include/linux/tty.h
85161 index 5171ef8..1048d83e 100644
85162 --- a/include/linux/tty.h
85163 +++ b/include/linux/tty.h
85164 @@ -202,7 +202,7 @@ struct tty_port {
85165 const struct tty_port_operations *ops; /* Port operations */
85166 spinlock_t lock; /* Lock protecting tty field */
85167 int blocked_open; /* Waiting to open */
85168 - int count; /* Usage count */
85169 + atomic_t count; /* Usage count */
85170 wait_queue_head_t open_wait; /* Open waiters */
85171 wait_queue_head_t close_wait; /* Close waiters */
85172 wait_queue_head_t delta_msr_wait; /* Modem status change */
85173 @@ -290,7 +290,7 @@ struct tty_struct {
85174 /* If the tty has a pending do_SAK, queue it here - akpm */
85175 struct work_struct SAK_work;
85176 struct tty_port *port;
85177 -};
85178 +} __randomize_layout;
85179
85180 /* Each of a tty's open files has private_data pointing to tty_file_private */
85181 struct tty_file_private {
85182 @@ -555,7 +555,7 @@ extern int tty_port_open(struct tty_port *port,
85183 struct tty_struct *tty, struct file *filp);
85184 static inline int tty_port_users(struct tty_port *port)
85185 {
85186 - return port->count + port->blocked_open;
85187 + return atomic_read(&port->count) + port->blocked_open;
85188 }
85189
85190 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
85191 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
85192 index 92e337c..f46757b 100644
85193 --- a/include/linux/tty_driver.h
85194 +++ b/include/linux/tty_driver.h
85195 @@ -291,7 +291,7 @@ struct tty_operations {
85196 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
85197 #endif
85198 const struct file_operations *proc_fops;
85199 -};
85200 +} __do_const __randomize_layout;
85201
85202 struct tty_driver {
85203 int magic; /* magic number for this structure */
85204 @@ -325,7 +325,7 @@ struct tty_driver {
85205
85206 const struct tty_operations *ops;
85207 struct list_head tty_drivers;
85208 -};
85209 +} __randomize_layout;
85210
85211 extern struct list_head tty_drivers;
85212
85213 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
85214 index 00c9d68..bc0188b 100644
85215 --- a/include/linux/tty_ldisc.h
85216 +++ b/include/linux/tty_ldisc.h
85217 @@ -215,7 +215,7 @@ struct tty_ldisc_ops {
85218
85219 struct module *owner;
85220
85221 - int refcount;
85222 + atomic_t refcount;
85223 };
85224
85225 struct tty_ldisc {
85226 diff --git a/include/linux/types.h b/include/linux/types.h
85227 index a0bb704..f511c77 100644
85228 --- a/include/linux/types.h
85229 +++ b/include/linux/types.h
85230 @@ -177,10 +177,26 @@ typedef struct {
85231 int counter;
85232 } atomic_t;
85233
85234 +#ifdef CONFIG_PAX_REFCOUNT
85235 +typedef struct {
85236 + int counter;
85237 +} atomic_unchecked_t;
85238 +#else
85239 +typedef atomic_t atomic_unchecked_t;
85240 +#endif
85241 +
85242 #ifdef CONFIG_64BIT
85243 typedef struct {
85244 long counter;
85245 } atomic64_t;
85246 +
85247 +#ifdef CONFIG_PAX_REFCOUNT
85248 +typedef struct {
85249 + long counter;
85250 +} atomic64_unchecked_t;
85251 +#else
85252 +typedef atomic64_t atomic64_unchecked_t;
85253 +#endif
85254 #endif
85255
85256 struct list_head {
85257 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
85258 index ecd3319..8a36ded 100644
85259 --- a/include/linux/uaccess.h
85260 +++ b/include/linux/uaccess.h
85261 @@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
85262 long ret; \
85263 mm_segment_t old_fs = get_fs(); \
85264 \
85265 - set_fs(KERNEL_DS); \
85266 pagefault_disable(); \
85267 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
85268 - pagefault_enable(); \
85269 + set_fs(KERNEL_DS); \
85270 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
85271 set_fs(old_fs); \
85272 + pagefault_enable(); \
85273 ret; \
85274 })
85275
85276 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
85277 index 2d1f9b6..d7a9fce 100644
85278 --- a/include/linux/uidgid.h
85279 +++ b/include/linux/uidgid.h
85280 @@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
85281
85282 #endif /* CONFIG_USER_NS */
85283
85284 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
85285 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
85286 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
85287 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
85288 +
85289 #endif /* _LINUX_UIDGID_H */
85290 diff --git a/include/linux/uio_driver.h b/include/linux/uio_driver.h
85291 index baa8171..9ca98ba 100644
85292 --- a/include/linux/uio_driver.h
85293 +++ b/include/linux/uio_driver.h
85294 @@ -67,7 +67,7 @@ struct uio_device {
85295 struct module *owner;
85296 struct device *dev;
85297 int minor;
85298 - atomic_t event;
85299 + atomic_unchecked_t event;
85300 struct fasync_struct *async_queue;
85301 wait_queue_head_t wait;
85302 struct uio_info *info;
85303 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
85304 index 99c1b4d..562e6f3 100644
85305 --- a/include/linux/unaligned/access_ok.h
85306 +++ b/include/linux/unaligned/access_ok.h
85307 @@ -4,34 +4,34 @@
85308 #include <linux/kernel.h>
85309 #include <asm/byteorder.h>
85310
85311 -static inline u16 get_unaligned_le16(const void *p)
85312 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
85313 {
85314 - return le16_to_cpup((__le16 *)p);
85315 + return le16_to_cpup((const __le16 *)p);
85316 }
85317
85318 -static inline u32 get_unaligned_le32(const void *p)
85319 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
85320 {
85321 - return le32_to_cpup((__le32 *)p);
85322 + return le32_to_cpup((const __le32 *)p);
85323 }
85324
85325 -static inline u64 get_unaligned_le64(const void *p)
85326 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
85327 {
85328 - return le64_to_cpup((__le64 *)p);
85329 + return le64_to_cpup((const __le64 *)p);
85330 }
85331
85332 -static inline u16 get_unaligned_be16(const void *p)
85333 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
85334 {
85335 - return be16_to_cpup((__be16 *)p);
85336 + return be16_to_cpup((const __be16 *)p);
85337 }
85338
85339 -static inline u32 get_unaligned_be32(const void *p)
85340 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
85341 {
85342 - return be32_to_cpup((__be32 *)p);
85343 + return be32_to_cpup((const __be32 *)p);
85344 }
85345
85346 -static inline u64 get_unaligned_be64(const void *p)
85347 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
85348 {
85349 - return be64_to_cpup((__be64 *)p);
85350 + return be64_to_cpup((const __be64 *)p);
85351 }
85352
85353 static inline void put_unaligned_le16(u16 val, void *p)
85354 diff --git a/include/linux/usb.h b/include/linux/usb.h
85355 index 447a7e2..9cea7e9 100644
85356 --- a/include/linux/usb.h
85357 +++ b/include/linux/usb.h
85358 @@ -571,7 +571,7 @@ struct usb_device {
85359 int maxchild;
85360
85361 u32 quirks;
85362 - atomic_t urbnum;
85363 + atomic_unchecked_t urbnum;
85364
85365 unsigned long active_duration;
85366
85367 @@ -1655,7 +1655,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
85368
85369 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
85370 __u8 request, __u8 requesttype, __u16 value, __u16 index,
85371 - void *data, __u16 size, int timeout);
85372 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
85373 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
85374 void *data, int len, int *actual_length, int timeout);
85375 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
85376 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
85377 index d5952bb..9a626d4 100644
85378 --- a/include/linux/usb/renesas_usbhs.h
85379 +++ b/include/linux/usb/renesas_usbhs.h
85380 @@ -39,7 +39,7 @@ enum {
85381 */
85382 struct renesas_usbhs_driver_callback {
85383 int (*notify_hotplug)(struct platform_device *pdev);
85384 -};
85385 +} __no_const;
85386
85387 /*
85388 * callback functions for platform
85389 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
85390 index e953726..8edb26a 100644
85391 --- a/include/linux/user_namespace.h
85392 +++ b/include/linux/user_namespace.h
85393 @@ -33,7 +33,7 @@ struct user_namespace {
85394 struct key *persistent_keyring_register;
85395 struct rw_semaphore persistent_keyring_register_sem;
85396 #endif
85397 -};
85398 +} __randomize_layout;
85399
85400 extern struct user_namespace init_user_ns;
85401
85402 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
85403 index 239e277..22a5cf5 100644
85404 --- a/include/linux/utsname.h
85405 +++ b/include/linux/utsname.h
85406 @@ -24,7 +24,7 @@ struct uts_namespace {
85407 struct new_utsname name;
85408 struct user_namespace *user_ns;
85409 unsigned int proc_inum;
85410 -};
85411 +} __randomize_layout;
85412 extern struct uts_namespace init_uts_ns;
85413
85414 #ifdef CONFIG_UTS_NS
85415 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
85416 index 6f8fbcf..4efc177 100644
85417 --- a/include/linux/vermagic.h
85418 +++ b/include/linux/vermagic.h
85419 @@ -25,9 +25,42 @@
85420 #define MODULE_ARCH_VERMAGIC ""
85421 #endif
85422
85423 +#ifdef CONFIG_PAX_REFCOUNT
85424 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
85425 +#else
85426 +#define MODULE_PAX_REFCOUNT ""
85427 +#endif
85428 +
85429 +#ifdef CONSTIFY_PLUGIN
85430 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
85431 +#else
85432 +#define MODULE_CONSTIFY_PLUGIN ""
85433 +#endif
85434 +
85435 +#ifdef STACKLEAK_PLUGIN
85436 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
85437 +#else
85438 +#define MODULE_STACKLEAK_PLUGIN ""
85439 +#endif
85440 +
85441 +#ifdef RANDSTRUCT_PLUGIN
85442 +#include <generated/randomize_layout_hash.h>
85443 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
85444 +#else
85445 +#define MODULE_RANDSTRUCT_PLUGIN
85446 +#endif
85447 +
85448 +#ifdef CONFIG_GRKERNSEC
85449 +#define MODULE_GRSEC "GRSEC "
85450 +#else
85451 +#define MODULE_GRSEC ""
85452 +#endif
85453 +
85454 #define VERMAGIC_STRING \
85455 UTS_RELEASE " " \
85456 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
85457 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
85458 - MODULE_ARCH_VERMAGIC
85459 + MODULE_ARCH_VERMAGIC \
85460 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
85461 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
85462
85463 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
85464 index b483abd..af305ad 100644
85465 --- a/include/linux/vga_switcheroo.h
85466 +++ b/include/linux/vga_switcheroo.h
85467 @@ -63,9 +63,9 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
85468
85469 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
85470
85471 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
85472 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
85473 void vga_switcheroo_fini_domain_pm_ops(struct device *dev);
85474 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
85475 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
85476 #else
85477
85478 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
85479 @@ -82,9 +82,9 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
85480
85481 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
85482
85483 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
85484 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
85485 static inline void vga_switcheroo_fini_domain_pm_ops(struct device *dev) {}
85486 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
85487 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
85488
85489 #endif
85490 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
85491 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
85492 index b87696f..1d11de7 100644
85493 --- a/include/linux/vmalloc.h
85494 +++ b/include/linux/vmalloc.h
85495 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
85496 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
85497 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
85498 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
85499 +
85500 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85501 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
85502 +#endif
85503 +
85504 /* bits [20..32] reserved for arch specific ioremap internals */
85505
85506 /*
85507 @@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
85508 unsigned long flags, pgprot_t prot);
85509 extern void vunmap(const void *addr);
85510
85511 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
85512 +extern void unmap_process_stacks(struct task_struct *task);
85513 +#endif
85514 +
85515 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
85516 unsigned long uaddr, void *kaddr,
85517 unsigned long size);
85518 @@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
85519
85520 /* for /dev/kmem */
85521 extern long vread(char *buf, char *addr, unsigned long count);
85522 -extern long vwrite(char *buf, char *addr, unsigned long count);
85523 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
85524
85525 /*
85526 * Internals. Dont't use..
85527 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
85528 index 82e7db7..f8ce3d0 100644
85529 --- a/include/linux/vmstat.h
85530 +++ b/include/linux/vmstat.h
85531 @@ -108,18 +108,18 @@ static inline void vm_events_fold_cpu(int cpu)
85532 /*
85533 * Zone based page accounting with per cpu differentials.
85534 */
85535 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
85536 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
85537
85538 static inline void zone_page_state_add(long x, struct zone *zone,
85539 enum zone_stat_item item)
85540 {
85541 - atomic_long_add(x, &zone->vm_stat[item]);
85542 - atomic_long_add(x, &vm_stat[item]);
85543 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
85544 + atomic_long_add_unchecked(x, &vm_stat[item]);
85545 }
85546
85547 -static inline unsigned long global_page_state(enum zone_stat_item item)
85548 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
85549 {
85550 - long x = atomic_long_read(&vm_stat[item]);
85551 + long x = atomic_long_read_unchecked(&vm_stat[item]);
85552 #ifdef CONFIG_SMP
85553 if (x < 0)
85554 x = 0;
85555 @@ -127,10 +127,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
85556 return x;
85557 }
85558
85559 -static inline unsigned long zone_page_state(struct zone *zone,
85560 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
85561 enum zone_stat_item item)
85562 {
85563 - long x = atomic_long_read(&zone->vm_stat[item]);
85564 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
85565 #ifdef CONFIG_SMP
85566 if (x < 0)
85567 x = 0;
85568 @@ -147,7 +147,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
85569 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
85570 enum zone_stat_item item)
85571 {
85572 - long x = atomic_long_read(&zone->vm_stat[item]);
85573 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
85574
85575 #ifdef CONFIG_SMP
85576 int cpu;
85577 @@ -234,14 +234,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
85578
85579 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
85580 {
85581 - atomic_long_inc(&zone->vm_stat[item]);
85582 - atomic_long_inc(&vm_stat[item]);
85583 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
85584 + atomic_long_inc_unchecked(&vm_stat[item]);
85585 }
85586
85587 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
85588 {
85589 - atomic_long_dec(&zone->vm_stat[item]);
85590 - atomic_long_dec(&vm_stat[item]);
85591 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
85592 + atomic_long_dec_unchecked(&vm_stat[item]);
85593 }
85594
85595 static inline void __inc_zone_page_state(struct page *page,
85596 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
85597 index 91b0a68..0e9adf6 100644
85598 --- a/include/linux/xattr.h
85599 +++ b/include/linux/xattr.h
85600 @@ -28,7 +28,7 @@ struct xattr_handler {
85601 size_t size, int handler_flags);
85602 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
85603 size_t size, int flags, int handler_flags);
85604 -};
85605 +} __do_const;
85606
85607 struct xattr {
85608 const char *name;
85609 @@ -37,6 +37,9 @@ struct xattr {
85610 };
85611
85612 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
85613 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
85614 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
85615 +#endif
85616 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
85617 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
85618 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
85619 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
85620 index 92dbbd3..13ab0b3 100644
85621 --- a/include/linux/zlib.h
85622 +++ b/include/linux/zlib.h
85623 @@ -31,6 +31,7 @@
85624 #define _ZLIB_H
85625
85626 #include <linux/zconf.h>
85627 +#include <linux/compiler.h>
85628
85629 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
85630 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
85631 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
85632
85633 /* basic functions */
85634
85635 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
85636 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
85637 /*
85638 Returns the number of bytes that needs to be allocated for a per-
85639 stream workspace with the specified parameters. A pointer to this
85640 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
85641 index eb76cfd..9fd0e7c 100644
85642 --- a/include/media/v4l2-dev.h
85643 +++ b/include/media/v4l2-dev.h
85644 @@ -75,7 +75,7 @@ struct v4l2_file_operations {
85645 int (*mmap) (struct file *, struct vm_area_struct *);
85646 int (*open) (struct file *);
85647 int (*release) (struct file *);
85648 -};
85649 +} __do_const;
85650
85651 /*
85652 * Newer version of video_device, handled by videodev2.c
85653 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
85654 index ffb69da..040393e 100644
85655 --- a/include/media/v4l2-device.h
85656 +++ b/include/media/v4l2-device.h
85657 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
85658 this function returns 0. If the name ends with a digit (e.g. cx18),
85659 then the name will be set to cx18-0 since cx180 looks really odd. */
85660 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
85661 - atomic_t *instance);
85662 + atomic_unchecked_t *instance);
85663
85664 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
85665 Since the parent disappears this ensures that v4l2_dev doesn't have an
85666 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
85667 index 2a25dec..bf6dd8a 100644
85668 --- a/include/net/9p/transport.h
85669 +++ b/include/net/9p/transport.h
85670 @@ -62,7 +62,7 @@ struct p9_trans_module {
85671 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
85672 int (*zc_request)(struct p9_client *, struct p9_req_t *,
85673 char *, char *, int , int, int, int);
85674 -};
85675 +} __do_const;
85676
85677 void v9fs_register_trans(struct p9_trans_module *m);
85678 void v9fs_unregister_trans(struct p9_trans_module *m);
85679 diff --git a/include/net/af_unix.h b/include/net/af_unix.h
85680 index a175ba4..196eb8242 100644
85681 --- a/include/net/af_unix.h
85682 +++ b/include/net/af_unix.h
85683 @@ -36,7 +36,7 @@ struct unix_skb_parms {
85684 u32 secid; /* Security ID */
85685 #endif
85686 u32 consumed;
85687 -};
85688 +} __randomize_layout;
85689
85690 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
85691 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
85692 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
85693 index ead99f0..6263c4b 100644
85694 --- a/include/net/bluetooth/l2cap.h
85695 +++ b/include/net/bluetooth/l2cap.h
85696 @@ -608,7 +608,7 @@ struct l2cap_ops {
85697 unsigned char *kdata,
85698 struct iovec *iov,
85699 int len);
85700 -};
85701 +} __do_const;
85702
85703 struct l2cap_conn {
85704 struct hci_conn *hcon;
85705 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
85706 index f2ae33d..c457cf0 100644
85707 --- a/include/net/caif/cfctrl.h
85708 +++ b/include/net/caif/cfctrl.h
85709 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
85710 void (*radioset_rsp)(void);
85711 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
85712 struct cflayer *client_layer);
85713 -};
85714 +} __no_const;
85715
85716 /* Link Setup Parameters for CAIF-Links. */
85717 struct cfctrl_link_param {
85718 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
85719 struct cfctrl {
85720 struct cfsrvl serv;
85721 struct cfctrl_rsp res;
85722 - atomic_t req_seq_no;
85723 - atomic_t rsp_seq_no;
85724 + atomic_unchecked_t req_seq_no;
85725 + atomic_unchecked_t rsp_seq_no;
85726 struct list_head list;
85727 /* Protects from simultaneous access to first_req list */
85728 spinlock_t info_list_lock;
85729 diff --git a/include/net/flow.h b/include/net/flow.h
85730 index 8109a15..504466d 100644
85731 --- a/include/net/flow.h
85732 +++ b/include/net/flow.h
85733 @@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
85734
85735 void flow_cache_flush(struct net *net);
85736 void flow_cache_flush_deferred(struct net *net);
85737 -extern atomic_t flow_cache_genid;
85738 +extern atomic_unchecked_t flow_cache_genid;
85739
85740 #endif
85741 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
85742 index af10c2c..a431cc5 100644
85743 --- a/include/net/genetlink.h
85744 +++ b/include/net/genetlink.h
85745 @@ -120,7 +120,7 @@ struct genl_ops {
85746 u8 cmd;
85747 u8 internal_flags;
85748 u8 flags;
85749 -};
85750 +} __do_const;
85751
85752 int __genl_register_family(struct genl_family *family);
85753
85754 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
85755 index 734d9b5..48a9a4b 100644
85756 --- a/include/net/gro_cells.h
85757 +++ b/include/net/gro_cells.h
85758 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
85759 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
85760
85761 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
85762 - atomic_long_inc(&dev->rx_dropped);
85763 + atomic_long_inc_unchecked(&dev->rx_dropped);
85764 kfree_skb(skb);
85765 return;
85766 }
85767 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
85768 index 848e85c..051c7de 100644
85769 --- a/include/net/inet_connection_sock.h
85770 +++ b/include/net/inet_connection_sock.h
85771 @@ -63,7 +63,7 @@ struct inet_connection_sock_af_ops {
85772 int (*bind_conflict)(const struct sock *sk,
85773 const struct inet_bind_bucket *tb, bool relax);
85774 void (*mtu_reduced)(struct sock *sk);
85775 -};
85776 +} __do_const;
85777
85778 /** inet_connection_sock - INET connection oriented sock
85779 *
85780 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
85781 index 80479ab..0c3f647 100644
85782 --- a/include/net/inetpeer.h
85783 +++ b/include/net/inetpeer.h
85784 @@ -47,7 +47,7 @@ struct inet_peer {
85785 */
85786 union {
85787 struct {
85788 - atomic_t rid; /* Frag reception counter */
85789 + atomic_unchecked_t rid; /* Frag reception counter */
85790 };
85791 struct rcu_head rcu;
85792 struct inet_peer *gc_next;
85793 diff --git a/include/net/ip.h b/include/net/ip.h
85794 index 0bb6207..a8878af 100644
85795 --- a/include/net/ip.h
85796 +++ b/include/net/ip.h
85797 @@ -316,7 +316,7 @@ static inline unsigned int ip_skb_dst_mtu(const struct sk_buff *skb)
85798 }
85799 }
85800
85801 -u32 ip_idents_reserve(u32 hash, int segs);
85802 +u32 ip_idents_reserve(u32 hash, int segs) __intentional_overflow(-1);
85803 void __ip_select_ident(struct iphdr *iph, int segs);
85804
85805 static inline void ip_select_ident_segs(struct sk_buff *skb, struct sock *sk, int segs)
85806 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
85807 index dc9d2a2..d985691 100644
85808 --- a/include/net/ip_fib.h
85809 +++ b/include/net/ip_fib.h
85810 @@ -170,7 +170,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
85811
85812 #define FIB_RES_SADDR(net, res) \
85813 ((FIB_RES_NH(res).nh_saddr_genid == \
85814 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
85815 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
85816 FIB_RES_NH(res).nh_saddr : \
85817 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
85818 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
85819 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
85820 index 615b20b..fd4cbd8 100644
85821 --- a/include/net/ip_vs.h
85822 +++ b/include/net/ip_vs.h
85823 @@ -534,7 +534,7 @@ struct ip_vs_conn {
85824 struct ip_vs_conn *control; /* Master control connection */
85825 atomic_t n_control; /* Number of controlled ones */
85826 struct ip_vs_dest *dest; /* real server */
85827 - atomic_t in_pkts; /* incoming packet counter */
85828 + atomic_unchecked_t in_pkts; /* incoming packet counter */
85829
85830 /* Packet transmitter for different forwarding methods. If it
85831 * mangles the packet, it must return NF_DROP or better NF_STOLEN,
85832 @@ -682,7 +682,7 @@ struct ip_vs_dest {
85833 __be16 port; /* port number of the server */
85834 union nf_inet_addr addr; /* IP address of the server */
85835 volatile unsigned int flags; /* dest status flags */
85836 - atomic_t conn_flags; /* flags to copy to conn */
85837 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
85838 atomic_t weight; /* server weight */
85839
85840 atomic_t refcnt; /* reference counter */
85841 @@ -928,11 +928,11 @@ struct netns_ipvs {
85842 /* ip_vs_lblc */
85843 int sysctl_lblc_expiration;
85844 struct ctl_table_header *lblc_ctl_header;
85845 - struct ctl_table *lblc_ctl_table;
85846 + ctl_table_no_const *lblc_ctl_table;
85847 /* ip_vs_lblcr */
85848 int sysctl_lblcr_expiration;
85849 struct ctl_table_header *lblcr_ctl_header;
85850 - struct ctl_table *lblcr_ctl_table;
85851 + ctl_table_no_const *lblcr_ctl_table;
85852 /* ip_vs_est */
85853 struct list_head est_list; /* estimator list */
85854 spinlock_t est_lock;
85855 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
85856 index 8d4f588..2e37ad2 100644
85857 --- a/include/net/irda/ircomm_tty.h
85858 +++ b/include/net/irda/ircomm_tty.h
85859 @@ -33,6 +33,7 @@
85860 #include <linux/termios.h>
85861 #include <linux/timer.h>
85862 #include <linux/tty.h> /* struct tty_struct */
85863 +#include <asm/local.h>
85864
85865 #include <net/irda/irias_object.h>
85866 #include <net/irda/ircomm_core.h>
85867 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
85868 index 714cc9a..ea05f3e 100644
85869 --- a/include/net/iucv/af_iucv.h
85870 +++ b/include/net/iucv/af_iucv.h
85871 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
85872 struct iucv_sock_list {
85873 struct hlist_head head;
85874 rwlock_t lock;
85875 - atomic_t autobind_name;
85876 + atomic_unchecked_t autobind_name;
85877 };
85878
85879 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
85880 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
85881 index f3be818..bf46196 100644
85882 --- a/include/net/llc_c_ac.h
85883 +++ b/include/net/llc_c_ac.h
85884 @@ -87,7 +87,7 @@
85885 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
85886 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
85887
85888 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
85889 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
85890
85891 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
85892 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
85893 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
85894 index 3948cf1..83b28c4 100644
85895 --- a/include/net/llc_c_ev.h
85896 +++ b/include/net/llc_c_ev.h
85897 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
85898 return (struct llc_conn_state_ev *)skb->cb;
85899 }
85900
85901 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
85902 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
85903 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
85904 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
85905
85906 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
85907 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
85908 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
85909 index 0e79cfb..f46db31 100644
85910 --- a/include/net/llc_c_st.h
85911 +++ b/include/net/llc_c_st.h
85912 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
85913 u8 next_state;
85914 llc_conn_ev_qfyr_t *ev_qualifiers;
85915 llc_conn_action_t *ev_actions;
85916 -};
85917 +} __do_const;
85918
85919 struct llc_conn_state {
85920 u8 current_state;
85921 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
85922 index a61b98c..aade1eb 100644
85923 --- a/include/net/llc_s_ac.h
85924 +++ b/include/net/llc_s_ac.h
85925 @@ -23,7 +23,7 @@
85926 #define SAP_ACT_TEST_IND 9
85927
85928 /* All action functions must look like this */
85929 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
85930 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
85931
85932 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
85933 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
85934 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
85935 index 567c681..cd73ac02 100644
85936 --- a/include/net/llc_s_st.h
85937 +++ b/include/net/llc_s_st.h
85938 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
85939 llc_sap_ev_t ev;
85940 u8 next_state;
85941 llc_sap_action_t *ev_actions;
85942 -};
85943 +} __do_const;
85944
85945 struct llc_sap_state {
85946 u8 curr_state;
85947 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
85948 index 0ad1f47..aaea45b 100644
85949 --- a/include/net/mac80211.h
85950 +++ b/include/net/mac80211.h
85951 @@ -4648,7 +4648,7 @@ struct rate_control_ops {
85952 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
85953
85954 u32 (*get_expected_throughput)(void *priv_sta);
85955 -};
85956 +} __do_const;
85957
85958 static inline int rate_supported(struct ieee80211_sta *sta,
85959 enum ieee80211_band band,
85960 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
85961 index f60558d..e5ed9bd 100644
85962 --- a/include/net/neighbour.h
85963 +++ b/include/net/neighbour.h
85964 @@ -163,7 +163,7 @@ struct neigh_ops {
85965 void (*error_report)(struct neighbour *, struct sk_buff *);
85966 int (*output)(struct neighbour *, struct sk_buff *);
85967 int (*connected_output)(struct neighbour *, struct sk_buff *);
85968 -};
85969 +} __do_const;
85970
85971 struct pneigh_entry {
85972 struct pneigh_entry *next;
85973 @@ -217,7 +217,7 @@ struct neigh_table {
85974 struct neigh_statistics __percpu *stats;
85975 struct neigh_hash_table __rcu *nht;
85976 struct pneigh_entry **phash_buckets;
85977 -};
85978 +} __randomize_layout;
85979
85980 static inline int neigh_parms_family(struct neigh_parms *p)
85981 {
85982 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
85983 index e0d6466..e2f3003 100644
85984 --- a/include/net/net_namespace.h
85985 +++ b/include/net/net_namespace.h
85986 @@ -129,8 +129,8 @@ struct net {
85987 struct netns_ipvs *ipvs;
85988 #endif
85989 struct sock *diag_nlsk;
85990 - atomic_t fnhe_genid;
85991 -};
85992 + atomic_unchecked_t fnhe_genid;
85993 +} __randomize_layout;
85994
85995 #include <linux/seq_file_net.h>
85996
85997 @@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
85998 #define __net_init __init
85999 #define __net_exit __exit_refok
86000 #define __net_initdata __initdata
86001 +#ifdef CONSTIFY_PLUGIN
86002 #define __net_initconst __initconst
86003 +#else
86004 +#define __net_initconst __initdata
86005 +#endif
86006 #endif
86007
86008 struct pernet_operations {
86009 @@ -296,7 +300,7 @@ struct pernet_operations {
86010 void (*exit_batch)(struct list_head *net_exit_list);
86011 int *id;
86012 size_t size;
86013 -};
86014 +} __do_const;
86015
86016 /*
86017 * Use these carefully. If you implement a network device and it
86018 @@ -344,12 +348,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
86019
86020 static inline int rt_genid_ipv4(struct net *net)
86021 {
86022 - return atomic_read(&net->ipv4.rt_genid);
86023 + return atomic_read_unchecked(&net->ipv4.rt_genid);
86024 }
86025
86026 static inline void rt_genid_bump_ipv4(struct net *net)
86027 {
86028 - atomic_inc(&net->ipv4.rt_genid);
86029 + atomic_inc_unchecked(&net->ipv4.rt_genid);
86030 }
86031
86032 extern void (*__fib6_flush_trees)(struct net *net);
86033 @@ -376,12 +380,12 @@ static inline void rt_genid_bump_all(struct net *net)
86034
86035 static inline int fnhe_genid(struct net *net)
86036 {
86037 - return atomic_read(&net->fnhe_genid);
86038 + return atomic_read_unchecked(&net->fnhe_genid);
86039 }
86040
86041 static inline void fnhe_genid_bump(struct net *net)
86042 {
86043 - atomic_inc(&net->fnhe_genid);
86044 + atomic_inc_unchecked(&net->fnhe_genid);
86045 }
86046
86047 #endif /* __NET_NET_NAMESPACE_H */
86048 diff --git a/include/net/netlink.h b/include/net/netlink.h
86049 index 7b903e1..ad9ca4b 100644
86050 --- a/include/net/netlink.h
86051 +++ b/include/net/netlink.h
86052 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
86053 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
86054 {
86055 if (mark)
86056 - skb_trim(skb, (unsigned char *) mark - skb->data);
86057 + skb_trim(skb, (const unsigned char *) mark - skb->data);
86058 }
86059
86060 /**
86061 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
86062 index 29d6a94..235d3d84 100644
86063 --- a/include/net/netns/conntrack.h
86064 +++ b/include/net/netns/conntrack.h
86065 @@ -14,10 +14,10 @@ struct nf_conntrack_ecache;
86066 struct nf_proto_net {
86067 #ifdef CONFIG_SYSCTL
86068 struct ctl_table_header *ctl_table_header;
86069 - struct ctl_table *ctl_table;
86070 + ctl_table_no_const *ctl_table;
86071 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
86072 struct ctl_table_header *ctl_compat_header;
86073 - struct ctl_table *ctl_compat_table;
86074 + ctl_table_no_const *ctl_compat_table;
86075 #endif
86076 #endif
86077 unsigned int users;
86078 @@ -60,7 +60,7 @@ struct nf_ip_net {
86079 struct nf_icmp_net icmpv6;
86080 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
86081 struct ctl_table_header *ctl_table_header;
86082 - struct ctl_table *ctl_table;
86083 + ctl_table_no_const *ctl_table;
86084 #endif
86085 };
86086
86087 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
86088 index 24945ce..f19e42f 100644
86089 --- a/include/net/netns/ipv4.h
86090 +++ b/include/net/netns/ipv4.h
86091 @@ -83,7 +83,7 @@ struct netns_ipv4 {
86092
86093 struct ping_group_range ping_group_range;
86094
86095 - atomic_t dev_addr_genid;
86096 + atomic_unchecked_t dev_addr_genid;
86097
86098 #ifdef CONFIG_SYSCTL
86099 unsigned long *sysctl_local_reserved_ports;
86100 @@ -97,6 +97,6 @@ struct netns_ipv4 {
86101 struct fib_rules_ops *mr_rules_ops;
86102 #endif
86103 #endif
86104 - atomic_t rt_genid;
86105 + atomic_unchecked_t rt_genid;
86106 };
86107 #endif
86108 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
86109 index 69ae41f..4f94868 100644
86110 --- a/include/net/netns/ipv6.h
86111 +++ b/include/net/netns/ipv6.h
86112 @@ -75,8 +75,8 @@ struct netns_ipv6 {
86113 struct fib_rules_ops *mr6_rules_ops;
86114 #endif
86115 #endif
86116 - atomic_t dev_addr_genid;
86117 - atomic_t fib6_sernum;
86118 + atomic_unchecked_t dev_addr_genid;
86119 + atomic_unchecked_t fib6_sernum;
86120 };
86121
86122 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
86123 diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
86124 index 9da7982..099321b9 100644
86125 --- a/include/net/netns/xfrm.h
86126 +++ b/include/net/netns/xfrm.h
86127 @@ -78,7 +78,7 @@ struct netns_xfrm {
86128
86129 /* flow cache part */
86130 struct flow_cache flow_cache_global;
86131 - atomic_t flow_cache_genid;
86132 + atomic_unchecked_t flow_cache_genid;
86133 struct list_head flow_cache_gc_list;
86134 spinlock_t flow_cache_gc_lock;
86135 struct work_struct flow_cache_gc_work;
86136 diff --git a/include/net/ping.h b/include/net/ping.h
86137 index 026479b..d9b2829 100644
86138 --- a/include/net/ping.h
86139 +++ b/include/net/ping.h
86140 @@ -54,7 +54,7 @@ struct ping_iter_state {
86141
86142 extern struct proto ping_prot;
86143 #if IS_ENABLED(CONFIG_IPV6)
86144 -extern struct pingv6_ops pingv6_ops;
86145 +extern struct pingv6_ops *pingv6_ops;
86146 #endif
86147
86148 struct pingfakehdr {
86149 diff --git a/include/net/protocol.h b/include/net/protocol.h
86150 index d6fcc1f..ca277058 100644
86151 --- a/include/net/protocol.h
86152 +++ b/include/net/protocol.h
86153 @@ -49,7 +49,7 @@ struct net_protocol {
86154 * socket lookup?
86155 */
86156 icmp_strict_tag_validation:1;
86157 -};
86158 +} __do_const;
86159
86160 #if IS_ENABLED(CONFIG_IPV6)
86161 struct inet6_protocol {
86162 @@ -62,7 +62,7 @@ struct inet6_protocol {
86163 u8 type, u8 code, int offset,
86164 __be32 info);
86165 unsigned int flags; /* INET6_PROTO_xxx */
86166 -};
86167 +} __do_const;
86168
86169 #define INET6_PROTO_NOPOLICY 0x1
86170 #define INET6_PROTO_FINAL 0x2
86171 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
86172 index e21b9f9..0191ef0 100644
86173 --- a/include/net/rtnetlink.h
86174 +++ b/include/net/rtnetlink.h
86175 @@ -93,7 +93,7 @@ struct rtnl_link_ops {
86176 int (*fill_slave_info)(struct sk_buff *skb,
86177 const struct net_device *dev,
86178 const struct net_device *slave_dev);
86179 -};
86180 +} __do_const;
86181
86182 int __rtnl_link_register(struct rtnl_link_ops *ops);
86183 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
86184 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
86185 index 4a5b9a3..ca27d73 100644
86186 --- a/include/net/sctp/checksum.h
86187 +++ b/include/net/sctp/checksum.h
86188 @@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
86189 unsigned int offset)
86190 {
86191 struct sctphdr *sh = sctp_hdr(skb);
86192 - __le32 ret, old = sh->checksum;
86193 - const struct skb_checksum_ops ops = {
86194 + __le32 ret, old = sh->checksum;
86195 + static const struct skb_checksum_ops ops = {
86196 .update = sctp_csum_update,
86197 .combine = sctp_csum_combine,
86198 };
86199 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
86200 index 72a31db..aaa63d9 100644
86201 --- a/include/net/sctp/sm.h
86202 +++ b/include/net/sctp/sm.h
86203 @@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
86204 typedef struct {
86205 sctp_state_fn_t *fn;
86206 const char *name;
86207 -} sctp_sm_table_entry_t;
86208 +} __do_const sctp_sm_table_entry_t;
86209
86210 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
86211 * currently in use.
86212 @@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
86213 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
86214
86215 /* Extern declarations for major data structures. */
86216 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
86217 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
86218
86219
86220 /* Get the size of a DATA chunk payload. */
86221 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
86222 index 4ff3f67..89ae38e 100644
86223 --- a/include/net/sctp/structs.h
86224 +++ b/include/net/sctp/structs.h
86225 @@ -509,7 +509,7 @@ struct sctp_pf {
86226 void (*to_sk_saddr)(union sctp_addr *, struct sock *sk);
86227 void (*to_sk_daddr)(union sctp_addr *, struct sock *sk);
86228 struct sctp_af *af;
86229 -};
86230 +} __do_const;
86231
86232
86233 /* Structure to track chunk fragments that have been acked, but peer
86234 diff --git a/include/net/sock.h b/include/net/sock.h
86235 index 7db3db1..a915cca 100644
86236 --- a/include/net/sock.h
86237 +++ b/include/net/sock.h
86238 @@ -355,7 +355,7 @@ struct sock {
86239 unsigned int sk_napi_id;
86240 unsigned int sk_ll_usec;
86241 #endif
86242 - atomic_t sk_drops;
86243 + atomic_unchecked_t sk_drops;
86244 int sk_rcvbuf;
86245
86246 struct sk_filter __rcu *sk_filter;
86247 @@ -1048,7 +1048,7 @@ struct proto {
86248 void (*destroy_cgroup)(struct mem_cgroup *memcg);
86249 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
86250 #endif
86251 -};
86252 +} __randomize_layout;
86253
86254 /*
86255 * Bits in struct cg_proto.flags
86256 @@ -1235,7 +1235,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
86257 return ret >> PAGE_SHIFT;
86258 }
86259
86260 -static inline long
86261 +static inline long __intentional_overflow(-1)
86262 sk_memory_allocated(const struct sock *sk)
86263 {
86264 struct proto *prot = sk->sk_prot;
86265 @@ -1380,7 +1380,7 @@ struct sock_iocb {
86266 struct scm_cookie *scm;
86267 struct msghdr *msg, async_msg;
86268 struct kiocb *kiocb;
86269 -};
86270 +} __randomize_layout;
86271
86272 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
86273 {
86274 @@ -1820,7 +1820,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
86275 }
86276
86277 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
86278 - char __user *from, char *to,
86279 + char __user *from, unsigned char *to,
86280 int copy, int offset)
86281 {
86282 if (skb->ip_summed == CHECKSUM_NONE) {
86283 @@ -2092,7 +2092,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
86284 }
86285 }
86286
86287 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
86288 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
86289
86290 /**
86291 * sk_page_frag - return an appropriate page_frag
86292 diff --git a/include/net/tcp.h b/include/net/tcp.h
86293 index 4062b4f..9ff45e7 100644
86294 --- a/include/net/tcp.h
86295 +++ b/include/net/tcp.h
86296 @@ -519,7 +519,7 @@ void tcp_retransmit_timer(struct sock *sk);
86297 void tcp_xmit_retransmit_queue(struct sock *);
86298 void tcp_simple_retransmit(struct sock *);
86299 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
86300 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
86301 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
86302
86303 void tcp_send_probe0(struct sock *);
86304 void tcp_send_partial(struct sock *);
86305 @@ -692,8 +692,8 @@ static inline u32 tcp_skb_timestamp(const struct sk_buff *skb)
86306 * If this grows please adjust skbuff.h:skbuff->cb[xxx] size appropriately.
86307 */
86308 struct tcp_skb_cb {
86309 - __u32 seq; /* Starting sequence number */
86310 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
86311 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
86312 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
86313 union {
86314 /* Note : tcp_tw_isn is used in input path only
86315 * (isn chosen by tcp_timewait_state_process())
86316 @@ -718,7 +718,7 @@ struct tcp_skb_cb {
86317
86318 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
86319 /* 1 byte hole */
86320 - __u32 ack_seq; /* Sequence number ACK'd */
86321 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
86322 union {
86323 struct inet_skb_parm h4;
86324 #if IS_ENABLED(CONFIG_IPV6)
86325 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
86326 index dc4865e..152ee4c 100644
86327 --- a/include/net/xfrm.h
86328 +++ b/include/net/xfrm.h
86329 @@ -285,7 +285,6 @@ struct xfrm_dst;
86330 struct xfrm_policy_afinfo {
86331 unsigned short family;
86332 struct dst_ops *dst_ops;
86333 - void (*garbage_collect)(struct net *net);
86334 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
86335 const xfrm_address_t *saddr,
86336 const xfrm_address_t *daddr);
86337 @@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
86338 struct net_device *dev,
86339 const struct flowi *fl);
86340 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
86341 -};
86342 +} __do_const;
86343
86344 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
86345 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
86346 @@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
86347 int (*transport_finish)(struct sk_buff *skb,
86348 int async);
86349 void (*local_error)(struct sk_buff *skb, u32 mtu);
86350 -};
86351 +} __do_const;
86352
86353 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
86354 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
86355 @@ -437,7 +436,7 @@ struct xfrm_mode {
86356 struct module *owner;
86357 unsigned int encap;
86358 int flags;
86359 -};
86360 +} __do_const;
86361
86362 /* Flags for xfrm_mode. */
86363 enum {
86364 @@ -534,7 +533,7 @@ struct xfrm_policy {
86365 struct timer_list timer;
86366
86367 struct flow_cache_object flo;
86368 - atomic_t genid;
86369 + atomic_unchecked_t genid;
86370 u32 priority;
86371 u32 index;
86372 struct xfrm_mark mark;
86373 @@ -1167,6 +1166,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
86374 }
86375
86376 void xfrm_garbage_collect(struct net *net);
86377 +void xfrm_garbage_collect_deferred(struct net *net);
86378
86379 #else
86380
86381 @@ -1205,6 +1205,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
86382 static inline void xfrm_garbage_collect(struct net *net)
86383 {
86384 }
86385 +static inline void xfrm_garbage_collect_deferred(struct net *net)
86386 +{
86387 +}
86388 #endif
86389
86390 static __inline__
86391 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
86392 index 1017e0b..227aa4d 100644
86393 --- a/include/rdma/iw_cm.h
86394 +++ b/include/rdma/iw_cm.h
86395 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
86396 int backlog);
86397
86398 int (*destroy_listen)(struct iw_cm_id *cm_id);
86399 -};
86400 +} __no_const;
86401
86402 /**
86403 * iw_create_cm_id - Create an IW CM identifier.
86404 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
86405 index 52beadf..598734c 100644
86406 --- a/include/scsi/libfc.h
86407 +++ b/include/scsi/libfc.h
86408 @@ -771,6 +771,7 @@ struct libfc_function_template {
86409 */
86410 void (*disc_stop_final) (struct fc_lport *);
86411 };
86412 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
86413
86414 /**
86415 * struct fc_disc - Discovery context
86416 @@ -875,7 +876,7 @@ struct fc_lport {
86417 struct fc_vport *vport;
86418
86419 /* Operational Information */
86420 - struct libfc_function_template tt;
86421 + libfc_function_template_no_const tt;
86422 u8 link_up;
86423 u8 qfull;
86424 enum fc_lport_state state;
86425 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
86426 index 27ecee7..5f42632 100644
86427 --- a/include/scsi/scsi_device.h
86428 +++ b/include/scsi/scsi_device.h
86429 @@ -186,9 +186,9 @@ struct scsi_device {
86430 unsigned int max_device_blocked; /* what device_blocked counts down from */
86431 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
86432
86433 - atomic_t iorequest_cnt;
86434 - atomic_t iodone_cnt;
86435 - atomic_t ioerr_cnt;
86436 + atomic_unchecked_t iorequest_cnt;
86437 + atomic_unchecked_t iodone_cnt;
86438 + atomic_unchecked_t ioerr_cnt;
86439
86440 struct device sdev_gendev,
86441 sdev_dev;
86442 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
86443 index 007a0bc..7188db8 100644
86444 --- a/include/scsi/scsi_transport_fc.h
86445 +++ b/include/scsi/scsi_transport_fc.h
86446 @@ -756,7 +756,8 @@ struct fc_function_template {
86447 unsigned long show_host_system_hostname:1;
86448
86449 unsigned long disable_target_scan:1;
86450 -};
86451 +} __do_const;
86452 +typedef struct fc_function_template __no_const fc_function_template_no_const;
86453
86454
86455 /**
86456 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
86457 index ae6c3b8..fd748ac 100644
86458 --- a/include/sound/compress_driver.h
86459 +++ b/include/sound/compress_driver.h
86460 @@ -128,7 +128,7 @@ struct snd_compr_ops {
86461 struct snd_compr_caps *caps);
86462 int (*get_codec_caps) (struct snd_compr_stream *stream,
86463 struct snd_compr_codec_caps *codec);
86464 -};
86465 +} __no_const;
86466
86467 /**
86468 * struct snd_compr: Compressed device
86469 diff --git a/include/sound/soc.h b/include/sound/soc.h
86470 index 7ba7130..d46594d 100644
86471 --- a/include/sound/soc.h
86472 +++ b/include/sound/soc.h
86473 @@ -853,7 +853,7 @@ struct snd_soc_codec_driver {
86474 enum snd_soc_dapm_type, int);
86475
86476 bool ignore_pmdown_time; /* Doesn't benefit from pmdown delay */
86477 -};
86478 +} __do_const;
86479
86480 /* SoC platform interface */
86481 struct snd_soc_platform_driver {
86482 @@ -882,7 +882,7 @@ struct snd_soc_platform_driver {
86483 const struct snd_compr_ops *compr_ops;
86484
86485 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
86486 -};
86487 +} __do_const;
86488
86489 struct snd_soc_dai_link_component {
86490 const char *name;
86491 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
86492 index 23c518a..d6ef510 100644
86493 --- a/include/target/target_core_base.h
86494 +++ b/include/target/target_core_base.h
86495 @@ -764,7 +764,7 @@ struct se_device {
86496 atomic_long_t write_bytes;
86497 /* Active commands on this virtual SE device */
86498 atomic_t simple_cmds;
86499 - atomic_t dev_ordered_id;
86500 + atomic_unchecked_t dev_ordered_id;
86501 atomic_t dev_ordered_sync;
86502 atomic_t dev_qf_count;
86503 int export_count;
86504 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
86505 new file mode 100644
86506 index 0000000..fb634b7
86507 --- /dev/null
86508 +++ b/include/trace/events/fs.h
86509 @@ -0,0 +1,53 @@
86510 +#undef TRACE_SYSTEM
86511 +#define TRACE_SYSTEM fs
86512 +
86513 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
86514 +#define _TRACE_FS_H
86515 +
86516 +#include <linux/fs.h>
86517 +#include <linux/tracepoint.h>
86518 +
86519 +TRACE_EVENT(do_sys_open,
86520 +
86521 + TP_PROTO(const char *filename, int flags, int mode),
86522 +
86523 + TP_ARGS(filename, flags, mode),
86524 +
86525 + TP_STRUCT__entry(
86526 + __string( filename, filename )
86527 + __field( int, flags )
86528 + __field( int, mode )
86529 + ),
86530 +
86531 + TP_fast_assign(
86532 + __assign_str(filename, filename);
86533 + __entry->flags = flags;
86534 + __entry->mode = mode;
86535 + ),
86536 +
86537 + TP_printk("\"%s\" %x %o",
86538 + __get_str(filename), __entry->flags, __entry->mode)
86539 +);
86540 +
86541 +TRACE_EVENT(open_exec,
86542 +
86543 + TP_PROTO(const char *filename),
86544 +
86545 + TP_ARGS(filename),
86546 +
86547 + TP_STRUCT__entry(
86548 + __string( filename, filename )
86549 + ),
86550 +
86551 + TP_fast_assign(
86552 + __assign_str(filename, filename);
86553 + ),
86554 +
86555 + TP_printk("\"%s\"",
86556 + __get_str(filename))
86557 +);
86558 +
86559 +#endif /* _TRACE_FS_H */
86560 +
86561 +/* This part must be outside protection */
86562 +#include <trace/define_trace.h>
86563 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
86564 index 3608beb..df39d8a 100644
86565 --- a/include/trace/events/irq.h
86566 +++ b/include/trace/events/irq.h
86567 @@ -36,7 +36,7 @@ struct softirq_action;
86568 */
86569 TRACE_EVENT(irq_handler_entry,
86570
86571 - TP_PROTO(int irq, struct irqaction *action),
86572 + TP_PROTO(int irq, const struct irqaction *action),
86573
86574 TP_ARGS(irq, action),
86575
86576 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
86577 */
86578 TRACE_EVENT(irq_handler_exit,
86579
86580 - TP_PROTO(int irq, struct irqaction *action, int ret),
86581 + TP_PROTO(int irq, const struct irqaction *action, int ret),
86582
86583 TP_ARGS(irq, action, ret),
86584
86585 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
86586 index 7caf44c..23c6f27 100644
86587 --- a/include/uapi/linux/a.out.h
86588 +++ b/include/uapi/linux/a.out.h
86589 @@ -39,6 +39,14 @@ enum machine_type {
86590 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
86591 };
86592
86593 +/* Constants for the N_FLAGS field */
86594 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
86595 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
86596 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
86597 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
86598 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
86599 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
86600 +
86601 #if !defined (N_MAGIC)
86602 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
86603 #endif
86604 diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
86605 index 22b6ad3..aeba37e 100644
86606 --- a/include/uapi/linux/bcache.h
86607 +++ b/include/uapi/linux/bcache.h
86608 @@ -5,6 +5,7 @@
86609 * Bcache on disk data structures
86610 */
86611
86612 +#include <linux/compiler.h>
86613 #include <asm/types.h>
86614
86615 #define BITMASK(name, type, field, offset, size) \
86616 @@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
86617 /* Btree keys - all units are in sectors */
86618
86619 struct bkey {
86620 - __u64 high;
86621 - __u64 low;
86622 + __u64 high __intentional_overflow(-1);
86623 + __u64 low __intentional_overflow(-1);
86624 __u64 ptr[];
86625 };
86626
86627 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
86628 index d876736..ccce5c0 100644
86629 --- a/include/uapi/linux/byteorder/little_endian.h
86630 +++ b/include/uapi/linux/byteorder/little_endian.h
86631 @@ -42,51 +42,51 @@
86632
86633 static inline __le64 __cpu_to_le64p(const __u64 *p)
86634 {
86635 - return (__force __le64)*p;
86636 + return (__force const __le64)*p;
86637 }
86638 -static inline __u64 __le64_to_cpup(const __le64 *p)
86639 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
86640 {
86641 - return (__force __u64)*p;
86642 + return (__force const __u64)*p;
86643 }
86644 static inline __le32 __cpu_to_le32p(const __u32 *p)
86645 {
86646 - return (__force __le32)*p;
86647 + return (__force const __le32)*p;
86648 }
86649 static inline __u32 __le32_to_cpup(const __le32 *p)
86650 {
86651 - return (__force __u32)*p;
86652 + return (__force const __u32)*p;
86653 }
86654 static inline __le16 __cpu_to_le16p(const __u16 *p)
86655 {
86656 - return (__force __le16)*p;
86657 + return (__force const __le16)*p;
86658 }
86659 static inline __u16 __le16_to_cpup(const __le16 *p)
86660 {
86661 - return (__force __u16)*p;
86662 + return (__force const __u16)*p;
86663 }
86664 static inline __be64 __cpu_to_be64p(const __u64 *p)
86665 {
86666 - return (__force __be64)__swab64p(p);
86667 + return (__force const __be64)__swab64p(p);
86668 }
86669 static inline __u64 __be64_to_cpup(const __be64 *p)
86670 {
86671 - return __swab64p((__u64 *)p);
86672 + return __swab64p((const __u64 *)p);
86673 }
86674 static inline __be32 __cpu_to_be32p(const __u32 *p)
86675 {
86676 - return (__force __be32)__swab32p(p);
86677 + return (__force const __be32)__swab32p(p);
86678 }
86679 -static inline __u32 __be32_to_cpup(const __be32 *p)
86680 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
86681 {
86682 - return __swab32p((__u32 *)p);
86683 + return __swab32p((const __u32 *)p);
86684 }
86685 static inline __be16 __cpu_to_be16p(const __u16 *p)
86686 {
86687 - return (__force __be16)__swab16p(p);
86688 + return (__force const __be16)__swab16p(p);
86689 }
86690 static inline __u16 __be16_to_cpup(const __be16 *p)
86691 {
86692 - return __swab16p((__u16 *)p);
86693 + return __swab16p((const __u16 *)p);
86694 }
86695 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
86696 #define __le64_to_cpus(x) do { (void)(x); } while (0)
86697 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
86698 index ea9bf25..5140c61 100644
86699 --- a/include/uapi/linux/elf.h
86700 +++ b/include/uapi/linux/elf.h
86701 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
86702 #define PT_GNU_EH_FRAME 0x6474e550
86703
86704 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
86705 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
86706 +
86707 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
86708 +
86709 +/* Constants for the e_flags field */
86710 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
86711 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
86712 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
86713 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
86714 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
86715 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
86716
86717 /*
86718 * Extended Numbering
86719 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
86720 #define DT_DEBUG 21
86721 #define DT_TEXTREL 22
86722 #define DT_JMPREL 23
86723 +#define DT_FLAGS 30
86724 + #define DF_TEXTREL 0x00000004
86725 #define DT_ENCODING 32
86726 #define OLD_DT_LOOS 0x60000000
86727 #define DT_LOOS 0x6000000d
86728 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
86729 #define PF_W 0x2
86730 #define PF_X 0x1
86731
86732 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
86733 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
86734 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
86735 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
86736 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
86737 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
86738 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
86739 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
86740 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
86741 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
86742 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
86743 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
86744 +
86745 typedef struct elf32_phdr{
86746 Elf32_Word p_type;
86747 Elf32_Off p_offset;
86748 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
86749 #define EI_OSABI 7
86750 #define EI_PAD 8
86751
86752 +#define EI_PAX 14
86753 +
86754 #define ELFMAG0 0x7f /* EI_MAG */
86755 #define ELFMAG1 'E'
86756 #define ELFMAG2 'L'
86757 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
86758 index aa169c4..6a2771d 100644
86759 --- a/include/uapi/linux/personality.h
86760 +++ b/include/uapi/linux/personality.h
86761 @@ -30,6 +30,7 @@ enum {
86762 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
86763 ADDR_NO_RANDOMIZE | \
86764 ADDR_COMPAT_LAYOUT | \
86765 + ADDR_LIMIT_3GB | \
86766 MMAP_PAGE_ZERO)
86767
86768 /*
86769 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
86770 index 7530e74..e714828 100644
86771 --- a/include/uapi/linux/screen_info.h
86772 +++ b/include/uapi/linux/screen_info.h
86773 @@ -43,7 +43,8 @@ struct screen_info {
86774 __u16 pages; /* 0x32 */
86775 __u16 vesa_attributes; /* 0x34 */
86776 __u32 capabilities; /* 0x36 */
86777 - __u8 _reserved[6]; /* 0x3a */
86778 + __u16 vesapm_size; /* 0x3a */
86779 + __u8 _reserved[4]; /* 0x3c */
86780 } __attribute__((packed));
86781
86782 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
86783 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
86784 index 0e011eb..82681b1 100644
86785 --- a/include/uapi/linux/swab.h
86786 +++ b/include/uapi/linux/swab.h
86787 @@ -43,7 +43,7 @@
86788 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
86789 */
86790
86791 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
86792 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
86793 {
86794 #ifdef __HAVE_BUILTIN_BSWAP16__
86795 return __builtin_bswap16(val);
86796 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
86797 #endif
86798 }
86799
86800 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
86801 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
86802 {
86803 #ifdef __HAVE_BUILTIN_BSWAP32__
86804 return __builtin_bswap32(val);
86805 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
86806 #endif
86807 }
86808
86809 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
86810 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
86811 {
86812 #ifdef __HAVE_BUILTIN_BSWAP64__
86813 return __builtin_bswap64(val);
86814 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
86815 index 43aaba1..1c30b48 100644
86816 --- a/include/uapi/linux/sysctl.h
86817 +++ b/include/uapi/linux/sysctl.h
86818 @@ -155,8 +155,6 @@ enum
86819 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
86820 };
86821
86822 -
86823 -
86824 /* CTL_VM names: */
86825 enum
86826 {
86827 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
86828 index 1590c49..5eab462 100644
86829 --- a/include/uapi/linux/xattr.h
86830 +++ b/include/uapi/linux/xattr.h
86831 @@ -73,5 +73,9 @@
86832 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
86833 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
86834
86835 +/* User namespace */
86836 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
86837 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
86838 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
86839
86840 #endif /* _UAPI_LINUX_XATTR_H */
86841 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
86842 index f9466fa..f4e2b81 100644
86843 --- a/include/video/udlfb.h
86844 +++ b/include/video/udlfb.h
86845 @@ -53,10 +53,10 @@ struct dlfb_data {
86846 u32 pseudo_palette[256];
86847 int blank_mode; /*one of FB_BLANK_ */
86848 /* blit-only rendering path metrics, exposed through sysfs */
86849 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
86850 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
86851 - atomic_t bytes_sent; /* to usb, after compression including overhead */
86852 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
86853 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
86854 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
86855 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
86856 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
86857 };
86858
86859 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
86860 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
86861 index 30f5362..8ed8ac9 100644
86862 --- a/include/video/uvesafb.h
86863 +++ b/include/video/uvesafb.h
86864 @@ -122,6 +122,7 @@ struct uvesafb_par {
86865 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
86866 u8 pmi_setpal; /* PMI for palette changes */
86867 u16 *pmi_base; /* protected mode interface location */
86868 + u8 *pmi_code; /* protected mode code location */
86869 void *pmi_start;
86870 void *pmi_pal;
86871 u8 *vbe_state_orig; /*
86872 diff --git a/init/Kconfig b/init/Kconfig
86873 index 2081a4d..98d1149 100644
86874 --- a/init/Kconfig
86875 +++ b/init/Kconfig
86876 @@ -1150,6 +1150,7 @@ endif # CGROUPS
86877
86878 config CHECKPOINT_RESTORE
86879 bool "Checkpoint/restore support" if EXPERT
86880 + depends on !GRKERNSEC
86881 default n
86882 help
86883 Enables additional kernel features in a sake of checkpoint/restore.
86884 @@ -1659,7 +1660,7 @@ config SLUB_DEBUG
86885
86886 config COMPAT_BRK
86887 bool "Disable heap randomization"
86888 - default y
86889 + default n
86890 help
86891 Randomizing heap placement makes heap exploits harder, but it
86892 also breaks ancient binaries (including anything libc5 based).
86893 @@ -1990,7 +1991,7 @@ config INIT_ALL_POSSIBLE
86894 config STOP_MACHINE
86895 bool
86896 default y
86897 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
86898 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
86899 help
86900 Need stop_machine() primitive.
86901
86902 diff --git a/init/Makefile b/init/Makefile
86903 index 7bc47ee..6da2dc7 100644
86904 --- a/init/Makefile
86905 +++ b/init/Makefile
86906 @@ -2,6 +2,9 @@
86907 # Makefile for the linux kernel.
86908 #
86909
86910 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
86911 +asflags-y := $(GCC_PLUGINS_AFLAGS)
86912 +
86913 obj-y := main.o version.o mounts.o
86914 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
86915 obj-y += noinitramfs.o
86916 diff --git a/init/do_mounts.c b/init/do_mounts.c
86917 index 9b3565c..3f90cf9 100644
86918 --- a/init/do_mounts.c
86919 +++ b/init/do_mounts.c
86920 @@ -360,11 +360,11 @@ static void __init get_fs_names(char *page)
86921 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
86922 {
86923 struct super_block *s;
86924 - int err = sys_mount(name, "/root", fs, flags, data);
86925 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
86926 if (err)
86927 return err;
86928
86929 - sys_chdir("/root");
86930 + sys_chdir((const char __force_user *)"/root");
86931 s = current->fs->pwd.dentry->d_sb;
86932 ROOT_DEV = s->s_dev;
86933 printk(KERN_INFO
86934 @@ -485,18 +485,18 @@ void __init change_floppy(char *fmt, ...)
86935 va_start(args, fmt);
86936 vsprintf(buf, fmt, args);
86937 va_end(args);
86938 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
86939 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
86940 if (fd >= 0) {
86941 sys_ioctl(fd, FDEJECT, 0);
86942 sys_close(fd);
86943 }
86944 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
86945 - fd = sys_open("/dev/console", O_RDWR, 0);
86946 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
86947 if (fd >= 0) {
86948 sys_ioctl(fd, TCGETS, (long)&termios);
86949 termios.c_lflag &= ~ICANON;
86950 sys_ioctl(fd, TCSETSF, (long)&termios);
86951 - sys_read(fd, &c, 1);
86952 + sys_read(fd, (char __user *)&c, 1);
86953 termios.c_lflag |= ICANON;
86954 sys_ioctl(fd, TCSETSF, (long)&termios);
86955 sys_close(fd);
86956 @@ -590,8 +590,8 @@ void __init prepare_namespace(void)
86957 mount_root();
86958 out:
86959 devtmpfs_mount("dev");
86960 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
86961 - sys_chroot(".");
86962 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
86963 + sys_chroot((const char __force_user *)".");
86964 }
86965
86966 static bool is_tmpfs;
86967 diff --git a/init/do_mounts.h b/init/do_mounts.h
86968 index f5b978a..69dbfe8 100644
86969 --- a/init/do_mounts.h
86970 +++ b/init/do_mounts.h
86971 @@ -15,15 +15,15 @@ extern int root_mountflags;
86972
86973 static inline int create_dev(char *name, dev_t dev)
86974 {
86975 - sys_unlink(name);
86976 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
86977 + sys_unlink((char __force_user *)name);
86978 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
86979 }
86980
86981 #if BITS_PER_LONG == 32
86982 static inline u32 bstat(char *name)
86983 {
86984 struct stat64 stat;
86985 - if (sys_stat64(name, &stat) != 0)
86986 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
86987 return 0;
86988 if (!S_ISBLK(stat.st_mode))
86989 return 0;
86990 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
86991 static inline u32 bstat(char *name)
86992 {
86993 struct stat stat;
86994 - if (sys_newstat(name, &stat) != 0)
86995 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
86996 return 0;
86997 if (!S_ISBLK(stat.st_mode))
86998 return 0;
86999 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
87000 index 3e0878e..8a9d7a0 100644
87001 --- a/init/do_mounts_initrd.c
87002 +++ b/init/do_mounts_initrd.c
87003 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
87004 {
87005 sys_unshare(CLONE_FS | CLONE_FILES);
87006 /* stdin/stdout/stderr for /linuxrc */
87007 - sys_open("/dev/console", O_RDWR, 0);
87008 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
87009 sys_dup(0);
87010 sys_dup(0);
87011 /* move initrd over / and chdir/chroot in initrd root */
87012 - sys_chdir("/root");
87013 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
87014 - sys_chroot(".");
87015 + sys_chdir((const char __force_user *)"/root");
87016 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
87017 + sys_chroot((const char __force_user *)".");
87018 sys_setsid();
87019 return 0;
87020 }
87021 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
87022 create_dev("/dev/root.old", Root_RAM0);
87023 /* mount initrd on rootfs' /root */
87024 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
87025 - sys_mkdir("/old", 0700);
87026 - sys_chdir("/old");
87027 + sys_mkdir((const char __force_user *)"/old", 0700);
87028 + sys_chdir((const char __force_user *)"/old");
87029
87030 /* try loading default modules from initrd */
87031 load_default_modules();
87032 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
87033 current->flags &= ~PF_FREEZER_SKIP;
87034
87035 /* move initrd to rootfs' /old */
87036 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
87037 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
87038 /* switch root and cwd back to / of rootfs */
87039 - sys_chroot("..");
87040 + sys_chroot((const char __force_user *)"..");
87041
87042 if (new_decode_dev(real_root_dev) == Root_RAM0) {
87043 - sys_chdir("/old");
87044 + sys_chdir((const char __force_user *)"/old");
87045 return;
87046 }
87047
87048 - sys_chdir("/");
87049 + sys_chdir((const char __force_user *)"/");
87050 ROOT_DEV = new_decode_dev(real_root_dev);
87051 mount_root();
87052
87053 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
87054 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
87055 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
87056 if (!error)
87057 printk("okay\n");
87058 else {
87059 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
87060 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
87061 if (error == -ENOENT)
87062 printk("/initrd does not exist. Ignored.\n");
87063 else
87064 printk("failed\n");
87065 printk(KERN_NOTICE "Unmounting old root\n");
87066 - sys_umount("/old", MNT_DETACH);
87067 + sys_umount((char __force_user *)"/old", MNT_DETACH);
87068 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
87069 if (fd < 0) {
87070 error = fd;
87071 @@ -127,11 +127,11 @@ int __init initrd_load(void)
87072 * mounted in the normal path.
87073 */
87074 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
87075 - sys_unlink("/initrd.image");
87076 + sys_unlink((const char __force_user *)"/initrd.image");
87077 handle_initrd();
87078 return 1;
87079 }
87080 }
87081 - sys_unlink("/initrd.image");
87082 + sys_unlink((const char __force_user *)"/initrd.image");
87083 return 0;
87084 }
87085 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
87086 index 8cb6db5..d729f50 100644
87087 --- a/init/do_mounts_md.c
87088 +++ b/init/do_mounts_md.c
87089 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
87090 partitioned ? "_d" : "", minor,
87091 md_setup_args[ent].device_names);
87092
87093 - fd = sys_open(name, 0, 0);
87094 + fd = sys_open((char __force_user *)name, 0, 0);
87095 if (fd < 0) {
87096 printk(KERN_ERR "md: open failed - cannot start "
87097 "array %s\n", name);
87098 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
87099 * array without it
87100 */
87101 sys_close(fd);
87102 - fd = sys_open(name, 0, 0);
87103 + fd = sys_open((char __force_user *)name, 0, 0);
87104 sys_ioctl(fd, BLKRRPART, 0);
87105 }
87106 sys_close(fd);
87107 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
87108
87109 wait_for_device_probe();
87110
87111 - fd = sys_open("/dev/md0", 0, 0);
87112 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
87113 if (fd >= 0) {
87114 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
87115 sys_close(fd);
87116 diff --git a/init/init_task.c b/init/init_task.c
87117 index ba0a7f36..2bcf1d5 100644
87118 --- a/init/init_task.c
87119 +++ b/init/init_task.c
87120 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
87121 * Initial thread structure. Alignment of this is handled by a special
87122 * linker map entry.
87123 */
87124 +#ifdef CONFIG_X86
87125 +union thread_union init_thread_union __init_task_data;
87126 +#else
87127 union thread_union init_thread_union __init_task_data =
87128 { INIT_THREAD_INFO(init_task) };
87129 +#endif
87130 diff --git a/init/initramfs.c b/init/initramfs.c
87131 index ad1bd77..dca2c1b 100644
87132 --- a/init/initramfs.c
87133 +++ b/init/initramfs.c
87134 @@ -25,7 +25,7 @@ static ssize_t __init xwrite(int fd, const char *p, size_t count)
87135
87136 /* sys_write only can write MAX_RW_COUNT aka 2G-4K bytes at most */
87137 while (count) {
87138 - ssize_t rv = sys_write(fd, p, count);
87139 + ssize_t rv = sys_write(fd, (char __force_user *)p, count);
87140
87141 if (rv < 0) {
87142 if (rv == -EINTR || rv == -EAGAIN)
87143 @@ -107,7 +107,7 @@ static void __init free_hash(void)
87144 }
87145 }
87146
87147 -static long __init do_utime(char *filename, time_t mtime)
87148 +static long __init do_utime(char __force_user *filename, time_t mtime)
87149 {
87150 struct timespec t[2];
87151
87152 @@ -142,7 +142,7 @@ static void __init dir_utime(void)
87153 struct dir_entry *de, *tmp;
87154 list_for_each_entry_safe(de, tmp, &dir_list, list) {
87155 list_del(&de->list);
87156 - do_utime(de->name, de->mtime);
87157 + do_utime((char __force_user *)de->name, de->mtime);
87158 kfree(de->name);
87159 kfree(de);
87160 }
87161 @@ -304,7 +304,7 @@ static int __init maybe_link(void)
87162 if (nlink >= 2) {
87163 char *old = find_link(major, minor, ino, mode, collected);
87164 if (old)
87165 - return (sys_link(old, collected) < 0) ? -1 : 1;
87166 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
87167 }
87168 return 0;
87169 }
87170 @@ -313,11 +313,11 @@ static void __init clean_path(char *path, umode_t fmode)
87171 {
87172 struct stat st;
87173
87174 - if (!sys_newlstat(path, &st) && (st.st_mode ^ fmode) & S_IFMT) {
87175 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode ^ fmode) & S_IFMT) {
87176 if (S_ISDIR(st.st_mode))
87177 - sys_rmdir(path);
87178 + sys_rmdir((char __force_user *)path);
87179 else
87180 - sys_unlink(path);
87181 + sys_unlink((char __force_user *)path);
87182 }
87183 }
87184
87185 @@ -338,7 +338,7 @@ static int __init do_name(void)
87186 int openflags = O_WRONLY|O_CREAT;
87187 if (ml != 1)
87188 openflags |= O_TRUNC;
87189 - wfd = sys_open(collected, openflags, mode);
87190 + wfd = sys_open((char __force_user *)collected, openflags, mode);
87191
87192 if (wfd >= 0) {
87193 sys_fchown(wfd, uid, gid);
87194 @@ -350,17 +350,17 @@ static int __init do_name(void)
87195 }
87196 }
87197 } else if (S_ISDIR(mode)) {
87198 - sys_mkdir(collected, mode);
87199 - sys_chown(collected, uid, gid);
87200 - sys_chmod(collected, mode);
87201 + sys_mkdir((char __force_user *)collected, mode);
87202 + sys_chown((char __force_user *)collected, uid, gid);
87203 + sys_chmod((char __force_user *)collected, mode);
87204 dir_add(collected, mtime);
87205 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
87206 S_ISFIFO(mode) || S_ISSOCK(mode)) {
87207 if (maybe_link() == 0) {
87208 - sys_mknod(collected, mode, rdev);
87209 - sys_chown(collected, uid, gid);
87210 - sys_chmod(collected, mode);
87211 - do_utime(collected, mtime);
87212 + sys_mknod((char __force_user *)collected, mode, rdev);
87213 + sys_chown((char __force_user *)collected, uid, gid);
87214 + sys_chmod((char __force_user *)collected, mode);
87215 + do_utime((char __force_user *)collected, mtime);
87216 }
87217 }
87218 return 0;
87219 @@ -372,7 +372,7 @@ static int __init do_copy(void)
87220 if (xwrite(wfd, victim, body_len) != body_len)
87221 error("write error");
87222 sys_close(wfd);
87223 - do_utime(vcollected, mtime);
87224 + do_utime((char __force_user *)vcollected, mtime);
87225 kfree(vcollected);
87226 eat(body_len);
87227 state = SkipIt;
87228 @@ -390,9 +390,9 @@ static int __init do_symlink(void)
87229 {
87230 collected[N_ALIGN(name_len) + body_len] = '\0';
87231 clean_path(collected, 0);
87232 - sys_symlink(collected + N_ALIGN(name_len), collected);
87233 - sys_lchown(collected, uid, gid);
87234 - do_utime(collected, mtime);
87235 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
87236 + sys_lchown((char __force_user *)collected, uid, gid);
87237 + do_utime((char __force_user *)collected, mtime);
87238 state = SkipIt;
87239 next_state = Reset;
87240 return 0;
87241 diff --git a/init/main.c b/init/main.c
87242 index 321d0ce..91b53e5 100644
87243 --- a/init/main.c
87244 +++ b/init/main.c
87245 @@ -98,6 +98,8 @@ extern void radix_tree_init(void);
87246 static inline void mark_rodata_ro(void) { }
87247 #endif
87248
87249 +extern void grsecurity_init(void);
87250 +
87251 /*
87252 * Debug helper: via this flag we know that we are in 'early bootup code'
87253 * where only the boot processor is running with IRQ disabled. This means
87254 @@ -159,6 +161,75 @@ static int __init set_reset_devices(char *str)
87255
87256 __setup("reset_devices", set_reset_devices);
87257
87258 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
87259 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
87260 +static int __init setup_grsec_proc_gid(char *str)
87261 +{
87262 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
87263 + return 1;
87264 +}
87265 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
87266 +#endif
87267 +
87268 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
87269 +unsigned long pax_user_shadow_base __read_only;
87270 +EXPORT_SYMBOL(pax_user_shadow_base);
87271 +extern char pax_enter_kernel_user[];
87272 +extern char pax_exit_kernel_user[];
87273 +#endif
87274 +
87275 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
87276 +static int __init setup_pax_nouderef(char *str)
87277 +{
87278 +#ifdef CONFIG_X86_32
87279 + unsigned int cpu;
87280 + struct desc_struct *gdt;
87281 +
87282 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
87283 + gdt = get_cpu_gdt_table(cpu);
87284 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
87285 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
87286 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
87287 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
87288 + }
87289 + loadsegment(ds, __KERNEL_DS);
87290 + loadsegment(es, __KERNEL_DS);
87291 + loadsegment(ss, __KERNEL_DS);
87292 +#else
87293 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
87294 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
87295 + clone_pgd_mask = ~(pgdval_t)0UL;
87296 + pax_user_shadow_base = 0UL;
87297 + setup_clear_cpu_cap(X86_FEATURE_PCID);
87298 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
87299 +#endif
87300 +
87301 + return 0;
87302 +}
87303 +early_param("pax_nouderef", setup_pax_nouderef);
87304 +
87305 +#ifdef CONFIG_X86_64
87306 +static int __init setup_pax_weakuderef(char *str)
87307 +{
87308 + if (clone_pgd_mask != ~(pgdval_t)0UL)
87309 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
87310 + return 1;
87311 +}
87312 +__setup("pax_weakuderef", setup_pax_weakuderef);
87313 +#endif
87314 +#endif
87315 +
87316 +#ifdef CONFIG_PAX_SOFTMODE
87317 +int pax_softmode;
87318 +
87319 +static int __init setup_pax_softmode(char *str)
87320 +{
87321 + get_option(&str, &pax_softmode);
87322 + return 1;
87323 +}
87324 +__setup("pax_softmode=", setup_pax_softmode);
87325 +#endif
87326 +
87327 static const char *argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
87328 const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
87329 static const char *panic_later, *panic_param;
87330 @@ -728,7 +799,7 @@ static bool __init_or_module initcall_blacklisted(initcall_t fn)
87331 struct blacklist_entry *entry;
87332 char *fn_name;
87333
87334 - fn_name = kasprintf(GFP_KERNEL, "%pf", fn);
87335 + fn_name = kasprintf(GFP_KERNEL, "%pX", fn);
87336 if (!fn_name)
87337 return false;
87338
87339 @@ -780,7 +851,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
87340 {
87341 int count = preempt_count();
87342 int ret;
87343 - char msgbuf[64];
87344 + const char *msg1 = "", *msg2 = "";
87345
87346 if (initcall_blacklisted(fn))
87347 return -EPERM;
87348 @@ -790,18 +861,17 @@ int __init_or_module do_one_initcall(initcall_t fn)
87349 else
87350 ret = fn();
87351
87352 - msgbuf[0] = 0;
87353 -
87354 if (preempt_count() != count) {
87355 - sprintf(msgbuf, "preemption imbalance ");
87356 + msg1 = " preemption imbalance";
87357 preempt_count_set(count);
87358 }
87359 if (irqs_disabled()) {
87360 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
87361 + msg2 = " disabled interrupts";
87362 local_irq_enable();
87363 }
87364 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
87365 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
87366
87367 + add_latent_entropy();
87368 return ret;
87369 }
87370
87371 @@ -907,8 +977,8 @@ static int run_init_process(const char *init_filename)
87372 {
87373 argv_init[0] = init_filename;
87374 return do_execve(getname_kernel(init_filename),
87375 - (const char __user *const __user *)argv_init,
87376 - (const char __user *const __user *)envp_init);
87377 + (const char __user *const __force_user *)argv_init,
87378 + (const char __user *const __force_user *)envp_init);
87379 }
87380
87381 static int try_to_run_init_process(const char *init_filename)
87382 @@ -925,6 +995,10 @@ static int try_to_run_init_process(const char *init_filename)
87383 return ret;
87384 }
87385
87386 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
87387 +extern int gr_init_ran;
87388 +#endif
87389 +
87390 static noinline void __init kernel_init_freeable(void);
87391
87392 static int __ref kernel_init(void *unused)
87393 @@ -949,6 +1023,11 @@ static int __ref kernel_init(void *unused)
87394 ramdisk_execute_command, ret);
87395 }
87396
87397 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
87398 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
87399 + gr_init_ran = 1;
87400 +#endif
87401 +
87402 /*
87403 * We try each of these until one succeeds.
87404 *
87405 @@ -1004,7 +1083,7 @@ static noinline void __init kernel_init_freeable(void)
87406 do_basic_setup();
87407
87408 /* Open the /dev/console on the rootfs, this should never fail */
87409 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
87410 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
87411 pr_err("Warning: unable to open an initial console.\n");
87412
87413 (void) sys_dup(0);
87414 @@ -1017,11 +1096,13 @@ static noinline void __init kernel_init_freeable(void)
87415 if (!ramdisk_execute_command)
87416 ramdisk_execute_command = "/init";
87417
87418 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
87419 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
87420 ramdisk_execute_command = NULL;
87421 prepare_namespace();
87422 }
87423
87424 + grsecurity_init();
87425 +
87426 /*
87427 * Ok, we have completed the initial bootup, and
87428 * we're essentially up and running. Get rid of the
87429 diff --git a/ipc/compat.c b/ipc/compat.c
87430 index 9b3c85f..1c4d897 100644
87431 --- a/ipc/compat.c
87432 +++ b/ipc/compat.c
87433 @@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
87434 COMPAT_SHMLBA);
87435 if (err < 0)
87436 return err;
87437 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
87438 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
87439 }
87440 case SHMDT:
87441 return sys_shmdt(compat_ptr(ptr));
87442 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
87443 index e8075b2..76f2c6a 100644
87444 --- a/ipc/ipc_sysctl.c
87445 +++ b/ipc/ipc_sysctl.c
87446 @@ -30,7 +30,7 @@ static void *get_ipc(struct ctl_table *table)
87447 static int proc_ipc_dointvec(struct ctl_table *table, int write,
87448 void __user *buffer, size_t *lenp, loff_t *ppos)
87449 {
87450 - struct ctl_table ipc_table;
87451 + ctl_table_no_const ipc_table;
87452
87453 memcpy(&ipc_table, table, sizeof(ipc_table));
87454 ipc_table.data = get_ipc(table);
87455 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(struct ctl_table *table, int write,
87456 static int proc_ipc_dointvec_minmax(struct ctl_table *table, int write,
87457 void __user *buffer, size_t *lenp, loff_t *ppos)
87458 {
87459 - struct ctl_table ipc_table;
87460 + ctl_table_no_const ipc_table;
87461
87462 memcpy(&ipc_table, table, sizeof(ipc_table));
87463 ipc_table.data = get_ipc(table);
87464 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(struct ctl_table *table, int write,
87465 static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
87466 void __user *buffer, size_t *lenp, loff_t *ppos)
87467 {
87468 - struct ctl_table ipc_table;
87469 + ctl_table_no_const ipc_table;
87470 size_t lenp_bef = *lenp;
87471 int rc;
87472
87473 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
87474 static int proc_ipc_doulongvec_minmax(struct ctl_table *table, int write,
87475 void __user *buffer, size_t *lenp, loff_t *ppos)
87476 {
87477 - struct ctl_table ipc_table;
87478 + ctl_table_no_const ipc_table;
87479 memcpy(&ipc_table, table, sizeof(ipc_table));
87480 ipc_table.data = get_ipc(table);
87481
87482 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
87483 static int proc_ipcauto_dointvec_minmax(struct ctl_table *table, int write,
87484 void __user *buffer, size_t *lenp, loff_t *ppos)
87485 {
87486 - struct ctl_table ipc_table;
87487 + ctl_table_no_const ipc_table;
87488 int oldval;
87489 int rc;
87490
87491 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
87492 index 68d4e95..1477ded 100644
87493 --- a/ipc/mq_sysctl.c
87494 +++ b/ipc/mq_sysctl.c
87495 @@ -25,7 +25,7 @@ static void *get_mq(struct ctl_table *table)
87496 static int proc_mq_dointvec(struct ctl_table *table, int write,
87497 void __user *buffer, size_t *lenp, loff_t *ppos)
87498 {
87499 - struct ctl_table mq_table;
87500 + ctl_table_no_const mq_table;
87501 memcpy(&mq_table, table, sizeof(mq_table));
87502 mq_table.data = get_mq(table);
87503
87504 @@ -35,7 +35,7 @@ static int proc_mq_dointvec(struct ctl_table *table, int write,
87505 static int proc_mq_dointvec_minmax(struct ctl_table *table, int write,
87506 void __user *buffer, size_t *lenp, loff_t *ppos)
87507 {
87508 - struct ctl_table mq_table;
87509 + ctl_table_no_const mq_table;
87510 memcpy(&mq_table, table, sizeof(mq_table));
87511 mq_table.data = get_mq(table);
87512
87513 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
87514 index 4fcf39a..d3cc2ec 100644
87515 --- a/ipc/mqueue.c
87516 +++ b/ipc/mqueue.c
87517 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
87518 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
87519 info->attr.mq_msgsize);
87520
87521 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
87522 spin_lock(&mq_lock);
87523 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
87524 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
87525 diff --git a/ipc/shm.c b/ipc/shm.c
87526 index 0145479..3d27947 100644
87527 --- a/ipc/shm.c
87528 +++ b/ipc/shm.c
87529 @@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
87530 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
87531 #endif
87532
87533 +#ifdef CONFIG_GRKERNSEC
87534 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
87535 + const u64 shm_createtime, const kuid_t cuid,
87536 + const int shmid);
87537 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
87538 + const u64 shm_createtime);
87539 +#endif
87540 +
87541 void shm_init_ns(struct ipc_namespace *ns)
87542 {
87543 ns->shm_ctlmax = SHMMAX;
87544 @@ -559,6 +567,9 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
87545 shp->shm_lprid = 0;
87546 shp->shm_atim = shp->shm_dtim = 0;
87547 shp->shm_ctim = get_seconds();
87548 +#ifdef CONFIG_GRKERNSEC
87549 + shp->shm_createtime = ktime_get_ns();
87550 +#endif
87551 shp->shm_segsz = size;
87552 shp->shm_nattch = 0;
87553 shp->shm_file = file;
87554 @@ -1095,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
87555 f_mode = FMODE_READ | FMODE_WRITE;
87556 }
87557 if (shmflg & SHM_EXEC) {
87558 +
87559 +#ifdef CONFIG_PAX_MPROTECT
87560 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
87561 + goto out;
87562 +#endif
87563 +
87564 prot |= PROT_EXEC;
87565 acc_mode |= S_IXUGO;
87566 }
87567 @@ -1119,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
87568 if (err)
87569 goto out_unlock;
87570
87571 +#ifdef CONFIG_GRKERNSEC
87572 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
87573 + shp->shm_perm.cuid, shmid) ||
87574 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
87575 + err = -EACCES;
87576 + goto out_unlock;
87577 + }
87578 +#endif
87579 +
87580 ipc_lock_object(&shp->shm_perm);
87581
87582 /* check if shm_destroy() is tearing down shp */
87583 @@ -1131,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
87584 path = shp->shm_file->f_path;
87585 path_get(&path);
87586 shp->shm_nattch++;
87587 +#ifdef CONFIG_GRKERNSEC
87588 + shp->shm_lapid = current->pid;
87589 +#endif
87590 size = i_size_read(path.dentry->d_inode);
87591 ipc_unlock_object(&shp->shm_perm);
87592 rcu_read_unlock();
87593 diff --git a/ipc/util.c b/ipc/util.c
87594 index 88adc32..3867c68 100644
87595 --- a/ipc/util.c
87596 +++ b/ipc/util.c
87597 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
87598 int (*show)(struct seq_file *, void *);
87599 };
87600
87601 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
87602 +
87603 static void ipc_memory_notifier(struct work_struct *work)
87604 {
87605 ipcns_notify(IPCNS_MEMCHANGED);
87606 @@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
87607 granted_mode >>= 6;
87608 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
87609 granted_mode >>= 3;
87610 +
87611 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
87612 + return -1;
87613 +
87614 /* is there some bit set in requested_mode but not in granted_mode? */
87615 if ((requested_mode & ~granted_mode & 0007) &&
87616 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
87617 diff --git a/kernel/audit.c b/kernel/audit.c
87618 index cebb11d..4e0295f 100644
87619 --- a/kernel/audit.c
87620 +++ b/kernel/audit.c
87621 @@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
87622 3) suppressed due to audit_rate_limit
87623 4) suppressed due to audit_backlog_limit
87624 */
87625 -static atomic_t audit_lost = ATOMIC_INIT(0);
87626 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
87627
87628 /* The netlink socket. */
87629 static struct sock *audit_sock;
87630 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
87631 unsigned long now;
87632 int print;
87633
87634 - atomic_inc(&audit_lost);
87635 + atomic_inc_unchecked(&audit_lost);
87636
87637 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
87638
87639 @@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
87640 if (print) {
87641 if (printk_ratelimit())
87642 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
87643 - atomic_read(&audit_lost),
87644 + atomic_read_unchecked(&audit_lost),
87645 audit_rate_limit,
87646 audit_backlog_limit);
87647 audit_panic(message);
87648 @@ -840,7 +840,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
87649 s.pid = audit_pid;
87650 s.rate_limit = audit_rate_limit;
87651 s.backlog_limit = audit_backlog_limit;
87652 - s.lost = atomic_read(&audit_lost);
87653 + s.lost = atomic_read_unchecked(&audit_lost);
87654 s.backlog = skb_queue_len(&audit_skb_queue);
87655 s.version = AUDIT_VERSION_LATEST;
87656 s.backlog_wait_time = audit_backlog_wait_time;
87657 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
87658 index e420a0c..38137fa 100644
87659 --- a/kernel/auditsc.c
87660 +++ b/kernel/auditsc.c
87661 @@ -2014,7 +2014,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
87662 }
87663
87664 /* global counter which is incremented every time something logs in */
87665 -static atomic_t session_id = ATOMIC_INIT(0);
87666 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
87667
87668 static int audit_set_loginuid_perm(kuid_t loginuid)
87669 {
87670 @@ -2081,7 +2081,7 @@ int audit_set_loginuid(kuid_t loginuid)
87671
87672 /* are we setting or clearing? */
87673 if (uid_valid(loginuid))
87674 - sessionid = (unsigned int)atomic_inc_return(&session_id);
87675 + sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
87676
87677 task->sessionid = sessionid;
87678 task->loginuid = loginuid;
87679 diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
87680 index d6594e4..00348e4 100644
87681 --- a/kernel/bpf/core.c
87682 +++ b/kernel/bpf/core.c
87683 @@ -143,7 +143,7 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
87684 * random section of illegal instructions.
87685 */
87686 size = round_up(proglen + sizeof(*hdr) + 128, PAGE_SIZE);
87687 - hdr = module_alloc(size);
87688 + hdr = module_alloc_exec(size);
87689 if (hdr == NULL)
87690 return NULL;
87691
87692 @@ -163,7 +163,7 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
87693
87694 void bpf_jit_binary_free(struct bpf_binary_header *hdr)
87695 {
87696 - module_free(NULL, hdr);
87697 + module_free_exec(NULL, hdr);
87698 }
87699 #endif /* CONFIG_BPF_JIT */
87700
87701 diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
87702 index ba61c8c..c60c486 100644
87703 --- a/kernel/bpf/syscall.c
87704 +++ b/kernel/bpf/syscall.c
87705 @@ -539,11 +539,15 @@ SYSCALL_DEFINE3(bpf, int, cmd, union bpf_attr __user *, uattr, unsigned int, siz
87706 int err;
87707
87708 /* the syscall is limited to root temporarily. This restriction will be
87709 - * lifted when security audit is clean. Note that eBPF+tracing must have
87710 - * this restriction, since it may pass kernel data to user space
87711 + * lifted by upstream when a half-assed security audit is clean. Note
87712 + * that eBPF+tracing must have this restriction, since it may pass
87713 + * kernel data to user space
87714 */
87715 if (!capable(CAP_SYS_ADMIN))
87716 return -EPERM;
87717 +#ifdef CONFIG_GRKERNSEC
87718 + return -EPERM;
87719 +#endif
87720
87721 if (!access_ok(VERIFY_READ, uattr, 1))
87722 return -EFAULT;
87723 diff --git a/kernel/capability.c b/kernel/capability.c
87724 index 989f5bf..d317ca0 100644
87725 --- a/kernel/capability.c
87726 +++ b/kernel/capability.c
87727 @@ -192,6 +192,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
87728 * before modification is attempted and the application
87729 * fails.
87730 */
87731 + if (tocopy > ARRAY_SIZE(kdata))
87732 + return -EFAULT;
87733 +
87734 if (copy_to_user(dataptr, kdata, tocopy
87735 * sizeof(struct __user_cap_data_struct))) {
87736 return -EFAULT;
87737 @@ -297,10 +300,11 @@ bool has_ns_capability(struct task_struct *t,
87738 int ret;
87739
87740 rcu_read_lock();
87741 - ret = security_capable(__task_cred(t), ns, cap);
87742 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
87743 + gr_task_is_capable(t, __task_cred(t), cap);
87744 rcu_read_unlock();
87745
87746 - return (ret == 0);
87747 + return ret;
87748 }
87749
87750 /**
87751 @@ -337,10 +341,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
87752 int ret;
87753
87754 rcu_read_lock();
87755 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
87756 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
87757 rcu_read_unlock();
87758
87759 - return (ret == 0);
87760 + return ret;
87761 }
87762
87763 /**
87764 @@ -378,7 +382,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
87765 BUG();
87766 }
87767
87768 - if (security_capable(current_cred(), ns, cap) == 0) {
87769 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
87770 current->flags |= PF_SUPERPRIV;
87771 return true;
87772 }
87773 @@ -386,6 +390,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
87774 }
87775 EXPORT_SYMBOL(ns_capable);
87776
87777 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
87778 +{
87779 + if (unlikely(!cap_valid(cap))) {
87780 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
87781 + BUG();
87782 + }
87783 +
87784 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
87785 + current->flags |= PF_SUPERPRIV;
87786 + return true;
87787 + }
87788 + return false;
87789 +}
87790 +EXPORT_SYMBOL(ns_capable_nolog);
87791 +
87792 /**
87793 * file_ns_capable - Determine if the file's opener had a capability in effect
87794 * @file: The file we want to check
87795 @@ -427,6 +446,12 @@ bool capable(int cap)
87796 }
87797 EXPORT_SYMBOL(capable);
87798
87799 +bool capable_nolog(int cap)
87800 +{
87801 + return ns_capable_nolog(&init_user_ns, cap);
87802 +}
87803 +EXPORT_SYMBOL(capable_nolog);
87804 +
87805 /**
87806 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
87807 * @inode: The inode in question
87808 @@ -444,3 +469,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
87809 kgid_has_mapping(ns, inode->i_gid);
87810 }
87811 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
87812 +
87813 +bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
87814 +{
87815 + struct user_namespace *ns = current_user_ns();
87816 +
87817 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
87818 + kgid_has_mapping(ns, inode->i_gid);
87819 +}
87820 +EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
87821 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
87822 index 136ecea..45157a6 100644
87823 --- a/kernel/cgroup.c
87824 +++ b/kernel/cgroup.c
87825 @@ -5276,6 +5276,9 @@ static void cgroup_release_agent(struct work_struct *work)
87826 if (!pathbuf || !agentbuf)
87827 goto out;
87828
87829 + if (agentbuf[0] == '\0')
87830 + goto out;
87831 +
87832 path = cgroup_path(cgrp, pathbuf, PATH_MAX);
87833 if (!path)
87834 goto out;
87835 @@ -5461,7 +5464,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
87836 struct task_struct *task;
87837 int count = 0;
87838
87839 - seq_printf(seq, "css_set %p\n", cset);
87840 + seq_printf(seq, "css_set %pK\n", cset);
87841
87842 list_for_each_entry(task, &cset->tasks, cg_list) {
87843 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
87844 diff --git a/kernel/compat.c b/kernel/compat.c
87845 index ebb3c36..1df606e 100644
87846 --- a/kernel/compat.c
87847 +++ b/kernel/compat.c
87848 @@ -13,6 +13,7 @@
87849
87850 #include <linux/linkage.h>
87851 #include <linux/compat.h>
87852 +#include <linux/module.h>
87853 #include <linux/errno.h>
87854 #include <linux/time.h>
87855 #include <linux/signal.h>
87856 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
87857 mm_segment_t oldfs;
87858 long ret;
87859
87860 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
87861 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
87862 oldfs = get_fs();
87863 set_fs(KERNEL_DS);
87864 ret = hrtimer_nanosleep_restart(restart);
87865 @@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
87866 oldfs = get_fs();
87867 set_fs(KERNEL_DS);
87868 ret = hrtimer_nanosleep(&tu,
87869 - rmtp ? (struct timespec __user *)&rmt : NULL,
87870 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
87871 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
87872 set_fs(oldfs);
87873
87874 @@ -379,7 +380,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
87875 mm_segment_t old_fs = get_fs();
87876
87877 set_fs(KERNEL_DS);
87878 - ret = sys_sigpending((old_sigset_t __user *) &s);
87879 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
87880 set_fs(old_fs);
87881 if (ret == 0)
87882 ret = put_user(s, set);
87883 @@ -469,7 +470,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
87884 mm_segment_t old_fs = get_fs();
87885
87886 set_fs(KERNEL_DS);
87887 - ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
87888 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
87889 set_fs(old_fs);
87890
87891 if (!ret) {
87892 @@ -551,8 +552,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
87893 set_fs (KERNEL_DS);
87894 ret = sys_wait4(pid,
87895 (stat_addr ?
87896 - (unsigned int __user *) &status : NULL),
87897 - options, (struct rusage __user *) &r);
87898 + (unsigned int __force_user *) &status : NULL),
87899 + options, (struct rusage __force_user *) &r);
87900 set_fs (old_fs);
87901
87902 if (ret > 0) {
87903 @@ -578,8 +579,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
87904 memset(&info, 0, sizeof(info));
87905
87906 set_fs(KERNEL_DS);
87907 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
87908 - uru ? (struct rusage __user *)&ru : NULL);
87909 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
87910 + uru ? (struct rusage __force_user *)&ru : NULL);
87911 set_fs(old_fs);
87912
87913 if ((ret < 0) || (info.si_signo == 0))
87914 @@ -713,8 +714,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
87915 oldfs = get_fs();
87916 set_fs(KERNEL_DS);
87917 err = sys_timer_settime(timer_id, flags,
87918 - (struct itimerspec __user *) &newts,
87919 - (struct itimerspec __user *) &oldts);
87920 + (struct itimerspec __force_user *) &newts,
87921 + (struct itimerspec __force_user *) &oldts);
87922 set_fs(oldfs);
87923 if (!err && old && put_compat_itimerspec(old, &oldts))
87924 return -EFAULT;
87925 @@ -731,7 +732,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
87926 oldfs = get_fs();
87927 set_fs(KERNEL_DS);
87928 err = sys_timer_gettime(timer_id,
87929 - (struct itimerspec __user *) &ts);
87930 + (struct itimerspec __force_user *) &ts);
87931 set_fs(oldfs);
87932 if (!err && put_compat_itimerspec(setting, &ts))
87933 return -EFAULT;
87934 @@ -750,7 +751,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
87935 oldfs = get_fs();
87936 set_fs(KERNEL_DS);
87937 err = sys_clock_settime(which_clock,
87938 - (struct timespec __user *) &ts);
87939 + (struct timespec __force_user *) &ts);
87940 set_fs(oldfs);
87941 return err;
87942 }
87943 @@ -765,7 +766,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
87944 oldfs = get_fs();
87945 set_fs(KERNEL_DS);
87946 err = sys_clock_gettime(which_clock,
87947 - (struct timespec __user *) &ts);
87948 + (struct timespec __force_user *) &ts);
87949 set_fs(oldfs);
87950 if (!err && compat_put_timespec(&ts, tp))
87951 return -EFAULT;
87952 @@ -785,7 +786,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
87953
87954 oldfs = get_fs();
87955 set_fs(KERNEL_DS);
87956 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
87957 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
87958 set_fs(oldfs);
87959
87960 err = compat_put_timex(utp, &txc);
87961 @@ -805,7 +806,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
87962 oldfs = get_fs();
87963 set_fs(KERNEL_DS);
87964 err = sys_clock_getres(which_clock,
87965 - (struct timespec __user *) &ts);
87966 + (struct timespec __force_user *) &ts);
87967 set_fs(oldfs);
87968 if (!err && tp && compat_put_timespec(&ts, tp))
87969 return -EFAULT;
87970 @@ -819,7 +820,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
87971 struct timespec tu;
87972 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
87973
87974 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
87975 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
87976 oldfs = get_fs();
87977 set_fs(KERNEL_DS);
87978 err = clock_nanosleep_restart(restart);
87979 @@ -851,8 +852,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
87980 oldfs = get_fs();
87981 set_fs(KERNEL_DS);
87982 err = sys_clock_nanosleep(which_clock, flags,
87983 - (struct timespec __user *) &in,
87984 - (struct timespec __user *) &out);
87985 + (struct timespec __force_user *) &in,
87986 + (struct timespec __force_user *) &out);
87987 set_fs(oldfs);
87988
87989 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
87990 @@ -1146,7 +1147,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
87991 mm_segment_t old_fs = get_fs();
87992
87993 set_fs(KERNEL_DS);
87994 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
87995 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
87996 set_fs(old_fs);
87997 if (compat_put_timespec(&t, interval))
87998 return -EFAULT;
87999 diff --git a/kernel/configs.c b/kernel/configs.c
88000 index c18b1f1..b9a0132 100644
88001 --- a/kernel/configs.c
88002 +++ b/kernel/configs.c
88003 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
88004 struct proc_dir_entry *entry;
88005
88006 /* create the current config file */
88007 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
88008 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
88009 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
88010 + &ikconfig_file_ops);
88011 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88012 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
88013 + &ikconfig_file_ops);
88014 +#endif
88015 +#else
88016 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
88017 &ikconfig_file_ops);
88018 +#endif
88019 +
88020 if (!entry)
88021 return -ENOMEM;
88022
88023 diff --git a/kernel/cred.c b/kernel/cred.c
88024 index e0573a4..26c0fd3 100644
88025 --- a/kernel/cred.c
88026 +++ b/kernel/cred.c
88027 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
88028 validate_creds(cred);
88029 alter_cred_subscribers(cred, -1);
88030 put_cred(cred);
88031 +
88032 +#ifdef CONFIG_GRKERNSEC_SETXID
88033 + cred = (struct cred *) tsk->delayed_cred;
88034 + if (cred != NULL) {
88035 + tsk->delayed_cred = NULL;
88036 + validate_creds(cred);
88037 + alter_cred_subscribers(cred, -1);
88038 + put_cred(cred);
88039 + }
88040 +#endif
88041 }
88042
88043 /**
88044 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
88045 * Always returns 0 thus allowing this function to be tail-called at the end
88046 * of, say, sys_setgid().
88047 */
88048 -int commit_creds(struct cred *new)
88049 +static int __commit_creds(struct cred *new)
88050 {
88051 struct task_struct *task = current;
88052 const struct cred *old = task->real_cred;
88053 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
88054
88055 get_cred(new); /* we will require a ref for the subj creds too */
88056
88057 + gr_set_role_label(task, new->uid, new->gid);
88058 +
88059 /* dumpability changes */
88060 if (!uid_eq(old->euid, new->euid) ||
88061 !gid_eq(old->egid, new->egid) ||
88062 @@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
88063 put_cred(old);
88064 return 0;
88065 }
88066 +#ifdef CONFIG_GRKERNSEC_SETXID
88067 +extern int set_user(struct cred *new);
88068 +
88069 +void gr_delayed_cred_worker(void)
88070 +{
88071 + const struct cred *new = current->delayed_cred;
88072 + struct cred *ncred;
88073 +
88074 + current->delayed_cred = NULL;
88075 +
88076 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
88077 + // from doing get_cred on it when queueing this
88078 + put_cred(new);
88079 + return;
88080 + } else if (new == NULL)
88081 + return;
88082 +
88083 + ncred = prepare_creds();
88084 + if (!ncred)
88085 + goto die;
88086 + // uids
88087 + ncred->uid = new->uid;
88088 + ncred->euid = new->euid;
88089 + ncred->suid = new->suid;
88090 + ncred->fsuid = new->fsuid;
88091 + // gids
88092 + ncred->gid = new->gid;
88093 + ncred->egid = new->egid;
88094 + ncred->sgid = new->sgid;
88095 + ncred->fsgid = new->fsgid;
88096 + // groups
88097 + set_groups(ncred, new->group_info);
88098 + // caps
88099 + ncred->securebits = new->securebits;
88100 + ncred->cap_inheritable = new->cap_inheritable;
88101 + ncred->cap_permitted = new->cap_permitted;
88102 + ncred->cap_effective = new->cap_effective;
88103 + ncred->cap_bset = new->cap_bset;
88104 +
88105 + if (set_user(ncred)) {
88106 + abort_creds(ncred);
88107 + goto die;
88108 + }
88109 +
88110 + // from doing get_cred on it when queueing this
88111 + put_cred(new);
88112 +
88113 + __commit_creds(ncred);
88114 + return;
88115 +die:
88116 + // from doing get_cred on it when queueing this
88117 + put_cred(new);
88118 + do_group_exit(SIGKILL);
88119 +}
88120 +#endif
88121 +
88122 +int commit_creds(struct cred *new)
88123 +{
88124 +#ifdef CONFIG_GRKERNSEC_SETXID
88125 + int ret;
88126 + int schedule_it = 0;
88127 + struct task_struct *t;
88128 + unsigned oldsecurebits = current_cred()->securebits;
88129 +
88130 + /* we won't get called with tasklist_lock held for writing
88131 + and interrupts disabled as the cred struct in that case is
88132 + init_cred
88133 + */
88134 + if (grsec_enable_setxid && !current_is_single_threaded() &&
88135 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
88136 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
88137 + schedule_it = 1;
88138 + }
88139 + ret = __commit_creds(new);
88140 + if (schedule_it) {
88141 + rcu_read_lock();
88142 + read_lock(&tasklist_lock);
88143 + for (t = next_thread(current); t != current;
88144 + t = next_thread(t)) {
88145 + /* we'll check if the thread has uid 0 in
88146 + * the delayed worker routine
88147 + */
88148 + if (task_securebits(t) == oldsecurebits &&
88149 + t->delayed_cred == NULL) {
88150 + t->delayed_cred = get_cred(new);
88151 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
88152 + set_tsk_need_resched(t);
88153 + }
88154 + }
88155 + read_unlock(&tasklist_lock);
88156 + rcu_read_unlock();
88157 + }
88158 +
88159 + return ret;
88160 +#else
88161 + return __commit_creds(new);
88162 +#endif
88163 +}
88164 +
88165 EXPORT_SYMBOL(commit_creds);
88166
88167 /**
88168 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
88169 index 1adf62b..7736e06 100644
88170 --- a/kernel/debug/debug_core.c
88171 +++ b/kernel/debug/debug_core.c
88172 @@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
88173 */
88174 static atomic_t masters_in_kgdb;
88175 static atomic_t slaves_in_kgdb;
88176 -static atomic_t kgdb_break_tasklet_var;
88177 +static atomic_unchecked_t kgdb_break_tasklet_var;
88178 atomic_t kgdb_setting_breakpoint;
88179
88180 struct task_struct *kgdb_usethread;
88181 @@ -134,7 +134,7 @@ int kgdb_single_step;
88182 static pid_t kgdb_sstep_pid;
88183
88184 /* to keep track of the CPU which is doing the single stepping*/
88185 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
88186 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
88187
88188 /*
88189 * If you are debugging a problem where roundup (the collection of
88190 @@ -549,7 +549,7 @@ return_normal:
88191 * kernel will only try for the value of sstep_tries before
88192 * giving up and continuing on.
88193 */
88194 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
88195 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
88196 (kgdb_info[cpu].task &&
88197 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
88198 atomic_set(&kgdb_active, -1);
88199 @@ -647,8 +647,8 @@ cpu_master_loop:
88200 }
88201
88202 kgdb_restore:
88203 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
88204 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
88205 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
88206 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
88207 if (kgdb_info[sstep_cpu].task)
88208 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
88209 else
88210 @@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
88211 static void kgdb_tasklet_bpt(unsigned long ing)
88212 {
88213 kgdb_breakpoint();
88214 - atomic_set(&kgdb_break_tasklet_var, 0);
88215 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
88216 }
88217
88218 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
88219
88220 void kgdb_schedule_breakpoint(void)
88221 {
88222 - if (atomic_read(&kgdb_break_tasklet_var) ||
88223 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
88224 atomic_read(&kgdb_active) != -1 ||
88225 atomic_read(&kgdb_setting_breakpoint))
88226 return;
88227 - atomic_inc(&kgdb_break_tasklet_var);
88228 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
88229 tasklet_schedule(&kgdb_tasklet_breakpoint);
88230 }
88231 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
88232 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
88233 index 379650b..30c5180 100644
88234 --- a/kernel/debug/kdb/kdb_main.c
88235 +++ b/kernel/debug/kdb/kdb_main.c
88236 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
88237 continue;
88238
88239 kdb_printf("%-20s%8u 0x%p ", mod->name,
88240 - mod->core_size, (void *)mod);
88241 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
88242 #ifdef CONFIG_MODULE_UNLOAD
88243 kdb_printf("%4ld ", module_refcount(mod));
88244 #endif
88245 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
88246 kdb_printf(" (Loading)");
88247 else
88248 kdb_printf(" (Live)");
88249 - kdb_printf(" 0x%p", mod->module_core);
88250 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
88251
88252 #ifdef CONFIG_MODULE_UNLOAD
88253 {
88254 diff --git a/kernel/events/core.c b/kernel/events/core.c
88255 index 1cd5eef..e8b5af9 100644
88256 --- a/kernel/events/core.c
88257 +++ b/kernel/events/core.c
88258 @@ -170,8 +170,15 @@ static struct srcu_struct pmus_srcu;
88259 * 0 - disallow raw tracepoint access for unpriv
88260 * 1 - disallow cpu events for unpriv
88261 * 2 - disallow kernel profiling for unpriv
88262 + * 3 - disallow all unpriv perf event use
88263 */
88264 -int sysctl_perf_event_paranoid __read_mostly = 1;
88265 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
88266 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
88267 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
88268 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
88269 +#else
88270 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
88271 +#endif
88272
88273 /* Minimum for 512 kiB + 1 user control page */
88274 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
88275 @@ -197,7 +204,7 @@ void update_perf_cpu_limits(void)
88276
88277 tmp *= sysctl_perf_cpu_time_max_percent;
88278 do_div(tmp, 100);
88279 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
88280 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
88281 }
88282
88283 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
88284 @@ -303,7 +310,7 @@ void perf_sample_event_took(u64 sample_len_ns)
88285 }
88286 }
88287
88288 -static atomic64_t perf_event_id;
88289 +static atomic64_unchecked_t perf_event_id;
88290
88291 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
88292 enum event_type_t event_type);
88293 @@ -3102,7 +3109,7 @@ static void __perf_event_read(void *info)
88294
88295 static inline u64 perf_event_count(struct perf_event *event)
88296 {
88297 - return local64_read(&event->count) + atomic64_read(&event->child_count);
88298 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
88299 }
88300
88301 static u64 perf_event_read(struct perf_event *event)
88302 @@ -3528,9 +3535,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
88303 mutex_lock(&event->child_mutex);
88304 total += perf_event_read(event);
88305 *enabled += event->total_time_enabled +
88306 - atomic64_read(&event->child_total_time_enabled);
88307 + atomic64_read_unchecked(&event->child_total_time_enabled);
88308 *running += event->total_time_running +
88309 - atomic64_read(&event->child_total_time_running);
88310 + atomic64_read_unchecked(&event->child_total_time_running);
88311
88312 list_for_each_entry(child, &event->child_list, child_list) {
88313 total += perf_event_read(child);
88314 @@ -3994,10 +4001,10 @@ void perf_event_update_userpage(struct perf_event *event)
88315 userpg->offset -= local64_read(&event->hw.prev_count);
88316
88317 userpg->time_enabled = enabled +
88318 - atomic64_read(&event->child_total_time_enabled);
88319 + atomic64_read_unchecked(&event->child_total_time_enabled);
88320
88321 userpg->time_running = running +
88322 - atomic64_read(&event->child_total_time_running);
88323 + atomic64_read_unchecked(&event->child_total_time_running);
88324
88325 arch_perf_update_userpage(userpg, now);
88326
88327 @@ -4561,7 +4568,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
88328
88329 /* Data. */
88330 sp = perf_user_stack_pointer(regs);
88331 - rem = __output_copy_user(handle, (void *) sp, dump_size);
88332 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
88333 dyn_size = dump_size - rem;
88334
88335 perf_output_skip(handle, rem);
88336 @@ -4652,11 +4659,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
88337 values[n++] = perf_event_count(event);
88338 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
88339 values[n++] = enabled +
88340 - atomic64_read(&event->child_total_time_enabled);
88341 + atomic64_read_unchecked(&event->child_total_time_enabled);
88342 }
88343 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
88344 values[n++] = running +
88345 - atomic64_read(&event->child_total_time_running);
88346 + atomic64_read_unchecked(&event->child_total_time_running);
88347 }
88348 if (read_format & PERF_FORMAT_ID)
88349 values[n++] = primary_event_id(event);
88350 @@ -6958,7 +6965,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
88351 event->parent = parent_event;
88352
88353 event->ns = get_pid_ns(task_active_pid_ns(current));
88354 - event->id = atomic64_inc_return(&perf_event_id);
88355 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
88356
88357 event->state = PERF_EVENT_STATE_INACTIVE;
88358
88359 @@ -7237,6 +7244,11 @@ SYSCALL_DEFINE5(perf_event_open,
88360 if (flags & ~PERF_FLAG_ALL)
88361 return -EINVAL;
88362
88363 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
88364 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
88365 + return -EACCES;
88366 +#endif
88367 +
88368 err = perf_copy_attr(attr_uptr, &attr);
88369 if (err)
88370 return err;
88371 @@ -7592,10 +7604,10 @@ static void sync_child_event(struct perf_event *child_event,
88372 /*
88373 * Add back the child's count to the parent's count:
88374 */
88375 - atomic64_add(child_val, &parent_event->child_count);
88376 - atomic64_add(child_event->total_time_enabled,
88377 + atomic64_add_unchecked(child_val, &parent_event->child_count);
88378 + atomic64_add_unchecked(child_event->total_time_enabled,
88379 &parent_event->child_total_time_enabled);
88380 - atomic64_add(child_event->total_time_running,
88381 + atomic64_add_unchecked(child_event->total_time_running,
88382 &parent_event->child_total_time_running);
88383
88384 /*
88385 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
88386 index 569b2187..19940d9 100644
88387 --- a/kernel/events/internal.h
88388 +++ b/kernel/events/internal.h
88389 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
88390 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
88391 }
88392
88393 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
88394 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
88395 static inline unsigned long \
88396 func_name(struct perf_output_handle *handle, \
88397 - const void *buf, unsigned long len) \
88398 + const void user *buf, unsigned long len) \
88399 { \
88400 unsigned long size, written; \
88401 \
88402 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
88403 return 0;
88404 }
88405
88406 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
88407 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
88408
88409 static inline unsigned long
88410 memcpy_skip(void *dst, const void *src, unsigned long n)
88411 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
88412 return 0;
88413 }
88414
88415 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
88416 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
88417
88418 #ifndef arch_perf_out_copy_user
88419 #define arch_perf_out_copy_user arch_perf_out_copy_user
88420 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
88421 }
88422 #endif
88423
88424 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
88425 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
88426
88427 /* Callchain handling */
88428 extern struct perf_callchain_entry *
88429 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
88430 index ed8f2cd..fe8030c 100644
88431 --- a/kernel/events/uprobes.c
88432 +++ b/kernel/events/uprobes.c
88433 @@ -1670,7 +1670,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
88434 {
88435 struct page *page;
88436 uprobe_opcode_t opcode;
88437 - int result;
88438 + long result;
88439
88440 pagefault_disable();
88441 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
88442 diff --git a/kernel/exit.c b/kernel/exit.c
88443 index 5d30019..934add5 100644
88444 --- a/kernel/exit.c
88445 +++ b/kernel/exit.c
88446 @@ -174,6 +174,10 @@ void release_task(struct task_struct *p)
88447 struct task_struct *leader;
88448 int zap_leader;
88449 repeat:
88450 +#ifdef CONFIG_NET
88451 + gr_del_task_from_ip_table(p);
88452 +#endif
88453 +
88454 /* don't need to get the RCU readlock here - the process is dead and
88455 * can't be modifying its own credentials. But shut RCU-lockdep up */
88456 rcu_read_lock();
88457 @@ -670,6 +674,8 @@ void do_exit(long code)
88458 int group_dead;
88459 TASKS_RCU(int tasks_rcu_i);
88460
88461 + set_fs(USER_DS);
88462 +
88463 profile_task_exit(tsk);
88464
88465 WARN_ON(blk_needs_flush_plug(tsk));
88466 @@ -686,7 +692,6 @@ void do_exit(long code)
88467 * mm_release()->clear_child_tid() from writing to a user-controlled
88468 * kernel address.
88469 */
88470 - set_fs(USER_DS);
88471
88472 ptrace_event(PTRACE_EVENT_EXIT, code);
88473
88474 @@ -744,6 +749,9 @@ void do_exit(long code)
88475 tsk->exit_code = code;
88476 taskstats_exit(tsk, group_dead);
88477
88478 + gr_acl_handle_psacct(tsk, code);
88479 + gr_acl_handle_exit();
88480 +
88481 exit_mm(tsk);
88482
88483 if (group_dead)
88484 @@ -863,7 +871,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
88485 * Take down every thread in the group. This is called by fatal signals
88486 * as well as by sys_exit_group (below).
88487 */
88488 -void
88489 +__noreturn void
88490 do_group_exit(int exit_code)
88491 {
88492 struct signal_struct *sig = current->signal;
88493 diff --git a/kernel/fork.c b/kernel/fork.c
88494 index 9b7d746..5b898ab 100644
88495 --- a/kernel/fork.c
88496 +++ b/kernel/fork.c
88497 @@ -183,6 +183,48 @@ void thread_info_cache_init(void)
88498 # endif
88499 #endif
88500
88501 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
88502 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
88503 + int node, void **lowmem_stack)
88504 +{
88505 + struct page *pages[THREAD_SIZE / PAGE_SIZE];
88506 + void *ret = NULL;
88507 + unsigned int i;
88508 +
88509 + *lowmem_stack = alloc_thread_info_node(tsk, node);
88510 + if (*lowmem_stack == NULL)
88511 + goto out;
88512 +
88513 + for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
88514 + pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
88515 +
88516 + /* use VM_IOREMAP to gain THREAD_SIZE alignment */
88517 + ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
88518 + if (ret == NULL) {
88519 + free_thread_info(*lowmem_stack);
88520 + *lowmem_stack = NULL;
88521 + }
88522 +
88523 +out:
88524 + return ret;
88525 +}
88526 +
88527 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
88528 +{
88529 + unmap_process_stacks(tsk);
88530 +}
88531 +#else
88532 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
88533 + int node, void **lowmem_stack)
88534 +{
88535 + return alloc_thread_info_node(tsk, node);
88536 +}
88537 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
88538 +{
88539 + free_thread_info(ti);
88540 +}
88541 +#endif
88542 +
88543 /* SLAB cache for signal_struct structures (tsk->signal) */
88544 static struct kmem_cache *signal_cachep;
88545
88546 @@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
88547 /* SLAB cache for mm_struct structures (tsk->mm) */
88548 static struct kmem_cache *mm_cachep;
88549
88550 -static void account_kernel_stack(struct thread_info *ti, int account)
88551 +static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
88552 {
88553 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
88554 + struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
88555 +#else
88556 struct zone *zone = page_zone(virt_to_page(ti));
88557 +#endif
88558
88559 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
88560 }
88561
88562 void free_task(struct task_struct *tsk)
88563 {
88564 - account_kernel_stack(tsk->stack, -1);
88565 + account_kernel_stack(tsk, tsk->stack, -1);
88566 arch_release_thread_info(tsk->stack);
88567 - free_thread_info(tsk->stack);
88568 + gr_free_thread_info(tsk, tsk->stack);
88569 rt_mutex_debug_task_free(tsk);
88570 ftrace_graph_exit_task(tsk);
88571 put_seccomp_filter(tsk);
88572 @@ -306,6 +352,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
88573 {
88574 struct task_struct *tsk;
88575 struct thread_info *ti;
88576 + void *lowmem_stack;
88577 int node = tsk_fork_get_node(orig);
88578 int err;
88579
88580 @@ -313,7 +360,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
88581 if (!tsk)
88582 return NULL;
88583
88584 - ti = alloc_thread_info_node(tsk, node);
88585 + ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
88586 if (!ti)
88587 goto free_tsk;
88588
88589 @@ -322,6 +369,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
88590 goto free_ti;
88591
88592 tsk->stack = ti;
88593 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
88594 + tsk->lowmem_stack = lowmem_stack;
88595 +#endif
88596 #ifdef CONFIG_SECCOMP
88597 /*
88598 * We must handle setting up seccomp filters once we're under
88599 @@ -338,7 +388,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
88600 set_task_stack_end_magic(tsk);
88601
88602 #ifdef CONFIG_CC_STACKPROTECTOR
88603 - tsk->stack_canary = get_random_int();
88604 + tsk->stack_canary = pax_get_random_long();
88605 #endif
88606
88607 /*
88608 @@ -352,24 +402,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
88609 tsk->splice_pipe = NULL;
88610 tsk->task_frag.page = NULL;
88611
88612 - account_kernel_stack(ti, 1);
88613 + account_kernel_stack(tsk, ti, 1);
88614
88615 return tsk;
88616
88617 free_ti:
88618 - free_thread_info(ti);
88619 + gr_free_thread_info(tsk, ti);
88620 free_tsk:
88621 free_task_struct(tsk);
88622 return NULL;
88623 }
88624
88625 #ifdef CONFIG_MMU
88626 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
88627 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
88628 +{
88629 + struct vm_area_struct *tmp;
88630 + unsigned long charge;
88631 + struct file *file;
88632 + int retval;
88633 +
88634 + charge = 0;
88635 + if (mpnt->vm_flags & VM_ACCOUNT) {
88636 + unsigned long len = vma_pages(mpnt);
88637 +
88638 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
88639 + goto fail_nomem;
88640 + charge = len;
88641 + }
88642 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
88643 + if (!tmp)
88644 + goto fail_nomem;
88645 + *tmp = *mpnt;
88646 + tmp->vm_mm = mm;
88647 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
88648 + retval = vma_dup_policy(mpnt, tmp);
88649 + if (retval)
88650 + goto fail_nomem_policy;
88651 + if (anon_vma_fork(tmp, mpnt))
88652 + goto fail_nomem_anon_vma_fork;
88653 + tmp->vm_flags &= ~VM_LOCKED;
88654 + tmp->vm_next = tmp->vm_prev = NULL;
88655 + tmp->vm_mirror = NULL;
88656 + file = tmp->vm_file;
88657 + if (file) {
88658 + struct inode *inode = file_inode(file);
88659 + struct address_space *mapping = file->f_mapping;
88660 +
88661 + get_file(file);
88662 + if (tmp->vm_flags & VM_DENYWRITE)
88663 + atomic_dec(&inode->i_writecount);
88664 + mutex_lock(&mapping->i_mmap_mutex);
88665 + if (tmp->vm_flags & VM_SHARED)
88666 + atomic_inc(&mapping->i_mmap_writable);
88667 + flush_dcache_mmap_lock(mapping);
88668 + /* insert tmp into the share list, just after mpnt */
88669 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
88670 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
88671 + else
88672 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
88673 + flush_dcache_mmap_unlock(mapping);
88674 + mutex_unlock(&mapping->i_mmap_mutex);
88675 + }
88676 +
88677 + /*
88678 + * Clear hugetlb-related page reserves for children. This only
88679 + * affects MAP_PRIVATE mappings. Faults generated by the child
88680 + * are not guaranteed to succeed, even if read-only
88681 + */
88682 + if (is_vm_hugetlb_page(tmp))
88683 + reset_vma_resv_huge_pages(tmp);
88684 +
88685 + return tmp;
88686 +
88687 +fail_nomem_anon_vma_fork:
88688 + mpol_put(vma_policy(tmp));
88689 +fail_nomem_policy:
88690 + kmem_cache_free(vm_area_cachep, tmp);
88691 +fail_nomem:
88692 + vm_unacct_memory(charge);
88693 + return NULL;
88694 +}
88695 +
88696 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
88697 {
88698 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
88699 struct rb_node **rb_link, *rb_parent;
88700 int retval;
88701 - unsigned long charge;
88702
88703 uprobe_start_dup_mmap();
88704 down_write(&oldmm->mmap_sem);
88705 @@ -397,55 +515,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
88706
88707 prev = NULL;
88708 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
88709 - struct file *file;
88710 -
88711 if (mpnt->vm_flags & VM_DONTCOPY) {
88712 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
88713 -vma_pages(mpnt));
88714 continue;
88715 }
88716 - charge = 0;
88717 - if (mpnt->vm_flags & VM_ACCOUNT) {
88718 - unsigned long len = vma_pages(mpnt);
88719 -
88720 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
88721 - goto fail_nomem;
88722 - charge = len;
88723 - }
88724 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
88725 - if (!tmp)
88726 - goto fail_nomem;
88727 - *tmp = *mpnt;
88728 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
88729 - retval = vma_dup_policy(mpnt, tmp);
88730 - if (retval)
88731 - goto fail_nomem_policy;
88732 - tmp->vm_mm = mm;
88733 - if (anon_vma_fork(tmp, mpnt))
88734 - goto fail_nomem_anon_vma_fork;
88735 - tmp->vm_flags &= ~VM_LOCKED;
88736 - tmp->vm_next = tmp->vm_prev = NULL;
88737 - file = tmp->vm_file;
88738 - if (file) {
88739 - struct inode *inode = file_inode(file);
88740 - struct address_space *mapping = file->f_mapping;
88741 -
88742 - get_file(file);
88743 - if (tmp->vm_flags & VM_DENYWRITE)
88744 - atomic_dec(&inode->i_writecount);
88745 - mutex_lock(&mapping->i_mmap_mutex);
88746 - if (tmp->vm_flags & VM_SHARED)
88747 - atomic_inc(&mapping->i_mmap_writable);
88748 - flush_dcache_mmap_lock(mapping);
88749 - /* insert tmp into the share list, just after mpnt */
88750 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
88751 - vma_nonlinear_insert(tmp,
88752 - &mapping->i_mmap_nonlinear);
88753 - else
88754 - vma_interval_tree_insert_after(tmp, mpnt,
88755 - &mapping->i_mmap);
88756 - flush_dcache_mmap_unlock(mapping);
88757 - mutex_unlock(&mapping->i_mmap_mutex);
88758 + tmp = dup_vma(mm, oldmm, mpnt);
88759 + if (!tmp) {
88760 + retval = -ENOMEM;
88761 + goto out;
88762 }
88763
88764 /*
88765 @@ -477,6 +555,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
88766 if (retval)
88767 goto out;
88768 }
88769 +
88770 +#ifdef CONFIG_PAX_SEGMEXEC
88771 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
88772 + struct vm_area_struct *mpnt_m;
88773 +
88774 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
88775 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
88776 +
88777 + if (!mpnt->vm_mirror)
88778 + continue;
88779 +
88780 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
88781 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
88782 + mpnt->vm_mirror = mpnt_m;
88783 + } else {
88784 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
88785 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
88786 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
88787 + mpnt->vm_mirror->vm_mirror = mpnt;
88788 + }
88789 + }
88790 + BUG_ON(mpnt_m);
88791 + }
88792 +#endif
88793 +
88794 /* a new mm has just been created */
88795 arch_dup_mmap(oldmm, mm);
88796 retval = 0;
88797 @@ -486,14 +589,6 @@ out:
88798 up_write(&oldmm->mmap_sem);
88799 uprobe_end_dup_mmap();
88800 return retval;
88801 -fail_nomem_anon_vma_fork:
88802 - mpol_put(vma_policy(tmp));
88803 -fail_nomem_policy:
88804 - kmem_cache_free(vm_area_cachep, tmp);
88805 -fail_nomem:
88806 - retval = -ENOMEM;
88807 - vm_unacct_memory(charge);
88808 - goto out;
88809 }
88810
88811 static inline int mm_alloc_pgd(struct mm_struct *mm)
88812 @@ -734,8 +829,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
88813 return ERR_PTR(err);
88814
88815 mm = get_task_mm(task);
88816 - if (mm && mm != current->mm &&
88817 - !ptrace_may_access(task, mode)) {
88818 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
88819 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
88820 mmput(mm);
88821 mm = ERR_PTR(-EACCES);
88822 }
88823 @@ -938,13 +1033,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
88824 spin_unlock(&fs->lock);
88825 return -EAGAIN;
88826 }
88827 - fs->users++;
88828 + atomic_inc(&fs->users);
88829 spin_unlock(&fs->lock);
88830 return 0;
88831 }
88832 tsk->fs = copy_fs_struct(fs);
88833 if (!tsk->fs)
88834 return -ENOMEM;
88835 + /* Carry through gr_chroot_dentry and is_chrooted instead
88836 + of recomputing it here. Already copied when the task struct
88837 + is duplicated. This allows pivot_root to not be treated as
88838 + a chroot
88839 + */
88840 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
88841 +
88842 return 0;
88843 }
88844
88845 @@ -1179,7 +1281,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
88846 * parts of the process environment (as per the clone
88847 * flags). The actual kick-off is left to the caller.
88848 */
88849 -static struct task_struct *copy_process(unsigned long clone_flags,
88850 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
88851 unsigned long stack_start,
88852 unsigned long stack_size,
88853 int __user *child_tidptr,
88854 @@ -1250,6 +1352,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
88855 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
88856 #endif
88857 retval = -EAGAIN;
88858 +
88859 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
88860 +
88861 if (atomic_read(&p->real_cred->user->processes) >=
88862 task_rlimit(p, RLIMIT_NPROC)) {
88863 if (p->real_cred->user != INIT_USER &&
88864 @@ -1499,6 +1604,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
88865 goto bad_fork_free_pid;
88866 }
88867
88868 + /* synchronizes with gr_set_acls()
88869 + we need to call this past the point of no return for fork()
88870 + */
88871 + gr_copy_label(p);
88872 +
88873 if (likely(p->pid)) {
88874 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
88875
88876 @@ -1589,6 +1699,8 @@ bad_fork_cleanup_count:
88877 bad_fork_free:
88878 free_task(p);
88879 fork_out:
88880 + gr_log_forkfail(retval);
88881 +
88882 return ERR_PTR(retval);
88883 }
88884
88885 @@ -1650,6 +1762,7 @@ long do_fork(unsigned long clone_flags,
88886
88887 p = copy_process(clone_flags, stack_start, stack_size,
88888 child_tidptr, NULL, trace);
88889 + add_latent_entropy();
88890 /*
88891 * Do this prior waking up the new thread - the thread pointer
88892 * might get invalid after that point, if the thread exits quickly.
88893 @@ -1666,6 +1779,8 @@ long do_fork(unsigned long clone_flags,
88894 if (clone_flags & CLONE_PARENT_SETTID)
88895 put_user(nr, parent_tidptr);
88896
88897 + gr_handle_brute_check();
88898 +
88899 if (clone_flags & CLONE_VFORK) {
88900 p->vfork_done = &vfork;
88901 init_completion(&vfork);
88902 @@ -1784,7 +1899,7 @@ void __init proc_caches_init(void)
88903 mm_cachep = kmem_cache_create("mm_struct",
88904 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
88905 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
88906 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
88907 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
88908 mmap_init();
88909 nsproxy_cache_init();
88910 }
88911 @@ -1824,7 +1939,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
88912 return 0;
88913
88914 /* don't need lock here; in the worst case we'll do useless copy */
88915 - if (fs->users == 1)
88916 + if (atomic_read(&fs->users) == 1)
88917 return 0;
88918
88919 *new_fsp = copy_fs_struct(fs);
88920 @@ -1936,7 +2051,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
88921 fs = current->fs;
88922 spin_lock(&fs->lock);
88923 current->fs = new_fs;
88924 - if (--fs->users)
88925 + gr_set_chroot_entries(current, &current->fs->root);
88926 + if (atomic_dec_return(&fs->users))
88927 new_fs = NULL;
88928 else
88929 new_fs = fs;
88930 diff --git a/kernel/futex.c b/kernel/futex.c
88931 index 63678b5..512f9af 100644
88932 --- a/kernel/futex.c
88933 +++ b/kernel/futex.c
88934 @@ -201,7 +201,7 @@ struct futex_pi_state {
88935 atomic_t refcount;
88936
88937 union futex_key key;
88938 -};
88939 +} __randomize_layout;
88940
88941 /**
88942 * struct futex_q - The hashed futex queue entry, one per waiting task
88943 @@ -235,7 +235,7 @@ struct futex_q {
88944 struct rt_mutex_waiter *rt_waiter;
88945 union futex_key *requeue_pi_key;
88946 u32 bitset;
88947 -};
88948 +} __randomize_layout;
88949
88950 static const struct futex_q futex_q_init = {
88951 /* list gets initialized in queue_me()*/
88952 @@ -402,6 +402,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
88953 struct page *page, *page_head;
88954 int err, ro = 0;
88955
88956 +#ifdef CONFIG_PAX_SEGMEXEC
88957 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
88958 + return -EFAULT;
88959 +#endif
88960 +
88961 /*
88962 * The futex address must be "naturally" aligned.
88963 */
88964 @@ -601,7 +606,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
88965
88966 static int get_futex_value_locked(u32 *dest, u32 __user *from)
88967 {
88968 - int ret;
88969 + unsigned long ret;
88970
88971 pagefault_disable();
88972 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
88973 @@ -3006,6 +3011,7 @@ static void __init futex_detect_cmpxchg(void)
88974 {
88975 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
88976 u32 curval;
88977 + mm_segment_t oldfs;
88978
88979 /*
88980 * This will fail and we want it. Some arch implementations do
88981 @@ -3017,8 +3023,11 @@ static void __init futex_detect_cmpxchg(void)
88982 * implementation, the non-functional ones will return
88983 * -ENOSYS.
88984 */
88985 + oldfs = get_fs();
88986 + set_fs(USER_DS);
88987 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
88988 futex_cmpxchg_enabled = 1;
88989 + set_fs(oldfs);
88990 #endif
88991 }
88992
88993 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
88994 index 55c8c93..9ba7ad6 100644
88995 --- a/kernel/futex_compat.c
88996 +++ b/kernel/futex_compat.c
88997 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
88998 return 0;
88999 }
89000
89001 -static void __user *futex_uaddr(struct robust_list __user *entry,
89002 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
89003 compat_long_t futex_offset)
89004 {
89005 compat_uptr_t base = ptr_to_compat(entry);
89006 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
89007 index b358a80..fc25240 100644
89008 --- a/kernel/gcov/base.c
89009 +++ b/kernel/gcov/base.c
89010 @@ -114,11 +114,6 @@ void gcov_enable_events(void)
89011 }
89012
89013 #ifdef CONFIG_MODULES
89014 -static inline int within(void *addr, void *start, unsigned long size)
89015 -{
89016 - return ((addr >= start) && (addr < start + size));
89017 -}
89018 -
89019 /* Update list and generate events when modules are unloaded. */
89020 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
89021 void *data)
89022 @@ -133,7 +128,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
89023
89024 /* Remove entries located in module from linked list. */
89025 while ((info = gcov_info_next(info))) {
89026 - if (within(info, mod->module_core, mod->core_size)) {
89027 + if (within_module_core_rw((unsigned long)info, mod)) {
89028 gcov_info_unlink(prev, info);
89029 if (gcov_events_enabled)
89030 gcov_event(GCOV_REMOVE, info);
89031 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
89032 index 9019f15..9a3c42e 100644
89033 --- a/kernel/jump_label.c
89034 +++ b/kernel/jump_label.c
89035 @@ -14,6 +14,7 @@
89036 #include <linux/err.h>
89037 #include <linux/static_key.h>
89038 #include <linux/jump_label_ratelimit.h>
89039 +#include <linux/mm.h>
89040
89041 #ifdef HAVE_JUMP_LABEL
89042
89043 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
89044
89045 size = (((unsigned long)stop - (unsigned long)start)
89046 / sizeof(struct jump_entry));
89047 + pax_open_kernel();
89048 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
89049 + pax_close_kernel();
89050 }
89051
89052 static void jump_label_update(struct static_key *key, int enable);
89053 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
89054 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
89055 struct jump_entry *iter;
89056
89057 + pax_open_kernel();
89058 for (iter = iter_start; iter < iter_stop; iter++) {
89059 if (within_module_init(iter->code, mod))
89060 iter->code = 0;
89061 }
89062 + pax_close_kernel();
89063 }
89064
89065 static int
89066 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
89067 index 5c5987f..bc502b0 100644
89068 --- a/kernel/kallsyms.c
89069 +++ b/kernel/kallsyms.c
89070 @@ -11,6 +11,9 @@
89071 * Changed the compression method from stem compression to "table lookup"
89072 * compression (see scripts/kallsyms.c for a more complete description)
89073 */
89074 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89075 +#define __INCLUDED_BY_HIDESYM 1
89076 +#endif
89077 #include <linux/kallsyms.h>
89078 #include <linux/module.h>
89079 #include <linux/init.h>
89080 @@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
89081
89082 static inline int is_kernel_inittext(unsigned long addr)
89083 {
89084 + if (system_state != SYSTEM_BOOTING)
89085 + return 0;
89086 +
89087 if (addr >= (unsigned long)_sinittext
89088 && addr <= (unsigned long)_einittext)
89089 return 1;
89090 return 0;
89091 }
89092
89093 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89094 +#ifdef CONFIG_MODULES
89095 +static inline int is_module_text(unsigned long addr)
89096 +{
89097 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
89098 + return 1;
89099 +
89100 + addr = ktla_ktva(addr);
89101 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
89102 +}
89103 +#else
89104 +static inline int is_module_text(unsigned long addr)
89105 +{
89106 + return 0;
89107 +}
89108 +#endif
89109 +#endif
89110 +
89111 static inline int is_kernel_text(unsigned long addr)
89112 {
89113 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
89114 @@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
89115
89116 static inline int is_kernel(unsigned long addr)
89117 {
89118 +
89119 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89120 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
89121 + return 1;
89122 +
89123 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
89124 +#else
89125 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
89126 +#endif
89127 +
89128 return 1;
89129 return in_gate_area_no_mm(addr);
89130 }
89131
89132 static int is_ksym_addr(unsigned long addr)
89133 {
89134 +
89135 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89136 + if (is_module_text(addr))
89137 + return 0;
89138 +#endif
89139 +
89140 if (all_var)
89141 return is_kernel(addr);
89142
89143 @@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
89144
89145 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
89146 {
89147 - iter->name[0] = '\0';
89148 iter->nameoff = get_symbol_offset(new_pos);
89149 iter->pos = new_pos;
89150 }
89151 @@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
89152 {
89153 struct kallsym_iter *iter = m->private;
89154
89155 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89156 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
89157 + return 0;
89158 +#endif
89159 +
89160 /* Some debugging symbols have no name. Ignore them. */
89161 if (!iter->name[0])
89162 return 0;
89163 @@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
89164 */
89165 type = iter->exported ? toupper(iter->type) :
89166 tolower(iter->type);
89167 +
89168 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
89169 type, iter->name, iter->module_name);
89170 } else
89171 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
89172 index 0aa69ea..a7fcafb 100644
89173 --- a/kernel/kcmp.c
89174 +++ b/kernel/kcmp.c
89175 @@ -100,6 +100,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
89176 struct task_struct *task1, *task2;
89177 int ret;
89178
89179 +#ifdef CONFIG_GRKERNSEC
89180 + return -ENOSYS;
89181 +#endif
89182 +
89183 rcu_read_lock();
89184
89185 /*
89186 diff --git a/kernel/kexec.c b/kernel/kexec.c
89187 index 2abf9f6..c40cf85 100644
89188 --- a/kernel/kexec.c
89189 +++ b/kernel/kexec.c
89190 @@ -1349,7 +1349,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
89191 compat_ulong_t, flags)
89192 {
89193 struct compat_kexec_segment in;
89194 - struct kexec_segment out, __user *ksegments;
89195 + struct kexec_segment out;
89196 + struct kexec_segment __user *ksegments;
89197 unsigned long i, result;
89198
89199 /* Don't allow clients that don't understand the native
89200 diff --git a/kernel/kmod.c b/kernel/kmod.c
89201 index 80f7a6d..3c476d3 100644
89202 --- a/kernel/kmod.c
89203 +++ b/kernel/kmod.c
89204 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
89205 kfree(info->argv);
89206 }
89207
89208 -static int call_modprobe(char *module_name, int wait)
89209 +static int call_modprobe(char *module_name, char *module_param, int wait)
89210 {
89211 struct subprocess_info *info;
89212 static char *envp[] = {
89213 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
89214 NULL
89215 };
89216
89217 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
89218 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
89219 if (!argv)
89220 goto out;
89221
89222 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
89223 argv[1] = "-q";
89224 argv[2] = "--";
89225 argv[3] = module_name; /* check free_modprobe_argv() */
89226 - argv[4] = NULL;
89227 + argv[4] = module_param;
89228 + argv[5] = NULL;
89229
89230 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
89231 NULL, free_modprobe_argv, NULL);
89232 @@ -129,9 +130,8 @@ out:
89233 * If module auto-loading support is disabled then this function
89234 * becomes a no-operation.
89235 */
89236 -int __request_module(bool wait, const char *fmt, ...)
89237 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
89238 {
89239 - va_list args;
89240 char module_name[MODULE_NAME_LEN];
89241 unsigned int max_modprobes;
89242 int ret;
89243 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
89244 if (!modprobe_path[0])
89245 return 0;
89246
89247 - va_start(args, fmt);
89248 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
89249 - va_end(args);
89250 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
89251 if (ret >= MODULE_NAME_LEN)
89252 return -ENAMETOOLONG;
89253
89254 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
89255 if (ret)
89256 return ret;
89257
89258 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
89259 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
89260 + /* hack to workaround consolekit/udisks stupidity */
89261 + read_lock(&tasklist_lock);
89262 + if (!strcmp(current->comm, "mount") &&
89263 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
89264 + read_unlock(&tasklist_lock);
89265 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
89266 + return -EPERM;
89267 + }
89268 + read_unlock(&tasklist_lock);
89269 + }
89270 +#endif
89271 +
89272 /* If modprobe needs a service that is in a module, we get a recursive
89273 * loop. Limit the number of running kmod threads to max_threads/2 or
89274 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
89275 @@ -188,16 +200,61 @@ int __request_module(bool wait, const char *fmt, ...)
89276
89277 trace_module_request(module_name, wait, _RET_IP_);
89278
89279 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
89280 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
89281
89282 atomic_dec(&kmod_concurrent);
89283 return ret;
89284 }
89285 +
89286 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
89287 +{
89288 + va_list args;
89289 + int ret;
89290 +
89291 + va_start(args, fmt);
89292 + ret = ____request_module(wait, module_param, fmt, args);
89293 + va_end(args);
89294 +
89295 + return ret;
89296 +}
89297 +
89298 +int __request_module(bool wait, const char *fmt, ...)
89299 +{
89300 + va_list args;
89301 + int ret;
89302 +
89303 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
89304 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
89305 + char module_param[MODULE_NAME_LEN];
89306 +
89307 + memset(module_param, 0, sizeof(module_param));
89308 +
89309 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
89310 +
89311 + va_start(args, fmt);
89312 + ret = ____request_module(wait, module_param, fmt, args);
89313 + va_end(args);
89314 +
89315 + return ret;
89316 + }
89317 +#endif
89318 +
89319 + va_start(args, fmt);
89320 + ret = ____request_module(wait, NULL, fmt, args);
89321 + va_end(args);
89322 +
89323 + return ret;
89324 +}
89325 +
89326 EXPORT_SYMBOL(__request_module);
89327 #endif /* CONFIG_MODULES */
89328
89329 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
89330 {
89331 +#ifdef CONFIG_GRKERNSEC
89332 + kfree(info->path);
89333 + info->path = info->origpath;
89334 +#endif
89335 if (info->cleanup)
89336 (*info->cleanup)(info);
89337 kfree(info);
89338 @@ -240,6 +297,20 @@ static int ____call_usermodehelper(void *data)
89339 */
89340 set_user_nice(current, 0);
89341
89342 +#ifdef CONFIG_GRKERNSEC
89343 + /* this is race-free as far as userland is concerned as we copied
89344 + out the path to be used prior to this point and are now operating
89345 + on that copy
89346 + */
89347 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
89348 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
89349 + strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
89350 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
89351 + retval = -EPERM;
89352 + goto out;
89353 + }
89354 +#endif
89355 +
89356 retval = -ENOMEM;
89357 new = prepare_kernel_cred(current);
89358 if (!new)
89359 @@ -262,8 +333,8 @@ static int ____call_usermodehelper(void *data)
89360 commit_creds(new);
89361
89362 retval = do_execve(getname_kernel(sub_info->path),
89363 - (const char __user *const __user *)sub_info->argv,
89364 - (const char __user *const __user *)sub_info->envp);
89365 + (const char __user *const __force_user *)sub_info->argv,
89366 + (const char __user *const __force_user *)sub_info->envp);
89367 out:
89368 sub_info->retval = retval;
89369 /* wait_for_helper() will call umh_complete if UHM_WAIT_PROC. */
89370 @@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
89371 *
89372 * Thus the __user pointer cast is valid here.
89373 */
89374 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
89375 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
89376
89377 /*
89378 * If ret is 0, either ____call_usermodehelper failed and the
89379 @@ -532,7 +603,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
89380 goto out;
89381
89382 INIT_WORK(&sub_info->work, __call_usermodehelper);
89383 +#ifdef CONFIG_GRKERNSEC
89384 + sub_info->origpath = path;
89385 + sub_info->path = kstrdup(path, gfp_mask);
89386 +#else
89387 sub_info->path = path;
89388 +#endif
89389 sub_info->argv = argv;
89390 sub_info->envp = envp;
89391
89392 @@ -645,7 +721,7 @@ EXPORT_SYMBOL(call_usermodehelper);
89393 static int proc_cap_handler(struct ctl_table *table, int write,
89394 void __user *buffer, size_t *lenp, loff_t *ppos)
89395 {
89396 - struct ctl_table t;
89397 + ctl_table_no_const t;
89398 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
89399 kernel_cap_t new_cap;
89400 int err, i;
89401 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
89402 index 3995f54..e247879 100644
89403 --- a/kernel/kprobes.c
89404 +++ b/kernel/kprobes.c
89405 @@ -31,6 +31,9 @@
89406 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
89407 * <prasanna@in.ibm.com> added function-return probes.
89408 */
89409 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89410 +#define __INCLUDED_BY_HIDESYM 1
89411 +#endif
89412 #include <linux/kprobes.h>
89413 #include <linux/hash.h>
89414 #include <linux/init.h>
89415 @@ -122,12 +125,12 @@ enum kprobe_slot_state {
89416
89417 static void *alloc_insn_page(void)
89418 {
89419 - return module_alloc(PAGE_SIZE);
89420 + return module_alloc_exec(PAGE_SIZE);
89421 }
89422
89423 static void free_insn_page(void *page)
89424 {
89425 - module_free(NULL, page);
89426 + module_free_exec(NULL, page);
89427 }
89428
89429 struct kprobe_insn_cache kprobe_insn_slots = {
89430 @@ -2187,11 +2190,11 @@ static void report_probe(struct seq_file *pi, struct kprobe *p,
89431 kprobe_type = "k";
89432
89433 if (sym)
89434 - seq_printf(pi, "%p %s %s+0x%x %s ",
89435 + seq_printf(pi, "%pK %s %s+0x%x %s ",
89436 p->addr, kprobe_type, sym, offset,
89437 (modname ? modname : " "));
89438 else
89439 - seq_printf(pi, "%p %s %p ",
89440 + seq_printf(pi, "%pK %s %pK ",
89441 p->addr, kprobe_type, p->addr);
89442
89443 if (!pp)
89444 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
89445 index 6683cce..daf8999 100644
89446 --- a/kernel/ksysfs.c
89447 +++ b/kernel/ksysfs.c
89448 @@ -50,6 +50,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
89449 {
89450 if (count+1 > UEVENT_HELPER_PATH_LEN)
89451 return -ENOENT;
89452 + if (!capable(CAP_SYS_ADMIN))
89453 + return -EPERM;
89454 memcpy(uevent_helper, buf, count);
89455 uevent_helper[count] = '\0';
89456 if (count && uevent_helper[count-1] == '\n')
89457 @@ -176,7 +178,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
89458 return count;
89459 }
89460
89461 -static struct bin_attribute notes_attr = {
89462 +static bin_attribute_no_const notes_attr __read_only = {
89463 .attr = {
89464 .name = "notes",
89465 .mode = S_IRUGO,
89466 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
89467 index 88d0d44..e9ce0ee 100644
89468 --- a/kernel/locking/lockdep.c
89469 +++ b/kernel/locking/lockdep.c
89470 @@ -599,6 +599,10 @@ static int static_obj(void *obj)
89471 end = (unsigned long) &_end,
89472 addr = (unsigned long) obj;
89473
89474 +#ifdef CONFIG_PAX_KERNEXEC
89475 + start = ktla_ktva(start);
89476 +#endif
89477 +
89478 /*
89479 * static variable?
89480 */
89481 @@ -740,6 +744,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
89482 if (!static_obj(lock->key)) {
89483 debug_locks_off();
89484 printk("INFO: trying to register non-static key.\n");
89485 + printk("lock:%pS key:%pS.\n", lock, lock->key);
89486 printk("the code is fine but needs lockdep annotation.\n");
89487 printk("turning off the locking correctness validator.\n");
89488 dump_stack();
89489 @@ -3081,7 +3086,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
89490 if (!class)
89491 return 0;
89492 }
89493 - atomic_inc((atomic_t *)&class->ops);
89494 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
89495 if (very_verbose(class)) {
89496 printk("\nacquire class [%p] %s", class->key, class->name);
89497 if (class->name_version > 1)
89498 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
89499 index ef43ac4..2720dfa 100644
89500 --- a/kernel/locking/lockdep_proc.c
89501 +++ b/kernel/locking/lockdep_proc.c
89502 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
89503 return 0;
89504 }
89505
89506 - seq_printf(m, "%p", class->key);
89507 + seq_printf(m, "%pK", class->key);
89508 #ifdef CONFIG_DEBUG_LOCKDEP
89509 seq_printf(m, " OPS:%8ld", class->ops);
89510 #endif
89511 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
89512
89513 list_for_each_entry(entry, &class->locks_after, entry) {
89514 if (entry->distance == 1) {
89515 - seq_printf(m, " -> [%p] ", entry->class->key);
89516 + seq_printf(m, " -> [%pK] ", entry->class->key);
89517 print_name(m, entry->class);
89518 seq_puts(m, "\n");
89519 }
89520 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
89521 if (!class->key)
89522 continue;
89523
89524 - seq_printf(m, "[%p] ", class->key);
89525 + seq_printf(m, "[%pK] ", class->key);
89526 print_name(m, class);
89527 seq_puts(m, "\n");
89528 }
89529 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
89530 if (!i)
89531 seq_line(m, '-', 40-namelen, namelen);
89532
89533 - snprintf(ip, sizeof(ip), "[<%p>]",
89534 + snprintf(ip, sizeof(ip), "[<%pK>]",
89535 (void *)class->contention_point[i]);
89536 seq_printf(m, "%40s %14lu %29s %pS\n",
89537 name, stats->contention_point[i],
89538 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
89539 if (!i)
89540 seq_line(m, '-', 40-namelen, namelen);
89541
89542 - snprintf(ip, sizeof(ip), "[<%p>]",
89543 + snprintf(ip, sizeof(ip), "[<%pK>]",
89544 (void *)class->contending_point[i]);
89545 seq_printf(m, "%40s %14lu %29s %pS\n",
89546 name, stats->contending_point[i],
89547 diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
89548 index 9887a90..0cd2b1d 100644
89549 --- a/kernel/locking/mcs_spinlock.c
89550 +++ b/kernel/locking/mcs_spinlock.c
89551 @@ -100,7 +100,7 @@ bool osq_lock(struct optimistic_spin_queue *lock)
89552
89553 prev = decode_cpu(old);
89554 node->prev = prev;
89555 - ACCESS_ONCE(prev->next) = node;
89556 + ACCESS_ONCE_RW(prev->next) = node;
89557
89558 /*
89559 * Normally @prev is untouchable after the above store; because at that
89560 @@ -172,8 +172,8 @@ unqueue:
89561 * it will wait in Step-A.
89562 */
89563
89564 - ACCESS_ONCE(next->prev) = prev;
89565 - ACCESS_ONCE(prev->next) = next;
89566 + ACCESS_ONCE_RW(next->prev) = prev;
89567 + ACCESS_ONCE_RW(prev->next) = next;
89568
89569 return false;
89570 }
89571 @@ -195,13 +195,13 @@ void osq_unlock(struct optimistic_spin_queue *lock)
89572 node = this_cpu_ptr(&osq_node);
89573 next = xchg(&node->next, NULL);
89574 if (next) {
89575 - ACCESS_ONCE(next->locked) = 1;
89576 + ACCESS_ONCE_RW(next->locked) = 1;
89577 return;
89578 }
89579
89580 next = osq_wait_next(lock, node, NULL);
89581 if (next)
89582 - ACCESS_ONCE(next->locked) = 1;
89583 + ACCESS_ONCE_RW(next->locked) = 1;
89584 }
89585
89586 #endif
89587 diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
89588 index 4d60986..5d351c1 100644
89589 --- a/kernel/locking/mcs_spinlock.h
89590 +++ b/kernel/locking/mcs_spinlock.h
89591 @@ -78,7 +78,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
89592 */
89593 return;
89594 }
89595 - ACCESS_ONCE(prev->next) = node;
89596 + ACCESS_ONCE_RW(prev->next) = node;
89597
89598 /* Wait until the lock holder passes the lock down. */
89599 arch_mcs_spin_lock_contended(&node->locked);
89600 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
89601 index 5cf6731..ce3bc5a 100644
89602 --- a/kernel/locking/mutex-debug.c
89603 +++ b/kernel/locking/mutex-debug.c
89604 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
89605 }
89606
89607 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
89608 - struct thread_info *ti)
89609 + struct task_struct *task)
89610 {
89611 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
89612
89613 /* Mark the current thread as blocked on the lock: */
89614 - ti->task->blocked_on = waiter;
89615 + task->blocked_on = waiter;
89616 }
89617
89618 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
89619 - struct thread_info *ti)
89620 + struct task_struct *task)
89621 {
89622 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
89623 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
89624 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
89625 - ti->task->blocked_on = NULL;
89626 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
89627 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
89628 + task->blocked_on = NULL;
89629
89630 list_del_init(&waiter->list);
89631 waiter->task = NULL;
89632 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
89633 index 0799fd3..d06ae3b 100644
89634 --- a/kernel/locking/mutex-debug.h
89635 +++ b/kernel/locking/mutex-debug.h
89636 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
89637 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
89638 extern void debug_mutex_add_waiter(struct mutex *lock,
89639 struct mutex_waiter *waiter,
89640 - struct thread_info *ti);
89641 + struct task_struct *task);
89642 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
89643 - struct thread_info *ti);
89644 + struct task_struct *task);
89645 extern void debug_mutex_unlock(struct mutex *lock);
89646 extern void debug_mutex_init(struct mutex *lock, const char *name,
89647 struct lock_class_key *key);
89648 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
89649 index dadbf88..4500507 100644
89650 --- a/kernel/locking/mutex.c
89651 +++ b/kernel/locking/mutex.c
89652 @@ -518,7 +518,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
89653 goto skip_wait;
89654
89655 debug_mutex_lock_common(lock, &waiter);
89656 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
89657 + debug_mutex_add_waiter(lock, &waiter, task);
89658
89659 /* add waiting tasks to the end of the waitqueue (FIFO): */
89660 list_add_tail(&waiter.list, &lock->wait_list);
89661 @@ -563,7 +563,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
89662 schedule_preempt_disabled();
89663 spin_lock_mutex(&lock->wait_lock, flags);
89664 }
89665 - mutex_remove_waiter(lock, &waiter, current_thread_info());
89666 + mutex_remove_waiter(lock, &waiter, task);
89667 /* set it to 0 if there are no waiters left: */
89668 if (likely(list_empty(&lock->wait_list)))
89669 atomic_set(&lock->count, 0);
89670 @@ -600,7 +600,7 @@ skip_wait:
89671 return 0;
89672
89673 err:
89674 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
89675 + mutex_remove_waiter(lock, &waiter, task);
89676 spin_unlock_mutex(&lock->wait_lock, flags);
89677 debug_mutex_free_waiter(&waiter);
89678 mutex_release(&lock->dep_map, 1, ip);
89679 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
89680 index 1d96dd0..994ff19 100644
89681 --- a/kernel/locking/rtmutex-tester.c
89682 +++ b/kernel/locking/rtmutex-tester.c
89683 @@ -22,7 +22,7 @@
89684 #define MAX_RT_TEST_MUTEXES 8
89685
89686 static spinlock_t rttest_lock;
89687 -static atomic_t rttest_event;
89688 +static atomic_unchecked_t rttest_event;
89689
89690 struct test_thread_data {
89691 int opcode;
89692 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
89693
89694 case RTTEST_LOCKCONT:
89695 td->mutexes[td->opdata] = 1;
89696 - td->event = atomic_add_return(1, &rttest_event);
89697 + td->event = atomic_add_return_unchecked(1, &rttest_event);
89698 return 0;
89699
89700 case RTTEST_RESET:
89701 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
89702 return 0;
89703
89704 case RTTEST_RESETEVENT:
89705 - atomic_set(&rttest_event, 0);
89706 + atomic_set_unchecked(&rttest_event, 0);
89707 return 0;
89708
89709 default:
89710 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
89711 return ret;
89712
89713 td->mutexes[id] = 1;
89714 - td->event = atomic_add_return(1, &rttest_event);
89715 + td->event = atomic_add_return_unchecked(1, &rttest_event);
89716 rt_mutex_lock(&mutexes[id]);
89717 - td->event = atomic_add_return(1, &rttest_event);
89718 + td->event = atomic_add_return_unchecked(1, &rttest_event);
89719 td->mutexes[id] = 4;
89720 return 0;
89721
89722 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
89723 return ret;
89724
89725 td->mutexes[id] = 1;
89726 - td->event = atomic_add_return(1, &rttest_event);
89727 + td->event = atomic_add_return_unchecked(1, &rttest_event);
89728 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
89729 - td->event = atomic_add_return(1, &rttest_event);
89730 + td->event = atomic_add_return_unchecked(1, &rttest_event);
89731 td->mutexes[id] = ret ? 0 : 4;
89732 return ret ? -EINTR : 0;
89733
89734 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
89735 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
89736 return ret;
89737
89738 - td->event = atomic_add_return(1, &rttest_event);
89739 + td->event = atomic_add_return_unchecked(1, &rttest_event);
89740 rt_mutex_unlock(&mutexes[id]);
89741 - td->event = atomic_add_return(1, &rttest_event);
89742 + td->event = atomic_add_return_unchecked(1, &rttest_event);
89743 td->mutexes[id] = 0;
89744 return 0;
89745
89746 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
89747 break;
89748
89749 td->mutexes[dat] = 2;
89750 - td->event = atomic_add_return(1, &rttest_event);
89751 + td->event = atomic_add_return_unchecked(1, &rttest_event);
89752 break;
89753
89754 default:
89755 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
89756 return;
89757
89758 td->mutexes[dat] = 3;
89759 - td->event = atomic_add_return(1, &rttest_event);
89760 + td->event = atomic_add_return_unchecked(1, &rttest_event);
89761 break;
89762
89763 case RTTEST_LOCKNOWAIT:
89764 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
89765 return;
89766
89767 td->mutexes[dat] = 1;
89768 - td->event = atomic_add_return(1, &rttest_event);
89769 + td->event = atomic_add_return_unchecked(1, &rttest_event);
89770 return;
89771
89772 default:
89773 diff --git a/kernel/module.c b/kernel/module.c
89774 index 88cec1d..d097c28 100644
89775 --- a/kernel/module.c
89776 +++ b/kernel/module.c
89777 @@ -60,6 +60,7 @@
89778 #include <linux/jump_label.h>
89779 #include <linux/pfn.h>
89780 #include <linux/bsearch.h>
89781 +#include <linux/grsecurity.h>
89782 #include <uapi/linux/module.h>
89783 #include "module-internal.h"
89784
89785 @@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
89786
89787 /* Bounds of module allocation, for speeding __module_address.
89788 * Protected by module_mutex. */
89789 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
89790 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
89791 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
89792
89793 int register_module_notifier(struct notifier_block * nb)
89794 {
89795 @@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
89796 return true;
89797
89798 list_for_each_entry_rcu(mod, &modules, list) {
89799 - struct symsearch arr[] = {
89800 + struct symsearch modarr[] = {
89801 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
89802 NOT_GPL_ONLY, false },
89803 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
89804 @@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
89805 if (mod->state == MODULE_STATE_UNFORMED)
89806 continue;
89807
89808 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
89809 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
89810 return true;
89811 }
89812 return false;
89813 @@ -488,7 +490,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
89814 if (!pcpusec->sh_size)
89815 return 0;
89816
89817 - if (align > PAGE_SIZE) {
89818 + if (align-1 >= PAGE_SIZE) {
89819 pr_warn("%s: per-cpu alignment %li > %li\n",
89820 mod->name, align, PAGE_SIZE);
89821 align = PAGE_SIZE;
89822 @@ -1060,7 +1062,7 @@ struct module_attribute module_uevent =
89823 static ssize_t show_coresize(struct module_attribute *mattr,
89824 struct module_kobject *mk, char *buffer)
89825 {
89826 - return sprintf(buffer, "%u\n", mk->mod->core_size);
89827 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
89828 }
89829
89830 static struct module_attribute modinfo_coresize =
89831 @@ -1069,7 +1071,7 @@ static struct module_attribute modinfo_coresize =
89832 static ssize_t show_initsize(struct module_attribute *mattr,
89833 struct module_kobject *mk, char *buffer)
89834 {
89835 - return sprintf(buffer, "%u\n", mk->mod->init_size);
89836 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
89837 }
89838
89839 static struct module_attribute modinfo_initsize =
89840 @@ -1161,12 +1163,29 @@ static int check_version(Elf_Shdr *sechdrs,
89841 goto bad_version;
89842 }
89843
89844 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
89845 + /*
89846 + * avoid potentially printing jibberish on attempted load
89847 + * of a module randomized with a different seed
89848 + */
89849 + pr_warn("no symbol version for %s\n", symname);
89850 +#else
89851 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
89852 +#endif
89853 return 0;
89854
89855 bad_version:
89856 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
89857 + /*
89858 + * avoid potentially printing jibberish on attempted load
89859 + * of a module randomized with a different seed
89860 + */
89861 + printk("attempted module disagrees about version of symbol %s\n",
89862 + symname);
89863 +#else
89864 printk("%s: disagrees about version of symbol %s\n",
89865 mod->name, symname);
89866 +#endif
89867 return 0;
89868 }
89869
89870 @@ -1282,7 +1301,7 @@ resolve_symbol_wait(struct module *mod,
89871 */
89872 #ifdef CONFIG_SYSFS
89873
89874 -#ifdef CONFIG_KALLSYMS
89875 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
89876 static inline bool sect_empty(const Elf_Shdr *sect)
89877 {
89878 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
89879 @@ -1422,7 +1441,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
89880 {
89881 unsigned int notes, loaded, i;
89882 struct module_notes_attrs *notes_attrs;
89883 - struct bin_attribute *nattr;
89884 + bin_attribute_no_const *nattr;
89885
89886 /* failed to create section attributes, so can't create notes */
89887 if (!mod->sect_attrs)
89888 @@ -1534,7 +1553,7 @@ static void del_usage_links(struct module *mod)
89889 static int module_add_modinfo_attrs(struct module *mod)
89890 {
89891 struct module_attribute *attr;
89892 - struct module_attribute *temp_attr;
89893 + module_attribute_no_const *temp_attr;
89894 int error = 0;
89895 int i;
89896
89897 @@ -1755,21 +1774,21 @@ static void set_section_ro_nx(void *base,
89898
89899 static void unset_module_core_ro_nx(struct module *mod)
89900 {
89901 - set_page_attributes(mod->module_core + mod->core_text_size,
89902 - mod->module_core + mod->core_size,
89903 + set_page_attributes(mod->module_core_rw,
89904 + mod->module_core_rw + mod->core_size_rw,
89905 set_memory_x);
89906 - set_page_attributes(mod->module_core,
89907 - mod->module_core + mod->core_ro_size,
89908 + set_page_attributes(mod->module_core_rx,
89909 + mod->module_core_rx + mod->core_size_rx,
89910 set_memory_rw);
89911 }
89912
89913 static void unset_module_init_ro_nx(struct module *mod)
89914 {
89915 - set_page_attributes(mod->module_init + mod->init_text_size,
89916 - mod->module_init + mod->init_size,
89917 + set_page_attributes(mod->module_init_rw,
89918 + mod->module_init_rw + mod->init_size_rw,
89919 set_memory_x);
89920 - set_page_attributes(mod->module_init,
89921 - mod->module_init + mod->init_ro_size,
89922 + set_page_attributes(mod->module_init_rx,
89923 + mod->module_init_rx + mod->init_size_rx,
89924 set_memory_rw);
89925 }
89926
89927 @@ -1782,14 +1801,14 @@ void set_all_modules_text_rw(void)
89928 list_for_each_entry_rcu(mod, &modules, list) {
89929 if (mod->state == MODULE_STATE_UNFORMED)
89930 continue;
89931 - if ((mod->module_core) && (mod->core_text_size)) {
89932 - set_page_attributes(mod->module_core,
89933 - mod->module_core + mod->core_text_size,
89934 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
89935 + set_page_attributes(mod->module_core_rx,
89936 + mod->module_core_rx + mod->core_size_rx,
89937 set_memory_rw);
89938 }
89939 - if ((mod->module_init) && (mod->init_text_size)) {
89940 - set_page_attributes(mod->module_init,
89941 - mod->module_init + mod->init_text_size,
89942 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
89943 + set_page_attributes(mod->module_init_rx,
89944 + mod->module_init_rx + mod->init_size_rx,
89945 set_memory_rw);
89946 }
89947 }
89948 @@ -1805,14 +1824,14 @@ void set_all_modules_text_ro(void)
89949 list_for_each_entry_rcu(mod, &modules, list) {
89950 if (mod->state == MODULE_STATE_UNFORMED)
89951 continue;
89952 - if ((mod->module_core) && (mod->core_text_size)) {
89953 - set_page_attributes(mod->module_core,
89954 - mod->module_core + mod->core_text_size,
89955 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
89956 + set_page_attributes(mod->module_core_rx,
89957 + mod->module_core_rx + mod->core_size_rx,
89958 set_memory_ro);
89959 }
89960 - if ((mod->module_init) && (mod->init_text_size)) {
89961 - set_page_attributes(mod->module_init,
89962 - mod->module_init + mod->init_text_size,
89963 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
89964 + set_page_attributes(mod->module_init_rx,
89965 + mod->module_init_rx + mod->init_size_rx,
89966 set_memory_ro);
89967 }
89968 }
89969 @@ -1865,16 +1884,19 @@ static void free_module(struct module *mod)
89970
89971 /* This may be NULL, but that's OK */
89972 unset_module_init_ro_nx(mod);
89973 - module_free(mod, mod->module_init);
89974 + module_free(mod, mod->module_init_rw);
89975 + module_free_exec(mod, mod->module_init_rx);
89976 kfree(mod->args);
89977 percpu_modfree(mod);
89978
89979 /* Free lock-classes: */
89980 - lockdep_free_key_range(mod->module_core, mod->core_size);
89981 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
89982 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
89983
89984 /* Finally, free the core (containing the module structure) */
89985 unset_module_core_ro_nx(mod);
89986 - module_free(mod, mod->module_core);
89987 + module_free_exec(mod, mod->module_core_rx);
89988 + module_free(mod, mod->module_core_rw);
89989
89990 #ifdef CONFIG_MPU
89991 update_protections(current->mm);
89992 @@ -1943,9 +1965,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
89993 int ret = 0;
89994 const struct kernel_symbol *ksym;
89995
89996 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
89997 + int is_fs_load = 0;
89998 + int register_filesystem_found = 0;
89999 + char *p;
90000 +
90001 + p = strstr(mod->args, "grsec_modharden_fs");
90002 + if (p) {
90003 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
90004 + /* copy \0 as well */
90005 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
90006 + is_fs_load = 1;
90007 + }
90008 +#endif
90009 +
90010 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
90011 const char *name = info->strtab + sym[i].st_name;
90012
90013 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90014 + /* it's a real shame this will never get ripped and copied
90015 + upstream! ;(
90016 + */
90017 + if (is_fs_load && !strcmp(name, "register_filesystem"))
90018 + register_filesystem_found = 1;
90019 +#endif
90020 +
90021 switch (sym[i].st_shndx) {
90022 case SHN_COMMON:
90023 /* Ignore common symbols */
90024 @@ -1970,7 +2014,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90025 ksym = resolve_symbol_wait(mod, info, name);
90026 /* Ok if resolved. */
90027 if (ksym && !IS_ERR(ksym)) {
90028 + pax_open_kernel();
90029 sym[i].st_value = ksym->value;
90030 + pax_close_kernel();
90031 break;
90032 }
90033
90034 @@ -1989,11 +2035,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90035 secbase = (unsigned long)mod_percpu(mod);
90036 else
90037 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
90038 + pax_open_kernel();
90039 sym[i].st_value += secbase;
90040 + pax_close_kernel();
90041 break;
90042 }
90043 }
90044
90045 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90046 + if (is_fs_load && !register_filesystem_found) {
90047 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
90048 + ret = -EPERM;
90049 + }
90050 +#endif
90051 +
90052 return ret;
90053 }
90054
90055 @@ -2077,22 +2132,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
90056 || s->sh_entsize != ~0UL
90057 || strstarts(sname, ".init"))
90058 continue;
90059 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
90060 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
90061 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
90062 + else
90063 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
90064 pr_debug("\t%s\n", sname);
90065 }
90066 - switch (m) {
90067 - case 0: /* executable */
90068 - mod->core_size = debug_align(mod->core_size);
90069 - mod->core_text_size = mod->core_size;
90070 - break;
90071 - case 1: /* RO: text and ro-data */
90072 - mod->core_size = debug_align(mod->core_size);
90073 - mod->core_ro_size = mod->core_size;
90074 - break;
90075 - case 3: /* whole core */
90076 - mod->core_size = debug_align(mod->core_size);
90077 - break;
90078 - }
90079 }
90080
90081 pr_debug("Init section allocation order:\n");
90082 @@ -2106,23 +2151,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
90083 || s->sh_entsize != ~0UL
90084 || !strstarts(sname, ".init"))
90085 continue;
90086 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
90087 - | INIT_OFFSET_MASK);
90088 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
90089 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
90090 + else
90091 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
90092 + s->sh_entsize |= INIT_OFFSET_MASK;
90093 pr_debug("\t%s\n", sname);
90094 }
90095 - switch (m) {
90096 - case 0: /* executable */
90097 - mod->init_size = debug_align(mod->init_size);
90098 - mod->init_text_size = mod->init_size;
90099 - break;
90100 - case 1: /* RO: text and ro-data */
90101 - mod->init_size = debug_align(mod->init_size);
90102 - mod->init_ro_size = mod->init_size;
90103 - break;
90104 - case 3: /* whole init */
90105 - mod->init_size = debug_align(mod->init_size);
90106 - break;
90107 - }
90108 }
90109 }
90110
90111 @@ -2295,7 +2330,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
90112
90113 /* Put symbol section at end of init part of module. */
90114 symsect->sh_flags |= SHF_ALLOC;
90115 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
90116 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
90117 info->index.sym) | INIT_OFFSET_MASK;
90118 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
90119
90120 @@ -2312,13 +2347,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
90121 }
90122
90123 /* Append room for core symbols at end of core part. */
90124 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
90125 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
90126 - mod->core_size += strtab_size;
90127 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
90128 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
90129 + mod->core_size_rx += strtab_size;
90130
90131 /* Put string table section at end of init part of module. */
90132 strsect->sh_flags |= SHF_ALLOC;
90133 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
90134 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
90135 info->index.str) | INIT_OFFSET_MASK;
90136 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
90137 }
90138 @@ -2336,12 +2371,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
90139 /* Make sure we get permanent strtab: don't use info->strtab. */
90140 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
90141
90142 + pax_open_kernel();
90143 +
90144 /* Set types up while we still have access to sections. */
90145 for (i = 0; i < mod->num_symtab; i++)
90146 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
90147
90148 - mod->core_symtab = dst = mod->module_core + info->symoffs;
90149 - mod->core_strtab = s = mod->module_core + info->stroffs;
90150 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
90151 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
90152 src = mod->symtab;
90153 for (ndst = i = 0; i < mod->num_symtab; i++) {
90154 if (i == 0 ||
90155 @@ -2353,6 +2390,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
90156 }
90157 }
90158 mod->core_num_syms = ndst;
90159 +
90160 + pax_close_kernel();
90161 }
90162 #else
90163 static inline void layout_symtab(struct module *mod, struct load_info *info)
90164 @@ -2386,17 +2425,33 @@ void * __weak module_alloc(unsigned long size)
90165 return vmalloc_exec(size);
90166 }
90167
90168 -static void *module_alloc_update_bounds(unsigned long size)
90169 +static void *module_alloc_update_bounds_rw(unsigned long size)
90170 {
90171 void *ret = module_alloc(size);
90172
90173 if (ret) {
90174 mutex_lock(&module_mutex);
90175 /* Update module bounds. */
90176 - if ((unsigned long)ret < module_addr_min)
90177 - module_addr_min = (unsigned long)ret;
90178 - if ((unsigned long)ret + size > module_addr_max)
90179 - module_addr_max = (unsigned long)ret + size;
90180 + if ((unsigned long)ret < module_addr_min_rw)
90181 + module_addr_min_rw = (unsigned long)ret;
90182 + if ((unsigned long)ret + size > module_addr_max_rw)
90183 + module_addr_max_rw = (unsigned long)ret + size;
90184 + mutex_unlock(&module_mutex);
90185 + }
90186 + return ret;
90187 +}
90188 +
90189 +static void *module_alloc_update_bounds_rx(unsigned long size)
90190 +{
90191 + void *ret = module_alloc_exec(size);
90192 +
90193 + if (ret) {
90194 + mutex_lock(&module_mutex);
90195 + /* Update module bounds. */
90196 + if ((unsigned long)ret < module_addr_min_rx)
90197 + module_addr_min_rx = (unsigned long)ret;
90198 + if ((unsigned long)ret + size > module_addr_max_rx)
90199 + module_addr_max_rx = (unsigned long)ret + size;
90200 mutex_unlock(&module_mutex);
90201 }
90202 return ret;
90203 @@ -2650,7 +2705,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
90204 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
90205
90206 if (info->index.sym == 0) {
90207 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90208 + /*
90209 + * avoid potentially printing jibberish on attempted load
90210 + * of a module randomized with a different seed
90211 + */
90212 + pr_warn("module has no symbols (stripped?)\n");
90213 +#else
90214 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
90215 +#endif
90216 return ERR_PTR(-ENOEXEC);
90217 }
90218
90219 @@ -2666,8 +2729,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
90220 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
90221 {
90222 const char *modmagic = get_modinfo(info, "vermagic");
90223 + const char *license = get_modinfo(info, "license");
90224 int err;
90225
90226 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
90227 + if (!license || !license_is_gpl_compatible(license))
90228 + return -ENOEXEC;
90229 +#endif
90230 +
90231 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
90232 modmagic = NULL;
90233
90234 @@ -2692,7 +2761,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
90235 }
90236
90237 /* Set up license info based on the info section */
90238 - set_license(mod, get_modinfo(info, "license"));
90239 + set_license(mod, license);
90240
90241 return 0;
90242 }
90243 @@ -2786,7 +2855,7 @@ static int move_module(struct module *mod, struct load_info *info)
90244 void *ptr;
90245
90246 /* Do the allocs. */
90247 - ptr = module_alloc_update_bounds(mod->core_size);
90248 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
90249 /*
90250 * The pointer to this block is stored in the module structure
90251 * which is inside the block. Just mark it as not being a
90252 @@ -2796,11 +2865,11 @@ static int move_module(struct module *mod, struct load_info *info)
90253 if (!ptr)
90254 return -ENOMEM;
90255
90256 - memset(ptr, 0, mod->core_size);
90257 - mod->module_core = ptr;
90258 + memset(ptr, 0, mod->core_size_rw);
90259 + mod->module_core_rw = ptr;
90260
90261 - if (mod->init_size) {
90262 - ptr = module_alloc_update_bounds(mod->init_size);
90263 + if (mod->init_size_rw) {
90264 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
90265 /*
90266 * The pointer to this block is stored in the module structure
90267 * which is inside the block. This block doesn't need to be
90268 @@ -2809,13 +2878,45 @@ static int move_module(struct module *mod, struct load_info *info)
90269 */
90270 kmemleak_ignore(ptr);
90271 if (!ptr) {
90272 - module_free(mod, mod->module_core);
90273 + module_free(mod, mod->module_core_rw);
90274 return -ENOMEM;
90275 }
90276 - memset(ptr, 0, mod->init_size);
90277 - mod->module_init = ptr;
90278 + memset(ptr, 0, mod->init_size_rw);
90279 + mod->module_init_rw = ptr;
90280 } else
90281 - mod->module_init = NULL;
90282 + mod->module_init_rw = NULL;
90283 +
90284 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
90285 + kmemleak_not_leak(ptr);
90286 + if (!ptr) {
90287 + if (mod->module_init_rw)
90288 + module_free(mod, mod->module_init_rw);
90289 + module_free(mod, mod->module_core_rw);
90290 + return -ENOMEM;
90291 + }
90292 +
90293 + pax_open_kernel();
90294 + memset(ptr, 0, mod->core_size_rx);
90295 + pax_close_kernel();
90296 + mod->module_core_rx = ptr;
90297 +
90298 + if (mod->init_size_rx) {
90299 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
90300 + kmemleak_ignore(ptr);
90301 + if (!ptr && mod->init_size_rx) {
90302 + module_free_exec(mod, mod->module_core_rx);
90303 + if (mod->module_init_rw)
90304 + module_free(mod, mod->module_init_rw);
90305 + module_free(mod, mod->module_core_rw);
90306 + return -ENOMEM;
90307 + }
90308 +
90309 + pax_open_kernel();
90310 + memset(ptr, 0, mod->init_size_rx);
90311 + pax_close_kernel();
90312 + mod->module_init_rx = ptr;
90313 + } else
90314 + mod->module_init_rx = NULL;
90315
90316 /* Transfer each section which specifies SHF_ALLOC */
90317 pr_debug("final section addresses:\n");
90318 @@ -2826,16 +2927,45 @@ static int move_module(struct module *mod, struct load_info *info)
90319 if (!(shdr->sh_flags & SHF_ALLOC))
90320 continue;
90321
90322 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
90323 - dest = mod->module_init
90324 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
90325 - else
90326 - dest = mod->module_core + shdr->sh_entsize;
90327 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
90328 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
90329 + dest = mod->module_init_rw
90330 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
90331 + else
90332 + dest = mod->module_init_rx
90333 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
90334 + } else {
90335 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
90336 + dest = mod->module_core_rw + shdr->sh_entsize;
90337 + else
90338 + dest = mod->module_core_rx + shdr->sh_entsize;
90339 + }
90340 +
90341 + if (shdr->sh_type != SHT_NOBITS) {
90342 +
90343 +#ifdef CONFIG_PAX_KERNEXEC
90344 +#ifdef CONFIG_X86_64
90345 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
90346 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
90347 +#endif
90348 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
90349 + pax_open_kernel();
90350 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
90351 + pax_close_kernel();
90352 + } else
90353 +#endif
90354
90355 - if (shdr->sh_type != SHT_NOBITS)
90356 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
90357 + }
90358 /* Update sh_addr to point to copy in image. */
90359 - shdr->sh_addr = (unsigned long)dest;
90360 +
90361 +#ifdef CONFIG_PAX_KERNEXEC
90362 + if (shdr->sh_flags & SHF_EXECINSTR)
90363 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
90364 + else
90365 +#endif
90366 +
90367 + shdr->sh_addr = (unsigned long)dest;
90368 pr_debug("\t0x%lx %s\n",
90369 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
90370 }
90371 @@ -2892,12 +3022,12 @@ static void flush_module_icache(const struct module *mod)
90372 * Do it before processing of module parameters, so the module
90373 * can provide parameter accessor functions of its own.
90374 */
90375 - if (mod->module_init)
90376 - flush_icache_range((unsigned long)mod->module_init,
90377 - (unsigned long)mod->module_init
90378 - + mod->init_size);
90379 - flush_icache_range((unsigned long)mod->module_core,
90380 - (unsigned long)mod->module_core + mod->core_size);
90381 + if (mod->module_init_rx)
90382 + flush_icache_range((unsigned long)mod->module_init_rx,
90383 + (unsigned long)mod->module_init_rx
90384 + + mod->init_size_rx);
90385 + flush_icache_range((unsigned long)mod->module_core_rx,
90386 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
90387
90388 set_fs(old_fs);
90389 }
90390 @@ -2954,8 +3084,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
90391 static void module_deallocate(struct module *mod, struct load_info *info)
90392 {
90393 percpu_modfree(mod);
90394 - module_free(mod, mod->module_init);
90395 - module_free(mod, mod->module_core);
90396 + module_free_exec(mod, mod->module_init_rx);
90397 + module_free_exec(mod, mod->module_core_rx);
90398 + module_free(mod, mod->module_init_rw);
90399 + module_free(mod, mod->module_core_rw);
90400 }
90401
90402 int __weak module_finalize(const Elf_Ehdr *hdr,
90403 @@ -2968,7 +3100,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
90404 static int post_relocation(struct module *mod, const struct load_info *info)
90405 {
90406 /* Sort exception table now relocations are done. */
90407 + pax_open_kernel();
90408 sort_extable(mod->extable, mod->extable + mod->num_exentries);
90409 + pax_close_kernel();
90410
90411 /* Copy relocated percpu area over. */
90412 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
90413 @@ -3077,11 +3211,12 @@ static int do_init_module(struct module *mod)
90414 mod->strtab = mod->core_strtab;
90415 #endif
90416 unset_module_init_ro_nx(mod);
90417 - module_free(mod, mod->module_init);
90418 - mod->module_init = NULL;
90419 - mod->init_size = 0;
90420 - mod->init_ro_size = 0;
90421 - mod->init_text_size = 0;
90422 + module_free(mod, mod->module_init_rw);
90423 + module_free_exec(mod, mod->module_init_rx);
90424 + mod->module_init_rw = NULL;
90425 + mod->module_init_rx = NULL;
90426 + mod->init_size_rw = 0;
90427 + mod->init_size_rx = 0;
90428 mutex_unlock(&module_mutex);
90429 wake_up_all(&module_wq);
90430
90431 @@ -3149,16 +3284,16 @@ static int complete_formation(struct module *mod, struct load_info *info)
90432 module_bug_finalize(info->hdr, info->sechdrs, mod);
90433
90434 /* Set RO and NX regions for core */
90435 - set_section_ro_nx(mod->module_core,
90436 - mod->core_text_size,
90437 - mod->core_ro_size,
90438 - mod->core_size);
90439 + set_section_ro_nx(mod->module_core_rx,
90440 + mod->core_size_rx,
90441 + mod->core_size_rx,
90442 + mod->core_size_rx);
90443
90444 /* Set RO and NX regions for init */
90445 - set_section_ro_nx(mod->module_init,
90446 - mod->init_text_size,
90447 - mod->init_ro_size,
90448 - mod->init_size);
90449 + set_section_ro_nx(mod->module_init_rx,
90450 + mod->init_size_rx,
90451 + mod->init_size_rx,
90452 + mod->init_size_rx);
90453
90454 /* Mark state as coming so strong_try_module_get() ignores us,
90455 * but kallsyms etc. can see us. */
90456 @@ -3242,9 +3377,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
90457 if (err)
90458 goto free_unload;
90459
90460 + /* Now copy in args */
90461 + mod->args = strndup_user(uargs, ~0UL >> 1);
90462 + if (IS_ERR(mod->args)) {
90463 + err = PTR_ERR(mod->args);
90464 + goto free_unload;
90465 + }
90466 +
90467 /* Set up MODINFO_ATTR fields */
90468 setup_modinfo(mod, info);
90469
90470 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90471 + {
90472 + char *p, *p2;
90473 +
90474 + if (strstr(mod->args, "grsec_modharden_netdev")) {
90475 + 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);
90476 + err = -EPERM;
90477 + goto free_modinfo;
90478 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
90479 + p += sizeof("grsec_modharden_normal") - 1;
90480 + p2 = strstr(p, "_");
90481 + if (p2) {
90482 + *p2 = '\0';
90483 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
90484 + *p2 = '_';
90485 + }
90486 + err = -EPERM;
90487 + goto free_modinfo;
90488 + }
90489 + }
90490 +#endif
90491 +
90492 /* Fix up syms, so that st_value is a pointer to location. */
90493 err = simplify_symbols(mod, info);
90494 if (err < 0)
90495 @@ -3260,13 +3424,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
90496
90497 flush_module_icache(mod);
90498
90499 - /* Now copy in args */
90500 - mod->args = strndup_user(uargs, ~0UL >> 1);
90501 - if (IS_ERR(mod->args)) {
90502 - err = PTR_ERR(mod->args);
90503 - goto free_arch_cleanup;
90504 - }
90505 -
90506 dynamic_debug_setup(info->debug, info->num_debug);
90507
90508 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
90509 @@ -3314,11 +3471,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
90510 ddebug_cleanup:
90511 dynamic_debug_remove(info->debug);
90512 synchronize_sched();
90513 - kfree(mod->args);
90514 - free_arch_cleanup:
90515 module_arch_cleanup(mod);
90516 free_modinfo:
90517 free_modinfo(mod);
90518 + kfree(mod->args);
90519 free_unload:
90520 module_unload_free(mod);
90521 unlink_mod:
90522 @@ -3403,10 +3559,16 @@ static const char *get_ksymbol(struct module *mod,
90523 unsigned long nextval;
90524
90525 /* At worse, next value is at end of module */
90526 - if (within_module_init(addr, mod))
90527 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
90528 + if (within_module_init_rx(addr, mod))
90529 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
90530 + else if (within_module_init_rw(addr, mod))
90531 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
90532 + else if (within_module_core_rx(addr, mod))
90533 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
90534 + else if (within_module_core_rw(addr, mod))
90535 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
90536 else
90537 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
90538 + return NULL;
90539
90540 /* Scan for closest preceding symbol, and next symbol. (ELF
90541 starts real symbols at 1). */
90542 @@ -3654,7 +3816,7 @@ static int m_show(struct seq_file *m, void *p)
90543 return 0;
90544
90545 seq_printf(m, "%s %u",
90546 - mod->name, mod->init_size + mod->core_size);
90547 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
90548 print_unload_info(m, mod);
90549
90550 /* Informative for users. */
90551 @@ -3663,7 +3825,7 @@ static int m_show(struct seq_file *m, void *p)
90552 mod->state == MODULE_STATE_COMING ? "Loading":
90553 "Live");
90554 /* Used by oprofile and other similar tools. */
90555 - seq_printf(m, " 0x%pK", mod->module_core);
90556 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
90557
90558 /* Taints info */
90559 if (mod->taints)
90560 @@ -3699,7 +3861,17 @@ static const struct file_operations proc_modules_operations = {
90561
90562 static int __init proc_modules_init(void)
90563 {
90564 +#ifndef CONFIG_GRKERNSEC_HIDESYM
90565 +#ifdef CONFIG_GRKERNSEC_PROC_USER
90566 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
90567 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
90568 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
90569 +#else
90570 proc_create("modules", 0, NULL, &proc_modules_operations);
90571 +#endif
90572 +#else
90573 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
90574 +#endif
90575 return 0;
90576 }
90577 module_init(proc_modules_init);
90578 @@ -3760,7 +3932,8 @@ struct module *__module_address(unsigned long addr)
90579 {
90580 struct module *mod;
90581
90582 - if (addr < module_addr_min || addr > module_addr_max)
90583 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
90584 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
90585 return NULL;
90586
90587 list_for_each_entry_rcu(mod, &modules, list) {
90588 @@ -3801,11 +3974,20 @@ bool is_module_text_address(unsigned long addr)
90589 */
90590 struct module *__module_text_address(unsigned long addr)
90591 {
90592 - struct module *mod = __module_address(addr);
90593 + struct module *mod;
90594 +
90595 +#ifdef CONFIG_X86_32
90596 + addr = ktla_ktva(addr);
90597 +#endif
90598 +
90599 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
90600 + return NULL;
90601 +
90602 + mod = __module_address(addr);
90603 +
90604 if (mod) {
90605 /* Make sure it's within the text section. */
90606 - if (!within(addr, mod->module_init, mod->init_text_size)
90607 - && !within(addr, mod->module_core, mod->core_text_size))
90608 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
90609 mod = NULL;
90610 }
90611 return mod;
90612 diff --git a/kernel/notifier.c b/kernel/notifier.c
90613 index 4803da6..1c5eea6 100644
90614 --- a/kernel/notifier.c
90615 +++ b/kernel/notifier.c
90616 @@ -5,6 +5,7 @@
90617 #include <linux/rcupdate.h>
90618 #include <linux/vmalloc.h>
90619 #include <linux/reboot.h>
90620 +#include <linux/mm.h>
90621
90622 /*
90623 * Notifier list for kernel code which wants to be called
90624 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
90625 while ((*nl) != NULL) {
90626 if (n->priority > (*nl)->priority)
90627 break;
90628 - nl = &((*nl)->next);
90629 + nl = (struct notifier_block **)&((*nl)->next);
90630 }
90631 - n->next = *nl;
90632 + pax_open_kernel();
90633 + *(const void **)&n->next = *nl;
90634 rcu_assign_pointer(*nl, n);
90635 + pax_close_kernel();
90636 return 0;
90637 }
90638
90639 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
90640 return 0;
90641 if (n->priority > (*nl)->priority)
90642 break;
90643 - nl = &((*nl)->next);
90644 + nl = (struct notifier_block **)&((*nl)->next);
90645 }
90646 - n->next = *nl;
90647 + pax_open_kernel();
90648 + *(const void **)&n->next = *nl;
90649 rcu_assign_pointer(*nl, n);
90650 + pax_close_kernel();
90651 return 0;
90652 }
90653
90654 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
90655 {
90656 while ((*nl) != NULL) {
90657 if ((*nl) == n) {
90658 + pax_open_kernel();
90659 rcu_assign_pointer(*nl, n->next);
90660 + pax_close_kernel();
90661 return 0;
90662 }
90663 - nl = &((*nl)->next);
90664 + nl = (struct notifier_block **)&((*nl)->next);
90665 }
90666 return -ENOENT;
90667 }
90668 diff --git a/kernel/padata.c b/kernel/padata.c
90669 index 161402f..598814c 100644
90670 --- a/kernel/padata.c
90671 +++ b/kernel/padata.c
90672 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
90673 * seq_nr mod. number of cpus in use.
90674 */
90675
90676 - seq_nr = atomic_inc_return(&pd->seq_nr);
90677 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
90678 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
90679
90680 return padata_index_to_cpu(pd, cpu_index);
90681 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
90682 padata_init_pqueues(pd);
90683 padata_init_squeues(pd);
90684 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
90685 - atomic_set(&pd->seq_nr, -1);
90686 + atomic_set_unchecked(&pd->seq_nr, -1);
90687 atomic_set(&pd->reorder_objects, 0);
90688 atomic_set(&pd->refcnt, 0);
90689 pd->pinst = pinst;
90690 diff --git a/kernel/panic.c b/kernel/panic.c
90691 index cf80672..f6771b2 100644
90692 --- a/kernel/panic.c
90693 +++ b/kernel/panic.c
90694 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(panic_blink);
90695 /*
90696 * Stop ourself in panic -- architecture code may override this
90697 */
90698 -void __weak panic_smp_self_stop(void)
90699 +void __weak __noreturn panic_smp_self_stop(void)
90700 {
90701 while (1)
90702 cpu_relax();
90703 @@ -422,7 +422,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
90704 disable_trace_on_warning();
90705
90706 pr_warn("------------[ cut here ]------------\n");
90707 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
90708 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
90709 raw_smp_processor_id(), current->pid, file, line, caller);
90710
90711 if (args)
90712 @@ -476,7 +476,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
90713 */
90714 __visible void __stack_chk_fail(void)
90715 {
90716 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
90717 + dump_stack();
90718 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
90719 __builtin_return_address(0));
90720 }
90721 EXPORT_SYMBOL(__stack_chk_fail);
90722 diff --git a/kernel/pid.c b/kernel/pid.c
90723 index 9b9a266..c20ef80 100644
90724 --- a/kernel/pid.c
90725 +++ b/kernel/pid.c
90726 @@ -33,6 +33,7 @@
90727 #include <linux/rculist.h>
90728 #include <linux/bootmem.h>
90729 #include <linux/hash.h>
90730 +#include <linux/security.h>
90731 #include <linux/pid_namespace.h>
90732 #include <linux/init_task.h>
90733 #include <linux/syscalls.h>
90734 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
90735
90736 int pid_max = PID_MAX_DEFAULT;
90737
90738 -#define RESERVED_PIDS 300
90739 +#define RESERVED_PIDS 500
90740
90741 int pid_max_min = RESERVED_PIDS + 1;
90742 int pid_max_max = PID_MAX_LIMIT;
90743 @@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
90744 */
90745 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
90746 {
90747 + struct task_struct *task;
90748 +
90749 rcu_lockdep_assert(rcu_read_lock_held(),
90750 "find_task_by_pid_ns() needs rcu_read_lock()"
90751 " protection");
90752 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
90753 +
90754 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
90755 +
90756 + if (gr_pid_is_chrooted(task))
90757 + return NULL;
90758 +
90759 + return task;
90760 }
90761
90762 struct task_struct *find_task_by_vpid(pid_t vnr)
90763 @@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
90764 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
90765 }
90766
90767 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
90768 +{
90769 + rcu_lockdep_assert(rcu_read_lock_held(),
90770 + "find_task_by_pid_ns() needs rcu_read_lock()"
90771 + " protection");
90772 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
90773 +}
90774 +
90775 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
90776 {
90777 struct pid *pid;
90778 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
90779 index db95d8e..a0ca23f 100644
90780 --- a/kernel/pid_namespace.c
90781 +++ b/kernel/pid_namespace.c
90782 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
90783 void __user *buffer, size_t *lenp, loff_t *ppos)
90784 {
90785 struct pid_namespace *pid_ns = task_active_pid_ns(current);
90786 - struct ctl_table tmp = *table;
90787 + ctl_table_no_const tmp = *table;
90788
90789 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
90790 return -EPERM;
90791 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
90792 index bbef57f..5f94462 100644
90793 --- a/kernel/power/Kconfig
90794 +++ b/kernel/power/Kconfig
90795 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
90796 config HIBERNATION
90797 bool "Hibernation (aka 'suspend to disk')"
90798 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
90799 + depends on !GRKERNSEC_KMEM
90800 + depends on !PAX_MEMORY_SANITIZE
90801 select HIBERNATE_CALLBACKS
90802 select LZO_COMPRESS
90803 select LZO_DECOMPRESS
90804 diff --git a/kernel/power/process.c b/kernel/power/process.c
90805 index 5a6ec86..3a8c884 100644
90806 --- a/kernel/power/process.c
90807 +++ b/kernel/power/process.c
90808 @@ -35,6 +35,7 @@ static int try_to_freeze_tasks(bool user_only)
90809 unsigned int elapsed_msecs;
90810 bool wakeup = false;
90811 int sleep_usecs = USEC_PER_MSEC;
90812 + bool timedout = false;
90813
90814 do_gettimeofday(&start);
90815
90816 @@ -45,13 +46,20 @@ static int try_to_freeze_tasks(bool user_only)
90817
90818 while (true) {
90819 todo = 0;
90820 + if (time_after(jiffies, end_time))
90821 + timedout = true;
90822 read_lock(&tasklist_lock);
90823 for_each_process_thread(g, p) {
90824 if (p == current || !freeze_task(p))
90825 continue;
90826
90827 - if (!freezer_should_skip(p))
90828 + if (!freezer_should_skip(p)) {
90829 todo++;
90830 + if (timedout) {
90831 + printk(KERN_ERR "Task refusing to freeze:\n");
90832 + sched_show_task(p);
90833 + }
90834 + }
90835 }
90836 read_unlock(&tasklist_lock);
90837
90838 @@ -60,7 +68,7 @@ static int try_to_freeze_tasks(bool user_only)
90839 todo += wq_busy;
90840 }
90841
90842 - if (!todo || time_after(jiffies, end_time))
90843 + if (!todo || timedout)
90844 break;
90845
90846 if (pm_wakeup_pending()) {
90847 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
90848 index ced2b84..ffc4791 100644
90849 --- a/kernel/printk/printk.c
90850 +++ b/kernel/printk/printk.c
90851 @@ -489,6 +489,11 @@ static int check_syslog_permissions(int type, bool from_file)
90852 if (from_file && type != SYSLOG_ACTION_OPEN)
90853 return 0;
90854
90855 +#ifdef CONFIG_GRKERNSEC_DMESG
90856 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
90857 + return -EPERM;
90858 +#endif
90859 +
90860 if (syslog_action_restricted(type)) {
90861 if (capable(CAP_SYSLOG))
90862 return 0;
90863 diff --git a/kernel/profile.c b/kernel/profile.c
90864 index 54bf5ba..df6e0a2 100644
90865 --- a/kernel/profile.c
90866 +++ b/kernel/profile.c
90867 @@ -37,7 +37,7 @@ struct profile_hit {
90868 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
90869 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
90870
90871 -static atomic_t *prof_buffer;
90872 +static atomic_unchecked_t *prof_buffer;
90873 static unsigned long prof_len, prof_shift;
90874
90875 int prof_on __read_mostly;
90876 @@ -256,7 +256,7 @@ static void profile_flip_buffers(void)
90877 hits[i].pc = 0;
90878 continue;
90879 }
90880 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
90881 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
90882 hits[i].hits = hits[i].pc = 0;
90883 }
90884 }
90885 @@ -317,9 +317,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
90886 * Add the current hit(s) and flush the write-queue out
90887 * to the global buffer:
90888 */
90889 - atomic_add(nr_hits, &prof_buffer[pc]);
90890 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
90891 for (i = 0; i < NR_PROFILE_HIT; ++i) {
90892 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
90893 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
90894 hits[i].pc = hits[i].hits = 0;
90895 }
90896 out:
90897 @@ -394,7 +394,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
90898 {
90899 unsigned long pc;
90900 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
90901 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
90902 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
90903 }
90904 #endif /* !CONFIG_SMP */
90905
90906 @@ -490,7 +490,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
90907 return -EFAULT;
90908 buf++; p++; count--; read++;
90909 }
90910 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
90911 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
90912 if (copy_to_user(buf, (void *)pnt, count))
90913 return -EFAULT;
90914 read += count;
90915 @@ -521,7 +521,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
90916 }
90917 #endif
90918 profile_discard_flip_buffers();
90919 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
90920 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
90921 return count;
90922 }
90923
90924 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
90925 index 54e7522..5b82dd6 100644
90926 --- a/kernel/ptrace.c
90927 +++ b/kernel/ptrace.c
90928 @@ -321,7 +321,7 @@ static int ptrace_attach(struct task_struct *task, long request,
90929 if (seize)
90930 flags |= PT_SEIZED;
90931 rcu_read_lock();
90932 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
90933 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
90934 flags |= PT_PTRACE_CAP;
90935 rcu_read_unlock();
90936 task->ptrace = flags;
90937 @@ -532,7 +532,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
90938 break;
90939 return -EIO;
90940 }
90941 - if (copy_to_user(dst, buf, retval))
90942 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
90943 return -EFAULT;
90944 copied += retval;
90945 src += retval;
90946 @@ -800,7 +800,7 @@ int ptrace_request(struct task_struct *child, long request,
90947 bool seized = child->ptrace & PT_SEIZED;
90948 int ret = -EIO;
90949 siginfo_t siginfo, *si;
90950 - void __user *datavp = (void __user *) data;
90951 + void __user *datavp = (__force void __user *) data;
90952 unsigned long __user *datalp = datavp;
90953 unsigned long flags;
90954
90955 @@ -1046,14 +1046,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
90956 goto out;
90957 }
90958
90959 + if (gr_handle_ptrace(child, request)) {
90960 + ret = -EPERM;
90961 + goto out_put_task_struct;
90962 + }
90963 +
90964 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
90965 ret = ptrace_attach(child, request, addr, data);
90966 /*
90967 * Some architectures need to do book-keeping after
90968 * a ptrace attach.
90969 */
90970 - if (!ret)
90971 + if (!ret) {
90972 arch_ptrace_attach(child);
90973 + gr_audit_ptrace(child);
90974 + }
90975 goto out_put_task_struct;
90976 }
90977
90978 @@ -1081,7 +1088,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
90979 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
90980 if (copied != sizeof(tmp))
90981 return -EIO;
90982 - return put_user(tmp, (unsigned long __user *)data);
90983 + return put_user(tmp, (__force unsigned long __user *)data);
90984 }
90985
90986 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
90987 @@ -1175,7 +1182,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
90988 }
90989
90990 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
90991 - compat_long_t, addr, compat_long_t, data)
90992 + compat_ulong_t, addr, compat_ulong_t, data)
90993 {
90994 struct task_struct *child;
90995 long ret;
90996 @@ -1191,14 +1198,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
90997 goto out;
90998 }
90999
91000 + if (gr_handle_ptrace(child, request)) {
91001 + ret = -EPERM;
91002 + goto out_put_task_struct;
91003 + }
91004 +
91005 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
91006 ret = ptrace_attach(child, request, addr, data);
91007 /*
91008 * Some architectures need to do book-keeping after
91009 * a ptrace attach.
91010 */
91011 - if (!ret)
91012 + if (!ret) {
91013 arch_ptrace_attach(child);
91014 + gr_audit_ptrace(child);
91015 + }
91016 goto out_put_task_struct;
91017 }
91018
91019 diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
91020 index 240fa90..5fa56bd 100644
91021 --- a/kernel/rcu/rcutorture.c
91022 +++ b/kernel/rcu/rcutorture.c
91023 @@ -134,12 +134,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
91024 rcu_torture_count) = { 0 };
91025 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
91026 rcu_torture_batch) = { 0 };
91027 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
91028 -static atomic_t n_rcu_torture_alloc;
91029 -static atomic_t n_rcu_torture_alloc_fail;
91030 -static atomic_t n_rcu_torture_free;
91031 -static atomic_t n_rcu_torture_mberror;
91032 -static atomic_t n_rcu_torture_error;
91033 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
91034 +static atomic_unchecked_t n_rcu_torture_alloc;
91035 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
91036 +static atomic_unchecked_t n_rcu_torture_free;
91037 +static atomic_unchecked_t n_rcu_torture_mberror;
91038 +static atomic_unchecked_t n_rcu_torture_error;
91039 static long n_rcu_torture_barrier_error;
91040 static long n_rcu_torture_boost_ktrerror;
91041 static long n_rcu_torture_boost_rterror;
91042 @@ -148,7 +148,7 @@ static long n_rcu_torture_boosts;
91043 static long n_rcu_torture_timers;
91044 static long n_barrier_attempts;
91045 static long n_barrier_successes;
91046 -static atomic_long_t n_cbfloods;
91047 +static atomic_long_unchecked_t n_cbfloods;
91048 static struct list_head rcu_torture_removed;
91049
91050 static int rcu_torture_writer_state;
91051 @@ -211,11 +211,11 @@ rcu_torture_alloc(void)
91052
91053 spin_lock_bh(&rcu_torture_lock);
91054 if (list_empty(&rcu_torture_freelist)) {
91055 - atomic_inc(&n_rcu_torture_alloc_fail);
91056 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
91057 spin_unlock_bh(&rcu_torture_lock);
91058 return NULL;
91059 }
91060 - atomic_inc(&n_rcu_torture_alloc);
91061 + atomic_inc_unchecked(&n_rcu_torture_alloc);
91062 p = rcu_torture_freelist.next;
91063 list_del_init(p);
91064 spin_unlock_bh(&rcu_torture_lock);
91065 @@ -228,7 +228,7 @@ rcu_torture_alloc(void)
91066 static void
91067 rcu_torture_free(struct rcu_torture *p)
91068 {
91069 - atomic_inc(&n_rcu_torture_free);
91070 + atomic_inc_unchecked(&n_rcu_torture_free);
91071 spin_lock_bh(&rcu_torture_lock);
91072 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
91073 spin_unlock_bh(&rcu_torture_lock);
91074 @@ -312,7 +312,7 @@ rcu_torture_pipe_update_one(struct rcu_torture *rp)
91075 i = rp->rtort_pipe_count;
91076 if (i > RCU_TORTURE_PIPE_LEN)
91077 i = RCU_TORTURE_PIPE_LEN;
91078 - atomic_inc(&rcu_torture_wcount[i]);
91079 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
91080 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
91081 rp->rtort_mbtest = 0;
91082 return true;
91083 @@ -799,7 +799,7 @@ rcu_torture_cbflood(void *arg)
91084 VERBOSE_TOROUT_STRING("rcu_torture_cbflood task started");
91085 do {
91086 schedule_timeout_interruptible(cbflood_inter_holdoff);
91087 - atomic_long_inc(&n_cbfloods);
91088 + atomic_long_inc_unchecked(&n_cbfloods);
91089 WARN_ON(signal_pending(current));
91090 for (i = 0; i < cbflood_n_burst; i++) {
91091 for (j = 0; j < cbflood_n_per_burst; j++) {
91092 @@ -917,7 +917,7 @@ rcu_torture_writer(void *arg)
91093 i = old_rp->rtort_pipe_count;
91094 if (i > RCU_TORTURE_PIPE_LEN)
91095 i = RCU_TORTURE_PIPE_LEN;
91096 - atomic_inc(&rcu_torture_wcount[i]);
91097 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
91098 old_rp->rtort_pipe_count++;
91099 switch (synctype[torture_random(&rand) % nsynctypes]) {
91100 case RTWS_DEF_FREE:
91101 @@ -1035,7 +1035,7 @@ static void rcu_torture_timer(unsigned long unused)
91102 return;
91103 }
91104 if (p->rtort_mbtest == 0)
91105 - atomic_inc(&n_rcu_torture_mberror);
91106 + atomic_inc_unchecked(&n_rcu_torture_mberror);
91107 spin_lock(&rand_lock);
91108 cur_ops->read_delay(&rand);
91109 n_rcu_torture_timers++;
91110 @@ -1105,7 +1105,7 @@ rcu_torture_reader(void *arg)
91111 continue;
91112 }
91113 if (p->rtort_mbtest == 0)
91114 - atomic_inc(&n_rcu_torture_mberror);
91115 + atomic_inc_unchecked(&n_rcu_torture_mberror);
91116 cur_ops->read_delay(&rand);
91117 preempt_disable();
91118 pipe_count = p->rtort_pipe_count;
91119 @@ -1172,11 +1172,11 @@ rcu_torture_stats_print(void)
91120 rcu_torture_current,
91121 rcu_torture_current_version,
91122 list_empty(&rcu_torture_freelist),
91123 - atomic_read(&n_rcu_torture_alloc),
91124 - atomic_read(&n_rcu_torture_alloc_fail),
91125 - atomic_read(&n_rcu_torture_free));
91126 + atomic_read_unchecked(&n_rcu_torture_alloc),
91127 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
91128 + atomic_read_unchecked(&n_rcu_torture_free));
91129 pr_cont("rtmbe: %d rtbke: %ld rtbre: %ld ",
91130 - atomic_read(&n_rcu_torture_mberror),
91131 + atomic_read_unchecked(&n_rcu_torture_mberror),
91132 n_rcu_torture_boost_ktrerror,
91133 n_rcu_torture_boost_rterror);
91134 pr_cont("rtbf: %ld rtb: %ld nt: %ld ",
91135 @@ -1188,17 +1188,17 @@ rcu_torture_stats_print(void)
91136 n_barrier_successes,
91137 n_barrier_attempts,
91138 n_rcu_torture_barrier_error);
91139 - pr_cont("cbflood: %ld\n", atomic_long_read(&n_cbfloods));
91140 + pr_cont("cbflood: %ld\n", atomic_long_read_unchecked(&n_cbfloods));
91141
91142 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
91143 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
91144 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
91145 n_rcu_torture_barrier_error != 0 ||
91146 n_rcu_torture_boost_ktrerror != 0 ||
91147 n_rcu_torture_boost_rterror != 0 ||
91148 n_rcu_torture_boost_failure != 0 ||
91149 i > 1) {
91150 pr_cont("%s", "!!! ");
91151 - atomic_inc(&n_rcu_torture_error);
91152 + atomic_inc_unchecked(&n_rcu_torture_error);
91153 WARN_ON_ONCE(1);
91154 }
91155 pr_cont("Reader Pipe: ");
91156 @@ -1215,7 +1215,7 @@ rcu_torture_stats_print(void)
91157 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
91158 pr_cont("Free-Block Circulation: ");
91159 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
91160 - pr_cont(" %d", atomic_read(&rcu_torture_wcount[i]));
91161 + pr_cont(" %d", atomic_read_unchecked(&rcu_torture_wcount[i]));
91162 }
91163 pr_cont("\n");
91164
91165 @@ -1559,7 +1559,7 @@ rcu_torture_cleanup(void)
91166
91167 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
91168
91169 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
91170 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
91171 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
91172 else if (torture_onoff_failures())
91173 rcu_torture_print_module_parms(cur_ops,
91174 @@ -1684,18 +1684,18 @@ rcu_torture_init(void)
91175
91176 rcu_torture_current = NULL;
91177 rcu_torture_current_version = 0;
91178 - atomic_set(&n_rcu_torture_alloc, 0);
91179 - atomic_set(&n_rcu_torture_alloc_fail, 0);
91180 - atomic_set(&n_rcu_torture_free, 0);
91181 - atomic_set(&n_rcu_torture_mberror, 0);
91182 - atomic_set(&n_rcu_torture_error, 0);
91183 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
91184 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
91185 + atomic_set_unchecked(&n_rcu_torture_free, 0);
91186 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
91187 + atomic_set_unchecked(&n_rcu_torture_error, 0);
91188 n_rcu_torture_barrier_error = 0;
91189 n_rcu_torture_boost_ktrerror = 0;
91190 n_rcu_torture_boost_rterror = 0;
91191 n_rcu_torture_boost_failure = 0;
91192 n_rcu_torture_boosts = 0;
91193 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
91194 - atomic_set(&rcu_torture_wcount[i], 0);
91195 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
91196 for_each_possible_cpu(cpu) {
91197 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
91198 per_cpu(rcu_torture_count, cpu)[i] = 0;
91199 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
91200 index c0623fc..329c091 100644
91201 --- a/kernel/rcu/tiny.c
91202 +++ b/kernel/rcu/tiny.c
91203 @@ -42,7 +42,7 @@
91204 /* Forward declarations for tiny_plugin.h. */
91205 struct rcu_ctrlblk;
91206 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
91207 -static void rcu_process_callbacks(struct softirq_action *unused);
91208 +static void rcu_process_callbacks(void);
91209 static void __call_rcu(struct rcu_head *head,
91210 void (*func)(struct rcu_head *rcu),
91211 struct rcu_ctrlblk *rcp);
91212 @@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
91213 false));
91214 }
91215
91216 -static void rcu_process_callbacks(struct softirq_action *unused)
91217 +static __latent_entropy void rcu_process_callbacks(void)
91218 {
91219 __rcu_process_callbacks(&rcu_sched_ctrlblk);
91220 __rcu_process_callbacks(&rcu_bh_ctrlblk);
91221 diff --git a/kernel/rcu/tiny_plugin.h b/kernel/rcu/tiny_plugin.h
91222 index 858c565..7efd915 100644
91223 --- a/kernel/rcu/tiny_plugin.h
91224 +++ b/kernel/rcu/tiny_plugin.h
91225 @@ -152,17 +152,17 @@ static void check_cpu_stall(struct rcu_ctrlblk *rcp)
91226 dump_stack();
91227 }
91228 if (*rcp->curtail && ULONG_CMP_GE(j, js))
91229 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies +
91230 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies +
91231 3 * rcu_jiffies_till_stall_check() + 3;
91232 else if (ULONG_CMP_GE(j, js))
91233 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91234 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91235 }
91236
91237 static void reset_cpu_stall_ticks(struct rcu_ctrlblk *rcp)
91238 {
91239 rcp->ticks_this_gp = 0;
91240 rcp->gp_start = jiffies;
91241 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91242 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91243 }
91244
91245 static void check_cpu_stalls(void)
91246 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
91247 index 9815447..2cdf92a 100644
91248 --- a/kernel/rcu/tree.c
91249 +++ b/kernel/rcu/tree.c
91250 @@ -274,7 +274,7 @@ static void rcu_momentary_dyntick_idle(void)
91251 */
91252 rdtp = this_cpu_ptr(&rcu_dynticks);
91253 smp_mb__before_atomic(); /* Earlier stuff before QS. */
91254 - atomic_add(2, &rdtp->dynticks); /* QS. */
91255 + atomic_add_unchecked(2, &rdtp->dynticks); /* QS. */
91256 smp_mb__after_atomic(); /* Later stuff after QS. */
91257 break;
91258 }
91259 @@ -534,9 +534,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
91260 rcu_prepare_for_idle(smp_processor_id());
91261 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
91262 smp_mb__before_atomic(); /* See above. */
91263 - atomic_inc(&rdtp->dynticks);
91264 + atomic_inc_unchecked(&rdtp->dynticks);
91265 smp_mb__after_atomic(); /* Force ordering with next sojourn. */
91266 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
91267 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
91268 rcu_dynticks_task_enter();
91269
91270 /*
91271 @@ -656,10 +656,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
91272 {
91273 rcu_dynticks_task_exit();
91274 smp_mb__before_atomic(); /* Force ordering w/previous sojourn. */
91275 - atomic_inc(&rdtp->dynticks);
91276 + atomic_inc_unchecked(&rdtp->dynticks);
91277 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
91278 smp_mb__after_atomic(); /* See above. */
91279 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
91280 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
91281 rcu_cleanup_after_idle(smp_processor_id());
91282 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
91283 if (!user && !is_idle_task(current)) {
91284 @@ -780,14 +780,14 @@ void rcu_nmi_enter(void)
91285 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
91286
91287 if (rdtp->dynticks_nmi_nesting == 0 &&
91288 - (atomic_read(&rdtp->dynticks) & 0x1))
91289 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
91290 return;
91291 rdtp->dynticks_nmi_nesting++;
91292 smp_mb__before_atomic(); /* Force delay from prior write. */
91293 - atomic_inc(&rdtp->dynticks);
91294 + atomic_inc_unchecked(&rdtp->dynticks);
91295 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
91296 smp_mb__after_atomic(); /* See above. */
91297 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
91298 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
91299 }
91300
91301 /**
91302 @@ -806,9 +806,9 @@ void rcu_nmi_exit(void)
91303 return;
91304 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
91305 smp_mb__before_atomic(); /* See above. */
91306 - atomic_inc(&rdtp->dynticks);
91307 + atomic_inc_unchecked(&rdtp->dynticks);
91308 smp_mb__after_atomic(); /* Force delay to next write. */
91309 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
91310 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
91311 }
91312
91313 /**
91314 @@ -821,7 +821,7 @@ void rcu_nmi_exit(void)
91315 */
91316 bool notrace __rcu_is_watching(void)
91317 {
91318 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
91319 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
91320 }
91321
91322 /**
91323 @@ -904,7 +904,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
91324 static int dyntick_save_progress_counter(struct rcu_data *rdp,
91325 bool *isidle, unsigned long *maxj)
91326 {
91327 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
91328 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
91329 rcu_sysidle_check_cpu(rdp, isidle, maxj);
91330 if ((rdp->dynticks_snap & 0x1) == 0) {
91331 trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, TPS("dti"));
91332 @@ -933,7 +933,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
91333 int *rcrmp;
91334 unsigned int snap;
91335
91336 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
91337 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
91338 snap = (unsigned int)rdp->dynticks_snap;
91339
91340 /*
91341 @@ -996,10 +996,10 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
91342 rdp->rsp->gp_start + jiffies_till_sched_qs) ||
91343 ULONG_CMP_GE(jiffies, rdp->rsp->jiffies_resched)) {
91344 if (!(ACCESS_ONCE(*rcrmp) & rdp->rsp->flavor_mask)) {
91345 - ACCESS_ONCE(rdp->cond_resched_completed) =
91346 + ACCESS_ONCE_RW(rdp->cond_resched_completed) =
91347 ACCESS_ONCE(rdp->mynode->completed);
91348 smp_mb(); /* ->cond_resched_completed before *rcrmp. */
91349 - ACCESS_ONCE(*rcrmp) =
91350 + ACCESS_ONCE_RW(*rcrmp) =
91351 ACCESS_ONCE(*rcrmp) + rdp->rsp->flavor_mask;
91352 resched_cpu(rdp->cpu); /* Force CPU into scheduler. */
91353 rdp->rsp->jiffies_resched += 5; /* Enable beating. */
91354 @@ -1021,7 +1021,7 @@ static void record_gp_stall_check_time(struct rcu_state *rsp)
91355 rsp->gp_start = j;
91356 smp_wmb(); /* Record start time before stall time. */
91357 j1 = rcu_jiffies_till_stall_check();
91358 - ACCESS_ONCE(rsp->jiffies_stall) = j + j1;
91359 + ACCESS_ONCE_RW(rsp->jiffies_stall) = j + j1;
91360 rsp->jiffies_resched = j + j1 / 2;
91361 }
91362
91363 @@ -1062,7 +1062,7 @@ static void print_other_cpu_stall(struct rcu_state *rsp)
91364 raw_spin_unlock_irqrestore(&rnp->lock, flags);
91365 return;
91366 }
91367 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
91368 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
91369 raw_spin_unlock_irqrestore(&rnp->lock, flags);
91370
91371 /*
91372 @@ -1139,7 +1139,7 @@ static void print_cpu_stall(struct rcu_state *rsp)
91373
91374 raw_spin_lock_irqsave(&rnp->lock, flags);
91375 if (ULONG_CMP_GE(jiffies, ACCESS_ONCE(rsp->jiffies_stall)))
91376 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies +
91377 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies +
91378 3 * rcu_jiffies_till_stall_check() + 3;
91379 raw_spin_unlock_irqrestore(&rnp->lock, flags);
91380
91381 @@ -1223,7 +1223,7 @@ void rcu_cpu_stall_reset(void)
91382 struct rcu_state *rsp;
91383
91384 for_each_rcu_flavor(rsp)
91385 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
91386 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
91387 }
91388
91389 /*
91390 @@ -1609,7 +1609,7 @@ static int rcu_gp_init(struct rcu_state *rsp)
91391 raw_spin_unlock_irq(&rnp->lock);
91392 return 0;
91393 }
91394 - ACCESS_ONCE(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
91395 + ACCESS_ONCE_RW(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
91396
91397 if (WARN_ON_ONCE(rcu_gp_in_progress(rsp))) {
91398 /*
91399 @@ -1650,9 +1650,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
91400 rdp = this_cpu_ptr(rsp->rda);
91401 rcu_preempt_check_blocked_tasks(rnp);
91402 rnp->qsmask = rnp->qsmaskinit;
91403 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
91404 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
91405 WARN_ON_ONCE(rnp->completed != rsp->completed);
91406 - ACCESS_ONCE(rnp->completed) = rsp->completed;
91407 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
91408 if (rnp == rdp->mynode)
91409 (void)__note_gp_changes(rsp, rnp, rdp);
91410 rcu_preempt_boost_start_gp(rnp);
91411 @@ -1697,7 +1697,7 @@ static int rcu_gp_fqs(struct rcu_state *rsp, int fqs_state_in)
91412 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
91413 raw_spin_lock_irq(&rnp->lock);
91414 smp_mb__after_unlock_lock();
91415 - ACCESS_ONCE(rsp->gp_flags) =
91416 + ACCESS_ONCE_RW(rsp->gp_flags) =
91417 ACCESS_ONCE(rsp->gp_flags) & ~RCU_GP_FLAG_FQS;
91418 raw_spin_unlock_irq(&rnp->lock);
91419 }
91420 @@ -1743,7 +1743,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
91421 rcu_for_each_node_breadth_first(rsp, rnp) {
91422 raw_spin_lock_irq(&rnp->lock);
91423 smp_mb__after_unlock_lock();
91424 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
91425 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
91426 rdp = this_cpu_ptr(rsp->rda);
91427 if (rnp == rdp->mynode)
91428 needgp = __note_gp_changes(rsp, rnp, rdp) || needgp;
91429 @@ -1758,14 +1758,14 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
91430 rcu_nocb_gp_set(rnp, nocb);
91431
91432 /* Declare grace period done. */
91433 - ACCESS_ONCE(rsp->completed) = rsp->gpnum;
91434 + ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
91435 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
91436 rsp->fqs_state = RCU_GP_IDLE;
91437 rdp = this_cpu_ptr(rsp->rda);
91438 /* Advance CBs to reduce false positives below. */
91439 needgp = rcu_advance_cbs(rsp, rnp, rdp) || needgp;
91440 if (needgp || cpu_needs_another_gp(rsp, rdp)) {
91441 - ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
91442 + ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
91443 trace_rcu_grace_period(rsp->name,
91444 ACCESS_ONCE(rsp->gpnum),
91445 TPS("newreq"));
91446 @@ -1890,7 +1890,7 @@ rcu_start_gp_advanced(struct rcu_state *rsp, struct rcu_node *rnp,
91447 */
91448 return false;
91449 }
91450 - ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
91451 + ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
91452 trace_rcu_grace_period(rsp->name, ACCESS_ONCE(rsp->gpnum),
91453 TPS("newreq"));
91454
91455 @@ -2111,7 +2111,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
91456 rsp->qlen += rdp->qlen;
91457 rdp->n_cbs_orphaned += rdp->qlen;
91458 rdp->qlen_lazy = 0;
91459 - ACCESS_ONCE(rdp->qlen) = 0;
91460 + ACCESS_ONCE_RW(rdp->qlen) = 0;
91461 }
91462
91463 /*
91464 @@ -2356,7 +2356,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
91465 }
91466 smp_mb(); /* List handling before counting for rcu_barrier(). */
91467 rdp->qlen_lazy -= count_lazy;
91468 - ACCESS_ONCE(rdp->qlen) = rdp->qlen - count;
91469 + ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen - count;
91470 rdp->n_cbs_invoked += count;
91471
91472 /* Reinstate batch limit if we have worked down the excess. */
91473 @@ -2519,7 +2519,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
91474 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
91475 return; /* Someone beat us to it. */
91476 }
91477 - ACCESS_ONCE(rsp->gp_flags) =
91478 + ACCESS_ONCE_RW(rsp->gp_flags) =
91479 ACCESS_ONCE(rsp->gp_flags) | RCU_GP_FLAG_FQS;
91480 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
91481 rcu_gp_kthread_wake(rsp);
91482 @@ -2565,7 +2565,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
91483 /*
91484 * Do RCU core processing for the current CPU.
91485 */
91486 -static void rcu_process_callbacks(struct softirq_action *unused)
91487 +static void rcu_process_callbacks(void)
91488 {
91489 struct rcu_state *rsp;
91490
91491 @@ -2677,7 +2677,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
91492 WARN_ON_ONCE((unsigned long)head & 0x1); /* Misaligned rcu_head! */
91493 if (debug_rcu_head_queue(head)) {
91494 /* Probable double call_rcu(), so leak the callback. */
91495 - ACCESS_ONCE(head->func) = rcu_leak_callback;
91496 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
91497 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
91498 return;
91499 }
91500 @@ -2705,7 +2705,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
91501 local_irq_restore(flags);
91502 return;
91503 }
91504 - ACCESS_ONCE(rdp->qlen) = rdp->qlen + 1;
91505 + ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen + 1;
91506 if (lazy)
91507 rdp->qlen_lazy++;
91508 else
91509 @@ -2975,11 +2975,11 @@ void synchronize_sched_expedited(void)
91510 * counter wrap on a 32-bit system. Quite a few more CPUs would of
91511 * course be required on a 64-bit system.
91512 */
91513 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
91514 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
91515 (ulong)atomic_long_read(&rsp->expedited_done) +
91516 ULONG_MAX / 8)) {
91517 synchronize_sched();
91518 - atomic_long_inc(&rsp->expedited_wrap);
91519 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
91520 return;
91521 }
91522
91523 @@ -2987,12 +2987,12 @@ void synchronize_sched_expedited(void)
91524 * Take a ticket. Note that atomic_inc_return() implies a
91525 * full memory barrier.
91526 */
91527 - snap = atomic_long_inc_return(&rsp->expedited_start);
91528 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
91529 firstsnap = snap;
91530 if (!try_get_online_cpus()) {
91531 /* CPU hotplug operation in flight, fall back to normal GP. */
91532 wait_rcu_gp(call_rcu_sched);
91533 - atomic_long_inc(&rsp->expedited_normal);
91534 + atomic_long_inc_unchecked(&rsp->expedited_normal);
91535 return;
91536 }
91537 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
91538 @@ -3005,14 +3005,14 @@ void synchronize_sched_expedited(void)
91539 synchronize_sched_expedited_cpu_stop,
91540 NULL) == -EAGAIN) {
91541 put_online_cpus();
91542 - atomic_long_inc(&rsp->expedited_tryfail);
91543 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
91544
91545 /* Check to see if someone else did our work for us. */
91546 s = atomic_long_read(&rsp->expedited_done);
91547 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
91548 /* ensure test happens before caller kfree */
91549 smp_mb__before_atomic(); /* ^^^ */
91550 - atomic_long_inc(&rsp->expedited_workdone1);
91551 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
91552 return;
91553 }
91554
91555 @@ -3021,7 +3021,7 @@ void synchronize_sched_expedited(void)
91556 udelay(trycount * num_online_cpus());
91557 } else {
91558 wait_rcu_gp(call_rcu_sched);
91559 - atomic_long_inc(&rsp->expedited_normal);
91560 + atomic_long_inc_unchecked(&rsp->expedited_normal);
91561 return;
91562 }
91563
91564 @@ -3030,7 +3030,7 @@ void synchronize_sched_expedited(void)
91565 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
91566 /* ensure test happens before caller kfree */
91567 smp_mb__before_atomic(); /* ^^^ */
91568 - atomic_long_inc(&rsp->expedited_workdone2);
91569 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
91570 return;
91571 }
91572
91573 @@ -3044,13 +3044,13 @@ void synchronize_sched_expedited(void)
91574 if (!try_get_online_cpus()) {
91575 /* CPU hotplug operation in flight, use normal GP. */
91576 wait_rcu_gp(call_rcu_sched);
91577 - atomic_long_inc(&rsp->expedited_normal);
91578 + atomic_long_inc_unchecked(&rsp->expedited_normal);
91579 return;
91580 }
91581 - snap = atomic_long_read(&rsp->expedited_start);
91582 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
91583 smp_mb(); /* ensure read is before try_stop_cpus(). */
91584 }
91585 - atomic_long_inc(&rsp->expedited_stoppedcpus);
91586 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
91587
91588 /*
91589 * Everyone up to our most recent fetch is covered by our grace
91590 @@ -3059,16 +3059,16 @@ void synchronize_sched_expedited(void)
91591 * than we did already did their update.
91592 */
91593 do {
91594 - atomic_long_inc(&rsp->expedited_done_tries);
91595 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
91596 s = atomic_long_read(&rsp->expedited_done);
91597 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
91598 /* ensure test happens before caller kfree */
91599 smp_mb__before_atomic(); /* ^^^ */
91600 - atomic_long_inc(&rsp->expedited_done_lost);
91601 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
91602 break;
91603 }
91604 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
91605 - atomic_long_inc(&rsp->expedited_done_exit);
91606 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
91607
91608 put_online_cpus();
91609 }
91610 @@ -3274,7 +3274,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
91611 * ACCESS_ONCE() to prevent the compiler from speculating
91612 * the increment to precede the early-exit check.
91613 */
91614 - ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
91615 + ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
91616 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
91617 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
91618 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
91619 @@ -3329,7 +3329,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
91620
91621 /* Increment ->n_barrier_done to prevent duplicate work. */
91622 smp_mb(); /* Keep increment after above mechanism. */
91623 - ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
91624 + ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
91625 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
91626 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
91627 smp_mb(); /* Keep increment before caller's subsequent code. */
91628 @@ -3374,10 +3374,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
91629 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
91630 init_callback_list(rdp);
91631 rdp->qlen_lazy = 0;
91632 - ACCESS_ONCE(rdp->qlen) = 0;
91633 + ACCESS_ONCE_RW(rdp->qlen) = 0;
91634 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
91635 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
91636 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
91637 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
91638 rdp->cpu = cpu;
91639 rdp->rsp = rsp;
91640 rcu_boot_init_nocb_percpu_data(rdp);
91641 @@ -3410,8 +3410,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp)
91642 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
91643 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
91644 rcu_sysidle_init_percpu_data(rdp->dynticks);
91645 - atomic_set(&rdp->dynticks->dynticks,
91646 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
91647 + atomic_set_unchecked(&rdp->dynticks->dynticks,
91648 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
91649 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
91650
91651 /* Add CPU to rcu_node bitmasks. */
91652 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
91653 index bbdc45d..c882ccb 100644
91654 --- a/kernel/rcu/tree.h
91655 +++ b/kernel/rcu/tree.h
91656 @@ -87,11 +87,11 @@ struct rcu_dynticks {
91657 long long dynticks_nesting; /* Track irq/process nesting level. */
91658 /* Process level is worth LLONG_MAX/2. */
91659 int dynticks_nmi_nesting; /* Track NMI nesting level. */
91660 - atomic_t dynticks; /* Even value for idle, else odd. */
91661 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
91662 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
91663 long long dynticks_idle_nesting;
91664 /* irq/process nesting level from idle. */
91665 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
91666 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
91667 /* "Idle" excludes userspace execution. */
91668 unsigned long dynticks_idle_jiffies;
91669 /* End of last non-NMI non-idle period. */
91670 @@ -466,17 +466,17 @@ struct rcu_state {
91671 /* _rcu_barrier(). */
91672 /* End of fields guarded by barrier_mutex. */
91673
91674 - atomic_long_t expedited_start; /* Starting ticket. */
91675 - atomic_long_t expedited_done; /* Done ticket. */
91676 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
91677 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
91678 - atomic_long_t expedited_workdone1; /* # done by others #1. */
91679 - atomic_long_t expedited_workdone2; /* # done by others #2. */
91680 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
91681 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
91682 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
91683 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
91684 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
91685 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
91686 + atomic_long_t expedited_done; /* Done ticket. */
91687 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
91688 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
91689 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
91690 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
91691 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
91692 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
91693 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
91694 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
91695 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
91696
91697 unsigned long jiffies_force_qs; /* Time at which to invoke */
91698 /* force_quiescent_state(). */
91699 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
91700 index c1d7f27..a64bf49 100644
91701 --- a/kernel/rcu/tree_plugin.h
91702 +++ b/kernel/rcu/tree_plugin.h
91703 @@ -709,7 +709,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
91704 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
91705 {
91706 return !rcu_preempted_readers_exp(rnp) &&
91707 - ACCESS_ONCE(rnp->expmask) == 0;
91708 + ACCESS_ONCE_RW(rnp->expmask) == 0;
91709 }
91710
91711 /*
91712 @@ -870,7 +870,7 @@ void synchronize_rcu_expedited(void)
91713
91714 /* Clean up and exit. */
91715 smp_mb(); /* ensure expedited GP seen before counter increment. */
91716 - ACCESS_ONCE(sync_rcu_preempt_exp_count) =
91717 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count) =
91718 sync_rcu_preempt_exp_count + 1;
91719 unlock_mb_ret:
91720 mutex_unlock(&sync_rcu_preempt_exp_mutex);
91721 @@ -1426,7 +1426,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
91722 free_cpumask_var(cm);
91723 }
91724
91725 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
91726 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
91727 .store = &rcu_cpu_kthread_task,
91728 .thread_should_run = rcu_cpu_kthread_should_run,
91729 .thread_fn = rcu_cpu_kthread,
91730 @@ -1900,7 +1900,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
91731 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
91732 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
91733 cpu, ticks_value, ticks_title,
91734 - atomic_read(&rdtp->dynticks) & 0xfff,
91735 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
91736 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
91737 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
91738 fast_no_hz);
91739 @@ -2044,7 +2044,7 @@ static void wake_nocb_leader(struct rcu_data *rdp, bool force)
91740 return;
91741 if (ACCESS_ONCE(rdp_leader->nocb_leader_sleep) || force) {
91742 /* Prior smp_mb__after_atomic() orders against prior enqueue. */
91743 - ACCESS_ONCE(rdp_leader->nocb_leader_sleep) = false;
91744 + ACCESS_ONCE_RW(rdp_leader->nocb_leader_sleep) = false;
91745 wake_up(&rdp_leader->nocb_wq);
91746 }
91747 }
91748 @@ -2096,7 +2096,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
91749
91750 /* Enqueue the callback on the nocb list and update counts. */
91751 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
91752 - ACCESS_ONCE(*old_rhpp) = rhp;
91753 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
91754 atomic_long_add(rhcount, &rdp->nocb_q_count);
91755 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
91756 smp_mb__after_atomic(); /* Store *old_rhpp before _wake test. */
91757 @@ -2286,7 +2286,7 @@ wait_again:
91758 continue; /* No CBs here, try next follower. */
91759
91760 /* Move callbacks to wait-for-GP list, which is empty. */
91761 - ACCESS_ONCE(rdp->nocb_head) = NULL;
91762 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
91763 rdp->nocb_gp_tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
91764 rdp->nocb_gp_count = atomic_long_xchg(&rdp->nocb_q_count, 0);
91765 rdp->nocb_gp_count_lazy =
91766 @@ -2413,7 +2413,7 @@ static int rcu_nocb_kthread(void *arg)
91767 list = ACCESS_ONCE(rdp->nocb_follower_head);
91768 BUG_ON(!list);
91769 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, "WokeNonEmpty");
91770 - ACCESS_ONCE(rdp->nocb_follower_head) = NULL;
91771 + ACCESS_ONCE_RW(rdp->nocb_follower_head) = NULL;
91772 tail = xchg(&rdp->nocb_follower_tail, &rdp->nocb_follower_head);
91773 c = atomic_long_xchg(&rdp->nocb_follower_count, 0);
91774 cl = atomic_long_xchg(&rdp->nocb_follower_count_lazy, 0);
91775 @@ -2443,8 +2443,8 @@ static int rcu_nocb_kthread(void *arg)
91776 list = next;
91777 }
91778 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
91779 - ACCESS_ONCE(rdp->nocb_p_count) = rdp->nocb_p_count - c;
91780 - ACCESS_ONCE(rdp->nocb_p_count_lazy) =
91781 + ACCESS_ONCE_RW(rdp->nocb_p_count) = rdp->nocb_p_count - c;
91782 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) =
91783 rdp->nocb_p_count_lazy - cl;
91784 rdp->n_nocbs_invoked += c;
91785 }
91786 @@ -2465,7 +2465,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
91787 if (!rcu_nocb_need_deferred_wakeup(rdp))
91788 return;
91789 ndw = ACCESS_ONCE(rdp->nocb_defer_wakeup);
91790 - ACCESS_ONCE(rdp->nocb_defer_wakeup) = RCU_NOGP_WAKE_NOT;
91791 + ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = RCU_NOGP_WAKE_NOT;
91792 wake_nocb_leader(rdp, ndw == RCU_NOGP_WAKE_FORCE);
91793 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWake"));
91794 }
91795 @@ -2584,7 +2584,7 @@ static void rcu_spawn_one_nocb_kthread(struct rcu_state *rsp, int cpu)
91796 t = kthread_run(rcu_nocb_kthread, rdp_spawn,
91797 "rcuo%c/%d", rsp->abbr, cpu);
91798 BUG_ON(IS_ERR(t));
91799 - ACCESS_ONCE(rdp_spawn->nocb_kthread) = t;
91800 + ACCESS_ONCE_RW(rdp_spawn->nocb_kthread) = t;
91801 }
91802
91803 /*
91804 @@ -2788,11 +2788,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
91805
91806 /* Record start of fully idle period. */
91807 j = jiffies;
91808 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
91809 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
91810 smp_mb__before_atomic();
91811 - atomic_inc(&rdtp->dynticks_idle);
91812 + atomic_inc_unchecked(&rdtp->dynticks_idle);
91813 smp_mb__after_atomic();
91814 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
91815 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
91816 }
91817
91818 /*
91819 @@ -2861,9 +2861,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
91820
91821 /* Record end of idle period. */
91822 smp_mb__before_atomic();
91823 - atomic_inc(&rdtp->dynticks_idle);
91824 + atomic_inc_unchecked(&rdtp->dynticks_idle);
91825 smp_mb__after_atomic();
91826 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
91827 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
91828
91829 /*
91830 * If we are the timekeeping CPU, we are permitted to be non-idle
91831 @@ -2908,7 +2908,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
91832 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
91833
91834 /* Pick up current idle and NMI-nesting counter and check. */
91835 - cur = atomic_read(&rdtp->dynticks_idle);
91836 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
91837 if (cur & 0x1) {
91838 *isidle = false; /* We are not idle! */
91839 return;
91840 @@ -2957,7 +2957,7 @@ static void rcu_sysidle(unsigned long j)
91841 case RCU_SYSIDLE_NOT:
91842
91843 /* First time all are idle, so note a short idle period. */
91844 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
91845 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
91846 break;
91847
91848 case RCU_SYSIDLE_SHORT:
91849 @@ -2995,7 +2995,7 @@ static void rcu_sysidle_cancel(void)
91850 {
91851 smp_mb();
91852 if (full_sysidle_state > RCU_SYSIDLE_SHORT)
91853 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
91854 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
91855 }
91856
91857 /*
91858 @@ -3047,7 +3047,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
91859 smp_mb(); /* grace period precedes setting inuse. */
91860
91861 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
91862 - ACCESS_ONCE(rshp->inuse) = 0;
91863 + ACCESS_ONCE_RW(rshp->inuse) = 0;
91864 }
91865
91866 /*
91867 @@ -3200,7 +3200,7 @@ static void rcu_bind_gp_kthread(void)
91868 static void rcu_dynticks_task_enter(void)
91869 {
91870 #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL)
91871 - ACCESS_ONCE(current->rcu_tasks_idle_cpu) = smp_processor_id();
91872 + ACCESS_ONCE_RW(current->rcu_tasks_idle_cpu) = smp_processor_id();
91873 #endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */
91874 }
91875
91876 @@ -3208,6 +3208,6 @@ static void rcu_dynticks_task_enter(void)
91877 static void rcu_dynticks_task_exit(void)
91878 {
91879 #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL)
91880 - ACCESS_ONCE(current->rcu_tasks_idle_cpu) = -1;
91881 + ACCESS_ONCE_RW(current->rcu_tasks_idle_cpu) = -1;
91882 #endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */
91883 }
91884 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
91885 index 5cdc62e..cc52e88 100644
91886 --- a/kernel/rcu/tree_trace.c
91887 +++ b/kernel/rcu/tree_trace.c
91888 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
91889 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
91890 rdp->passed_quiesce, rdp->qs_pending);
91891 seq_printf(m, " dt=%d/%llx/%d df=%lu",
91892 - atomic_read(&rdp->dynticks->dynticks),
91893 + atomic_read_unchecked(&rdp->dynticks->dynticks),
91894 rdp->dynticks->dynticks_nesting,
91895 rdp->dynticks->dynticks_nmi_nesting,
91896 rdp->dynticks_fqs);
91897 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
91898 struct rcu_state *rsp = (struct rcu_state *)m->private;
91899
91900 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",
91901 - atomic_long_read(&rsp->expedited_start),
91902 + atomic_long_read_unchecked(&rsp->expedited_start),
91903 atomic_long_read(&rsp->expedited_done),
91904 - atomic_long_read(&rsp->expedited_wrap),
91905 - atomic_long_read(&rsp->expedited_tryfail),
91906 - atomic_long_read(&rsp->expedited_workdone1),
91907 - atomic_long_read(&rsp->expedited_workdone2),
91908 - atomic_long_read(&rsp->expedited_normal),
91909 - atomic_long_read(&rsp->expedited_stoppedcpus),
91910 - atomic_long_read(&rsp->expedited_done_tries),
91911 - atomic_long_read(&rsp->expedited_done_lost),
91912 - atomic_long_read(&rsp->expedited_done_exit));
91913 + atomic_long_read_unchecked(&rsp->expedited_wrap),
91914 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
91915 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
91916 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
91917 + atomic_long_read_unchecked(&rsp->expedited_normal),
91918 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
91919 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
91920 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
91921 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
91922 return 0;
91923 }
91924
91925 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
91926 index 3ef8ba5..8c5ebfb6 100644
91927 --- a/kernel/rcu/update.c
91928 +++ b/kernel/rcu/update.c
91929 @@ -342,10 +342,10 @@ int rcu_jiffies_till_stall_check(void)
91930 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
91931 */
91932 if (till_stall_check < 3) {
91933 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
91934 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
91935 till_stall_check = 3;
91936 } else if (till_stall_check > 300) {
91937 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
91938 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
91939 till_stall_check = 300;
91940 }
91941 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
91942 @@ -501,7 +501,7 @@ static void check_holdout_task(struct task_struct *t,
91943 !ACCESS_ONCE(t->on_rq) ||
91944 (IS_ENABLED(CONFIG_NO_HZ_FULL) &&
91945 !is_idle_task(t) && t->rcu_tasks_idle_cpu >= 0)) {
91946 - ACCESS_ONCE(t->rcu_tasks_holdout) = false;
91947 + ACCESS_ONCE_RW(t->rcu_tasks_holdout) = false;
91948 list_del_init(&t->rcu_tasks_holdout_list);
91949 put_task_struct(t);
91950 return;
91951 @@ -588,7 +588,7 @@ static int __noreturn rcu_tasks_kthread(void *arg)
91952 !is_idle_task(t)) {
91953 get_task_struct(t);
91954 t->rcu_tasks_nvcsw = ACCESS_ONCE(t->nvcsw);
91955 - ACCESS_ONCE(t->rcu_tasks_holdout) = true;
91956 + ACCESS_ONCE_RW(t->rcu_tasks_holdout) = true;
91957 list_add(&t->rcu_tasks_holdout_list,
91958 &rcu_tasks_holdouts);
91959 }
91960 @@ -685,7 +685,7 @@ static void rcu_spawn_tasks_kthread(void)
91961 t = kthread_run(rcu_tasks_kthread, NULL, "rcu_tasks_kthread");
91962 BUG_ON(IS_ERR(t));
91963 smp_mb(); /* Ensure others see full kthread. */
91964 - ACCESS_ONCE(rcu_tasks_kthread_ptr) = t;
91965 + ACCESS_ONCE_RW(rcu_tasks_kthread_ptr) = t;
91966 mutex_unlock(&rcu_tasks_kthread_mutex);
91967 }
91968
91969 diff --git a/kernel/resource.c b/kernel/resource.c
91970 index 0bcebff..e7cd5b2 100644
91971 --- a/kernel/resource.c
91972 +++ b/kernel/resource.c
91973 @@ -161,8 +161,18 @@ static const struct file_operations proc_iomem_operations = {
91974
91975 static int __init ioresources_init(void)
91976 {
91977 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
91978 +#ifdef CONFIG_GRKERNSEC_PROC_USER
91979 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
91980 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
91981 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
91982 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
91983 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
91984 +#endif
91985 +#else
91986 proc_create("ioports", 0, NULL, &proc_ioports_operations);
91987 proc_create("iomem", 0, NULL, &proc_iomem_operations);
91988 +#endif
91989 return 0;
91990 }
91991 __initcall(ioresources_init);
91992 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
91993 index 8a2e230..6020954 100644
91994 --- a/kernel/sched/auto_group.c
91995 +++ b/kernel/sched/auto_group.c
91996 @@ -11,7 +11,7 @@
91997
91998 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
91999 static struct autogroup autogroup_default;
92000 -static atomic_t autogroup_seq_nr;
92001 +static atomic_unchecked_t autogroup_seq_nr;
92002
92003 void __init autogroup_init(struct task_struct *init_task)
92004 {
92005 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
92006
92007 kref_init(&ag->kref);
92008 init_rwsem(&ag->lock);
92009 - ag->id = atomic_inc_return(&autogroup_seq_nr);
92010 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
92011 ag->tg = tg;
92012 #ifdef CONFIG_RT_GROUP_SCHED
92013 /*
92014 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
92015 index a63f4dc..349bbb0 100644
92016 --- a/kernel/sched/completion.c
92017 +++ b/kernel/sched/completion.c
92018 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
92019 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
92020 * or number of jiffies left till timeout) if completed.
92021 */
92022 -long __sched
92023 +long __sched __intentional_overflow(-1)
92024 wait_for_completion_interruptible_timeout(struct completion *x,
92025 unsigned long timeout)
92026 {
92027 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
92028 *
92029 * Return: -ERESTARTSYS if interrupted, 0 if completed.
92030 */
92031 -int __sched wait_for_completion_killable(struct completion *x)
92032 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
92033 {
92034 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
92035 if (t == -ERESTARTSYS)
92036 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
92037 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
92038 * or number of jiffies left till timeout) if completed.
92039 */
92040 -long __sched
92041 +long __sched __intentional_overflow(-1)
92042 wait_for_completion_killable_timeout(struct completion *x,
92043 unsigned long timeout)
92044 {
92045 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
92046 index 89e7283..072bc26 100644
92047 --- a/kernel/sched/core.c
92048 +++ b/kernel/sched/core.c
92049 @@ -1885,7 +1885,7 @@ void set_numabalancing_state(bool enabled)
92050 int sysctl_numa_balancing(struct ctl_table *table, int write,
92051 void __user *buffer, size_t *lenp, loff_t *ppos)
92052 {
92053 - struct ctl_table t;
92054 + ctl_table_no_const t;
92055 int err;
92056 int state = numabalancing_enabled;
92057
92058 @@ -2348,8 +2348,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
92059 next->active_mm = oldmm;
92060 atomic_inc(&oldmm->mm_count);
92061 enter_lazy_tlb(oldmm, next);
92062 - } else
92063 + } else {
92064 switch_mm(oldmm, mm, next);
92065 + populate_stack();
92066 + }
92067
92068 if (!prev->mm) {
92069 prev->active_mm = NULL;
92070 @@ -3160,6 +3162,8 @@ int can_nice(const struct task_struct *p, const int nice)
92071 /* convert nice value [19,-20] to rlimit style value [1,40] */
92072 int nice_rlim = nice_to_rlimit(nice);
92073
92074 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
92075 +
92076 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
92077 capable(CAP_SYS_NICE));
92078 }
92079 @@ -3186,7 +3190,8 @@ SYSCALL_DEFINE1(nice, int, increment)
92080 nice = task_nice(current) + increment;
92081
92082 nice = clamp_val(nice, MIN_NICE, MAX_NICE);
92083 - if (increment < 0 && !can_nice(current, nice))
92084 + if (increment < 0 && (!can_nice(current, nice) ||
92085 + gr_handle_chroot_nice()))
92086 return -EPERM;
92087
92088 retval = security_task_setnice(current, nice);
92089 @@ -3465,6 +3470,7 @@ recheck:
92090 if (policy != p->policy && !rlim_rtprio)
92091 return -EPERM;
92092
92093 + gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
92094 /* can't increase priority */
92095 if (attr->sched_priority > p->rt_priority &&
92096 attr->sched_priority > rlim_rtprio)
92097 @@ -4885,6 +4891,7 @@ void idle_task_exit(void)
92098
92099 if (mm != &init_mm) {
92100 switch_mm(mm, &init_mm, current);
92101 + populate_stack();
92102 finish_arch_post_lock_switch();
92103 }
92104 mmdrop(mm);
92105 @@ -4980,7 +4987,7 @@ static void migrate_tasks(unsigned int dead_cpu)
92106
92107 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
92108
92109 -static struct ctl_table sd_ctl_dir[] = {
92110 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
92111 {
92112 .procname = "sched_domain",
92113 .mode = 0555,
92114 @@ -4997,17 +5004,17 @@ static struct ctl_table sd_ctl_root[] = {
92115 {}
92116 };
92117
92118 -static struct ctl_table *sd_alloc_ctl_entry(int n)
92119 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
92120 {
92121 - struct ctl_table *entry =
92122 + ctl_table_no_const *entry =
92123 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
92124
92125 return entry;
92126 }
92127
92128 -static void sd_free_ctl_entry(struct ctl_table **tablep)
92129 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
92130 {
92131 - struct ctl_table *entry;
92132 + ctl_table_no_const *entry;
92133
92134 /*
92135 * In the intermediate directories, both the child directory and
92136 @@ -5015,22 +5022,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
92137 * will always be set. In the lowest directory the names are
92138 * static strings and all have proc handlers.
92139 */
92140 - for (entry = *tablep; entry->mode; entry++) {
92141 - if (entry->child)
92142 - sd_free_ctl_entry(&entry->child);
92143 + for (entry = tablep; entry->mode; entry++) {
92144 + if (entry->child) {
92145 + sd_free_ctl_entry(entry->child);
92146 + pax_open_kernel();
92147 + entry->child = NULL;
92148 + pax_close_kernel();
92149 + }
92150 if (entry->proc_handler == NULL)
92151 kfree(entry->procname);
92152 }
92153
92154 - kfree(*tablep);
92155 - *tablep = NULL;
92156 + kfree(tablep);
92157 }
92158
92159 static int min_load_idx = 0;
92160 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
92161
92162 static void
92163 -set_table_entry(struct ctl_table *entry,
92164 +set_table_entry(ctl_table_no_const *entry,
92165 const char *procname, void *data, int maxlen,
92166 umode_t mode, proc_handler *proc_handler,
92167 bool load_idx)
92168 @@ -5050,7 +5060,7 @@ set_table_entry(struct ctl_table *entry,
92169 static struct ctl_table *
92170 sd_alloc_ctl_domain_table(struct sched_domain *sd)
92171 {
92172 - struct ctl_table *table = sd_alloc_ctl_entry(14);
92173 + ctl_table_no_const *table = sd_alloc_ctl_entry(14);
92174
92175 if (table == NULL)
92176 return NULL;
92177 @@ -5088,9 +5098,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
92178 return table;
92179 }
92180
92181 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
92182 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
92183 {
92184 - struct ctl_table *entry, *table;
92185 + ctl_table_no_const *entry, *table;
92186 struct sched_domain *sd;
92187 int domain_num = 0, i;
92188 char buf[32];
92189 @@ -5117,11 +5127,13 @@ static struct ctl_table_header *sd_sysctl_header;
92190 static void register_sched_domain_sysctl(void)
92191 {
92192 int i, cpu_num = num_possible_cpus();
92193 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
92194 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
92195 char buf[32];
92196
92197 WARN_ON(sd_ctl_dir[0].child);
92198 + pax_open_kernel();
92199 sd_ctl_dir[0].child = entry;
92200 + pax_close_kernel();
92201
92202 if (entry == NULL)
92203 return;
92204 @@ -5144,8 +5156,12 @@ static void unregister_sched_domain_sysctl(void)
92205 if (sd_sysctl_header)
92206 unregister_sysctl_table(sd_sysctl_header);
92207 sd_sysctl_header = NULL;
92208 - if (sd_ctl_dir[0].child)
92209 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
92210 + if (sd_ctl_dir[0].child) {
92211 + sd_free_ctl_entry(sd_ctl_dir[0].child);
92212 + pax_open_kernel();
92213 + sd_ctl_dir[0].child = NULL;
92214 + pax_close_kernel();
92215 + }
92216 }
92217 #else
92218 static void register_sched_domain_sysctl(void)
92219 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
92220 index ef2b104..69961f6 100644
92221 --- a/kernel/sched/fair.c
92222 +++ b/kernel/sched/fair.c
92223 @@ -1906,7 +1906,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
92224
92225 static void reset_ptenuma_scan(struct task_struct *p)
92226 {
92227 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
92228 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
92229 p->mm->numa_scan_offset = 0;
92230 }
92231
92232 @@ -7465,7 +7465,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
92233 * run_rebalance_domains is triggered when needed from the scheduler tick.
92234 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
92235 */
92236 -static void run_rebalance_domains(struct softirq_action *h)
92237 +static __latent_entropy void run_rebalance_domains(void)
92238 {
92239 struct rq *this_rq = this_rq();
92240 enum cpu_idle_type idle = this_rq->idle_balance ?
92241 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
92242 index 2df8ef0..aae070f 100644
92243 --- a/kernel/sched/sched.h
92244 +++ b/kernel/sched/sched.h
92245 @@ -1140,7 +1140,7 @@ struct sched_class {
92246 #ifdef CONFIG_FAIR_GROUP_SCHED
92247 void (*task_move_group) (struct task_struct *p, int on_rq);
92248 #endif
92249 -};
92250 +} __do_const;
92251
92252 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
92253 {
92254 diff --git a/kernel/signal.c b/kernel/signal.c
92255 index 8f0876f..1153a5a 100644
92256 --- a/kernel/signal.c
92257 +++ b/kernel/signal.c
92258 @@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
92259
92260 int print_fatal_signals __read_mostly;
92261
92262 -static void __user *sig_handler(struct task_struct *t, int sig)
92263 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
92264 {
92265 return t->sighand->action[sig - 1].sa.sa_handler;
92266 }
92267
92268 -static int sig_handler_ignored(void __user *handler, int sig)
92269 +static int sig_handler_ignored(__sighandler_t handler, int sig)
92270 {
92271 /* Is it explicitly or implicitly ignored? */
92272 return handler == SIG_IGN ||
92273 @@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
92274
92275 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
92276 {
92277 - void __user *handler;
92278 + __sighandler_t handler;
92279
92280 handler = sig_handler(t, sig);
92281
92282 @@ -372,6 +372,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
92283 atomic_inc(&user->sigpending);
92284 rcu_read_unlock();
92285
92286 + if (!override_rlimit)
92287 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
92288 +
92289 if (override_rlimit ||
92290 atomic_read(&user->sigpending) <=
92291 task_rlimit(t, RLIMIT_SIGPENDING)) {
92292 @@ -499,7 +502,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
92293
92294 int unhandled_signal(struct task_struct *tsk, int sig)
92295 {
92296 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
92297 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
92298 if (is_global_init(tsk))
92299 return 1;
92300 if (handler != SIG_IGN && handler != SIG_DFL)
92301 @@ -793,6 +796,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
92302 }
92303 }
92304
92305 + /* allow glibc communication via tgkill to other threads in our
92306 + thread group */
92307 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
92308 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
92309 + && gr_handle_signal(t, sig))
92310 + return -EPERM;
92311 +
92312 return security_task_kill(t, info, sig, 0);
92313 }
92314
92315 @@ -1176,7 +1186,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
92316 return send_signal(sig, info, p, 1);
92317 }
92318
92319 -static int
92320 +int
92321 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
92322 {
92323 return send_signal(sig, info, t, 0);
92324 @@ -1213,6 +1223,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
92325 unsigned long int flags;
92326 int ret, blocked, ignored;
92327 struct k_sigaction *action;
92328 + int is_unhandled = 0;
92329
92330 spin_lock_irqsave(&t->sighand->siglock, flags);
92331 action = &t->sighand->action[sig-1];
92332 @@ -1227,9 +1238,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
92333 }
92334 if (action->sa.sa_handler == SIG_DFL)
92335 t->signal->flags &= ~SIGNAL_UNKILLABLE;
92336 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
92337 + is_unhandled = 1;
92338 ret = specific_send_sig_info(sig, info, t);
92339 spin_unlock_irqrestore(&t->sighand->siglock, flags);
92340
92341 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
92342 + normal operation */
92343 + if (is_unhandled) {
92344 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
92345 + gr_handle_crash(t, sig);
92346 + }
92347 +
92348 return ret;
92349 }
92350
92351 @@ -1300,8 +1320,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
92352 ret = check_kill_permission(sig, info, p);
92353 rcu_read_unlock();
92354
92355 - if (!ret && sig)
92356 + if (!ret && sig) {
92357 ret = do_send_sig_info(sig, info, p, true);
92358 + if (!ret)
92359 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
92360 + }
92361
92362 return ret;
92363 }
92364 @@ -2903,7 +2926,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
92365 int error = -ESRCH;
92366
92367 rcu_read_lock();
92368 - p = find_task_by_vpid(pid);
92369 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
92370 + /* allow glibc communication via tgkill to other threads in our
92371 + thread group */
92372 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
92373 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
92374 + p = find_task_by_vpid_unrestricted(pid);
92375 + else
92376 +#endif
92377 + p = find_task_by_vpid(pid);
92378 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
92379 error = check_kill_permission(sig, info, p);
92380 /*
92381 @@ -3236,8 +3267,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
92382 }
92383 seg = get_fs();
92384 set_fs(KERNEL_DS);
92385 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
92386 - (stack_t __force __user *) &uoss,
92387 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
92388 + (stack_t __force_user *) &uoss,
92389 compat_user_stack_pointer());
92390 set_fs(seg);
92391 if (ret >= 0 && uoss_ptr) {
92392 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
92393 index eb89e18..a4e6792 100644
92394 --- a/kernel/smpboot.c
92395 +++ b/kernel/smpboot.c
92396 @@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
92397 }
92398 smpboot_unpark_thread(plug_thread, cpu);
92399 }
92400 - list_add(&plug_thread->list, &hotplug_threads);
92401 + pax_list_add(&plug_thread->list, &hotplug_threads);
92402 out:
92403 mutex_unlock(&smpboot_threads_lock);
92404 return ret;
92405 @@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
92406 {
92407 get_online_cpus();
92408 mutex_lock(&smpboot_threads_lock);
92409 - list_del(&plug_thread->list);
92410 + pax_list_del(&plug_thread->list);
92411 smpboot_destroy_threads(plug_thread);
92412 mutex_unlock(&smpboot_threads_lock);
92413 put_online_cpus();
92414 diff --git a/kernel/softirq.c b/kernel/softirq.c
92415 index 0699add..d365ad8 100644
92416 --- a/kernel/softirq.c
92417 +++ b/kernel/softirq.c
92418 @@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
92419 EXPORT_SYMBOL(irq_stat);
92420 #endif
92421
92422 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
92423 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
92424
92425 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
92426
92427 @@ -266,7 +266,7 @@ restart:
92428 kstat_incr_softirqs_this_cpu(vec_nr);
92429
92430 trace_softirq_entry(vec_nr);
92431 - h->action(h);
92432 + h->action();
92433 trace_softirq_exit(vec_nr);
92434 if (unlikely(prev_count != preempt_count())) {
92435 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
92436 @@ -426,7 +426,7 @@ void __raise_softirq_irqoff(unsigned int nr)
92437 or_softirq_pending(1UL << nr);
92438 }
92439
92440 -void open_softirq(int nr, void (*action)(struct softirq_action *))
92441 +void __init open_softirq(int nr, void (*action)(void))
92442 {
92443 softirq_vec[nr].action = action;
92444 }
92445 @@ -478,7 +478,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
92446 }
92447 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
92448
92449 -static void tasklet_action(struct softirq_action *a)
92450 +static void tasklet_action(void)
92451 {
92452 struct tasklet_struct *list;
92453
92454 @@ -514,7 +514,7 @@ static void tasklet_action(struct softirq_action *a)
92455 }
92456 }
92457
92458 -static void tasklet_hi_action(struct softirq_action *a)
92459 +static __latent_entropy void tasklet_hi_action(void)
92460 {
92461 struct tasklet_struct *list;
92462
92463 @@ -741,7 +741,7 @@ static struct notifier_block cpu_nfb = {
92464 .notifier_call = cpu_callback
92465 };
92466
92467 -static struct smp_hotplug_thread softirq_threads = {
92468 +static struct smp_hotplug_thread softirq_threads __read_only = {
92469 .store = &ksoftirqd,
92470 .thread_should_run = ksoftirqd_should_run,
92471 .thread_fn = run_ksoftirqd,
92472 diff --git a/kernel/sys.c b/kernel/sys.c
92473 index 1eaa2f0..d80d27c 100644
92474 --- a/kernel/sys.c
92475 +++ b/kernel/sys.c
92476 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
92477 error = -EACCES;
92478 goto out;
92479 }
92480 +
92481 + if (gr_handle_chroot_setpriority(p, niceval)) {
92482 + error = -EACCES;
92483 + goto out;
92484 + }
92485 +
92486 no_nice = security_task_setnice(p, niceval);
92487 if (no_nice) {
92488 error = no_nice;
92489 @@ -353,6 +359,20 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
92490 goto error;
92491 }
92492
92493 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
92494 + goto error;
92495 +
92496 + if (!gid_eq(new->gid, old->gid)) {
92497 + /* make sure we generate a learn log for what will
92498 + end up being a role transition after a full-learning
92499 + policy is generated
92500 + CAP_SETGID is required to perform a transition
92501 + we may not log a CAP_SETGID check above, e.g.
92502 + in the case where new rgid = old egid
92503 + */
92504 + gr_learn_cap(current, new, CAP_SETGID);
92505 + }
92506 +
92507 if (rgid != (gid_t) -1 ||
92508 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
92509 new->sgid = new->egid;
92510 @@ -388,6 +408,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
92511 old = current_cred();
92512
92513 retval = -EPERM;
92514 +
92515 + if (gr_check_group_change(kgid, kgid, kgid))
92516 + goto error;
92517 +
92518 if (ns_capable(old->user_ns, CAP_SETGID))
92519 new->gid = new->egid = new->sgid = new->fsgid = kgid;
92520 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
92521 @@ -405,7 +429,7 @@ error:
92522 /*
92523 * change the user struct in a credentials set to match the new UID
92524 */
92525 -static int set_user(struct cred *new)
92526 +int set_user(struct cred *new)
92527 {
92528 struct user_struct *new_user;
92529
92530 @@ -485,7 +509,18 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
92531 goto error;
92532 }
92533
92534 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
92535 + goto error;
92536 +
92537 if (!uid_eq(new->uid, old->uid)) {
92538 + /* make sure we generate a learn log for what will
92539 + end up being a role transition after a full-learning
92540 + policy is generated
92541 + CAP_SETUID is required to perform a transition
92542 + we may not log a CAP_SETUID check above, e.g.
92543 + in the case where new ruid = old euid
92544 + */
92545 + gr_learn_cap(current, new, CAP_SETUID);
92546 retval = set_user(new);
92547 if (retval < 0)
92548 goto error;
92549 @@ -535,6 +570,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
92550 old = current_cred();
92551
92552 retval = -EPERM;
92553 +
92554 + if (gr_check_crash_uid(kuid))
92555 + goto error;
92556 + if (gr_check_user_change(kuid, kuid, kuid))
92557 + goto error;
92558 +
92559 if (ns_capable(old->user_ns, CAP_SETUID)) {
92560 new->suid = new->uid = kuid;
92561 if (!uid_eq(kuid, old->uid)) {
92562 @@ -604,6 +645,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
92563 goto error;
92564 }
92565
92566 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
92567 + goto error;
92568 +
92569 if (ruid != (uid_t) -1) {
92570 new->uid = kruid;
92571 if (!uid_eq(kruid, old->uid)) {
92572 @@ -688,6 +732,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
92573 goto error;
92574 }
92575
92576 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
92577 + goto error;
92578 +
92579 if (rgid != (gid_t) -1)
92580 new->gid = krgid;
92581 if (egid != (gid_t) -1)
92582 @@ -752,12 +799,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
92583 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
92584 ns_capable(old->user_ns, CAP_SETUID)) {
92585 if (!uid_eq(kuid, old->fsuid)) {
92586 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
92587 + goto error;
92588 +
92589 new->fsuid = kuid;
92590 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
92591 goto change_okay;
92592 }
92593 }
92594
92595 +error:
92596 abort_creds(new);
92597 return old_fsuid;
92598
92599 @@ -790,12 +841,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
92600 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
92601 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
92602 ns_capable(old->user_ns, CAP_SETGID)) {
92603 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
92604 + goto error;
92605 +
92606 if (!gid_eq(kgid, old->fsgid)) {
92607 new->fsgid = kgid;
92608 goto change_okay;
92609 }
92610 }
92611
92612 +error:
92613 abort_creds(new);
92614 return old_fsgid;
92615
92616 @@ -1172,19 +1227,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
92617 return -EFAULT;
92618
92619 down_read(&uts_sem);
92620 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
92621 + error = __copy_to_user(name->sysname, &utsname()->sysname,
92622 __OLD_UTS_LEN);
92623 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
92624 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
92625 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
92626 __OLD_UTS_LEN);
92627 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
92628 - error |= __copy_to_user(&name->release, &utsname()->release,
92629 + error |= __copy_to_user(name->release, &utsname()->release,
92630 __OLD_UTS_LEN);
92631 error |= __put_user(0, name->release + __OLD_UTS_LEN);
92632 - error |= __copy_to_user(&name->version, &utsname()->version,
92633 + error |= __copy_to_user(name->version, &utsname()->version,
92634 __OLD_UTS_LEN);
92635 error |= __put_user(0, name->version + __OLD_UTS_LEN);
92636 - error |= __copy_to_user(&name->machine, &utsname()->machine,
92637 + error |= __copy_to_user(name->machine, &utsname()->machine,
92638 __OLD_UTS_LEN);
92639 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
92640 up_read(&uts_sem);
92641 @@ -1385,6 +1440,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
92642 */
92643 new_rlim->rlim_cur = 1;
92644 }
92645 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
92646 + is changed to a lower value. Since tasks can be created by the same
92647 + user in between this limit change and an execve by this task, force
92648 + a recheck only for this task by setting PF_NPROC_EXCEEDED
92649 + */
92650 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
92651 + tsk->flags |= PF_NPROC_EXCEEDED;
92652 }
92653 if (!retval) {
92654 if (old_rlim)
92655 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
92656 index 15f2511..181b356 100644
92657 --- a/kernel/sysctl.c
92658 +++ b/kernel/sysctl.c
92659 @@ -94,7 +94,6 @@
92660
92661
92662 #if defined(CONFIG_SYSCTL)
92663 -
92664 /* External variables not in a header file. */
92665 extern int max_threads;
92666 extern int suid_dumpable;
92667 @@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
92668
92669 /* Constants used for minimum and maximum */
92670 #ifdef CONFIG_LOCKUP_DETECTOR
92671 -static int sixty = 60;
92672 +static int sixty __read_only = 60;
92673 #endif
92674
92675 -static int __maybe_unused neg_one = -1;
92676 +static int __maybe_unused neg_one __read_only = -1;
92677
92678 -static int zero;
92679 -static int __maybe_unused one = 1;
92680 -static int __maybe_unused two = 2;
92681 -static int __maybe_unused four = 4;
92682 -static unsigned long one_ul = 1;
92683 -static int one_hundred = 100;
92684 +static int zero __read_only = 0;
92685 +static int __maybe_unused one __read_only = 1;
92686 +static int __maybe_unused two __read_only = 2;
92687 +static int __maybe_unused three __read_only = 3;
92688 +static int __maybe_unused four __read_only = 4;
92689 +static unsigned long one_ul __read_only = 1;
92690 +static int one_hundred __read_only = 100;
92691 #ifdef CONFIG_PRINTK
92692 -static int ten_thousand = 10000;
92693 +static int ten_thousand __read_only = 10000;
92694 #endif
92695
92696 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
92697 @@ -181,10 +181,8 @@ static int proc_taint(struct ctl_table *table, int write,
92698 void __user *buffer, size_t *lenp, loff_t *ppos);
92699 #endif
92700
92701 -#ifdef CONFIG_PRINTK
92702 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
92703 void __user *buffer, size_t *lenp, loff_t *ppos);
92704 -#endif
92705
92706 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
92707 void __user *buffer, size_t *lenp, loff_t *ppos);
92708 @@ -215,6 +213,8 @@ static int sysrq_sysctl_handler(struct ctl_table *table, int write,
92709
92710 #endif
92711
92712 +extern struct ctl_table grsecurity_table[];
92713 +
92714 static struct ctl_table kern_table[];
92715 static struct ctl_table vm_table[];
92716 static struct ctl_table fs_table[];
92717 @@ -229,6 +229,20 @@ extern struct ctl_table epoll_table[];
92718 int sysctl_legacy_va_layout;
92719 #endif
92720
92721 +#ifdef CONFIG_PAX_SOFTMODE
92722 +static struct ctl_table pax_table[] = {
92723 + {
92724 + .procname = "softmode",
92725 + .data = &pax_softmode,
92726 + .maxlen = sizeof(unsigned int),
92727 + .mode = 0600,
92728 + .proc_handler = &proc_dointvec,
92729 + },
92730 +
92731 + { }
92732 +};
92733 +#endif
92734 +
92735 /* The default sysctl tables: */
92736
92737 static struct ctl_table sysctl_base_table[] = {
92738 @@ -277,6 +291,22 @@ static int max_extfrag_threshold = 1000;
92739 #endif
92740
92741 static struct ctl_table kern_table[] = {
92742 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
92743 + {
92744 + .procname = "grsecurity",
92745 + .mode = 0500,
92746 + .child = grsecurity_table,
92747 + },
92748 +#endif
92749 +
92750 +#ifdef CONFIG_PAX_SOFTMODE
92751 + {
92752 + .procname = "pax",
92753 + .mode = 0500,
92754 + .child = pax_table,
92755 + },
92756 +#endif
92757 +
92758 {
92759 .procname = "sched_child_runs_first",
92760 .data = &sysctl_sched_child_runs_first,
92761 @@ -642,7 +672,7 @@ static struct ctl_table kern_table[] = {
92762 .data = &modprobe_path,
92763 .maxlen = KMOD_PATH_LEN,
92764 .mode = 0644,
92765 - .proc_handler = proc_dostring,
92766 + .proc_handler = proc_dostring_modpriv,
92767 },
92768 {
92769 .procname = "modules_disabled",
92770 @@ -809,16 +839,20 @@ static struct ctl_table kern_table[] = {
92771 .extra1 = &zero,
92772 .extra2 = &one,
92773 },
92774 +#endif
92775 {
92776 .procname = "kptr_restrict",
92777 .data = &kptr_restrict,
92778 .maxlen = sizeof(int),
92779 .mode = 0644,
92780 .proc_handler = proc_dointvec_minmax_sysadmin,
92781 +#ifdef CONFIG_GRKERNSEC_HIDESYM
92782 + .extra1 = &two,
92783 +#else
92784 .extra1 = &zero,
92785 +#endif
92786 .extra2 = &two,
92787 },
92788 -#endif
92789 {
92790 .procname = "ngroups_max",
92791 .data = &ngroups_max,
92792 @@ -1065,10 +1099,17 @@ static struct ctl_table kern_table[] = {
92793 */
92794 {
92795 .procname = "perf_event_paranoid",
92796 - .data = &sysctl_perf_event_paranoid,
92797 - .maxlen = sizeof(sysctl_perf_event_paranoid),
92798 + .data = &sysctl_perf_event_legitimately_concerned,
92799 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
92800 .mode = 0644,
92801 - .proc_handler = proc_dointvec,
92802 + /* go ahead, be a hero */
92803 + .proc_handler = proc_dointvec_minmax_sysadmin,
92804 + .extra1 = &neg_one,
92805 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
92806 + .extra2 = &three,
92807 +#else
92808 + .extra2 = &two,
92809 +#endif
92810 },
92811 {
92812 .procname = "perf_event_mlock_kb",
92813 @@ -1327,6 +1368,13 @@ static struct ctl_table vm_table[] = {
92814 .proc_handler = proc_dointvec_minmax,
92815 .extra1 = &zero,
92816 },
92817 + {
92818 + .procname = "heap_stack_gap",
92819 + .data = &sysctl_heap_stack_gap,
92820 + .maxlen = sizeof(sysctl_heap_stack_gap),
92821 + .mode = 0644,
92822 + .proc_handler = proc_doulongvec_minmax,
92823 + },
92824 #else
92825 {
92826 .procname = "nr_trim_pages",
92827 @@ -1809,6 +1857,16 @@ int proc_dostring(struct ctl_table *table, int write,
92828 (char __user *)buffer, lenp, ppos);
92829 }
92830
92831 +int proc_dostring_modpriv(struct ctl_table *table, int write,
92832 + void __user *buffer, size_t *lenp, loff_t *ppos)
92833 +{
92834 + if (write && !capable(CAP_SYS_MODULE))
92835 + return -EPERM;
92836 +
92837 + return _proc_do_string(table->data, table->maxlen, write,
92838 + buffer, lenp, ppos);
92839 +}
92840 +
92841 static size_t proc_skip_spaces(char **buf)
92842 {
92843 size_t ret;
92844 @@ -1914,6 +1972,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
92845 len = strlen(tmp);
92846 if (len > *size)
92847 len = *size;
92848 + if (len > sizeof(tmp))
92849 + len = sizeof(tmp);
92850 if (copy_to_user(*buf, tmp, len))
92851 return -EFAULT;
92852 *size -= len;
92853 @@ -2091,7 +2151,7 @@ int proc_dointvec(struct ctl_table *table, int write,
92854 static int proc_taint(struct ctl_table *table, int write,
92855 void __user *buffer, size_t *lenp, loff_t *ppos)
92856 {
92857 - struct ctl_table t;
92858 + ctl_table_no_const t;
92859 unsigned long tmptaint = get_taint();
92860 int err;
92861
92862 @@ -2119,7 +2179,6 @@ static int proc_taint(struct ctl_table *table, int write,
92863 return err;
92864 }
92865
92866 -#ifdef CONFIG_PRINTK
92867 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
92868 void __user *buffer, size_t *lenp, loff_t *ppos)
92869 {
92870 @@ -2128,7 +2187,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
92871
92872 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
92873 }
92874 -#endif
92875
92876 struct do_proc_dointvec_minmax_conv_param {
92877 int *min;
92878 @@ -2688,6 +2746,12 @@ int proc_dostring(struct ctl_table *table, int write,
92879 return -ENOSYS;
92880 }
92881
92882 +int proc_dostring_modpriv(struct ctl_table *table, int write,
92883 + void __user *buffer, size_t *lenp, loff_t *ppos)
92884 +{
92885 + return -ENOSYS;
92886 +}
92887 +
92888 int proc_dointvec(struct ctl_table *table, int write,
92889 void __user *buffer, size_t *lenp, loff_t *ppos)
92890 {
92891 @@ -2744,5 +2808,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
92892 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
92893 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
92894 EXPORT_SYMBOL(proc_dostring);
92895 +EXPORT_SYMBOL(proc_dostring_modpriv);
92896 EXPORT_SYMBOL(proc_doulongvec_minmax);
92897 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
92898 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
92899 index b312fcc7..753d72d 100644
92900 --- a/kernel/taskstats.c
92901 +++ b/kernel/taskstats.c
92902 @@ -28,9 +28,12 @@
92903 #include <linux/fs.h>
92904 #include <linux/file.h>
92905 #include <linux/pid_namespace.h>
92906 +#include <linux/grsecurity.h>
92907 #include <net/genetlink.h>
92908 #include <linux/atomic.h>
92909
92910 +extern int gr_is_taskstats_denied(int pid);
92911 +
92912 /*
92913 * Maximum length of a cpumask that can be specified in
92914 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
92915 @@ -576,6 +579,9 @@ err:
92916
92917 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
92918 {
92919 + if (gr_is_taskstats_denied(current->pid))
92920 + return -EACCES;
92921 +
92922 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
92923 return cmd_attr_register_cpumask(info);
92924 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
92925 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
92926 index a7077d3..dd48a49 100644
92927 --- a/kernel/time/alarmtimer.c
92928 +++ b/kernel/time/alarmtimer.c
92929 @@ -823,7 +823,7 @@ static int __init alarmtimer_init(void)
92930 struct platform_device *pdev;
92931 int error = 0;
92932 int i;
92933 - struct k_clock alarm_clock = {
92934 + static struct k_clock alarm_clock = {
92935 .clock_getres = alarm_clock_getres,
92936 .clock_get = alarm_clock_get,
92937 .timer_create = alarm_timer_create,
92938 diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
92939 index 37e50aa..57a9501 100644
92940 --- a/kernel/time/hrtimer.c
92941 +++ b/kernel/time/hrtimer.c
92942 @@ -1399,7 +1399,7 @@ void hrtimer_peek_ahead_timers(void)
92943 local_irq_restore(flags);
92944 }
92945
92946 -static void run_hrtimer_softirq(struct softirq_action *h)
92947 +static __latent_entropy void run_hrtimer_softirq(void)
92948 {
92949 hrtimer_peek_ahead_timers();
92950 }
92951 diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
92952 index a16b678..8c5bd9d 100644
92953 --- a/kernel/time/posix-cpu-timers.c
92954 +++ b/kernel/time/posix-cpu-timers.c
92955 @@ -1450,14 +1450,14 @@ struct k_clock clock_posix_cpu = {
92956
92957 static __init int init_posix_cpu_timers(void)
92958 {
92959 - struct k_clock process = {
92960 + static struct k_clock process = {
92961 .clock_getres = process_cpu_clock_getres,
92962 .clock_get = process_cpu_clock_get,
92963 .timer_create = process_cpu_timer_create,
92964 .nsleep = process_cpu_nsleep,
92965 .nsleep_restart = process_cpu_nsleep_restart,
92966 };
92967 - struct k_clock thread = {
92968 + static struct k_clock thread = {
92969 .clock_getres = thread_cpu_clock_getres,
92970 .clock_get = thread_cpu_clock_get,
92971 .timer_create = thread_cpu_timer_create,
92972 diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
92973 index 31ea01f..7fc61ef 100644
92974 --- a/kernel/time/posix-timers.c
92975 +++ b/kernel/time/posix-timers.c
92976 @@ -43,6 +43,7 @@
92977 #include <linux/hash.h>
92978 #include <linux/posix-clock.h>
92979 #include <linux/posix-timers.h>
92980 +#include <linux/grsecurity.h>
92981 #include <linux/syscalls.h>
92982 #include <linux/wait.h>
92983 #include <linux/workqueue.h>
92984 @@ -124,7 +125,7 @@ static DEFINE_SPINLOCK(hash_lock);
92985 * which we beg off on and pass to do_sys_settimeofday().
92986 */
92987
92988 -static struct k_clock posix_clocks[MAX_CLOCKS];
92989 +static struct k_clock *posix_clocks[MAX_CLOCKS];
92990
92991 /*
92992 * These ones are defined below.
92993 @@ -277,7 +278,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
92994 */
92995 static __init int init_posix_timers(void)
92996 {
92997 - struct k_clock clock_realtime = {
92998 + static struct k_clock clock_realtime = {
92999 .clock_getres = hrtimer_get_res,
93000 .clock_get = posix_clock_realtime_get,
93001 .clock_set = posix_clock_realtime_set,
93002 @@ -289,7 +290,7 @@ static __init int init_posix_timers(void)
93003 .timer_get = common_timer_get,
93004 .timer_del = common_timer_del,
93005 };
93006 - struct k_clock clock_monotonic = {
93007 + static struct k_clock clock_monotonic = {
93008 .clock_getres = hrtimer_get_res,
93009 .clock_get = posix_ktime_get_ts,
93010 .nsleep = common_nsleep,
93011 @@ -299,19 +300,19 @@ static __init int init_posix_timers(void)
93012 .timer_get = common_timer_get,
93013 .timer_del = common_timer_del,
93014 };
93015 - struct k_clock clock_monotonic_raw = {
93016 + static struct k_clock clock_monotonic_raw = {
93017 .clock_getres = hrtimer_get_res,
93018 .clock_get = posix_get_monotonic_raw,
93019 };
93020 - struct k_clock clock_realtime_coarse = {
93021 + static struct k_clock clock_realtime_coarse = {
93022 .clock_getres = posix_get_coarse_res,
93023 .clock_get = posix_get_realtime_coarse,
93024 };
93025 - struct k_clock clock_monotonic_coarse = {
93026 + static struct k_clock clock_monotonic_coarse = {
93027 .clock_getres = posix_get_coarse_res,
93028 .clock_get = posix_get_monotonic_coarse,
93029 };
93030 - struct k_clock clock_tai = {
93031 + static struct k_clock clock_tai = {
93032 .clock_getres = hrtimer_get_res,
93033 .clock_get = posix_get_tai,
93034 .nsleep = common_nsleep,
93035 @@ -321,7 +322,7 @@ static __init int init_posix_timers(void)
93036 .timer_get = common_timer_get,
93037 .timer_del = common_timer_del,
93038 };
93039 - struct k_clock clock_boottime = {
93040 + static struct k_clock clock_boottime = {
93041 .clock_getres = hrtimer_get_res,
93042 .clock_get = posix_get_boottime,
93043 .nsleep = common_nsleep,
93044 @@ -533,7 +534,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
93045 return;
93046 }
93047
93048 - posix_clocks[clock_id] = *new_clock;
93049 + posix_clocks[clock_id] = new_clock;
93050 }
93051 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
93052
93053 @@ -579,9 +580,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
93054 return (id & CLOCKFD_MASK) == CLOCKFD ?
93055 &clock_posix_dynamic : &clock_posix_cpu;
93056
93057 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
93058 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
93059 return NULL;
93060 - return &posix_clocks[id];
93061 + return posix_clocks[id];
93062 }
93063
93064 static int common_timer_create(struct k_itimer *new_timer)
93065 @@ -599,7 +600,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
93066 struct k_clock *kc = clockid_to_kclock(which_clock);
93067 struct k_itimer *new_timer;
93068 int error, new_timer_id;
93069 - sigevent_t event;
93070 + sigevent_t event = { };
93071 int it_id_set = IT_ID_NOT_SET;
93072
93073 if (!kc)
93074 @@ -1014,6 +1015,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
93075 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
93076 return -EFAULT;
93077
93078 + /* only the CLOCK_REALTIME clock can be set, all other clocks
93079 + have their clock_set fptr set to a nosettime dummy function
93080 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
93081 + call common_clock_set, which calls do_sys_settimeofday, which
93082 + we hook
93083 + */
93084 +
93085 return kc->clock_set(which_clock, &new_tp);
93086 }
93087
93088 diff --git a/kernel/time/time.c b/kernel/time/time.c
93089 index a9ae20f..d3fbde7 100644
93090 --- a/kernel/time/time.c
93091 +++ b/kernel/time/time.c
93092 @@ -173,6 +173,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
93093 return error;
93094
93095 if (tz) {
93096 + /* we log in do_settimeofday called below, so don't log twice
93097 + */
93098 + if (!tv)
93099 + gr_log_timechange();
93100 +
93101 sys_tz = *tz;
93102 update_vsyscall_tz();
93103 if (firsttime) {
93104 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
93105 index ec1791f..6a086cd 100644
93106 --- a/kernel/time/timekeeping.c
93107 +++ b/kernel/time/timekeeping.c
93108 @@ -15,6 +15,7 @@
93109 #include <linux/init.h>
93110 #include <linux/mm.h>
93111 #include <linux/sched.h>
93112 +#include <linux/grsecurity.h>
93113 #include <linux/syscore_ops.h>
93114 #include <linux/clocksource.h>
93115 #include <linux/jiffies.h>
93116 @@ -717,6 +718,8 @@ int do_settimeofday(const struct timespec *tv)
93117 if (!timespec_valid_strict(tv))
93118 return -EINVAL;
93119
93120 + gr_log_timechange();
93121 +
93122 raw_spin_lock_irqsave(&timekeeper_lock, flags);
93123 write_seqcount_begin(&tk_core.seq);
93124
93125 diff --git a/kernel/time/timer.c b/kernel/time/timer.c
93126 index 3260ffd..c93cd5e 100644
93127 --- a/kernel/time/timer.c
93128 +++ b/kernel/time/timer.c
93129 @@ -1394,7 +1394,7 @@ void update_process_times(int user_tick)
93130 /*
93131 * This function runs timers and the timer-tq in bottom half context.
93132 */
93133 -static void run_timer_softirq(struct softirq_action *h)
93134 +static __latent_entropy void run_timer_softirq(void)
93135 {
93136 struct tvec_base *base = __this_cpu_read(tvec_bases);
93137
93138 @@ -1457,7 +1457,7 @@ static void process_timeout(unsigned long __data)
93139 *
93140 * In all cases the return value is guaranteed to be non-negative.
93141 */
93142 -signed long __sched schedule_timeout(signed long timeout)
93143 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
93144 {
93145 struct timer_list timer;
93146 unsigned long expire;
93147 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
93148 index 61ed862..3b52c65 100644
93149 --- a/kernel/time/timer_list.c
93150 +++ b/kernel/time/timer_list.c
93151 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
93152
93153 static void print_name_offset(struct seq_file *m, void *sym)
93154 {
93155 +#ifdef CONFIG_GRKERNSEC_HIDESYM
93156 + SEQ_printf(m, "<%p>", NULL);
93157 +#else
93158 char symname[KSYM_NAME_LEN];
93159
93160 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
93161 SEQ_printf(m, "<%pK>", sym);
93162 else
93163 SEQ_printf(m, "%s", symname);
93164 +#endif
93165 }
93166
93167 static void
93168 @@ -119,7 +123,11 @@ next_one:
93169 static void
93170 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
93171 {
93172 +#ifdef CONFIG_GRKERNSEC_HIDESYM
93173 + SEQ_printf(m, " .base: %p\n", NULL);
93174 +#else
93175 SEQ_printf(m, " .base: %pK\n", base);
93176 +#endif
93177 SEQ_printf(m, " .index: %d\n",
93178 base->index);
93179 SEQ_printf(m, " .resolution: %Lu nsecs\n",
93180 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
93181 {
93182 struct proc_dir_entry *pe;
93183
93184 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
93185 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
93186 +#else
93187 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
93188 +#endif
93189 if (!pe)
93190 return -ENOMEM;
93191 return 0;
93192 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
93193 index 1fb08f2..ca4bb1e 100644
93194 --- a/kernel/time/timer_stats.c
93195 +++ b/kernel/time/timer_stats.c
93196 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
93197 static unsigned long nr_entries;
93198 static struct entry entries[MAX_ENTRIES];
93199
93200 -static atomic_t overflow_count;
93201 +static atomic_unchecked_t overflow_count;
93202
93203 /*
93204 * The entries are in a hash-table, for fast lookup:
93205 @@ -140,7 +140,7 @@ static void reset_entries(void)
93206 nr_entries = 0;
93207 memset(entries, 0, sizeof(entries));
93208 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
93209 - atomic_set(&overflow_count, 0);
93210 + atomic_set_unchecked(&overflow_count, 0);
93211 }
93212
93213 static struct entry *alloc_entry(void)
93214 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
93215 if (likely(entry))
93216 entry->count++;
93217 else
93218 - atomic_inc(&overflow_count);
93219 + atomic_inc_unchecked(&overflow_count);
93220
93221 out_unlock:
93222 raw_spin_unlock_irqrestore(lock, flags);
93223 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
93224
93225 static void print_name_offset(struct seq_file *m, unsigned long addr)
93226 {
93227 +#ifdef CONFIG_GRKERNSEC_HIDESYM
93228 + seq_printf(m, "<%p>", NULL);
93229 +#else
93230 char symname[KSYM_NAME_LEN];
93231
93232 if (lookup_symbol_name(addr, symname) < 0)
93233 - seq_printf(m, "<%p>", (void *)addr);
93234 + seq_printf(m, "<%pK>", (void *)addr);
93235 else
93236 seq_printf(m, "%s", symname);
93237 +#endif
93238 }
93239
93240 static int tstats_show(struct seq_file *m, void *v)
93241 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
93242
93243 seq_puts(m, "Timer Stats Version: v0.3\n");
93244 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
93245 - if (atomic_read(&overflow_count))
93246 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
93247 + if (atomic_read_unchecked(&overflow_count))
93248 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
93249 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
93250
93251 for (i = 0; i < nr_entries; i++) {
93252 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
93253 {
93254 struct proc_dir_entry *pe;
93255
93256 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
93257 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
93258 +#else
93259 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
93260 +#endif
93261 if (!pe)
93262 return -ENOMEM;
93263 return 0;
93264 diff --git a/kernel/torture.c b/kernel/torture.c
93265 index dd70993..0bf694b 100644
93266 --- a/kernel/torture.c
93267 +++ b/kernel/torture.c
93268 @@ -482,7 +482,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
93269 mutex_lock(&fullstop_mutex);
93270 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
93271 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
93272 - ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
93273 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
93274 } else {
93275 pr_warn("Concurrent rmmod and shutdown illegal!\n");
93276 }
93277 @@ -549,14 +549,14 @@ static int torture_stutter(void *arg)
93278 if (!torture_must_stop()) {
93279 if (stutter > 1) {
93280 schedule_timeout_interruptible(stutter - 1);
93281 - ACCESS_ONCE(stutter_pause_test) = 2;
93282 + ACCESS_ONCE_RW(stutter_pause_test) = 2;
93283 }
93284 schedule_timeout_interruptible(1);
93285 - ACCESS_ONCE(stutter_pause_test) = 1;
93286 + ACCESS_ONCE_RW(stutter_pause_test) = 1;
93287 }
93288 if (!torture_must_stop())
93289 schedule_timeout_interruptible(stutter);
93290 - ACCESS_ONCE(stutter_pause_test) = 0;
93291 + ACCESS_ONCE_RW(stutter_pause_test) = 0;
93292 torture_shutdown_absorb("torture_stutter");
93293 } while (!torture_must_stop());
93294 torture_kthread_stopping("torture_stutter");
93295 @@ -648,7 +648,7 @@ bool torture_cleanup_begin(void)
93296 schedule_timeout_uninterruptible(10);
93297 return true;
93298 }
93299 - ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
93300 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
93301 mutex_unlock(&fullstop_mutex);
93302 torture_shutdown_cleanup();
93303 torture_shuffle_cleanup();
93304 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
93305 index c1bd4ad..4b861dc 100644
93306 --- a/kernel/trace/blktrace.c
93307 +++ b/kernel/trace/blktrace.c
93308 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
93309 struct blk_trace *bt = filp->private_data;
93310 char buf[16];
93311
93312 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
93313 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
93314
93315 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
93316 }
93317 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
93318 return 1;
93319
93320 bt = buf->chan->private_data;
93321 - atomic_inc(&bt->dropped);
93322 + atomic_inc_unchecked(&bt->dropped);
93323 return 0;
93324 }
93325
93326 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
93327
93328 bt->dir = dir;
93329 bt->dev = dev;
93330 - atomic_set(&bt->dropped, 0);
93331 + atomic_set_unchecked(&bt->dropped, 0);
93332 INIT_LIST_HEAD(&bt->running_list);
93333
93334 ret = -EIO;
93335 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
93336 index 31c90fe..051ce98 100644
93337 --- a/kernel/trace/ftrace.c
93338 +++ b/kernel/trace/ftrace.c
93339 @@ -2183,12 +2183,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
93340 if (unlikely(ftrace_disabled))
93341 return 0;
93342
93343 + ret = ftrace_arch_code_modify_prepare();
93344 + FTRACE_WARN_ON(ret);
93345 + if (ret)
93346 + return 0;
93347 +
93348 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
93349 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
93350 if (ret) {
93351 ftrace_bug(ret, ip);
93352 - return 0;
93353 }
93354 - return 1;
93355 + return ret ? 0 : 1;
93356 }
93357
93358 /*
93359 @@ -4492,8 +4497,10 @@ static int ftrace_process_locs(struct module *mod,
93360 if (!count)
93361 return 0;
93362
93363 + pax_open_kernel();
93364 sort(start, count, sizeof(*start),
93365 ftrace_cmp_ips, ftrace_swap_ips);
93366 + pax_close_kernel();
93367
93368 start_pg = ftrace_allocate_pages(count);
93369 if (!start_pg)
93370 @@ -5340,7 +5347,7 @@ static int alloc_retstack_tasklist(struct ftrace_ret_stack **ret_stack_list)
93371
93372 if (t->ret_stack == NULL) {
93373 atomic_set(&t->tracing_graph_pause, 0);
93374 - atomic_set(&t->trace_overrun, 0);
93375 + atomic_set_unchecked(&t->trace_overrun, 0);
93376 t->curr_ret_stack = -1;
93377 /* Make sure the tasks see the -1 first: */
93378 smp_wmb();
93379 @@ -5553,7 +5560,7 @@ static void
93380 graph_init_task(struct task_struct *t, struct ftrace_ret_stack *ret_stack)
93381 {
93382 atomic_set(&t->tracing_graph_pause, 0);
93383 - atomic_set(&t->trace_overrun, 0);
93384 + atomic_set_unchecked(&t->trace_overrun, 0);
93385 t->ftrace_timestamp = 0;
93386 /* make curr_ret_stack visible before we add the ret_stack */
93387 smp_wmb();
93388 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
93389 index a56e07c..d46f0ba 100644
93390 --- a/kernel/trace/ring_buffer.c
93391 +++ b/kernel/trace/ring_buffer.c
93392 @@ -352,9 +352,9 @@ struct buffer_data_page {
93393 */
93394 struct buffer_page {
93395 struct list_head list; /* list of buffer pages */
93396 - local_t write; /* index for next write */
93397 + local_unchecked_t write; /* index for next write */
93398 unsigned read; /* index for next read */
93399 - local_t entries; /* entries on this page */
93400 + local_unchecked_t entries; /* entries on this page */
93401 unsigned long real_end; /* real end of data */
93402 struct buffer_data_page *page; /* Actual data page */
93403 };
93404 @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
93405 unsigned long last_overrun;
93406 local_t entries_bytes;
93407 local_t entries;
93408 - local_t overrun;
93409 - local_t commit_overrun;
93410 + local_unchecked_t overrun;
93411 + local_unchecked_t commit_overrun;
93412 local_t dropped_events;
93413 local_t committing;
93414 local_t commits;
93415 @@ -1032,8 +1032,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
93416 *
93417 * We add a counter to the write field to denote this.
93418 */
93419 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
93420 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
93421 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
93422 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
93423
93424 /*
93425 * Just make sure we have seen our old_write and synchronize
93426 @@ -1061,8 +1061,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
93427 * cmpxchg to only update if an interrupt did not already
93428 * do it for us. If the cmpxchg fails, we don't care.
93429 */
93430 - (void)local_cmpxchg(&next_page->write, old_write, val);
93431 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
93432 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
93433 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
93434
93435 /*
93436 * No need to worry about races with clearing out the commit.
93437 @@ -1429,12 +1429,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
93438
93439 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
93440 {
93441 - return local_read(&bpage->entries) & RB_WRITE_MASK;
93442 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
93443 }
93444
93445 static inline unsigned long rb_page_write(struct buffer_page *bpage)
93446 {
93447 - return local_read(&bpage->write) & RB_WRITE_MASK;
93448 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
93449 }
93450
93451 static int
93452 @@ -1529,7 +1529,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
93453 * bytes consumed in ring buffer from here.
93454 * Increment overrun to account for the lost events.
93455 */
93456 - local_add(page_entries, &cpu_buffer->overrun);
93457 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
93458 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
93459 }
93460
93461 @@ -2091,7 +2091,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
93462 * it is our responsibility to update
93463 * the counters.
93464 */
93465 - local_add(entries, &cpu_buffer->overrun);
93466 + local_add_unchecked(entries, &cpu_buffer->overrun);
93467 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
93468
93469 /*
93470 @@ -2241,7 +2241,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
93471 if (tail == BUF_PAGE_SIZE)
93472 tail_page->real_end = 0;
93473
93474 - local_sub(length, &tail_page->write);
93475 + local_sub_unchecked(length, &tail_page->write);
93476 return;
93477 }
93478
93479 @@ -2276,7 +2276,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
93480 rb_event_set_padding(event);
93481
93482 /* Set the write back to the previous setting */
93483 - local_sub(length, &tail_page->write);
93484 + local_sub_unchecked(length, &tail_page->write);
93485 return;
93486 }
93487
93488 @@ -2288,7 +2288,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
93489
93490 /* Set write to end of buffer */
93491 length = (tail + length) - BUF_PAGE_SIZE;
93492 - local_sub(length, &tail_page->write);
93493 + local_sub_unchecked(length, &tail_page->write);
93494 }
93495
93496 /*
93497 @@ -2314,7 +2314,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
93498 * about it.
93499 */
93500 if (unlikely(next_page == commit_page)) {
93501 - local_inc(&cpu_buffer->commit_overrun);
93502 + local_inc_unchecked(&cpu_buffer->commit_overrun);
93503 goto out_reset;
93504 }
93505
93506 @@ -2370,7 +2370,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
93507 cpu_buffer->tail_page) &&
93508 (cpu_buffer->commit_page ==
93509 cpu_buffer->reader_page))) {
93510 - local_inc(&cpu_buffer->commit_overrun);
93511 + local_inc_unchecked(&cpu_buffer->commit_overrun);
93512 goto out_reset;
93513 }
93514 }
93515 @@ -2418,7 +2418,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
93516 length += RB_LEN_TIME_EXTEND;
93517
93518 tail_page = cpu_buffer->tail_page;
93519 - write = local_add_return(length, &tail_page->write);
93520 + write = local_add_return_unchecked(length, &tail_page->write);
93521
93522 /* set write to only the index of the write */
93523 write &= RB_WRITE_MASK;
93524 @@ -2442,7 +2442,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
93525 kmemcheck_annotate_bitfield(event, bitfield);
93526 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
93527
93528 - local_inc(&tail_page->entries);
93529 + local_inc_unchecked(&tail_page->entries);
93530
93531 /*
93532 * If this is the first commit on the page, then update
93533 @@ -2475,7 +2475,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
93534
93535 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
93536 unsigned long write_mask =
93537 - local_read(&bpage->write) & ~RB_WRITE_MASK;
93538 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
93539 unsigned long event_length = rb_event_length(event);
93540 /*
93541 * This is on the tail page. It is possible that
93542 @@ -2485,7 +2485,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
93543 */
93544 old_index += write_mask;
93545 new_index += write_mask;
93546 - index = local_cmpxchg(&bpage->write, old_index, new_index);
93547 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
93548 if (index == old_index) {
93549 /* update counters */
93550 local_sub(event_length, &cpu_buffer->entries_bytes);
93551 @@ -2877,7 +2877,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
93552
93553 /* Do the likely case first */
93554 if (likely(bpage->page == (void *)addr)) {
93555 - local_dec(&bpage->entries);
93556 + local_dec_unchecked(&bpage->entries);
93557 return;
93558 }
93559
93560 @@ -2889,7 +2889,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
93561 start = bpage;
93562 do {
93563 if (bpage->page == (void *)addr) {
93564 - local_dec(&bpage->entries);
93565 + local_dec_unchecked(&bpage->entries);
93566 return;
93567 }
93568 rb_inc_page(cpu_buffer, &bpage);
93569 @@ -3173,7 +3173,7 @@ static inline unsigned long
93570 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
93571 {
93572 return local_read(&cpu_buffer->entries) -
93573 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
93574 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
93575 }
93576
93577 /**
93578 @@ -3262,7 +3262,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
93579 return 0;
93580
93581 cpu_buffer = buffer->buffers[cpu];
93582 - ret = local_read(&cpu_buffer->overrun);
93583 + ret = local_read_unchecked(&cpu_buffer->overrun);
93584
93585 return ret;
93586 }
93587 @@ -3285,7 +3285,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
93588 return 0;
93589
93590 cpu_buffer = buffer->buffers[cpu];
93591 - ret = local_read(&cpu_buffer->commit_overrun);
93592 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
93593
93594 return ret;
93595 }
93596 @@ -3370,7 +3370,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
93597 /* if you care about this being correct, lock the buffer */
93598 for_each_buffer_cpu(buffer, cpu) {
93599 cpu_buffer = buffer->buffers[cpu];
93600 - overruns += local_read(&cpu_buffer->overrun);
93601 + overruns += local_read_unchecked(&cpu_buffer->overrun);
93602 }
93603
93604 return overruns;
93605 @@ -3541,8 +3541,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
93606 /*
93607 * Reset the reader page to size zero.
93608 */
93609 - local_set(&cpu_buffer->reader_page->write, 0);
93610 - local_set(&cpu_buffer->reader_page->entries, 0);
93611 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
93612 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
93613 local_set(&cpu_buffer->reader_page->page->commit, 0);
93614 cpu_buffer->reader_page->real_end = 0;
93615
93616 @@ -3576,7 +3576,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
93617 * want to compare with the last_overrun.
93618 */
93619 smp_mb();
93620 - overwrite = local_read(&(cpu_buffer->overrun));
93621 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
93622
93623 /*
93624 * Here's the tricky part.
93625 @@ -4148,8 +4148,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
93626
93627 cpu_buffer->head_page
93628 = list_entry(cpu_buffer->pages, struct buffer_page, list);
93629 - local_set(&cpu_buffer->head_page->write, 0);
93630 - local_set(&cpu_buffer->head_page->entries, 0);
93631 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
93632 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
93633 local_set(&cpu_buffer->head_page->page->commit, 0);
93634
93635 cpu_buffer->head_page->read = 0;
93636 @@ -4159,14 +4159,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
93637
93638 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
93639 INIT_LIST_HEAD(&cpu_buffer->new_pages);
93640 - local_set(&cpu_buffer->reader_page->write, 0);
93641 - local_set(&cpu_buffer->reader_page->entries, 0);
93642 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
93643 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
93644 local_set(&cpu_buffer->reader_page->page->commit, 0);
93645 cpu_buffer->reader_page->read = 0;
93646
93647 local_set(&cpu_buffer->entries_bytes, 0);
93648 - local_set(&cpu_buffer->overrun, 0);
93649 - local_set(&cpu_buffer->commit_overrun, 0);
93650 + local_set_unchecked(&cpu_buffer->overrun, 0);
93651 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
93652 local_set(&cpu_buffer->dropped_events, 0);
93653 local_set(&cpu_buffer->entries, 0);
93654 local_set(&cpu_buffer->committing, 0);
93655 @@ -4571,8 +4571,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
93656 rb_init_page(bpage);
93657 bpage = reader->page;
93658 reader->page = *data_page;
93659 - local_set(&reader->write, 0);
93660 - local_set(&reader->entries, 0);
93661 + local_set_unchecked(&reader->write, 0);
93662 + local_set_unchecked(&reader->entries, 0);
93663 reader->read = 0;
93664 *data_page = bpage;
93665
93666 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
93667 index 426962b..e8e2d9a 100644
93668 --- a/kernel/trace/trace.c
93669 +++ b/kernel/trace/trace.c
93670 @@ -3488,7 +3488,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
93671 return 0;
93672 }
93673
93674 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
93675 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
93676 {
93677 /* do nothing if flag is already set */
93678 if (!!(trace_flags & mask) == !!enabled)
93679 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
93680 index 385391f..8d2250f 100644
93681 --- a/kernel/trace/trace.h
93682 +++ b/kernel/trace/trace.h
93683 @@ -1280,7 +1280,7 @@ extern const char *__stop___tracepoint_str[];
93684 void trace_printk_init_buffers(void);
93685 void trace_printk_start_comm(void);
93686 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
93687 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
93688 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
93689
93690 /*
93691 * Normal trace_printk() and friends allocates special buffers
93692 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
93693 index 57b67b1..66082a9 100644
93694 --- a/kernel/trace/trace_clock.c
93695 +++ b/kernel/trace/trace_clock.c
93696 @@ -124,7 +124,7 @@ u64 notrace trace_clock_global(void)
93697 return now;
93698 }
93699
93700 -static atomic64_t trace_counter;
93701 +static atomic64_unchecked_t trace_counter;
93702
93703 /*
93704 * trace_clock_counter(): simply an atomic counter.
93705 @@ -133,5 +133,5 @@ static atomic64_t trace_counter;
93706 */
93707 u64 notrace trace_clock_counter(void)
93708 {
93709 - return atomic64_add_return(1, &trace_counter);
93710 + return atomic64_inc_return_unchecked(&trace_counter);
93711 }
93712 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
93713 index 1b0df1e..4ebb965 100644
93714 --- a/kernel/trace/trace_events.c
93715 +++ b/kernel/trace/trace_events.c
93716 @@ -1720,7 +1720,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
93717 return 0;
93718 }
93719
93720 -struct ftrace_module_file_ops;
93721 static void __add_event_to_tracers(struct ftrace_event_call *call);
93722
93723 /* Add an additional event_call dynamically */
93724 diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c
93725 index f0a0c98..3692dc8 100644
93726 --- a/kernel/trace/trace_functions_graph.c
93727 +++ b/kernel/trace/trace_functions_graph.c
93728 @@ -133,7 +133,7 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
93729
93730 /* The return trace stack is full */
93731 if (current->curr_ret_stack == FTRACE_RETFUNC_DEPTH - 1) {
93732 - atomic_inc(&current->trace_overrun);
93733 + atomic_inc_unchecked(&current->trace_overrun);
93734 return -EBUSY;
93735 }
93736
93737 @@ -230,7 +230,7 @@ ftrace_pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret,
93738 *ret = current->ret_stack[index].ret;
93739 trace->func = current->ret_stack[index].func;
93740 trace->calltime = current->ret_stack[index].calltime;
93741 - trace->overrun = atomic_read(&current->trace_overrun);
93742 + trace->overrun = atomic_read_unchecked(&current->trace_overrun);
93743 trace->depth = index;
93744 }
93745
93746 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
93747 index 0abd9b8..6a663a2 100644
93748 --- a/kernel/trace/trace_mmiotrace.c
93749 +++ b/kernel/trace/trace_mmiotrace.c
93750 @@ -24,7 +24,7 @@ struct header_iter {
93751 static struct trace_array *mmio_trace_array;
93752 static bool overrun_detected;
93753 static unsigned long prev_overruns;
93754 -static atomic_t dropped_count;
93755 +static atomic_unchecked_t dropped_count;
93756
93757 static void mmio_reset_data(struct trace_array *tr)
93758 {
93759 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
93760
93761 static unsigned long count_overruns(struct trace_iterator *iter)
93762 {
93763 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
93764 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
93765 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
93766
93767 if (over > prev_overruns)
93768 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
93769 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
93770 sizeof(*entry), 0, pc);
93771 if (!event) {
93772 - atomic_inc(&dropped_count);
93773 + atomic_inc_unchecked(&dropped_count);
93774 return;
93775 }
93776 entry = ring_buffer_event_data(event);
93777 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
93778 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
93779 sizeof(*entry), 0, pc);
93780 if (!event) {
93781 - atomic_inc(&dropped_count);
93782 + atomic_inc_unchecked(&dropped_count);
93783 return;
93784 }
93785 entry = ring_buffer_event_data(event);
93786 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
93787 index c6977d5..d243785 100644
93788 --- a/kernel/trace/trace_output.c
93789 +++ b/kernel/trace/trace_output.c
93790 @@ -712,14 +712,16 @@ int register_ftrace_event(struct trace_event *event)
93791 goto out;
93792 }
93793
93794 + pax_open_kernel();
93795 if (event->funcs->trace == NULL)
93796 - event->funcs->trace = trace_nop_print;
93797 + *(void **)&event->funcs->trace = trace_nop_print;
93798 if (event->funcs->raw == NULL)
93799 - event->funcs->raw = trace_nop_print;
93800 + *(void **)&event->funcs->raw = trace_nop_print;
93801 if (event->funcs->hex == NULL)
93802 - event->funcs->hex = trace_nop_print;
93803 + *(void **)&event->funcs->hex = trace_nop_print;
93804 if (event->funcs->binary == NULL)
93805 - event->funcs->binary = trace_nop_print;
93806 + *(void **)&event->funcs->binary = trace_nop_print;
93807 + pax_close_kernel();
93808
93809 key = event->type & (EVENT_HASHSIZE - 1);
93810
93811 diff --git a/kernel/trace/trace_seq.c b/kernel/trace/trace_seq.c
93812 index 1f24ed9..10407ec 100644
93813 --- a/kernel/trace/trace_seq.c
93814 +++ b/kernel/trace/trace_seq.c
93815 @@ -367,7 +367,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
93816
93817 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
93818 if (!IS_ERR(p)) {
93819 - p = mangle_path(s->buffer + s->len, p, "\n");
93820 + p = mangle_path(s->buffer + s->len, p, "\n\\");
93821 if (p) {
93822 s->len = p - s->buffer;
93823 return 1;
93824 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
93825 index 16eddb3..758b308 100644
93826 --- a/kernel/trace/trace_stack.c
93827 +++ b/kernel/trace/trace_stack.c
93828 @@ -90,7 +90,7 @@ check_stack(unsigned long ip, unsigned long *stack)
93829 return;
93830
93831 /* we do not handle interrupt stacks yet */
93832 - if (!object_is_on_stack(stack))
93833 + if (!object_starts_on_stack(stack))
93834 return;
93835
93836 local_irq_save(flags);
93837 diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c
93838 index 29228c4..301bc8c 100644
93839 --- a/kernel/trace/trace_syscalls.c
93840 +++ b/kernel/trace/trace_syscalls.c
93841 @@ -602,6 +602,8 @@ static int perf_sysenter_enable(struct ftrace_event_call *call)
93842 int num;
93843
93844 num = ((struct syscall_metadata *)call->data)->syscall_nr;
93845 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
93846 + return -EINVAL;
93847
93848 mutex_lock(&syscall_trace_lock);
93849 if (!sys_perf_refcount_enter)
93850 @@ -622,6 +624,8 @@ static void perf_sysenter_disable(struct ftrace_event_call *call)
93851 int num;
93852
93853 num = ((struct syscall_metadata *)call->data)->syscall_nr;
93854 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
93855 + return;
93856
93857 mutex_lock(&syscall_trace_lock);
93858 sys_perf_refcount_enter--;
93859 @@ -674,6 +678,8 @@ static int perf_sysexit_enable(struct ftrace_event_call *call)
93860 int num;
93861
93862 num = ((struct syscall_metadata *)call->data)->syscall_nr;
93863 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
93864 + return -EINVAL;
93865
93866 mutex_lock(&syscall_trace_lock);
93867 if (!sys_perf_refcount_exit)
93868 @@ -694,6 +700,8 @@ static void perf_sysexit_disable(struct ftrace_event_call *call)
93869 int num;
93870
93871 num = ((struct syscall_metadata *)call->data)->syscall_nr;
93872 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
93873 + return;
93874
93875 mutex_lock(&syscall_trace_lock);
93876 sys_perf_refcount_exit--;
93877 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
93878 index aa312b0..395f343 100644
93879 --- a/kernel/user_namespace.c
93880 +++ b/kernel/user_namespace.c
93881 @@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
93882 !kgid_has_mapping(parent_ns, group))
93883 return -EPERM;
93884
93885 +#ifdef CONFIG_GRKERNSEC
93886 + /*
93887 + * This doesn't really inspire confidence:
93888 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
93889 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
93890 + * Increases kernel attack surface in areas developers
93891 + * previously cared little about ("low importance due
93892 + * to requiring "root" capability")
93893 + * To be removed when this code receives *proper* review
93894 + */
93895 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
93896 + !capable(CAP_SETGID))
93897 + return -EPERM;
93898 +#endif
93899 +
93900 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
93901 if (!ns)
93902 return -ENOMEM;
93903 @@ -872,7 +887,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
93904 if (atomic_read(&current->mm->mm_users) > 1)
93905 return -EINVAL;
93906
93907 - if (current->fs->users != 1)
93908 + if (atomic_read(&current->fs->users) != 1)
93909 return -EINVAL;
93910
93911 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
93912 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
93913 index c8eac43..4b5f08f 100644
93914 --- a/kernel/utsname_sysctl.c
93915 +++ b/kernel/utsname_sysctl.c
93916 @@ -47,7 +47,7 @@ static void put_uts(struct ctl_table *table, int write, void *which)
93917 static int proc_do_uts_string(struct ctl_table *table, int write,
93918 void __user *buffer, size_t *lenp, loff_t *ppos)
93919 {
93920 - struct ctl_table uts_table;
93921 + ctl_table_no_const uts_table;
93922 int r;
93923 memcpy(&uts_table, table, sizeof(uts_table));
93924 uts_table.data = get_uts(table, write);
93925 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
93926 index 70bf118..4be3c37 100644
93927 --- a/kernel/watchdog.c
93928 +++ b/kernel/watchdog.c
93929 @@ -572,7 +572,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
93930 static void watchdog_nmi_disable(unsigned int cpu) { return; }
93931 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
93932
93933 -static struct smp_hotplug_thread watchdog_threads = {
93934 +static struct smp_hotplug_thread watchdog_threads __read_only = {
93935 .store = &softlockup_watchdog,
93936 .thread_should_run = watchdog_should_run,
93937 .thread_fn = watchdog,
93938 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
93939 index 09b685d..d3565e3 100644
93940 --- a/kernel/workqueue.c
93941 +++ b/kernel/workqueue.c
93942 @@ -4508,7 +4508,7 @@ static void rebind_workers(struct worker_pool *pool)
93943 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
93944 worker_flags |= WORKER_REBOUND;
93945 worker_flags &= ~WORKER_UNBOUND;
93946 - ACCESS_ONCE(worker->flags) = worker_flags;
93947 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
93948 }
93949
93950 spin_unlock_irq(&pool->lock);
93951 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
93952 index 4e35a5d..8a1f3f0 100644
93953 --- a/lib/Kconfig.debug
93954 +++ b/lib/Kconfig.debug
93955 @@ -894,7 +894,7 @@ config DEBUG_MUTEXES
93956
93957 config DEBUG_WW_MUTEX_SLOWPATH
93958 bool "Wait/wound mutex debugging: Slowpath testing"
93959 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
93960 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
93961 select DEBUG_LOCK_ALLOC
93962 select DEBUG_SPINLOCK
93963 select DEBUG_MUTEXES
93964 @@ -911,7 +911,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
93965
93966 config DEBUG_LOCK_ALLOC
93967 bool "Lock debugging: detect incorrect freeing of live locks"
93968 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
93969 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
93970 select DEBUG_SPINLOCK
93971 select DEBUG_MUTEXES
93972 select LOCKDEP
93973 @@ -925,7 +925,7 @@ config DEBUG_LOCK_ALLOC
93974
93975 config PROVE_LOCKING
93976 bool "Lock debugging: prove locking correctness"
93977 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
93978 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
93979 select LOCKDEP
93980 select DEBUG_SPINLOCK
93981 select DEBUG_MUTEXES
93982 @@ -976,7 +976,7 @@ config LOCKDEP
93983
93984 config LOCK_STAT
93985 bool "Lock usage statistics"
93986 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
93987 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
93988 select LOCKDEP
93989 select DEBUG_SPINLOCK
93990 select DEBUG_MUTEXES
93991 @@ -1449,6 +1449,7 @@ config LATENCYTOP
93992 depends on DEBUG_KERNEL
93993 depends on STACKTRACE_SUPPORT
93994 depends on PROC_FS
93995 + depends on !GRKERNSEC_HIDESYM
93996 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
93997 select KALLSYMS
93998 select KALLSYMS_ALL
93999 @@ -1465,7 +1466,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
94000 config DEBUG_STRICT_USER_COPY_CHECKS
94001 bool "Strict user copy size checks"
94002 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
94003 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
94004 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
94005 help
94006 Enabling this option turns a certain set of sanity checks for user
94007 copy operations into compile time failures.
94008 @@ -1593,7 +1594,7 @@ endmenu # runtime tests
94009
94010 config PROVIDE_OHCI1394_DMA_INIT
94011 bool "Remote debugging over FireWire early on boot"
94012 - depends on PCI && X86
94013 + depends on PCI && X86 && !GRKERNSEC
94014 help
94015 If you want to debug problems which hang or crash the kernel early
94016 on boot and the crashing machine has a FireWire port, you can use
94017 diff --git a/lib/Makefile b/lib/Makefile
94018 index 0211d2b..93f5cc3 100644
94019 --- a/lib/Makefile
94020 +++ b/lib/Makefile
94021 @@ -55,7 +55,7 @@ obj-$(CONFIG_BTREE) += btree.o
94022 obj-$(CONFIG_INTERVAL_TREE) += interval_tree.o
94023 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
94024 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
94025 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
94026 +obj-y += list_debug.o
94027 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
94028
94029 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
94030 diff --git a/lib/average.c b/lib/average.c
94031 index 114d1be..ab0350c 100644
94032 --- a/lib/average.c
94033 +++ b/lib/average.c
94034 @@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
94035 {
94036 unsigned long internal = ACCESS_ONCE(avg->internal);
94037
94038 - ACCESS_ONCE(avg->internal) = internal ?
94039 + ACCESS_ONCE_RW(avg->internal) = internal ?
94040 (((internal << avg->weight) - internal) +
94041 (val << avg->factor)) >> avg->weight :
94042 (val << avg->factor);
94043 diff --git a/lib/bitmap.c b/lib/bitmap.c
94044 index b499ab6..fbdb76c 100644
94045 --- a/lib/bitmap.c
94046 +++ b/lib/bitmap.c
94047 @@ -433,7 +433,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
94048 {
94049 int c, old_c, totaldigits, ndigits, nchunks, nbits;
94050 u32 chunk;
94051 - const char __user __force *ubuf = (const char __user __force *)buf;
94052 + const char __user *ubuf = (const char __force_user *)buf;
94053
94054 bitmap_zero(maskp, nmaskbits);
94055
94056 @@ -518,7 +518,7 @@ int bitmap_parse_user(const char __user *ubuf,
94057 {
94058 if (!access_ok(VERIFY_READ, ubuf, ulen))
94059 return -EFAULT;
94060 - return __bitmap_parse((const char __force *)ubuf,
94061 + return __bitmap_parse((const char __force_kernel *)ubuf,
94062 ulen, 1, maskp, nmaskbits);
94063
94064 }
94065 @@ -609,7 +609,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
94066 {
94067 unsigned a, b;
94068 int c, old_c, totaldigits;
94069 - const char __user __force *ubuf = (const char __user __force *)buf;
94070 + const char __user *ubuf = (const char __force_user *)buf;
94071 int exp_digit, in_range;
94072
94073 totaldigits = c = 0;
94074 @@ -704,7 +704,7 @@ int bitmap_parselist_user(const char __user *ubuf,
94075 {
94076 if (!access_ok(VERIFY_READ, ubuf, ulen))
94077 return -EFAULT;
94078 - return __bitmap_parselist((const char __force *)ubuf,
94079 + return __bitmap_parselist((const char __force_kernel *)ubuf,
94080 ulen, 1, maskp, nmaskbits);
94081 }
94082 EXPORT_SYMBOL(bitmap_parselist_user);
94083 diff --git a/lib/bug.c b/lib/bug.c
94084 index d1d7c78..b354235 100644
94085 --- a/lib/bug.c
94086 +++ b/lib/bug.c
94087 @@ -137,6 +137,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
94088 return BUG_TRAP_TYPE_NONE;
94089
94090 bug = find_bug(bugaddr);
94091 + if (!bug)
94092 + return BUG_TRAP_TYPE_NONE;
94093
94094 file = NULL;
94095 line = 0;
94096 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
94097 index 547f7f9..a6d4ba0 100644
94098 --- a/lib/debugobjects.c
94099 +++ b/lib/debugobjects.c
94100 @@ -289,7 +289,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
94101 if (limit > 4)
94102 return;
94103
94104 - is_on_stack = object_is_on_stack(addr);
94105 + is_on_stack = object_starts_on_stack(addr);
94106 if (is_on_stack == onstack)
94107 return;
94108
94109 diff --git a/lib/div64.c b/lib/div64.c
94110 index 4382ad7..08aa558 100644
94111 --- a/lib/div64.c
94112 +++ b/lib/div64.c
94113 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
94114 EXPORT_SYMBOL(__div64_32);
94115
94116 #ifndef div_s64_rem
94117 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
94118 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
94119 {
94120 u64 quotient;
94121
94122 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
94123 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
94124 */
94125 #ifndef div64_u64
94126 -u64 div64_u64(u64 dividend, u64 divisor)
94127 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
94128 {
94129 u32 high = divisor >> 32;
94130 u64 quot;
94131 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
94132 index add80cc..0d27550 100644
94133 --- a/lib/dma-debug.c
94134 +++ b/lib/dma-debug.c
94135 @@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
94136
94137 void dma_debug_add_bus(struct bus_type *bus)
94138 {
94139 - struct notifier_block *nb;
94140 + notifier_block_no_const *nb;
94141
94142 if (global_disable)
94143 return;
94144 @@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
94145
94146 static void check_for_stack(struct device *dev, void *addr)
94147 {
94148 - if (object_is_on_stack(addr))
94149 + if (object_starts_on_stack(addr))
94150 err_printk(dev, NULL, "DMA-API: device driver maps memory from "
94151 "stack [addr=%p]\n", addr);
94152 }
94153 diff --git a/lib/hash.c b/lib/hash.c
94154 index fea973f..386626f 100644
94155 --- a/lib/hash.c
94156 +++ b/lib/hash.c
94157 @@ -14,7 +14,7 @@
94158 #include <linux/hash.h>
94159 #include <linux/cache.h>
94160
94161 -static struct fast_hash_ops arch_hash_ops __read_mostly = {
94162 +static struct fast_hash_ops arch_hash_ops __read_only = {
94163 .hash = jhash,
94164 .hash2 = jhash2,
94165 };
94166 diff --git a/lib/inflate.c b/lib/inflate.c
94167 index 013a761..c28f3fc 100644
94168 --- a/lib/inflate.c
94169 +++ b/lib/inflate.c
94170 @@ -269,7 +269,7 @@ static void free(void *where)
94171 malloc_ptr = free_mem_ptr;
94172 }
94173 #else
94174 -#define malloc(a) kmalloc(a, GFP_KERNEL)
94175 +#define malloc(a) kmalloc((a), GFP_KERNEL)
94176 #define free(a) kfree(a)
94177 #endif
94178
94179 diff --git a/lib/ioremap.c b/lib/ioremap.c
94180 index 0c9216c..863bd89 100644
94181 --- a/lib/ioremap.c
94182 +++ b/lib/ioremap.c
94183 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
94184 unsigned long next;
94185
94186 phys_addr -= addr;
94187 - pmd = pmd_alloc(&init_mm, pud, addr);
94188 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
94189 if (!pmd)
94190 return -ENOMEM;
94191 do {
94192 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
94193 unsigned long next;
94194
94195 phys_addr -= addr;
94196 - pud = pud_alloc(&init_mm, pgd, addr);
94197 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
94198 if (!pud)
94199 return -ENOMEM;
94200 do {
94201 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
94202 index bd2bea9..6b3c95e 100644
94203 --- a/lib/is_single_threaded.c
94204 +++ b/lib/is_single_threaded.c
94205 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
94206 struct task_struct *p, *t;
94207 bool ret;
94208
94209 + if (!mm)
94210 + return true;
94211 +
94212 if (atomic_read(&task->signal->live) != 1)
94213 return false;
94214
94215 diff --git a/lib/kobject.c b/lib/kobject.c
94216 index 58751bb..93a1853 100644
94217 --- a/lib/kobject.c
94218 +++ b/lib/kobject.c
94219 @@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
94220
94221
94222 static DEFINE_SPINLOCK(kobj_ns_type_lock);
94223 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
94224 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
94225
94226 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
94227 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
94228 {
94229 enum kobj_ns_type type = ops->type;
94230 int error;
94231 diff --git a/lib/list_debug.c b/lib/list_debug.c
94232 index c24c2f7..f0296f4 100644
94233 --- a/lib/list_debug.c
94234 +++ b/lib/list_debug.c
94235 @@ -11,7 +11,9 @@
94236 #include <linux/bug.h>
94237 #include <linux/kernel.h>
94238 #include <linux/rculist.h>
94239 +#include <linux/mm.h>
94240
94241 +#ifdef CONFIG_DEBUG_LIST
94242 /*
94243 * Insert a new entry between two known consecutive entries.
94244 *
94245 @@ -19,21 +21,40 @@
94246 * the prev/next entries already!
94247 */
94248
94249 +static bool __list_add_debug(struct list_head *new,
94250 + struct list_head *prev,
94251 + struct list_head *next)
94252 +{
94253 + if (unlikely(next->prev != prev)) {
94254 + printk(KERN_ERR "list_add corruption. next->prev should be "
94255 + "prev (%p), but was %p. (next=%p).\n",
94256 + prev, next->prev, next);
94257 + BUG();
94258 + return false;
94259 + }
94260 + if (unlikely(prev->next != next)) {
94261 + printk(KERN_ERR "list_add corruption. prev->next should be "
94262 + "next (%p), but was %p. (prev=%p).\n",
94263 + next, prev->next, prev);
94264 + BUG();
94265 + return false;
94266 + }
94267 + if (unlikely(new == prev || new == next)) {
94268 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
94269 + new, prev, next);
94270 + BUG();
94271 + return false;
94272 + }
94273 + return true;
94274 +}
94275 +
94276 void __list_add(struct list_head *new,
94277 - struct list_head *prev,
94278 - struct list_head *next)
94279 + struct list_head *prev,
94280 + struct list_head *next)
94281 {
94282 - WARN(next->prev != prev,
94283 - "list_add corruption. next->prev should be "
94284 - "prev (%p), but was %p. (next=%p).\n",
94285 - prev, next->prev, next);
94286 - WARN(prev->next != next,
94287 - "list_add corruption. prev->next should be "
94288 - "next (%p), but was %p. (prev=%p).\n",
94289 - next, prev->next, prev);
94290 - WARN(new == prev || new == next,
94291 - "list_add double add: new=%p, prev=%p, next=%p.\n",
94292 - new, prev, next);
94293 + if (!__list_add_debug(new, prev, next))
94294 + return;
94295 +
94296 next->prev = new;
94297 new->next = next;
94298 new->prev = prev;
94299 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
94300 }
94301 EXPORT_SYMBOL(__list_add);
94302
94303 -void __list_del_entry(struct list_head *entry)
94304 +static bool __list_del_entry_debug(struct list_head *entry)
94305 {
94306 struct list_head *prev, *next;
94307
94308 prev = entry->prev;
94309 next = entry->next;
94310
94311 - if (WARN(next == LIST_POISON1,
94312 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
94313 - entry, LIST_POISON1) ||
94314 - WARN(prev == LIST_POISON2,
94315 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
94316 - entry, LIST_POISON2) ||
94317 - WARN(prev->next != entry,
94318 - "list_del corruption. prev->next should be %p, "
94319 - "but was %p\n", entry, prev->next) ||
94320 - WARN(next->prev != entry,
94321 - "list_del corruption. next->prev should be %p, "
94322 - "but was %p\n", entry, next->prev))
94323 + if (unlikely(next == LIST_POISON1)) {
94324 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
94325 + entry, LIST_POISON1);
94326 + BUG();
94327 + return false;
94328 + }
94329 + if (unlikely(prev == LIST_POISON2)) {
94330 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
94331 + entry, LIST_POISON2);
94332 + BUG();
94333 + return false;
94334 + }
94335 + if (unlikely(entry->prev->next != entry)) {
94336 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
94337 + "but was %p\n", entry, prev->next);
94338 + BUG();
94339 + return false;
94340 + }
94341 + if (unlikely(entry->next->prev != entry)) {
94342 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
94343 + "but was %p\n", entry, next->prev);
94344 + BUG();
94345 + return false;
94346 + }
94347 + return true;
94348 +}
94349 +
94350 +void __list_del_entry(struct list_head *entry)
94351 +{
94352 + if (!__list_del_entry_debug(entry))
94353 return;
94354
94355 - __list_del(prev, next);
94356 + __list_del(entry->prev, entry->next);
94357 }
94358 EXPORT_SYMBOL(__list_del_entry);
94359
94360 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
94361 void __list_add_rcu(struct list_head *new,
94362 struct list_head *prev, struct list_head *next)
94363 {
94364 - WARN(next->prev != prev,
94365 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
94366 - prev, next->prev, next);
94367 - WARN(prev->next != next,
94368 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
94369 - next, prev->next, prev);
94370 + if (!__list_add_debug(new, prev, next))
94371 + return;
94372 +
94373 new->next = next;
94374 new->prev = prev;
94375 rcu_assign_pointer(list_next_rcu(prev), new);
94376 next->prev = new;
94377 }
94378 EXPORT_SYMBOL(__list_add_rcu);
94379 +#endif
94380 +
94381 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
94382 +{
94383 +#ifdef CONFIG_DEBUG_LIST
94384 + if (!__list_add_debug(new, prev, next))
94385 + return;
94386 +#endif
94387 +
94388 + pax_open_kernel();
94389 + next->prev = new;
94390 + new->next = next;
94391 + new->prev = prev;
94392 + prev->next = new;
94393 + pax_close_kernel();
94394 +}
94395 +EXPORT_SYMBOL(__pax_list_add);
94396 +
94397 +void pax_list_del(struct list_head *entry)
94398 +{
94399 +#ifdef CONFIG_DEBUG_LIST
94400 + if (!__list_del_entry_debug(entry))
94401 + return;
94402 +#endif
94403 +
94404 + pax_open_kernel();
94405 + __list_del(entry->prev, entry->next);
94406 + entry->next = LIST_POISON1;
94407 + entry->prev = LIST_POISON2;
94408 + pax_close_kernel();
94409 +}
94410 +EXPORT_SYMBOL(pax_list_del);
94411 +
94412 +void pax_list_del_init(struct list_head *entry)
94413 +{
94414 + pax_open_kernel();
94415 + __list_del(entry->prev, entry->next);
94416 + INIT_LIST_HEAD(entry);
94417 + pax_close_kernel();
94418 +}
94419 +EXPORT_SYMBOL(pax_list_del_init);
94420 +
94421 +void __pax_list_add_rcu(struct list_head *new,
94422 + struct list_head *prev, struct list_head *next)
94423 +{
94424 +#ifdef CONFIG_DEBUG_LIST
94425 + if (!__list_add_debug(new, prev, next))
94426 + return;
94427 +#endif
94428 +
94429 + pax_open_kernel();
94430 + new->next = next;
94431 + new->prev = prev;
94432 + rcu_assign_pointer(list_next_rcu(prev), new);
94433 + next->prev = new;
94434 + pax_close_kernel();
94435 +}
94436 +EXPORT_SYMBOL(__pax_list_add_rcu);
94437 +
94438 +void pax_list_del_rcu(struct list_head *entry)
94439 +{
94440 +#ifdef CONFIG_DEBUG_LIST
94441 + if (!__list_del_entry_debug(entry))
94442 + return;
94443 +#endif
94444 +
94445 + pax_open_kernel();
94446 + __list_del(entry->prev, entry->next);
94447 + entry->next = LIST_POISON1;
94448 + entry->prev = LIST_POISON2;
94449 + pax_close_kernel();
94450 +}
94451 +EXPORT_SYMBOL(pax_list_del_rcu);
94452 diff --git a/lib/lockref.c b/lib/lockref.c
94453 index d2233de..fa1a2f6 100644
94454 --- a/lib/lockref.c
94455 +++ b/lib/lockref.c
94456 @@ -48,13 +48,13 @@
94457 void lockref_get(struct lockref *lockref)
94458 {
94459 CMPXCHG_LOOP(
94460 - new.count++;
94461 + __lockref_inc(&new);
94462 ,
94463 return;
94464 );
94465
94466 spin_lock(&lockref->lock);
94467 - lockref->count++;
94468 + __lockref_inc(lockref);
94469 spin_unlock(&lockref->lock);
94470 }
94471 EXPORT_SYMBOL(lockref_get);
94472 @@ -69,7 +69,7 @@ int lockref_get_not_zero(struct lockref *lockref)
94473 int retval;
94474
94475 CMPXCHG_LOOP(
94476 - new.count++;
94477 + __lockref_inc(&new);
94478 if (!old.count)
94479 return 0;
94480 ,
94481 @@ -79,7 +79,7 @@ int lockref_get_not_zero(struct lockref *lockref)
94482 spin_lock(&lockref->lock);
94483 retval = 0;
94484 if (lockref->count) {
94485 - lockref->count++;
94486 + __lockref_inc(lockref);
94487 retval = 1;
94488 }
94489 spin_unlock(&lockref->lock);
94490 @@ -96,7 +96,7 @@ EXPORT_SYMBOL(lockref_get_not_zero);
94491 int lockref_get_or_lock(struct lockref *lockref)
94492 {
94493 CMPXCHG_LOOP(
94494 - new.count++;
94495 + __lockref_inc(&new);
94496 if (!old.count)
94497 break;
94498 ,
94499 @@ -106,7 +106,7 @@ int lockref_get_or_lock(struct lockref *lockref)
94500 spin_lock(&lockref->lock);
94501 if (!lockref->count)
94502 return 0;
94503 - lockref->count++;
94504 + __lockref_inc(lockref);
94505 spin_unlock(&lockref->lock);
94506 return 1;
94507 }
94508 @@ -120,7 +120,7 @@ EXPORT_SYMBOL(lockref_get_or_lock);
94509 int lockref_put_or_lock(struct lockref *lockref)
94510 {
94511 CMPXCHG_LOOP(
94512 - new.count--;
94513 + __lockref_dec(&new);
94514 if (old.count <= 1)
94515 break;
94516 ,
94517 @@ -130,7 +130,7 @@ int lockref_put_or_lock(struct lockref *lockref)
94518 spin_lock(&lockref->lock);
94519 if (lockref->count <= 1)
94520 return 0;
94521 - lockref->count--;
94522 + __lockref_dec(lockref);
94523 spin_unlock(&lockref->lock);
94524 return 1;
94525 }
94526 @@ -157,7 +157,7 @@ int lockref_get_not_dead(struct lockref *lockref)
94527 int retval;
94528
94529 CMPXCHG_LOOP(
94530 - new.count++;
94531 + __lockref_inc(&new);
94532 if ((int)old.count < 0)
94533 return 0;
94534 ,
94535 @@ -167,7 +167,7 @@ int lockref_get_not_dead(struct lockref *lockref)
94536 spin_lock(&lockref->lock);
94537 retval = 0;
94538 if ((int) lockref->count >= 0) {
94539 - lockref->count++;
94540 + __lockref_inc(lockref);
94541 retval = 1;
94542 }
94543 spin_unlock(&lockref->lock);
94544 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
94545 index 6111bcb..02e816b 100644
94546 --- a/lib/percpu-refcount.c
94547 +++ b/lib/percpu-refcount.c
94548 @@ -31,7 +31,7 @@
94549 * atomic_long_t can't hit 0 before we've added up all the percpu refs.
94550 */
94551
94552 -#define PERCPU_COUNT_BIAS (1LU << (BITS_PER_LONG - 1))
94553 +#define PERCPU_COUNT_BIAS (1LU << (BITS_PER_LONG - 2))
94554
94555 static DECLARE_WAIT_QUEUE_HEAD(percpu_ref_switch_waitq);
94556
94557 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
94558 index 3291a8e..346a91e 100644
94559 --- a/lib/radix-tree.c
94560 +++ b/lib/radix-tree.c
94561 @@ -67,7 +67,7 @@ struct radix_tree_preload {
94562 int nr;
94563 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
94564 };
94565 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
94566 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
94567
94568 static inline void *ptr_to_indirect(void *ptr)
94569 {
94570 diff --git a/lib/random32.c b/lib/random32.c
94571 index 0bee183..526f12f 100644
94572 --- a/lib/random32.c
94573 +++ b/lib/random32.c
94574 @@ -47,7 +47,7 @@ static inline void prandom_state_selftest(void)
94575 }
94576 #endif
94577
94578 -static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
94579 +static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
94580
94581 /**
94582 * prandom_u32_state - seeded pseudo-random number generator.
94583 diff --git a/lib/rbtree.c b/lib/rbtree.c
94584 index c16c81a..4dcbda1 100644
94585 --- a/lib/rbtree.c
94586 +++ b/lib/rbtree.c
94587 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
94588 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
94589
94590 static const struct rb_augment_callbacks dummy_callbacks = {
94591 - dummy_propagate, dummy_copy, dummy_rotate
94592 + .propagate = dummy_propagate,
94593 + .copy = dummy_copy,
94594 + .rotate = dummy_rotate
94595 };
94596
94597 void rb_insert_color(struct rb_node *node, struct rb_root *root)
94598 diff --git a/lib/show_mem.c b/lib/show_mem.c
94599 index 5e25627..3ed9d7f 100644
94600 --- a/lib/show_mem.c
94601 +++ b/lib/show_mem.c
94602 @@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
94603 quicklist_total_size());
94604 #endif
94605 #ifdef CONFIG_MEMORY_FAILURE
94606 - printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
94607 + printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
94608 #endif
94609 }
94610 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
94611 index bb2b201..46abaf9 100644
94612 --- a/lib/strncpy_from_user.c
94613 +++ b/lib/strncpy_from_user.c
94614 @@ -21,7 +21,7 @@
94615 */
94616 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
94617 {
94618 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
94619 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
94620 long res = 0;
94621
94622 /*
94623 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
94624 index a28df52..3d55877 100644
94625 --- a/lib/strnlen_user.c
94626 +++ b/lib/strnlen_user.c
94627 @@ -26,7 +26,7 @@
94628 */
94629 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
94630 {
94631 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
94632 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
94633 long align, res = 0;
94634 unsigned long c;
94635
94636 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
94637 index 4abda07..b9d3765 100644
94638 --- a/lib/swiotlb.c
94639 +++ b/lib/swiotlb.c
94640 @@ -682,7 +682,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
94641
94642 void
94643 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
94644 - dma_addr_t dev_addr)
94645 + dma_addr_t dev_addr, struct dma_attrs *attrs)
94646 {
94647 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
94648
94649 diff --git a/lib/usercopy.c b/lib/usercopy.c
94650 index 4f5b1dd..7cab418 100644
94651 --- a/lib/usercopy.c
94652 +++ b/lib/usercopy.c
94653 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
94654 WARN(1, "Buffer overflow detected!\n");
94655 }
94656 EXPORT_SYMBOL(copy_from_user_overflow);
94657 +
94658 +void copy_to_user_overflow(void)
94659 +{
94660 + WARN(1, "Buffer overflow detected!\n");
94661 +}
94662 +EXPORT_SYMBOL(copy_to_user_overflow);
94663 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
94664 index ec337f6..8484eb2 100644
94665 --- a/lib/vsprintf.c
94666 +++ b/lib/vsprintf.c
94667 @@ -16,6 +16,9 @@
94668 * - scnprintf and vscnprintf
94669 */
94670
94671 +#ifdef CONFIG_GRKERNSEC_HIDESYM
94672 +#define __INCLUDED_BY_HIDESYM 1
94673 +#endif
94674 #include <stdarg.h>
94675 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
94676 #include <linux/types.h>
94677 @@ -625,7 +628,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
94678 #ifdef CONFIG_KALLSYMS
94679 if (*fmt == 'B')
94680 sprint_backtrace(sym, value);
94681 - else if (*fmt != 'f' && *fmt != 's')
94682 + else if (*fmt != 'f' && *fmt != 's' && *fmt != 'X')
94683 sprint_symbol(sym, value);
94684 else
94685 sprint_symbol_no_offset(sym, value);
94686 @@ -1240,7 +1243,11 @@ char *address_val(char *buf, char *end, const void *addr,
94687 return number(buf, end, num, spec);
94688 }
94689
94690 +#ifdef CONFIG_GRKERNSEC_HIDESYM
94691 +int kptr_restrict __read_mostly = 2;
94692 +#else
94693 int kptr_restrict __read_mostly;
94694 +#endif
94695
94696 /*
94697 * Show a '%p' thing. A kernel extension is that the '%p' is followed
94698 @@ -1251,8 +1258,10 @@ int kptr_restrict __read_mostly;
94699 *
94700 * - 'F' For symbolic function descriptor pointers with offset
94701 * - 'f' For simple symbolic function names without offset
94702 + * - 'X' For simple symbolic function names without offset approved for use with GRKERNSEC_HIDESYM
94703 * - 'S' For symbolic direct pointers with offset
94704 * - 's' For symbolic direct pointers without offset
94705 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
94706 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
94707 * - 'B' For backtraced symbolic direct pointers with offset
94708 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
94709 @@ -1331,12 +1340,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
94710
94711 if (!ptr && *fmt != 'K') {
94712 /*
94713 - * Print (null) with the same width as a pointer so it makes
94714 + * Print (nil) with the same width as a pointer so it makes
94715 * tabular output look nice.
94716 */
94717 if (spec.field_width == -1)
94718 spec.field_width = default_width;
94719 - return string(buf, end, "(null)", spec);
94720 + return string(buf, end, "(nil)", spec);
94721 }
94722
94723 switch (*fmt) {
94724 @@ -1346,6 +1355,14 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
94725 /* Fallthrough */
94726 case 'S':
94727 case 's':
94728 +#ifdef CONFIG_GRKERNSEC_HIDESYM
94729 + break;
94730 +#else
94731 + return symbol_string(buf, end, ptr, spec, fmt);
94732 +#endif
94733 + case 'X':
94734 + ptr = dereference_function_descriptor(ptr);
94735 + case 'A':
94736 case 'B':
94737 return symbol_string(buf, end, ptr, spec, fmt);
94738 case 'R':
94739 @@ -1403,6 +1420,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
94740 va_end(va);
94741 return buf;
94742 }
94743 + case 'P':
94744 + break;
94745 case 'K':
94746 /*
94747 * %pK cannot be used in IRQ context because its test
94748 @@ -1460,6 +1479,22 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
94749 ((const struct file *)ptr)->f_path.dentry,
94750 spec, fmt);
94751 }
94752 +
94753 +#ifdef CONFIG_GRKERNSEC_HIDESYM
94754 + /* 'P' = approved pointers to copy to userland,
94755 + as in the /proc/kallsyms case, as we make it display nothing
94756 + for non-root users, and the real contents for root users
94757 + 'X' = approved simple symbols
94758 + Also ignore 'K' pointers, since we force their NULLing for non-root users
94759 + above
94760 + */
94761 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'X' && *fmt != 'K' && is_usercopy_object(buf)) {
94762 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
94763 + dump_stack();
94764 + ptr = NULL;
94765 + }
94766 +#endif
94767 +
94768 spec.flags |= SMALL;
94769 if (spec.field_width == -1) {
94770 spec.field_width = default_width;
94771 @@ -2160,11 +2195,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
94772 typeof(type) value; \
94773 if (sizeof(type) == 8) { \
94774 args = PTR_ALIGN(args, sizeof(u32)); \
94775 - *(u32 *)&value = *(u32 *)args; \
94776 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
94777 + *(u32 *)&value = *(const u32 *)args; \
94778 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
94779 } else { \
94780 args = PTR_ALIGN(args, sizeof(type)); \
94781 - value = *(typeof(type) *)args; \
94782 + value = *(const typeof(type) *)args; \
94783 } \
94784 args += sizeof(type); \
94785 value; \
94786 @@ -2227,7 +2262,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
94787 case FORMAT_TYPE_STR: {
94788 const char *str_arg = args;
94789 args += strlen(str_arg) + 1;
94790 - str = string(str, end, (char *)str_arg, spec);
94791 + str = string(str, end, str_arg, spec);
94792 break;
94793 }
94794
94795 diff --git a/localversion-grsec b/localversion-grsec
94796 new file mode 100644
94797 index 0000000..7cd6065
94798 --- /dev/null
94799 +++ b/localversion-grsec
94800 @@ -0,0 +1 @@
94801 +-grsec
94802 diff --git a/mm/Kconfig b/mm/Kconfig
94803 index 1d1ae6b..0f05885 100644
94804 --- a/mm/Kconfig
94805 +++ b/mm/Kconfig
94806 @@ -341,10 +341,11 @@ config KSM
94807 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
94808
94809 config DEFAULT_MMAP_MIN_ADDR
94810 - int "Low address space to protect from user allocation"
94811 + int "Low address space to protect from user allocation"
94812 depends on MMU
94813 - default 4096
94814 - help
94815 + default 32768 if ALPHA || ARM || PARISC || SPARC32
94816 + default 65536
94817 + help
94818 This is the portion of low virtual memory which should be protected
94819 from userspace allocation. Keeping a user from writing to low pages
94820 can help reduce the impact of kernel NULL pointer bugs.
94821 @@ -375,7 +376,7 @@ config MEMORY_FAILURE
94822
94823 config HWPOISON_INJECT
94824 tristate "HWPoison pages injector"
94825 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
94826 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
94827 select PROC_PAGE_MONITOR
94828
94829 config NOMMU_INITIAL_TRIM_EXCESS
94830 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
94831 index 0ae0df5..82ac56b 100644
94832 --- a/mm/backing-dev.c
94833 +++ b/mm/backing-dev.c
94834 @@ -12,7 +12,7 @@
94835 #include <linux/device.h>
94836 #include <trace/events/writeback.h>
94837
94838 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
94839 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
94840
94841 struct backing_dev_info default_backing_dev_info = {
94842 .name = "default",
94843 @@ -525,7 +525,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
94844 return err;
94845
94846 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
94847 - atomic_long_inc_return(&bdi_seq));
94848 + atomic_long_inc_return_unchecked(&bdi_seq));
94849 if (err) {
94850 bdi_destroy(bdi);
94851 return err;
94852 diff --git a/mm/filemap.c b/mm/filemap.c
94853 index 14b4642..d71ba82 100644
94854 --- a/mm/filemap.c
94855 +++ b/mm/filemap.c
94856 @@ -2101,7 +2101,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
94857 struct address_space *mapping = file->f_mapping;
94858
94859 if (!mapping->a_ops->readpage)
94860 - return -ENOEXEC;
94861 + return -ENODEV;
94862 file_accessed(file);
94863 vma->vm_ops = &generic_file_vm_ops;
94864 return 0;
94865 @@ -2279,6 +2279,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
94866 *pos = i_size_read(inode);
94867
94868 if (limit != RLIM_INFINITY) {
94869 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
94870 if (*pos >= limit) {
94871 send_sig(SIGXFSZ, current, 0);
94872 return -EFBIG;
94873 diff --git a/mm/fremap.c b/mm/fremap.c
94874 index 72b8fa3..c5b39f1 100644
94875 --- a/mm/fremap.c
94876 +++ b/mm/fremap.c
94877 @@ -180,6 +180,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
94878 retry:
94879 vma = find_vma(mm, start);
94880
94881 +#ifdef CONFIG_PAX_SEGMEXEC
94882 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
94883 + goto out;
94884 +#endif
94885 +
94886 /*
94887 * Make sure the vma is shared, that it supports prefaulting,
94888 * and that the remapped range is valid and fully within
94889 diff --git a/mm/gup.c b/mm/gup.c
94890 index cd62c8c..3bb2053 100644
94891 --- a/mm/gup.c
94892 +++ b/mm/gup.c
94893 @@ -274,11 +274,6 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma,
94894 unsigned int fault_flags = 0;
94895 int ret;
94896
94897 - /* For mlock, just skip the stack guard page. */
94898 - if ((*flags & FOLL_MLOCK) &&
94899 - (stack_guard_page_start(vma, address) ||
94900 - stack_guard_page_end(vma, address + PAGE_SIZE)))
94901 - return -ENOENT;
94902 if (*flags & FOLL_WRITE)
94903 fault_flags |= FAULT_FLAG_WRITE;
94904 if (nonblocking)
94905 @@ -444,14 +439,14 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
94906 if (!(gup_flags & FOLL_FORCE))
94907 gup_flags |= FOLL_NUMA;
94908
94909 - do {
94910 + while (nr_pages) {
94911 struct page *page;
94912 unsigned int foll_flags = gup_flags;
94913 unsigned int page_increm;
94914
94915 /* first iteration or cross vma bound */
94916 if (!vma || start >= vma->vm_end) {
94917 - vma = find_extend_vma(mm, start);
94918 + vma = find_vma(mm, start);
94919 if (!vma && in_gate_area(mm, start)) {
94920 int ret;
94921 ret = get_gate_page(mm, start & PAGE_MASK,
94922 @@ -463,7 +458,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
94923 goto next_page;
94924 }
94925
94926 - if (!vma || check_vma_flags(vma, gup_flags))
94927 + if (!vma || start < vma->vm_start || check_vma_flags(vma, gup_flags))
94928 return i ? : -EFAULT;
94929 if (is_vm_hugetlb_page(vma)) {
94930 i = follow_hugetlb_page(mm, vma, pages, vmas,
94931 @@ -518,7 +513,7 @@ next_page:
94932 i += page_increm;
94933 start += page_increm * PAGE_SIZE;
94934 nr_pages -= page_increm;
94935 - } while (nr_pages);
94936 + }
94937 return i;
94938 }
94939 EXPORT_SYMBOL(__get_user_pages);
94940 diff --git a/mm/highmem.c b/mm/highmem.c
94941 index 123bcd3..0de52ba 100644
94942 --- a/mm/highmem.c
94943 +++ b/mm/highmem.c
94944 @@ -195,8 +195,9 @@ static void flush_all_zero_pkmaps(void)
94945 * So no dangers, even with speculative execution.
94946 */
94947 page = pte_page(pkmap_page_table[i]);
94948 + pax_open_kernel();
94949 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
94950 -
94951 + pax_close_kernel();
94952 set_page_address(page, NULL);
94953 need_flush = 1;
94954 }
94955 @@ -259,9 +260,11 @@ start:
94956 }
94957 }
94958 vaddr = PKMAP_ADDR(last_pkmap_nr);
94959 +
94960 + pax_open_kernel();
94961 set_pte_at(&init_mm, vaddr,
94962 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
94963 -
94964 + pax_close_kernel();
94965 pkmap_count[last_pkmap_nr] = 1;
94966 set_page_address(page, (void *)vaddr);
94967
94968 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
94969 index 9fd7227..5628939 100644
94970 --- a/mm/hugetlb.c
94971 +++ b/mm/hugetlb.c
94972 @@ -2258,6 +2258,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
94973 struct ctl_table *table, int write,
94974 void __user *buffer, size_t *length, loff_t *ppos)
94975 {
94976 + ctl_table_no_const t;
94977 struct hstate *h = &default_hstate;
94978 unsigned long tmp = h->max_huge_pages;
94979 int ret;
94980 @@ -2265,9 +2266,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
94981 if (!hugepages_supported())
94982 return -ENOTSUPP;
94983
94984 - table->data = &tmp;
94985 - table->maxlen = sizeof(unsigned long);
94986 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
94987 + t = *table;
94988 + t.data = &tmp;
94989 + t.maxlen = sizeof(unsigned long);
94990 + ret = proc_doulongvec_minmax(&t, write, buffer, length, ppos);
94991 if (ret)
94992 goto out;
94993
94994 @@ -2302,6 +2304,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
94995 struct hstate *h = &default_hstate;
94996 unsigned long tmp;
94997 int ret;
94998 + ctl_table_no_const hugetlb_table;
94999
95000 if (!hugepages_supported())
95001 return -ENOTSUPP;
95002 @@ -2311,9 +2314,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
95003 if (write && hstate_is_gigantic(h))
95004 return -EINVAL;
95005
95006 - table->data = &tmp;
95007 - table->maxlen = sizeof(unsigned long);
95008 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
95009 + hugetlb_table = *table;
95010 + hugetlb_table.data = &tmp;
95011 + hugetlb_table.maxlen = sizeof(unsigned long);
95012 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
95013 if (ret)
95014 goto out;
95015
95016 @@ -2792,6 +2796,27 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
95017 mutex_unlock(&mapping->i_mmap_mutex);
95018 }
95019
95020 +#ifdef CONFIG_PAX_SEGMEXEC
95021 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
95022 +{
95023 + struct mm_struct *mm = vma->vm_mm;
95024 + struct vm_area_struct *vma_m;
95025 + unsigned long address_m;
95026 + pte_t *ptep_m;
95027 +
95028 + vma_m = pax_find_mirror_vma(vma);
95029 + if (!vma_m)
95030 + return;
95031 +
95032 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
95033 + address_m = address + SEGMEXEC_TASK_SIZE;
95034 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
95035 + get_page(page_m);
95036 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
95037 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
95038 +}
95039 +#endif
95040 +
95041 /*
95042 * Hugetlb_cow() should be called with page lock of the original hugepage held.
95043 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
95044 @@ -2903,6 +2928,11 @@ retry_avoidcopy:
95045 make_huge_pte(vma, new_page, 1));
95046 page_remove_rmap(old_page);
95047 hugepage_add_new_anon_rmap(new_page, vma, address);
95048 +
95049 +#ifdef CONFIG_PAX_SEGMEXEC
95050 + pax_mirror_huge_pte(vma, address, new_page);
95051 +#endif
95052 +
95053 /* Make the old page be freed below */
95054 new_page = old_page;
95055 }
95056 @@ -3063,6 +3093,10 @@ retry:
95057 && (vma->vm_flags & VM_SHARED)));
95058 set_huge_pte_at(mm, address, ptep, new_pte);
95059
95060 +#ifdef CONFIG_PAX_SEGMEXEC
95061 + pax_mirror_huge_pte(vma, address, page);
95062 +#endif
95063 +
95064 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
95065 /* Optimization, do the COW without a second fault */
95066 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
95067 @@ -3129,6 +3163,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95068 struct hstate *h = hstate_vma(vma);
95069 struct address_space *mapping;
95070
95071 +#ifdef CONFIG_PAX_SEGMEXEC
95072 + struct vm_area_struct *vma_m;
95073 +#endif
95074 +
95075 address &= huge_page_mask(h);
95076
95077 ptep = huge_pte_offset(mm, address);
95078 @@ -3142,6 +3180,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95079 VM_FAULT_SET_HINDEX(hstate_index(h));
95080 }
95081
95082 +#ifdef CONFIG_PAX_SEGMEXEC
95083 + vma_m = pax_find_mirror_vma(vma);
95084 + if (vma_m) {
95085 + unsigned long address_m;
95086 +
95087 + if (vma->vm_start > vma_m->vm_start) {
95088 + address_m = address;
95089 + address -= SEGMEXEC_TASK_SIZE;
95090 + vma = vma_m;
95091 + h = hstate_vma(vma);
95092 + } else
95093 + address_m = address + SEGMEXEC_TASK_SIZE;
95094 +
95095 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
95096 + return VM_FAULT_OOM;
95097 + address_m &= HPAGE_MASK;
95098 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
95099 + }
95100 +#endif
95101 +
95102 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
95103 if (!ptep)
95104 return VM_FAULT_OOM;
95105 diff --git a/mm/internal.h b/mm/internal.h
95106 index a4f90ba..fbdc32b 100644
95107 --- a/mm/internal.h
95108 +++ b/mm/internal.h
95109 @@ -134,6 +134,7 @@ __find_buddy_index(unsigned long page_idx, unsigned int order)
95110
95111 extern int __isolate_free_page(struct page *page, unsigned int order);
95112 extern void __free_pages_bootmem(struct page *page, unsigned int order);
95113 +extern void free_compound_page(struct page *page);
95114 extern void prep_compound_page(struct page *page, unsigned long order);
95115 #ifdef CONFIG_MEMORY_FAILURE
95116 extern bool is_free_buddy_page(struct page *page);
95117 @@ -390,7 +391,7 @@ extern u32 hwpoison_filter_enable;
95118
95119 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
95120 unsigned long, unsigned long,
95121 - unsigned long, unsigned long);
95122 + unsigned long, unsigned long) __intentional_overflow(-1);
95123
95124 extern void set_pageblock_order(void);
95125 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
95126 diff --git a/mm/iov_iter.c b/mm/iov_iter.c
95127 index e34a3cb..a810efe 100644
95128 --- a/mm/iov_iter.c
95129 +++ b/mm/iov_iter.c
95130 @@ -307,7 +307,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
95131
95132 while (bytes) {
95133 char __user *buf = iov->iov_base + base;
95134 - int copy = min(bytes, iov->iov_len - base);
95135 + size_t copy = min(bytes, iov->iov_len - base);
95136
95137 base = 0;
95138 left = __copy_from_user_inatomic(vaddr, buf, copy);
95139 @@ -335,7 +335,7 @@ static size_t copy_from_user_atomic_iovec(struct page *page,
95140
95141 kaddr = kmap_atomic(page);
95142 if (likely(i->nr_segs == 1)) {
95143 - int left;
95144 + size_t left;
95145 char __user *buf = i->iov->iov_base + i->iov_offset;
95146 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
95147 copied = bytes - left;
95148 @@ -365,7 +365,7 @@ static void advance_iovec(struct iov_iter *i, size_t bytes)
95149 * zero-length segments (without overruning the iovec).
95150 */
95151 while (bytes || unlikely(i->count && !iov->iov_len)) {
95152 - int copy;
95153 + size_t copy;
95154
95155 copy = min(bytes, iov->iov_len - base);
95156 BUG_ON(!i->count || i->count < copy);
95157 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
95158 index 3cda50c..032ba634 100644
95159 --- a/mm/kmemleak.c
95160 +++ b/mm/kmemleak.c
95161 @@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
95162
95163 for (i = 0; i < object->trace_len; i++) {
95164 void *ptr = (void *)object->trace[i];
95165 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
95166 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
95167 }
95168 }
95169
95170 @@ -1905,7 +1905,7 @@ static int __init kmemleak_late_init(void)
95171 return -ENOMEM;
95172 }
95173
95174 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
95175 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
95176 &kmemleak_fops);
95177 if (!dentry)
95178 pr_warning("Failed to create the debugfs kmemleak file\n");
95179 diff --git a/mm/maccess.c b/mm/maccess.c
95180 index d53adf9..03a24bf 100644
95181 --- a/mm/maccess.c
95182 +++ b/mm/maccess.c
95183 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
95184 set_fs(KERNEL_DS);
95185 pagefault_disable();
95186 ret = __copy_from_user_inatomic(dst,
95187 - (__force const void __user *)src, size);
95188 + (const void __force_user *)src, size);
95189 pagefault_enable();
95190 set_fs(old_fs);
95191
95192 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
95193
95194 set_fs(KERNEL_DS);
95195 pagefault_disable();
95196 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
95197 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
95198 pagefault_enable();
95199 set_fs(old_fs);
95200
95201 diff --git a/mm/madvise.c b/mm/madvise.c
95202 index 0938b30..199abe8 100644
95203 --- a/mm/madvise.c
95204 +++ b/mm/madvise.c
95205 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
95206 pgoff_t pgoff;
95207 unsigned long new_flags = vma->vm_flags;
95208
95209 +#ifdef CONFIG_PAX_SEGMEXEC
95210 + struct vm_area_struct *vma_m;
95211 +#endif
95212 +
95213 switch (behavior) {
95214 case MADV_NORMAL:
95215 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
95216 @@ -126,6 +130,13 @@ success:
95217 /*
95218 * vm_flags is protected by the mmap_sem held in write mode.
95219 */
95220 +
95221 +#ifdef CONFIG_PAX_SEGMEXEC
95222 + vma_m = pax_find_mirror_vma(vma);
95223 + if (vma_m)
95224 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
95225 +#endif
95226 +
95227 vma->vm_flags = new_flags;
95228
95229 out:
95230 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
95231 struct vm_area_struct **prev,
95232 unsigned long start, unsigned long end)
95233 {
95234 +
95235 +#ifdef CONFIG_PAX_SEGMEXEC
95236 + struct vm_area_struct *vma_m;
95237 +#endif
95238 +
95239 *prev = vma;
95240 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
95241 return -EINVAL;
95242 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
95243 zap_page_range(vma, start, end - start, &details);
95244 } else
95245 zap_page_range(vma, start, end - start, NULL);
95246 +
95247 +#ifdef CONFIG_PAX_SEGMEXEC
95248 + vma_m = pax_find_mirror_vma(vma);
95249 + if (vma_m) {
95250 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
95251 + struct zap_details details = {
95252 + .nonlinear_vma = vma_m,
95253 + .last_index = ULONG_MAX,
95254 + };
95255 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
95256 + } else
95257 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
95258 + }
95259 +#endif
95260 +
95261 return 0;
95262 }
95263
95264 @@ -488,6 +519,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
95265 if (end < start)
95266 return error;
95267
95268 +#ifdef CONFIG_PAX_SEGMEXEC
95269 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
95270 + if (end > SEGMEXEC_TASK_SIZE)
95271 + return error;
95272 + } else
95273 +#endif
95274 +
95275 + if (end > TASK_SIZE)
95276 + return error;
95277 +
95278 error = 0;
95279 if (end == start)
95280 return error;
95281 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
95282 index 8639f6b..b623882a 100644
95283 --- a/mm/memory-failure.c
95284 +++ b/mm/memory-failure.c
95285 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
95286
95287 int sysctl_memory_failure_recovery __read_mostly = 1;
95288
95289 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
95290 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
95291
95292 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
95293
95294 @@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
95295 pfn, t->comm, t->pid);
95296 si.si_signo = SIGBUS;
95297 si.si_errno = 0;
95298 - si.si_addr = (void *)addr;
95299 + si.si_addr = (void __user *)addr;
95300 #ifdef __ARCH_SI_TRAPNO
95301 si.si_trapno = trapno;
95302 #endif
95303 @@ -791,7 +791,7 @@ static struct page_state {
95304 unsigned long res;
95305 char *msg;
95306 int (*action)(struct page *p, unsigned long pfn);
95307 -} error_states[] = {
95308 +} __do_const error_states[] = {
95309 { reserved, reserved, "reserved kernel", me_kernel },
95310 /*
95311 * free pages are specially detected outside this table:
95312 @@ -1099,7 +1099,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
95313 nr_pages = 1 << compound_order(hpage);
95314 else /* normal page or thp */
95315 nr_pages = 1;
95316 - atomic_long_add(nr_pages, &num_poisoned_pages);
95317 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
95318
95319 /*
95320 * We need/can do nothing about count=0 pages.
95321 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
95322 if (PageHWPoison(hpage)) {
95323 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
95324 || (p != hpage && TestSetPageHWPoison(hpage))) {
95325 - atomic_long_sub(nr_pages, &num_poisoned_pages);
95326 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
95327 unlock_page(hpage);
95328 return 0;
95329 }
95330 @@ -1196,14 +1196,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
95331 */
95332 if (!PageHWPoison(p)) {
95333 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
95334 - atomic_long_sub(nr_pages, &num_poisoned_pages);
95335 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
95336 put_page(hpage);
95337 res = 0;
95338 goto out;
95339 }
95340 if (hwpoison_filter(p)) {
95341 if (TestClearPageHWPoison(p))
95342 - atomic_long_sub(nr_pages, &num_poisoned_pages);
95343 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
95344 unlock_page(hpage);
95345 put_page(hpage);
95346 return 0;
95347 @@ -1433,7 +1433,7 @@ int unpoison_memory(unsigned long pfn)
95348 return 0;
95349 }
95350 if (TestClearPageHWPoison(p))
95351 - atomic_long_dec(&num_poisoned_pages);
95352 + atomic_long_dec_unchecked(&num_poisoned_pages);
95353 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
95354 return 0;
95355 }
95356 @@ -1447,7 +1447,7 @@ int unpoison_memory(unsigned long pfn)
95357 */
95358 if (TestClearPageHWPoison(page)) {
95359 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
95360 - atomic_long_sub(nr_pages, &num_poisoned_pages);
95361 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
95362 freeit = 1;
95363 if (PageHuge(page))
95364 clear_page_hwpoison_huge_page(page);
95365 @@ -1572,11 +1572,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
95366 if (PageHuge(page)) {
95367 set_page_hwpoison_huge_page(hpage);
95368 dequeue_hwpoisoned_huge_page(hpage);
95369 - atomic_long_add(1 << compound_order(hpage),
95370 + atomic_long_add_unchecked(1 << compound_order(hpage),
95371 &num_poisoned_pages);
95372 } else {
95373 SetPageHWPoison(page);
95374 - atomic_long_inc(&num_poisoned_pages);
95375 + atomic_long_inc_unchecked(&num_poisoned_pages);
95376 }
95377 }
95378 return ret;
95379 @@ -1615,7 +1615,7 @@ static int __soft_offline_page(struct page *page, int flags)
95380 put_page(page);
95381 pr_info("soft_offline: %#lx: invalidated\n", pfn);
95382 SetPageHWPoison(page);
95383 - atomic_long_inc(&num_poisoned_pages);
95384 + atomic_long_inc_unchecked(&num_poisoned_pages);
95385 return 0;
95386 }
95387
95388 @@ -1666,7 +1666,7 @@ static int __soft_offline_page(struct page *page, int flags)
95389 if (!is_free_buddy_page(page))
95390 pr_info("soft offline: %#lx: page leaked\n",
95391 pfn);
95392 - atomic_long_inc(&num_poisoned_pages);
95393 + atomic_long_inc_unchecked(&num_poisoned_pages);
95394 }
95395 } else {
95396 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
95397 @@ -1736,11 +1736,11 @@ int soft_offline_page(struct page *page, int flags)
95398 if (PageHuge(page)) {
95399 set_page_hwpoison_huge_page(hpage);
95400 dequeue_hwpoisoned_huge_page(hpage);
95401 - atomic_long_add(1 << compound_order(hpage),
95402 + atomic_long_add_unchecked(1 << compound_order(hpage),
95403 &num_poisoned_pages);
95404 } else {
95405 SetPageHWPoison(page);
95406 - atomic_long_inc(&num_poisoned_pages);
95407 + atomic_long_inc_unchecked(&num_poisoned_pages);
95408 }
95409 }
95410 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
95411 diff --git a/mm/memory.c b/mm/memory.c
95412 index d5f2ae9..4d678b2 100644
95413 --- a/mm/memory.c
95414 +++ b/mm/memory.c
95415 @@ -415,6 +415,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
95416 free_pte_range(tlb, pmd, addr);
95417 } while (pmd++, addr = next, addr != end);
95418
95419 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
95420 start &= PUD_MASK;
95421 if (start < floor)
95422 return;
95423 @@ -429,6 +430,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
95424 pmd = pmd_offset(pud, start);
95425 pud_clear(pud);
95426 pmd_free_tlb(tlb, pmd, start);
95427 +#endif
95428 +
95429 }
95430
95431 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
95432 @@ -448,6 +451,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
95433 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
95434 } while (pud++, addr = next, addr != end);
95435
95436 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
95437 start &= PGDIR_MASK;
95438 if (start < floor)
95439 return;
95440 @@ -462,6 +466,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
95441 pud = pud_offset(pgd, start);
95442 pgd_clear(pgd);
95443 pud_free_tlb(tlb, pud, start);
95444 +#endif
95445 +
95446 }
95447
95448 /*
95449 @@ -691,10 +697,10 @@ static void print_bad_pte(struct vm_area_struct *vma, unsigned long addr,
95450 * Choose text because data symbols depend on CONFIG_KALLSYMS_ALL=y
95451 */
95452 if (vma->vm_ops)
95453 - printk(KERN_ALERT "vma->vm_ops->fault: %pSR\n",
95454 + printk(KERN_ALERT "vma->vm_ops->fault: %pAR\n",
95455 vma->vm_ops->fault);
95456 if (vma->vm_file)
95457 - printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pSR\n",
95458 + printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pAR\n",
95459 vma->vm_file->f_op->mmap);
95460 dump_stack();
95461 add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
95462 @@ -1501,6 +1507,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
95463 page_add_file_rmap(page);
95464 set_pte_at(mm, addr, pte, mk_pte(page, prot));
95465
95466 +#ifdef CONFIG_PAX_SEGMEXEC
95467 + pax_mirror_file_pte(vma, addr, page, ptl);
95468 +#endif
95469 +
95470 retval = 0;
95471 pte_unmap_unlock(pte, ptl);
95472 return retval;
95473 @@ -1545,9 +1555,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
95474 if (!page_count(page))
95475 return -EINVAL;
95476 if (!(vma->vm_flags & VM_MIXEDMAP)) {
95477 +
95478 +#ifdef CONFIG_PAX_SEGMEXEC
95479 + struct vm_area_struct *vma_m;
95480 +#endif
95481 +
95482 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
95483 BUG_ON(vma->vm_flags & VM_PFNMAP);
95484 vma->vm_flags |= VM_MIXEDMAP;
95485 +
95486 +#ifdef CONFIG_PAX_SEGMEXEC
95487 + vma_m = pax_find_mirror_vma(vma);
95488 + if (vma_m)
95489 + vma_m->vm_flags |= VM_MIXEDMAP;
95490 +#endif
95491 +
95492 }
95493 return insert_page(vma, addr, page, vma->vm_page_prot);
95494 }
95495 @@ -1630,6 +1652,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
95496 unsigned long pfn)
95497 {
95498 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
95499 + BUG_ON(vma->vm_mirror);
95500
95501 if (addr < vma->vm_start || addr >= vma->vm_end)
95502 return -EFAULT;
95503 @@ -1877,7 +1900,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
95504
95505 BUG_ON(pud_huge(*pud));
95506
95507 - pmd = pmd_alloc(mm, pud, addr);
95508 + pmd = (mm == &init_mm) ?
95509 + pmd_alloc_kernel(mm, pud, addr) :
95510 + pmd_alloc(mm, pud, addr);
95511 if (!pmd)
95512 return -ENOMEM;
95513 do {
95514 @@ -1897,7 +1922,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
95515 unsigned long next;
95516 int err;
95517
95518 - pud = pud_alloc(mm, pgd, addr);
95519 + pud = (mm == &init_mm) ?
95520 + pud_alloc_kernel(mm, pgd, addr) :
95521 + pud_alloc(mm, pgd, addr);
95522 if (!pud)
95523 return -ENOMEM;
95524 do {
95525 @@ -2019,6 +2046,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
95526 return ret;
95527 }
95528
95529 +#ifdef CONFIG_PAX_SEGMEXEC
95530 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
95531 +{
95532 + struct mm_struct *mm = vma->vm_mm;
95533 + spinlock_t *ptl;
95534 + pte_t *pte, entry;
95535 +
95536 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
95537 + entry = *pte;
95538 + if (!pte_present(entry)) {
95539 + if (!pte_none(entry)) {
95540 + BUG_ON(pte_file(entry));
95541 + free_swap_and_cache(pte_to_swp_entry(entry));
95542 + pte_clear_not_present_full(mm, address, pte, 0);
95543 + }
95544 + } else {
95545 + struct page *page;
95546 +
95547 + flush_cache_page(vma, address, pte_pfn(entry));
95548 + entry = ptep_clear_flush(vma, address, pte);
95549 + BUG_ON(pte_dirty(entry));
95550 + page = vm_normal_page(vma, address, entry);
95551 + if (page) {
95552 + update_hiwater_rss(mm);
95553 + if (PageAnon(page))
95554 + dec_mm_counter_fast(mm, MM_ANONPAGES);
95555 + else
95556 + dec_mm_counter_fast(mm, MM_FILEPAGES);
95557 + page_remove_rmap(page);
95558 + page_cache_release(page);
95559 + }
95560 + }
95561 + pte_unmap_unlock(pte, ptl);
95562 +}
95563 +
95564 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
95565 + *
95566 + * the ptl of the lower mapped page is held on entry and is not released on exit
95567 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
95568 + */
95569 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
95570 +{
95571 + struct mm_struct *mm = vma->vm_mm;
95572 + unsigned long address_m;
95573 + spinlock_t *ptl_m;
95574 + struct vm_area_struct *vma_m;
95575 + pmd_t *pmd_m;
95576 + pte_t *pte_m, entry_m;
95577 +
95578 + BUG_ON(!page_m || !PageAnon(page_m));
95579 +
95580 + vma_m = pax_find_mirror_vma(vma);
95581 + if (!vma_m)
95582 + return;
95583 +
95584 + BUG_ON(!PageLocked(page_m));
95585 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
95586 + address_m = address + SEGMEXEC_TASK_SIZE;
95587 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
95588 + pte_m = pte_offset_map(pmd_m, address_m);
95589 + ptl_m = pte_lockptr(mm, pmd_m);
95590 + if (ptl != ptl_m) {
95591 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
95592 + if (!pte_none(*pte_m))
95593 + goto out;
95594 + }
95595 +
95596 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
95597 + page_cache_get(page_m);
95598 + page_add_anon_rmap(page_m, vma_m, address_m);
95599 + inc_mm_counter_fast(mm, MM_ANONPAGES);
95600 + set_pte_at(mm, address_m, pte_m, entry_m);
95601 + update_mmu_cache(vma_m, address_m, pte_m);
95602 +out:
95603 + if (ptl != ptl_m)
95604 + spin_unlock(ptl_m);
95605 + pte_unmap(pte_m);
95606 + unlock_page(page_m);
95607 +}
95608 +
95609 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
95610 +{
95611 + struct mm_struct *mm = vma->vm_mm;
95612 + unsigned long address_m;
95613 + spinlock_t *ptl_m;
95614 + struct vm_area_struct *vma_m;
95615 + pmd_t *pmd_m;
95616 + pte_t *pte_m, entry_m;
95617 +
95618 + BUG_ON(!page_m || PageAnon(page_m));
95619 +
95620 + vma_m = pax_find_mirror_vma(vma);
95621 + if (!vma_m)
95622 + return;
95623 +
95624 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
95625 + address_m = address + SEGMEXEC_TASK_SIZE;
95626 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
95627 + pte_m = pte_offset_map(pmd_m, address_m);
95628 + ptl_m = pte_lockptr(mm, pmd_m);
95629 + if (ptl != ptl_m) {
95630 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
95631 + if (!pte_none(*pte_m))
95632 + goto out;
95633 + }
95634 +
95635 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
95636 + page_cache_get(page_m);
95637 + page_add_file_rmap(page_m);
95638 + inc_mm_counter_fast(mm, MM_FILEPAGES);
95639 + set_pte_at(mm, address_m, pte_m, entry_m);
95640 + update_mmu_cache(vma_m, address_m, pte_m);
95641 +out:
95642 + if (ptl != ptl_m)
95643 + spin_unlock(ptl_m);
95644 + pte_unmap(pte_m);
95645 +}
95646 +
95647 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
95648 +{
95649 + struct mm_struct *mm = vma->vm_mm;
95650 + unsigned long address_m;
95651 + spinlock_t *ptl_m;
95652 + struct vm_area_struct *vma_m;
95653 + pmd_t *pmd_m;
95654 + pte_t *pte_m, entry_m;
95655 +
95656 + vma_m = pax_find_mirror_vma(vma);
95657 + if (!vma_m)
95658 + return;
95659 +
95660 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
95661 + address_m = address + SEGMEXEC_TASK_SIZE;
95662 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
95663 + pte_m = pte_offset_map(pmd_m, address_m);
95664 + ptl_m = pte_lockptr(mm, pmd_m);
95665 + if (ptl != ptl_m) {
95666 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
95667 + if (!pte_none(*pte_m))
95668 + goto out;
95669 + }
95670 +
95671 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
95672 + set_pte_at(mm, address_m, pte_m, entry_m);
95673 +out:
95674 + if (ptl != ptl_m)
95675 + spin_unlock(ptl_m);
95676 + pte_unmap(pte_m);
95677 +}
95678 +
95679 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
95680 +{
95681 + struct page *page_m;
95682 + pte_t entry;
95683 +
95684 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
95685 + goto out;
95686 +
95687 + entry = *pte;
95688 + page_m = vm_normal_page(vma, address, entry);
95689 + if (!page_m)
95690 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
95691 + else if (PageAnon(page_m)) {
95692 + if (pax_find_mirror_vma(vma)) {
95693 + pte_unmap_unlock(pte, ptl);
95694 + lock_page(page_m);
95695 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
95696 + if (pte_same(entry, *pte))
95697 + pax_mirror_anon_pte(vma, address, page_m, ptl);
95698 + else
95699 + unlock_page(page_m);
95700 + }
95701 + } else
95702 + pax_mirror_file_pte(vma, address, page_m, ptl);
95703 +
95704 +out:
95705 + pte_unmap_unlock(pte, ptl);
95706 +}
95707 +#endif
95708 +
95709 /*
95710 * This routine handles present pages, when users try to write
95711 * to a shared page. It is done by copying the page to a new address
95712 @@ -2218,6 +2425,12 @@ gotten:
95713 */
95714 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
95715 if (likely(pte_same(*page_table, orig_pte))) {
95716 +
95717 +#ifdef CONFIG_PAX_SEGMEXEC
95718 + if (pax_find_mirror_vma(vma))
95719 + BUG_ON(!trylock_page(new_page));
95720 +#endif
95721 +
95722 if (old_page) {
95723 if (!PageAnon(old_page)) {
95724 dec_mm_counter_fast(mm, MM_FILEPAGES);
95725 @@ -2271,6 +2484,10 @@ gotten:
95726 page_remove_rmap(old_page);
95727 }
95728
95729 +#ifdef CONFIG_PAX_SEGMEXEC
95730 + pax_mirror_anon_pte(vma, address, new_page, ptl);
95731 +#endif
95732 +
95733 /* Free the old page.. */
95734 new_page = old_page;
95735 ret |= VM_FAULT_WRITE;
95736 @@ -2545,6 +2762,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
95737 swap_free(entry);
95738 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
95739 try_to_free_swap(page);
95740 +
95741 +#ifdef CONFIG_PAX_SEGMEXEC
95742 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
95743 +#endif
95744 +
95745 unlock_page(page);
95746 if (page != swapcache) {
95747 /*
95748 @@ -2568,6 +2790,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
95749
95750 /* No need to invalidate - it was non-present before */
95751 update_mmu_cache(vma, address, page_table);
95752 +
95753 +#ifdef CONFIG_PAX_SEGMEXEC
95754 + pax_mirror_anon_pte(vma, address, page, ptl);
95755 +#endif
95756 +
95757 unlock:
95758 pte_unmap_unlock(page_table, ptl);
95759 out:
95760 @@ -2587,40 +2814,6 @@ out_release:
95761 }
95762
95763 /*
95764 - * This is like a special single-page "expand_{down|up}wards()",
95765 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
95766 - * doesn't hit another vma.
95767 - */
95768 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
95769 -{
95770 - address &= PAGE_MASK;
95771 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
95772 - struct vm_area_struct *prev = vma->vm_prev;
95773 -
95774 - /*
95775 - * Is there a mapping abutting this one below?
95776 - *
95777 - * That's only ok if it's the same stack mapping
95778 - * that has gotten split..
95779 - */
95780 - if (prev && prev->vm_end == address)
95781 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
95782 -
95783 - expand_downwards(vma, address - PAGE_SIZE);
95784 - }
95785 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
95786 - struct vm_area_struct *next = vma->vm_next;
95787 -
95788 - /* As VM_GROWSDOWN but s/below/above/ */
95789 - if (next && next->vm_start == address + PAGE_SIZE)
95790 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
95791 -
95792 - expand_upwards(vma, address + PAGE_SIZE);
95793 - }
95794 - return 0;
95795 -}
95796 -
95797 -/*
95798 * We enter with non-exclusive mmap_sem (to exclude vma changes,
95799 * but allow concurrent faults), and pte mapped but not yet locked.
95800 * We return with mmap_sem still held, but pte unmapped and unlocked.
95801 @@ -2630,27 +2823,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
95802 unsigned int flags)
95803 {
95804 struct mem_cgroup *memcg;
95805 - struct page *page;
95806 + struct page *page = NULL;
95807 spinlock_t *ptl;
95808 pte_t entry;
95809
95810 - pte_unmap(page_table);
95811 -
95812 - /* Check if we need to add a guard page to the stack */
95813 - if (check_stack_guard_page(vma, address) < 0)
95814 - return VM_FAULT_SIGBUS;
95815 -
95816 - /* Use the zero-page for reads */
95817 if (!(flags & FAULT_FLAG_WRITE)) {
95818 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
95819 vma->vm_page_prot));
95820 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
95821 + ptl = pte_lockptr(mm, pmd);
95822 + spin_lock(ptl);
95823 if (!pte_none(*page_table))
95824 goto unlock;
95825 goto setpte;
95826 }
95827
95828 /* Allocate our own private page. */
95829 + pte_unmap(page_table);
95830 +
95831 if (unlikely(anon_vma_prepare(vma)))
95832 goto oom;
95833 page = alloc_zeroed_user_highpage_movable(vma, address);
95834 @@ -2674,6 +2863,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
95835 if (!pte_none(*page_table))
95836 goto release;
95837
95838 +#ifdef CONFIG_PAX_SEGMEXEC
95839 + if (pax_find_mirror_vma(vma))
95840 + BUG_ON(!trylock_page(page));
95841 +#endif
95842 +
95843 inc_mm_counter_fast(mm, MM_ANONPAGES);
95844 page_add_new_anon_rmap(page, vma, address);
95845 mem_cgroup_commit_charge(page, memcg, false);
95846 @@ -2683,6 +2877,12 @@ setpte:
95847
95848 /* No need to invalidate - it was non-present before */
95849 update_mmu_cache(vma, address, page_table);
95850 +
95851 +#ifdef CONFIG_PAX_SEGMEXEC
95852 + if (page)
95853 + pax_mirror_anon_pte(vma, address, page, ptl);
95854 +#endif
95855 +
95856 unlock:
95857 pte_unmap_unlock(page_table, ptl);
95858 return 0;
95859 @@ -2913,6 +3113,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95860 return ret;
95861 }
95862 do_set_pte(vma, address, fault_page, pte, false, false);
95863 +
95864 +#ifdef CONFIG_PAX_SEGMEXEC
95865 + pax_mirror_file_pte(vma, address, fault_page, ptl);
95866 +#endif
95867 +
95868 unlock_page(fault_page);
95869 unlock_out:
95870 pte_unmap_unlock(pte, ptl);
95871 @@ -2955,7 +3160,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95872 page_cache_release(fault_page);
95873 goto uncharge_out;
95874 }
95875 +
95876 +#ifdef CONFIG_PAX_SEGMEXEC
95877 + if (pax_find_mirror_vma(vma))
95878 + BUG_ON(!trylock_page(new_page));
95879 +#endif
95880 +
95881 do_set_pte(vma, address, new_page, pte, true, true);
95882 +
95883 +#ifdef CONFIG_PAX_SEGMEXEC
95884 + pax_mirror_anon_pte(vma, address, new_page, ptl);
95885 +#endif
95886 +
95887 mem_cgroup_commit_charge(new_page, memcg, false);
95888 lru_cache_add_active_or_unevictable(new_page, vma);
95889 pte_unmap_unlock(pte, ptl);
95890 @@ -3005,6 +3221,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95891 return ret;
95892 }
95893 do_set_pte(vma, address, fault_page, pte, true, false);
95894 +
95895 +#ifdef CONFIG_PAX_SEGMEXEC
95896 + pax_mirror_file_pte(vma, address, fault_page, ptl);
95897 +#endif
95898 +
95899 pte_unmap_unlock(pte, ptl);
95900
95901 if (set_page_dirty(fault_page))
95902 @@ -3246,6 +3467,12 @@ static int handle_pte_fault(struct mm_struct *mm,
95903 if (flags & FAULT_FLAG_WRITE)
95904 flush_tlb_fix_spurious_fault(vma, address);
95905 }
95906 +
95907 +#ifdef CONFIG_PAX_SEGMEXEC
95908 + pax_mirror_pte(vma, address, pte, pmd, ptl);
95909 + return 0;
95910 +#endif
95911 +
95912 unlock:
95913 pte_unmap_unlock(pte, ptl);
95914 return 0;
95915 @@ -3265,9 +3492,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95916 pmd_t *pmd;
95917 pte_t *pte;
95918
95919 +#ifdef CONFIG_PAX_SEGMEXEC
95920 + struct vm_area_struct *vma_m;
95921 +#endif
95922 +
95923 if (unlikely(is_vm_hugetlb_page(vma)))
95924 return hugetlb_fault(mm, vma, address, flags);
95925
95926 +#ifdef CONFIG_PAX_SEGMEXEC
95927 + vma_m = pax_find_mirror_vma(vma);
95928 + if (vma_m) {
95929 + unsigned long address_m;
95930 + pgd_t *pgd_m;
95931 + pud_t *pud_m;
95932 + pmd_t *pmd_m;
95933 +
95934 + if (vma->vm_start > vma_m->vm_start) {
95935 + address_m = address;
95936 + address -= SEGMEXEC_TASK_SIZE;
95937 + vma = vma_m;
95938 + } else
95939 + address_m = address + SEGMEXEC_TASK_SIZE;
95940 +
95941 + pgd_m = pgd_offset(mm, address_m);
95942 + pud_m = pud_alloc(mm, pgd_m, address_m);
95943 + if (!pud_m)
95944 + return VM_FAULT_OOM;
95945 + pmd_m = pmd_alloc(mm, pud_m, address_m);
95946 + if (!pmd_m)
95947 + return VM_FAULT_OOM;
95948 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
95949 + return VM_FAULT_OOM;
95950 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
95951 + }
95952 +#endif
95953 +
95954 pgd = pgd_offset(mm, address);
95955 pud = pud_alloc(mm, pgd, address);
95956 if (!pud)
95957 @@ -3401,6 +3660,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
95958 spin_unlock(&mm->page_table_lock);
95959 return 0;
95960 }
95961 +
95962 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
95963 +{
95964 + pud_t *new = pud_alloc_one(mm, address);
95965 + if (!new)
95966 + return -ENOMEM;
95967 +
95968 + smp_wmb(); /* See comment in __pte_alloc */
95969 +
95970 + spin_lock(&mm->page_table_lock);
95971 + if (pgd_present(*pgd)) /* Another has populated it */
95972 + pud_free(mm, new);
95973 + else
95974 + pgd_populate_kernel(mm, pgd, new);
95975 + spin_unlock(&mm->page_table_lock);
95976 + return 0;
95977 +}
95978 #endif /* __PAGETABLE_PUD_FOLDED */
95979
95980 #ifndef __PAGETABLE_PMD_FOLDED
95981 @@ -3431,6 +3707,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
95982 spin_unlock(&mm->page_table_lock);
95983 return 0;
95984 }
95985 +
95986 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
95987 +{
95988 + pmd_t *new = pmd_alloc_one(mm, address);
95989 + if (!new)
95990 + return -ENOMEM;
95991 +
95992 + smp_wmb(); /* See comment in __pte_alloc */
95993 +
95994 + spin_lock(&mm->page_table_lock);
95995 +#ifndef __ARCH_HAS_4LEVEL_HACK
95996 + if (pud_present(*pud)) /* Another has populated it */
95997 + pmd_free(mm, new);
95998 + else
95999 + pud_populate_kernel(mm, pud, new);
96000 +#else
96001 + if (pgd_present(*pud)) /* Another has populated it */
96002 + pmd_free(mm, new);
96003 + else
96004 + pgd_populate_kernel(mm, pud, new);
96005 +#endif /* __ARCH_HAS_4LEVEL_HACK */
96006 + spin_unlock(&mm->page_table_lock);
96007 + return 0;
96008 +}
96009 #endif /* __PAGETABLE_PMD_FOLDED */
96010
96011 static int __follow_pte(struct mm_struct *mm, unsigned long address,
96012 @@ -3540,8 +3840,8 @@ out:
96013 return ret;
96014 }
96015
96016 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
96017 - void *buf, int len, int write)
96018 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
96019 + void *buf, size_t len, int write)
96020 {
96021 resource_size_t phys_addr;
96022 unsigned long prot = 0;
96023 @@ -3567,8 +3867,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
96024 * Access another process' address space as given in mm. If non-NULL, use the
96025 * given task for page fault accounting.
96026 */
96027 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96028 - unsigned long addr, void *buf, int len, int write)
96029 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96030 + unsigned long addr, void *buf, size_t len, int write)
96031 {
96032 struct vm_area_struct *vma;
96033 void *old_buf = buf;
96034 @@ -3576,7 +3876,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96035 down_read(&mm->mmap_sem);
96036 /* ignore errors, just check how much was successfully transferred */
96037 while (len) {
96038 - int bytes, ret, offset;
96039 + ssize_t bytes, ret, offset;
96040 void *maddr;
96041 struct page *page = NULL;
96042
96043 @@ -3637,8 +3937,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96044 *
96045 * The caller must hold a reference on @mm.
96046 */
96047 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
96048 - void *buf, int len, int write)
96049 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
96050 + void *buf, size_t len, int write)
96051 {
96052 return __access_remote_vm(NULL, mm, addr, buf, len, write);
96053 }
96054 @@ -3648,11 +3948,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
96055 * Source/target buffer must be kernel space,
96056 * Do not walk the page table directly, use get_user_pages
96057 */
96058 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
96059 - void *buf, int len, int write)
96060 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
96061 + void *buf, size_t len, int write)
96062 {
96063 struct mm_struct *mm;
96064 - int ret;
96065 + ssize_t ret;
96066
96067 mm = get_task_mm(tsk);
96068 if (!mm)
96069 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
96070 index e58725a..e0be017 100644
96071 --- a/mm/mempolicy.c
96072 +++ b/mm/mempolicy.c
96073 @@ -750,6 +750,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
96074 unsigned long vmstart;
96075 unsigned long vmend;
96076
96077 +#ifdef CONFIG_PAX_SEGMEXEC
96078 + struct vm_area_struct *vma_m;
96079 +#endif
96080 +
96081 vma = find_vma(mm, start);
96082 if (!vma || vma->vm_start > start)
96083 return -EFAULT;
96084 @@ -793,6 +797,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
96085 err = vma_replace_policy(vma, new_pol);
96086 if (err)
96087 goto out;
96088 +
96089 +#ifdef CONFIG_PAX_SEGMEXEC
96090 + vma_m = pax_find_mirror_vma(vma);
96091 + if (vma_m) {
96092 + err = vma_replace_policy(vma_m, new_pol);
96093 + if (err)
96094 + goto out;
96095 + }
96096 +#endif
96097 +
96098 }
96099
96100 out:
96101 @@ -1212,6 +1226,17 @@ static long do_mbind(unsigned long start, unsigned long len,
96102
96103 if (end < start)
96104 return -EINVAL;
96105 +
96106 +#ifdef CONFIG_PAX_SEGMEXEC
96107 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
96108 + if (end > SEGMEXEC_TASK_SIZE)
96109 + return -EINVAL;
96110 + } else
96111 +#endif
96112 +
96113 + if (end > TASK_SIZE)
96114 + return -EINVAL;
96115 +
96116 if (end == start)
96117 return 0;
96118
96119 @@ -1437,8 +1462,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
96120 */
96121 tcred = __task_cred(task);
96122 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
96123 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
96124 - !capable(CAP_SYS_NICE)) {
96125 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
96126 rcu_read_unlock();
96127 err = -EPERM;
96128 goto out_put;
96129 @@ -1469,6 +1493,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
96130 goto out;
96131 }
96132
96133 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
96134 + if (mm != current->mm &&
96135 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
96136 + mmput(mm);
96137 + err = -EPERM;
96138 + goto out;
96139 + }
96140 +#endif
96141 +
96142 err = do_migrate_pages(mm, old, new,
96143 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
96144
96145 diff --git a/mm/migrate.c b/mm/migrate.c
96146 index 0143995..b294728 100644
96147 --- a/mm/migrate.c
96148 +++ b/mm/migrate.c
96149 @@ -1495,8 +1495,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
96150 */
96151 tcred = __task_cred(task);
96152 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
96153 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
96154 - !capable(CAP_SYS_NICE)) {
96155 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
96156 rcu_read_unlock();
96157 err = -EPERM;
96158 goto out;
96159 diff --git a/mm/mlock.c b/mm/mlock.c
96160 index 73cf098..ab547c7 100644
96161 --- a/mm/mlock.c
96162 +++ b/mm/mlock.c
96163 @@ -14,6 +14,7 @@
96164 #include <linux/pagevec.h>
96165 #include <linux/mempolicy.h>
96166 #include <linux/syscalls.h>
96167 +#include <linux/security.h>
96168 #include <linux/sched.h>
96169 #include <linux/export.h>
96170 #include <linux/rmap.h>
96171 @@ -613,7 +614,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
96172 {
96173 unsigned long nstart, end, tmp;
96174 struct vm_area_struct * vma, * prev;
96175 - int error;
96176 + int error = 0;
96177
96178 VM_BUG_ON(start & ~PAGE_MASK);
96179 VM_BUG_ON(len != PAGE_ALIGN(len));
96180 @@ -622,6 +623,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
96181 return -EINVAL;
96182 if (end == start)
96183 return 0;
96184 + if (end > TASK_SIZE)
96185 + return -EINVAL;
96186 +
96187 vma = find_vma(current->mm, start);
96188 if (!vma || vma->vm_start > start)
96189 return -ENOMEM;
96190 @@ -633,6 +637,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
96191 for (nstart = start ; ; ) {
96192 vm_flags_t newflags;
96193
96194 +#ifdef CONFIG_PAX_SEGMEXEC
96195 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
96196 + break;
96197 +#endif
96198 +
96199 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
96200
96201 newflags = vma->vm_flags & ~VM_LOCKED;
96202 @@ -746,6 +755,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
96203 locked += current->mm->locked_vm;
96204
96205 /* check against resource limits */
96206 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
96207 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
96208 error = do_mlock(start, len, 1);
96209
96210 @@ -783,6 +793,11 @@ static int do_mlockall(int flags)
96211 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
96212 vm_flags_t newflags;
96213
96214 +#ifdef CONFIG_PAX_SEGMEXEC
96215 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
96216 + break;
96217 +#endif
96218 +
96219 newflags = vma->vm_flags & ~VM_LOCKED;
96220 if (flags & MCL_CURRENT)
96221 newflags |= VM_LOCKED;
96222 @@ -814,8 +829,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
96223 lock_limit >>= PAGE_SHIFT;
96224
96225 ret = -ENOMEM;
96226 +
96227 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
96228 +
96229 down_write(&current->mm->mmap_sem);
96230 -
96231 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
96232 capable(CAP_IPC_LOCK))
96233 ret = do_mlockall(flags);
96234 diff --git a/mm/mmap.c b/mm/mmap.c
96235 index ae91989..d8308c7 100644
96236 --- a/mm/mmap.c
96237 +++ b/mm/mmap.c
96238 @@ -41,6 +41,7 @@
96239 #include <linux/notifier.h>
96240 #include <linux/memory.h>
96241 #include <linux/printk.h>
96242 +#include <linux/random.h>
96243
96244 #include <asm/uaccess.h>
96245 #include <asm/cacheflush.h>
96246 @@ -57,6 +58,16 @@
96247 #define arch_rebalance_pgtables(addr, len) (addr)
96248 #endif
96249
96250 +static inline void verify_mm_writelocked(struct mm_struct *mm)
96251 +{
96252 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
96253 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
96254 + up_read(&mm->mmap_sem);
96255 + BUG();
96256 + }
96257 +#endif
96258 +}
96259 +
96260 static void unmap_region(struct mm_struct *mm,
96261 struct vm_area_struct *vma, struct vm_area_struct *prev,
96262 unsigned long start, unsigned long end);
96263 @@ -76,16 +87,25 @@ static void unmap_region(struct mm_struct *mm,
96264 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
96265 *
96266 */
96267 -pgprot_t protection_map[16] = {
96268 +pgprot_t protection_map[16] __read_only = {
96269 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
96270 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
96271 };
96272
96273 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
96274 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
96275 {
96276 - return __pgprot(pgprot_val(protection_map[vm_flags &
96277 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
96278 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
96279 pgprot_val(arch_vm_get_page_prot(vm_flags)));
96280 +
96281 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
96282 + if (!(__supported_pte_mask & _PAGE_NX) &&
96283 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
96284 + (vm_flags & (VM_READ | VM_WRITE)))
96285 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
96286 +#endif
96287 +
96288 + return prot;
96289 }
96290 EXPORT_SYMBOL(vm_get_page_prot);
96291
96292 @@ -114,6 +134,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
96293 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
96294 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
96295 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
96296 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
96297 /*
96298 * Make sure vm_committed_as in one cacheline and not cacheline shared with
96299 * other variables. It can be updated by several CPUs frequently.
96300 @@ -274,6 +295,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
96301 struct vm_area_struct *next = vma->vm_next;
96302
96303 might_sleep();
96304 + BUG_ON(vma->vm_mirror);
96305 if (vma->vm_ops && vma->vm_ops->close)
96306 vma->vm_ops->close(vma);
96307 if (vma->vm_file)
96308 @@ -287,6 +309,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len);
96309
96310 SYSCALL_DEFINE1(brk, unsigned long, brk)
96311 {
96312 + unsigned long rlim;
96313 unsigned long retval;
96314 unsigned long newbrk, oldbrk;
96315 struct mm_struct *mm = current->mm;
96316 @@ -317,7 +340,13 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
96317 * segment grow beyond its set limit the in case where the limit is
96318 * not page aligned -Ram Gupta
96319 */
96320 - if (check_data_rlimit(rlimit(RLIMIT_DATA), brk, mm->start_brk,
96321 + rlim = rlimit(RLIMIT_DATA);
96322 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
96323 + /* force a minimum 16MB brk heap on setuid/setgid binaries */
96324 + if (rlim < PAGE_SIZE && (get_dumpable(mm) != SUID_DUMP_USER) && gr_is_global_nonroot(current_uid()))
96325 + rlim = 4096 * PAGE_SIZE;
96326 +#endif
96327 + if (check_data_rlimit(rlim, brk, mm->start_brk,
96328 mm->end_data, mm->start_data))
96329 goto out;
96330
96331 @@ -976,6 +1005,12 @@ static int
96332 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
96333 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
96334 {
96335 +
96336 +#ifdef CONFIG_PAX_SEGMEXEC
96337 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
96338 + return 0;
96339 +#endif
96340 +
96341 if (is_mergeable_vma(vma, file, vm_flags) &&
96342 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
96343 if (vma->vm_pgoff == vm_pgoff)
96344 @@ -995,6 +1030,12 @@ static int
96345 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
96346 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
96347 {
96348 +
96349 +#ifdef CONFIG_PAX_SEGMEXEC
96350 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
96351 + return 0;
96352 +#endif
96353 +
96354 if (is_mergeable_vma(vma, file, vm_flags) &&
96355 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
96356 pgoff_t vm_pglen;
96357 @@ -1044,6 +1085,13 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
96358 struct vm_area_struct *area, *next;
96359 int err;
96360
96361 +#ifdef CONFIG_PAX_SEGMEXEC
96362 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
96363 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
96364 +
96365 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
96366 +#endif
96367 +
96368 /*
96369 * We later require that vma->vm_flags == vm_flags,
96370 * so this tests vma->vm_flags & VM_SPECIAL, too.
96371 @@ -1059,6 +1107,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
96372 if (next && next->vm_end == end) /* cases 6, 7, 8 */
96373 next = next->vm_next;
96374
96375 +#ifdef CONFIG_PAX_SEGMEXEC
96376 + if (prev)
96377 + prev_m = pax_find_mirror_vma(prev);
96378 + if (area)
96379 + area_m = pax_find_mirror_vma(area);
96380 + if (next)
96381 + next_m = pax_find_mirror_vma(next);
96382 +#endif
96383 +
96384 /*
96385 * Can it merge with the predecessor?
96386 */
96387 @@ -1078,9 +1135,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
96388 /* cases 1, 6 */
96389 err = vma_adjust(prev, prev->vm_start,
96390 next->vm_end, prev->vm_pgoff, NULL);
96391 - } else /* cases 2, 5, 7 */
96392 +
96393 +#ifdef CONFIG_PAX_SEGMEXEC
96394 + if (!err && prev_m)
96395 + err = vma_adjust(prev_m, prev_m->vm_start,
96396 + next_m->vm_end, prev_m->vm_pgoff, NULL);
96397 +#endif
96398 +
96399 + } else { /* cases 2, 5, 7 */
96400 err = vma_adjust(prev, prev->vm_start,
96401 end, prev->vm_pgoff, NULL);
96402 +
96403 +#ifdef CONFIG_PAX_SEGMEXEC
96404 + if (!err && prev_m)
96405 + err = vma_adjust(prev_m, prev_m->vm_start,
96406 + end_m, prev_m->vm_pgoff, NULL);
96407 +#endif
96408 +
96409 + }
96410 if (err)
96411 return NULL;
96412 khugepaged_enter_vma_merge(prev, vm_flags);
96413 @@ -1094,12 +1166,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
96414 mpol_equal(policy, vma_policy(next)) &&
96415 can_vma_merge_before(next, vm_flags,
96416 anon_vma, file, pgoff+pglen)) {
96417 - if (prev && addr < prev->vm_end) /* case 4 */
96418 + if (prev && addr < prev->vm_end) { /* case 4 */
96419 err = vma_adjust(prev, prev->vm_start,
96420 addr, prev->vm_pgoff, NULL);
96421 - else /* cases 3, 8 */
96422 +
96423 +#ifdef CONFIG_PAX_SEGMEXEC
96424 + if (!err && prev_m)
96425 + err = vma_adjust(prev_m, prev_m->vm_start,
96426 + addr_m, prev_m->vm_pgoff, NULL);
96427 +#endif
96428 +
96429 + } else { /* cases 3, 8 */
96430 err = vma_adjust(area, addr, next->vm_end,
96431 next->vm_pgoff - pglen, NULL);
96432 +
96433 +#ifdef CONFIG_PAX_SEGMEXEC
96434 + if (!err && area_m)
96435 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
96436 + next_m->vm_pgoff - pglen, NULL);
96437 +#endif
96438 +
96439 + }
96440 if (err)
96441 return NULL;
96442 khugepaged_enter_vma_merge(area, vm_flags);
96443 @@ -1208,8 +1295,10 @@ none:
96444 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
96445 struct file *file, long pages)
96446 {
96447 - const unsigned long stack_flags
96448 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
96449 +
96450 +#ifdef CONFIG_PAX_RANDMMAP
96451 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
96452 +#endif
96453
96454 mm->total_vm += pages;
96455
96456 @@ -1217,7 +1306,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
96457 mm->shared_vm += pages;
96458 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
96459 mm->exec_vm += pages;
96460 - } else if (flags & stack_flags)
96461 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
96462 mm->stack_vm += pages;
96463 }
96464 #endif /* CONFIG_PROC_FS */
96465 @@ -1247,6 +1336,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
96466 locked += mm->locked_vm;
96467 lock_limit = rlimit(RLIMIT_MEMLOCK);
96468 lock_limit >>= PAGE_SHIFT;
96469 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
96470 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
96471 return -EAGAIN;
96472 }
96473 @@ -1273,7 +1363,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
96474 * (the exception is when the underlying filesystem is noexec
96475 * mounted, in which case we dont add PROT_EXEC.)
96476 */
96477 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
96478 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
96479 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
96480 prot |= PROT_EXEC;
96481
96482 @@ -1299,7 +1389,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
96483 /* Obtain the address to map to. we verify (or select) it and ensure
96484 * that it represents a valid section of the address space.
96485 */
96486 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
96487 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
96488 if (addr & ~PAGE_MASK)
96489 return addr;
96490
96491 @@ -1310,6 +1400,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
96492 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
96493 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
96494
96495 +#ifdef CONFIG_PAX_MPROTECT
96496 + if (mm->pax_flags & MF_PAX_MPROTECT) {
96497 +
96498 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
96499 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
96500 + mm->binfmt->handle_mmap)
96501 + mm->binfmt->handle_mmap(file);
96502 +#endif
96503 +
96504 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
96505 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
96506 + gr_log_rwxmmap(file);
96507 +
96508 +#ifdef CONFIG_PAX_EMUPLT
96509 + vm_flags &= ~VM_EXEC;
96510 +#else
96511 + return -EPERM;
96512 +#endif
96513 +
96514 + }
96515 +
96516 + if (!(vm_flags & VM_EXEC))
96517 + vm_flags &= ~VM_MAYEXEC;
96518 +#else
96519 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
96520 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
96521 +#endif
96522 + else
96523 + vm_flags &= ~VM_MAYWRITE;
96524 + }
96525 +#endif
96526 +
96527 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
96528 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
96529 + vm_flags &= ~VM_PAGEEXEC;
96530 +#endif
96531 +
96532 if (flags & MAP_LOCKED)
96533 if (!can_do_mlock())
96534 return -EPERM;
96535 @@ -1397,6 +1524,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
96536 vm_flags |= VM_NORESERVE;
96537 }
96538
96539 + if (!gr_acl_handle_mmap(file, prot))
96540 + return -EACCES;
96541 +
96542 addr = mmap_region(file, addr, len, vm_flags, pgoff);
96543 if (!IS_ERR_VALUE(addr) &&
96544 ((vm_flags & VM_LOCKED) ||
96545 @@ -1490,7 +1620,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
96546 vm_flags_t vm_flags = vma->vm_flags;
96547
96548 /* If it was private or non-writable, the write bit is already clear */
96549 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
96550 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
96551 return 0;
96552
96553 /* The backer wishes to know when pages are first written to? */
96554 @@ -1541,7 +1671,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
96555 struct rb_node **rb_link, *rb_parent;
96556 unsigned long charged = 0;
96557
96558 +#ifdef CONFIG_PAX_SEGMEXEC
96559 + struct vm_area_struct *vma_m = NULL;
96560 +#endif
96561 +
96562 + /*
96563 + * mm->mmap_sem is required to protect against another thread
96564 + * changing the mappings in case we sleep.
96565 + */
96566 + verify_mm_writelocked(mm);
96567 +
96568 /* Check against address space limit. */
96569 +
96570 +#ifdef CONFIG_PAX_RANDMMAP
96571 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
96572 +#endif
96573 +
96574 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
96575 unsigned long nr_pages;
96576
96577 @@ -1560,11 +1705,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
96578
96579 /* Clear old maps */
96580 error = -ENOMEM;
96581 -munmap_back:
96582 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
96583 if (do_munmap(mm, addr, len))
96584 return -ENOMEM;
96585 - goto munmap_back;
96586 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
96587 }
96588
96589 /*
96590 @@ -1595,6 +1739,16 @@ munmap_back:
96591 goto unacct_error;
96592 }
96593
96594 +#ifdef CONFIG_PAX_SEGMEXEC
96595 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
96596 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
96597 + if (!vma_m) {
96598 + error = -ENOMEM;
96599 + goto free_vma;
96600 + }
96601 + }
96602 +#endif
96603 +
96604 vma->vm_mm = mm;
96605 vma->vm_start = addr;
96606 vma->vm_end = addr + len;
96607 @@ -1625,6 +1779,13 @@ munmap_back:
96608 if (error)
96609 goto unmap_and_free_vma;
96610
96611 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
96612 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
96613 + vma->vm_flags |= VM_PAGEEXEC;
96614 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
96615 + }
96616 +#endif
96617 +
96618 /* Can addr have changed??
96619 *
96620 * Answer: Yes, several device drivers can do it in their
96621 @@ -1643,6 +1804,12 @@ munmap_back:
96622 }
96623
96624 vma_link(mm, vma, prev, rb_link, rb_parent);
96625 +
96626 +#ifdef CONFIG_PAX_SEGMEXEC
96627 + if (vma_m)
96628 + BUG_ON(pax_mirror_vma(vma_m, vma));
96629 +#endif
96630 +
96631 /* Once vma denies write, undo our temporary denial count */
96632 if (file) {
96633 if (vm_flags & VM_SHARED)
96634 @@ -1655,6 +1822,7 @@ out:
96635 perf_event_mmap(vma);
96636
96637 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
96638 + track_exec_limit(mm, addr, addr + len, vm_flags);
96639 if (vm_flags & VM_LOCKED) {
96640 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
96641 vma == get_gate_vma(current->mm)))
96642 @@ -1692,6 +1860,12 @@ allow_write_and_free_vma:
96643 if (vm_flags & VM_DENYWRITE)
96644 allow_write_access(file);
96645 free_vma:
96646 +
96647 +#ifdef CONFIG_PAX_SEGMEXEC
96648 + if (vma_m)
96649 + kmem_cache_free(vm_area_cachep, vma_m);
96650 +#endif
96651 +
96652 kmem_cache_free(vm_area_cachep, vma);
96653 unacct_error:
96654 if (charged)
96655 @@ -1699,7 +1873,63 @@ unacct_error:
96656 return error;
96657 }
96658
96659 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
96660 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
96661 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
96662 +{
96663 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
96664 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
96665 +
96666 + return 0;
96667 +}
96668 +#endif
96669 +
96670 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
96671 +{
96672 + if (!vma) {
96673 +#ifdef CONFIG_STACK_GROWSUP
96674 + if (addr > sysctl_heap_stack_gap)
96675 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
96676 + else
96677 + vma = find_vma(current->mm, 0);
96678 + if (vma && (vma->vm_flags & VM_GROWSUP))
96679 + return false;
96680 +#endif
96681 + return true;
96682 + }
96683 +
96684 + if (addr + len > vma->vm_start)
96685 + return false;
96686 +
96687 + if (vma->vm_flags & VM_GROWSDOWN)
96688 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
96689 +#ifdef CONFIG_STACK_GROWSUP
96690 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
96691 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
96692 +#endif
96693 + else if (offset)
96694 + return offset <= vma->vm_start - addr - len;
96695 +
96696 + return true;
96697 +}
96698 +
96699 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
96700 +{
96701 + if (vma->vm_start < len)
96702 + return -ENOMEM;
96703 +
96704 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
96705 + if (offset <= vma->vm_start - len)
96706 + return vma->vm_start - len - offset;
96707 + else
96708 + return -ENOMEM;
96709 + }
96710 +
96711 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
96712 + return vma->vm_start - len - sysctl_heap_stack_gap;
96713 + return -ENOMEM;
96714 +}
96715 +
96716 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
96717 {
96718 /*
96719 * We implement the search by looking for an rbtree node that
96720 @@ -1747,11 +1977,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
96721 }
96722 }
96723
96724 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
96725 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
96726 check_current:
96727 /* Check if current node has a suitable gap */
96728 if (gap_start > high_limit)
96729 return -ENOMEM;
96730 +
96731 + if (gap_end - gap_start > info->threadstack_offset)
96732 + gap_start += info->threadstack_offset;
96733 + else
96734 + gap_start = gap_end;
96735 +
96736 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
96737 + if (gap_end - gap_start > sysctl_heap_stack_gap)
96738 + gap_start += sysctl_heap_stack_gap;
96739 + else
96740 + gap_start = gap_end;
96741 + }
96742 + if (vma->vm_flags & VM_GROWSDOWN) {
96743 + if (gap_end - gap_start > sysctl_heap_stack_gap)
96744 + gap_end -= sysctl_heap_stack_gap;
96745 + else
96746 + gap_end = gap_start;
96747 + }
96748 if (gap_end >= low_limit && gap_end - gap_start >= length)
96749 goto found;
96750
96751 @@ -1801,7 +2049,7 @@ found:
96752 return gap_start;
96753 }
96754
96755 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
96756 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
96757 {
96758 struct mm_struct *mm = current->mm;
96759 struct vm_area_struct *vma;
96760 @@ -1855,6 +2103,24 @@ check_current:
96761 gap_end = vma->vm_start;
96762 if (gap_end < low_limit)
96763 return -ENOMEM;
96764 +
96765 + if (gap_end - gap_start > info->threadstack_offset)
96766 + gap_end -= info->threadstack_offset;
96767 + else
96768 + gap_end = gap_start;
96769 +
96770 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
96771 + if (gap_end - gap_start > sysctl_heap_stack_gap)
96772 + gap_start += sysctl_heap_stack_gap;
96773 + else
96774 + gap_start = gap_end;
96775 + }
96776 + if (vma->vm_flags & VM_GROWSDOWN) {
96777 + if (gap_end - gap_start > sysctl_heap_stack_gap)
96778 + gap_end -= sysctl_heap_stack_gap;
96779 + else
96780 + gap_end = gap_start;
96781 + }
96782 if (gap_start <= high_limit && gap_end - gap_start >= length)
96783 goto found;
96784
96785 @@ -1918,6 +2184,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
96786 struct mm_struct *mm = current->mm;
96787 struct vm_area_struct *vma;
96788 struct vm_unmapped_area_info info;
96789 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
96790
96791 if (len > TASK_SIZE - mmap_min_addr)
96792 return -ENOMEM;
96793 @@ -1925,11 +2192,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
96794 if (flags & MAP_FIXED)
96795 return addr;
96796
96797 +#ifdef CONFIG_PAX_RANDMMAP
96798 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
96799 +#endif
96800 +
96801 if (addr) {
96802 addr = PAGE_ALIGN(addr);
96803 vma = find_vma(mm, addr);
96804 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
96805 - (!vma || addr + len <= vma->vm_start))
96806 + check_heap_stack_gap(vma, addr, len, offset))
96807 return addr;
96808 }
96809
96810 @@ -1938,6 +2209,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
96811 info.low_limit = mm->mmap_base;
96812 info.high_limit = TASK_SIZE;
96813 info.align_mask = 0;
96814 + info.threadstack_offset = offset;
96815 return vm_unmapped_area(&info);
96816 }
96817 #endif
96818 @@ -1956,6 +2228,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
96819 struct mm_struct *mm = current->mm;
96820 unsigned long addr = addr0;
96821 struct vm_unmapped_area_info info;
96822 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
96823
96824 /* requested length too big for entire address space */
96825 if (len > TASK_SIZE - mmap_min_addr)
96826 @@ -1964,12 +2237,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
96827 if (flags & MAP_FIXED)
96828 return addr;
96829
96830 +#ifdef CONFIG_PAX_RANDMMAP
96831 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
96832 +#endif
96833 +
96834 /* requesting a specific address */
96835 if (addr) {
96836 addr = PAGE_ALIGN(addr);
96837 vma = find_vma(mm, addr);
96838 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
96839 - (!vma || addr + len <= vma->vm_start))
96840 + check_heap_stack_gap(vma, addr, len, offset))
96841 return addr;
96842 }
96843
96844 @@ -1978,6 +2255,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
96845 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
96846 info.high_limit = mm->mmap_base;
96847 info.align_mask = 0;
96848 + info.threadstack_offset = offset;
96849 addr = vm_unmapped_area(&info);
96850
96851 /*
96852 @@ -1990,6 +2268,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
96853 VM_BUG_ON(addr != -ENOMEM);
96854 info.flags = 0;
96855 info.low_limit = TASK_UNMAPPED_BASE;
96856 +
96857 +#ifdef CONFIG_PAX_RANDMMAP
96858 + if (mm->pax_flags & MF_PAX_RANDMMAP)
96859 + info.low_limit += mm->delta_mmap;
96860 +#endif
96861 +
96862 info.high_limit = TASK_SIZE;
96863 addr = vm_unmapped_area(&info);
96864 }
96865 @@ -2090,6 +2374,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
96866 return vma;
96867 }
96868
96869 +#ifdef CONFIG_PAX_SEGMEXEC
96870 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
96871 +{
96872 + struct vm_area_struct *vma_m;
96873 +
96874 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
96875 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
96876 + BUG_ON(vma->vm_mirror);
96877 + return NULL;
96878 + }
96879 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
96880 + vma_m = vma->vm_mirror;
96881 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
96882 + BUG_ON(vma->vm_file != vma_m->vm_file);
96883 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
96884 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
96885 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
96886 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
96887 + return vma_m;
96888 +}
96889 +#endif
96890 +
96891 /*
96892 * Verify that the stack growth is acceptable and
96893 * update accounting. This is shared with both the
96894 @@ -2106,6 +2412,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
96895 return -ENOMEM;
96896
96897 /* Stack limit test */
96898 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
96899 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
96900 return -ENOMEM;
96901
96902 @@ -2116,6 +2423,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
96903 locked = mm->locked_vm + grow;
96904 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
96905 limit >>= PAGE_SHIFT;
96906 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
96907 if (locked > limit && !capable(CAP_IPC_LOCK))
96908 return -ENOMEM;
96909 }
96910 @@ -2145,37 +2453,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
96911 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
96912 * vma is the last one with address > vma->vm_end. Have to extend vma.
96913 */
96914 +#ifndef CONFIG_IA64
96915 +static
96916 +#endif
96917 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
96918 {
96919 int error;
96920 + bool locknext;
96921
96922 if (!(vma->vm_flags & VM_GROWSUP))
96923 return -EFAULT;
96924
96925 + /* Also guard against wrapping around to address 0. */
96926 + if (address < PAGE_ALIGN(address+1))
96927 + address = PAGE_ALIGN(address+1);
96928 + else
96929 + return -ENOMEM;
96930 +
96931 /*
96932 * We must make sure the anon_vma is allocated
96933 * so that the anon_vma locking is not a noop.
96934 */
96935 if (unlikely(anon_vma_prepare(vma)))
96936 return -ENOMEM;
96937 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
96938 + if (locknext && anon_vma_prepare(vma->vm_next))
96939 + return -ENOMEM;
96940 vma_lock_anon_vma(vma);
96941 + if (locknext)
96942 + vma_lock_anon_vma(vma->vm_next);
96943
96944 /*
96945 * vma->vm_start/vm_end cannot change under us because the caller
96946 * is required to hold the mmap_sem in read mode. We need the
96947 - * anon_vma lock to serialize against concurrent expand_stacks.
96948 - * Also guard against wrapping around to address 0.
96949 + * anon_vma locks to serialize against concurrent expand_stacks
96950 + * and expand_upwards.
96951 */
96952 - if (address < PAGE_ALIGN(address+4))
96953 - address = PAGE_ALIGN(address+4);
96954 - else {
96955 - vma_unlock_anon_vma(vma);
96956 - return -ENOMEM;
96957 - }
96958 error = 0;
96959
96960 /* Somebody else might have raced and expanded it already */
96961 - if (address > vma->vm_end) {
96962 + 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)
96963 + error = -ENOMEM;
96964 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
96965 unsigned long size, grow;
96966
96967 size = address - vma->vm_start;
96968 @@ -2210,6 +2529,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
96969 }
96970 }
96971 }
96972 + if (locknext)
96973 + vma_unlock_anon_vma(vma->vm_next);
96974 vma_unlock_anon_vma(vma);
96975 khugepaged_enter_vma_merge(vma, vma->vm_flags);
96976 validate_mm(vma->vm_mm);
96977 @@ -2224,6 +2545,8 @@ int expand_downwards(struct vm_area_struct *vma,
96978 unsigned long address)
96979 {
96980 int error;
96981 + bool lockprev = false;
96982 + struct vm_area_struct *prev;
96983
96984 /*
96985 * We must make sure the anon_vma is allocated
96986 @@ -2237,6 +2560,15 @@ int expand_downwards(struct vm_area_struct *vma,
96987 if (error)
96988 return error;
96989
96990 + prev = vma->vm_prev;
96991 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
96992 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
96993 +#endif
96994 + if (lockprev && anon_vma_prepare(prev))
96995 + return -ENOMEM;
96996 + if (lockprev)
96997 + vma_lock_anon_vma(prev);
96998 +
96999 vma_lock_anon_vma(vma);
97000
97001 /*
97002 @@ -2246,9 +2578,17 @@ int expand_downwards(struct vm_area_struct *vma,
97003 */
97004
97005 /* Somebody else might have raced and expanded it already */
97006 - if (address < vma->vm_start) {
97007 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
97008 + error = -ENOMEM;
97009 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
97010 unsigned long size, grow;
97011
97012 +#ifdef CONFIG_PAX_SEGMEXEC
97013 + struct vm_area_struct *vma_m;
97014 +
97015 + vma_m = pax_find_mirror_vma(vma);
97016 +#endif
97017 +
97018 size = vma->vm_end - address;
97019 grow = (vma->vm_start - address) >> PAGE_SHIFT;
97020
97021 @@ -2273,13 +2613,27 @@ int expand_downwards(struct vm_area_struct *vma,
97022 vma->vm_pgoff -= grow;
97023 anon_vma_interval_tree_post_update_vma(vma);
97024 vma_gap_update(vma);
97025 +
97026 +#ifdef CONFIG_PAX_SEGMEXEC
97027 + if (vma_m) {
97028 + anon_vma_interval_tree_pre_update_vma(vma_m);
97029 + vma_m->vm_start -= grow << PAGE_SHIFT;
97030 + vma_m->vm_pgoff -= grow;
97031 + anon_vma_interval_tree_post_update_vma(vma_m);
97032 + vma_gap_update(vma_m);
97033 + }
97034 +#endif
97035 +
97036 spin_unlock(&vma->vm_mm->page_table_lock);
97037
97038 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
97039 perf_event_mmap(vma);
97040 }
97041 }
97042 }
97043 vma_unlock_anon_vma(vma);
97044 + if (lockprev)
97045 + vma_unlock_anon_vma(prev);
97046 khugepaged_enter_vma_merge(vma, vma->vm_flags);
97047 validate_mm(vma->vm_mm);
97048 return error;
97049 @@ -2377,6 +2731,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
97050 do {
97051 long nrpages = vma_pages(vma);
97052
97053 +#ifdef CONFIG_PAX_SEGMEXEC
97054 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
97055 + vma = remove_vma(vma);
97056 + continue;
97057 + }
97058 +#endif
97059 +
97060 if (vma->vm_flags & VM_ACCOUNT)
97061 nr_accounted += nrpages;
97062 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
97063 @@ -2421,6 +2782,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
97064 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
97065 vma->vm_prev = NULL;
97066 do {
97067 +
97068 +#ifdef CONFIG_PAX_SEGMEXEC
97069 + if (vma->vm_mirror) {
97070 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
97071 + vma->vm_mirror->vm_mirror = NULL;
97072 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
97073 + vma->vm_mirror = NULL;
97074 + }
97075 +#endif
97076 +
97077 vma_rb_erase(vma, &mm->mm_rb);
97078 mm->map_count--;
97079 tail_vma = vma;
97080 @@ -2448,14 +2819,33 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97081 struct vm_area_struct *new;
97082 int err = -ENOMEM;
97083
97084 +#ifdef CONFIG_PAX_SEGMEXEC
97085 + struct vm_area_struct *vma_m, *new_m = NULL;
97086 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
97087 +#endif
97088 +
97089 if (is_vm_hugetlb_page(vma) && (addr &
97090 ~(huge_page_mask(hstate_vma(vma)))))
97091 return -EINVAL;
97092
97093 +#ifdef CONFIG_PAX_SEGMEXEC
97094 + vma_m = pax_find_mirror_vma(vma);
97095 +#endif
97096 +
97097 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
97098 if (!new)
97099 goto out_err;
97100
97101 +#ifdef CONFIG_PAX_SEGMEXEC
97102 + if (vma_m) {
97103 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
97104 + if (!new_m) {
97105 + kmem_cache_free(vm_area_cachep, new);
97106 + goto out_err;
97107 + }
97108 + }
97109 +#endif
97110 +
97111 /* most fields are the same, copy all, and then fixup */
97112 *new = *vma;
97113
97114 @@ -2468,6 +2858,22 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97115 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
97116 }
97117
97118 +#ifdef CONFIG_PAX_SEGMEXEC
97119 + if (vma_m) {
97120 + *new_m = *vma_m;
97121 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
97122 + new_m->vm_mirror = new;
97123 + new->vm_mirror = new_m;
97124 +
97125 + if (new_below)
97126 + new_m->vm_end = addr_m;
97127 + else {
97128 + new_m->vm_start = addr_m;
97129 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
97130 + }
97131 + }
97132 +#endif
97133 +
97134 err = vma_dup_policy(vma, new);
97135 if (err)
97136 goto out_free_vma;
97137 @@ -2488,6 +2894,38 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97138 else
97139 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
97140
97141 +#ifdef CONFIG_PAX_SEGMEXEC
97142 + if (!err && vma_m) {
97143 + struct mempolicy *pol = vma_policy(new);
97144 +
97145 + if (anon_vma_clone(new_m, vma_m))
97146 + goto out_free_mpol;
97147 +
97148 + mpol_get(pol);
97149 + set_vma_policy(new_m, pol);
97150 +
97151 + if (new_m->vm_file)
97152 + get_file(new_m->vm_file);
97153 +
97154 + if (new_m->vm_ops && new_m->vm_ops->open)
97155 + new_m->vm_ops->open(new_m);
97156 +
97157 + if (new_below)
97158 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
97159 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
97160 + else
97161 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
97162 +
97163 + if (err) {
97164 + if (new_m->vm_ops && new_m->vm_ops->close)
97165 + new_m->vm_ops->close(new_m);
97166 + if (new_m->vm_file)
97167 + fput(new_m->vm_file);
97168 + mpol_put(pol);
97169 + }
97170 + }
97171 +#endif
97172 +
97173 /* Success. */
97174 if (!err)
97175 return 0;
97176 @@ -2497,10 +2935,18 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97177 new->vm_ops->close(new);
97178 if (new->vm_file)
97179 fput(new->vm_file);
97180 - unlink_anon_vmas(new);
97181 out_free_mpol:
97182 mpol_put(vma_policy(new));
97183 out_free_vma:
97184 +
97185 +#ifdef CONFIG_PAX_SEGMEXEC
97186 + if (new_m) {
97187 + unlink_anon_vmas(new_m);
97188 + kmem_cache_free(vm_area_cachep, new_m);
97189 + }
97190 +#endif
97191 +
97192 + unlink_anon_vmas(new);
97193 kmem_cache_free(vm_area_cachep, new);
97194 out_err:
97195 return err;
97196 @@ -2513,6 +2959,15 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97197 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97198 unsigned long addr, int new_below)
97199 {
97200 +
97201 +#ifdef CONFIG_PAX_SEGMEXEC
97202 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
97203 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
97204 + if (mm->map_count >= sysctl_max_map_count-1)
97205 + return -ENOMEM;
97206 + } else
97207 +#endif
97208 +
97209 if (mm->map_count >= sysctl_max_map_count)
97210 return -ENOMEM;
97211
97212 @@ -2524,11 +2979,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97213 * work. This now handles partial unmappings.
97214 * Jeremy Fitzhardinge <jeremy@goop.org>
97215 */
97216 +#ifdef CONFIG_PAX_SEGMEXEC
97217 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97218 {
97219 + int ret = __do_munmap(mm, start, len);
97220 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
97221 + return ret;
97222 +
97223 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
97224 +}
97225 +
97226 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97227 +#else
97228 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97229 +#endif
97230 +{
97231 unsigned long end;
97232 struct vm_area_struct *vma, *prev, *last;
97233
97234 + /*
97235 + * mm->mmap_sem is required to protect against another thread
97236 + * changing the mappings in case we sleep.
97237 + */
97238 + verify_mm_writelocked(mm);
97239 +
97240 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
97241 return -EINVAL;
97242
97243 @@ -2604,6 +3078,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97244 /* Fix up all other VM information */
97245 remove_vma_list(mm, vma);
97246
97247 + track_exec_limit(mm, start, end, 0UL);
97248 +
97249 return 0;
97250 }
97251
97252 @@ -2612,6 +3088,13 @@ int vm_munmap(unsigned long start, size_t len)
97253 int ret;
97254 struct mm_struct *mm = current->mm;
97255
97256 +
97257 +#ifdef CONFIG_PAX_SEGMEXEC
97258 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
97259 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
97260 + return -EINVAL;
97261 +#endif
97262 +
97263 down_write(&mm->mmap_sem);
97264 ret = do_munmap(mm, start, len);
97265 up_write(&mm->mmap_sem);
97266 @@ -2625,16 +3108,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
97267 return vm_munmap(addr, len);
97268 }
97269
97270 -static inline void verify_mm_writelocked(struct mm_struct *mm)
97271 -{
97272 -#ifdef CONFIG_DEBUG_VM
97273 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
97274 - WARN_ON(1);
97275 - up_read(&mm->mmap_sem);
97276 - }
97277 -#endif
97278 -}
97279 -
97280 /*
97281 * this is really a simplified "do_mmap". it only handles
97282 * anonymous maps. eventually we may be able to do some
97283 @@ -2648,6 +3121,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97284 struct rb_node **rb_link, *rb_parent;
97285 pgoff_t pgoff = addr >> PAGE_SHIFT;
97286 int error;
97287 + unsigned long charged;
97288
97289 len = PAGE_ALIGN(len);
97290 if (!len)
97291 @@ -2655,10 +3129,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97292
97293 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
97294
97295 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
97296 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
97297 + flags &= ~VM_EXEC;
97298 +
97299 +#ifdef CONFIG_PAX_MPROTECT
97300 + if (mm->pax_flags & MF_PAX_MPROTECT)
97301 + flags &= ~VM_MAYEXEC;
97302 +#endif
97303 +
97304 + }
97305 +#endif
97306 +
97307 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
97308 if (error & ~PAGE_MASK)
97309 return error;
97310
97311 + charged = len >> PAGE_SHIFT;
97312 +
97313 error = mlock_future_check(mm, mm->def_flags, len);
97314 if (error)
97315 return error;
97316 @@ -2672,21 +3160,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97317 /*
97318 * Clear old maps. this also does some error checking for us
97319 */
97320 - munmap_back:
97321 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
97322 if (do_munmap(mm, addr, len))
97323 return -ENOMEM;
97324 - goto munmap_back;
97325 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
97326 }
97327
97328 /* Check against address space limits *after* clearing old maps... */
97329 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
97330 + if (!may_expand_vm(mm, charged))
97331 return -ENOMEM;
97332
97333 if (mm->map_count > sysctl_max_map_count)
97334 return -ENOMEM;
97335
97336 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
97337 + if (security_vm_enough_memory_mm(mm, charged))
97338 return -ENOMEM;
97339
97340 /* Can we just expand an old private anonymous mapping? */
97341 @@ -2700,7 +3187,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97342 */
97343 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
97344 if (!vma) {
97345 - vm_unacct_memory(len >> PAGE_SHIFT);
97346 + vm_unacct_memory(charged);
97347 return -ENOMEM;
97348 }
97349
97350 @@ -2714,10 +3201,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97351 vma_link(mm, vma, prev, rb_link, rb_parent);
97352 out:
97353 perf_event_mmap(vma);
97354 - mm->total_vm += len >> PAGE_SHIFT;
97355 + mm->total_vm += charged;
97356 if (flags & VM_LOCKED)
97357 - mm->locked_vm += (len >> PAGE_SHIFT);
97358 + mm->locked_vm += charged;
97359 vma->vm_flags |= VM_SOFTDIRTY;
97360 + track_exec_limit(mm, addr, addr + len, flags);
97361 return addr;
97362 }
97363
97364 @@ -2779,6 +3267,7 @@ void exit_mmap(struct mm_struct *mm)
97365 while (vma) {
97366 if (vma->vm_flags & VM_ACCOUNT)
97367 nr_accounted += vma_pages(vma);
97368 + vma->vm_mirror = NULL;
97369 vma = remove_vma(vma);
97370 }
97371 vm_unacct_memory(nr_accounted);
97372 @@ -2796,6 +3285,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
97373 struct vm_area_struct *prev;
97374 struct rb_node **rb_link, *rb_parent;
97375
97376 +#ifdef CONFIG_PAX_SEGMEXEC
97377 + struct vm_area_struct *vma_m = NULL;
97378 +#endif
97379 +
97380 + if (security_mmap_addr(vma->vm_start))
97381 + return -EPERM;
97382 +
97383 /*
97384 * The vm_pgoff of a purely anonymous vma should be irrelevant
97385 * until its first write fault, when page's anon_vma and index
97386 @@ -2819,7 +3315,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
97387 security_vm_enough_memory_mm(mm, vma_pages(vma)))
97388 return -ENOMEM;
97389
97390 +#ifdef CONFIG_PAX_SEGMEXEC
97391 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
97392 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
97393 + if (!vma_m)
97394 + return -ENOMEM;
97395 + }
97396 +#endif
97397 +
97398 vma_link(mm, vma, prev, rb_link, rb_parent);
97399 +
97400 +#ifdef CONFIG_PAX_SEGMEXEC
97401 + if (vma_m)
97402 + BUG_ON(pax_mirror_vma(vma_m, vma));
97403 +#endif
97404 +
97405 return 0;
97406 }
97407
97408 @@ -2838,6 +3348,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
97409 struct rb_node **rb_link, *rb_parent;
97410 bool faulted_in_anon_vma = true;
97411
97412 + BUG_ON(vma->vm_mirror);
97413 +
97414 /*
97415 * If anonymous vma has not yet been faulted, update new pgoff
97416 * to match new location, to increase its chance of merging.
97417 @@ -2902,6 +3414,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
97418 return NULL;
97419 }
97420
97421 +#ifdef CONFIG_PAX_SEGMEXEC
97422 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
97423 +{
97424 + struct vm_area_struct *prev_m;
97425 + struct rb_node **rb_link_m, *rb_parent_m;
97426 + struct mempolicy *pol_m;
97427 +
97428 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
97429 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
97430 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
97431 + *vma_m = *vma;
97432 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
97433 + if (anon_vma_clone(vma_m, vma))
97434 + return -ENOMEM;
97435 + pol_m = vma_policy(vma_m);
97436 + mpol_get(pol_m);
97437 + set_vma_policy(vma_m, pol_m);
97438 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
97439 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
97440 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
97441 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
97442 + if (vma_m->vm_file)
97443 + get_file(vma_m->vm_file);
97444 + if (vma_m->vm_ops && vma_m->vm_ops->open)
97445 + vma_m->vm_ops->open(vma_m);
97446 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
97447 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
97448 + vma_m->vm_mirror = vma;
97449 + vma->vm_mirror = vma_m;
97450 + return 0;
97451 +}
97452 +#endif
97453 +
97454 /*
97455 * Return true if the calling process may expand its vm space by the passed
97456 * number of pages
97457 @@ -2913,6 +3458,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
97458
97459 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
97460
97461 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
97462 if (cur + npages > lim)
97463 return 0;
97464 return 1;
97465 @@ -2995,6 +3541,22 @@ static struct vm_area_struct *__install_special_mapping(
97466 vma->vm_start = addr;
97467 vma->vm_end = addr + len;
97468
97469 +#ifdef CONFIG_PAX_MPROTECT
97470 + if (mm->pax_flags & MF_PAX_MPROTECT) {
97471 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
97472 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
97473 + return ERR_PTR(-EPERM);
97474 + if (!(vm_flags & VM_EXEC))
97475 + vm_flags &= ~VM_MAYEXEC;
97476 +#else
97477 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
97478 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
97479 +#endif
97480 + else
97481 + vm_flags &= ~VM_MAYWRITE;
97482 + }
97483 +#endif
97484 +
97485 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
97486 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
97487
97488 diff --git a/mm/mprotect.c b/mm/mprotect.c
97489 index ace9345..63320dc 100644
97490 --- a/mm/mprotect.c
97491 +++ b/mm/mprotect.c
97492 @@ -24,10 +24,18 @@
97493 #include <linux/migrate.h>
97494 #include <linux/perf_event.h>
97495 #include <linux/ksm.h>
97496 +#include <linux/sched/sysctl.h>
97497 +
97498 +#ifdef CONFIG_PAX_MPROTECT
97499 +#include <linux/elf.h>
97500 +#include <linux/binfmts.h>
97501 +#endif
97502 +
97503 #include <asm/uaccess.h>
97504 #include <asm/pgtable.h>
97505 #include <asm/cacheflush.h>
97506 #include <asm/tlbflush.h>
97507 +#include <asm/mmu_context.h>
97508
97509 /*
97510 * For a prot_numa update we only hold mmap_sem for read so there is a
97511 @@ -251,6 +259,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
97512 return pages;
97513 }
97514
97515 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
97516 +/* called while holding the mmap semaphor for writing except stack expansion */
97517 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
97518 +{
97519 + unsigned long oldlimit, newlimit = 0UL;
97520 +
97521 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
97522 + return;
97523 +
97524 + spin_lock(&mm->page_table_lock);
97525 + oldlimit = mm->context.user_cs_limit;
97526 + if ((prot & VM_EXEC) && oldlimit < end)
97527 + /* USER_CS limit moved up */
97528 + newlimit = end;
97529 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
97530 + /* USER_CS limit moved down */
97531 + newlimit = start;
97532 +
97533 + if (newlimit) {
97534 + mm->context.user_cs_limit = newlimit;
97535 +
97536 +#ifdef CONFIG_SMP
97537 + wmb();
97538 + cpus_clear(mm->context.cpu_user_cs_mask);
97539 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
97540 +#endif
97541 +
97542 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
97543 + }
97544 + spin_unlock(&mm->page_table_lock);
97545 + if (newlimit == end) {
97546 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
97547 +
97548 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
97549 + if (is_vm_hugetlb_page(vma))
97550 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
97551 + else
97552 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
97553 + }
97554 +}
97555 +#endif
97556 +
97557 int
97558 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
97559 unsigned long start, unsigned long end, unsigned long newflags)
97560 @@ -263,11 +313,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
97561 int error;
97562 int dirty_accountable = 0;
97563
97564 +#ifdef CONFIG_PAX_SEGMEXEC
97565 + struct vm_area_struct *vma_m = NULL;
97566 + unsigned long start_m, end_m;
97567 +
97568 + start_m = start + SEGMEXEC_TASK_SIZE;
97569 + end_m = end + SEGMEXEC_TASK_SIZE;
97570 +#endif
97571 +
97572 if (newflags == oldflags) {
97573 *pprev = vma;
97574 return 0;
97575 }
97576
97577 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
97578 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
97579 +
97580 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
97581 + return -ENOMEM;
97582 +
97583 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
97584 + return -ENOMEM;
97585 + }
97586 +
97587 /*
97588 * If we make a private mapping writable we increase our commit;
97589 * but (without finer accounting) cannot reduce our commit if we
97590 @@ -284,6 +352,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
97591 }
97592 }
97593
97594 +#ifdef CONFIG_PAX_SEGMEXEC
97595 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
97596 + if (start != vma->vm_start) {
97597 + error = split_vma(mm, vma, start, 1);
97598 + if (error)
97599 + goto fail;
97600 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
97601 + *pprev = (*pprev)->vm_next;
97602 + }
97603 +
97604 + if (end != vma->vm_end) {
97605 + error = split_vma(mm, vma, end, 0);
97606 + if (error)
97607 + goto fail;
97608 + }
97609 +
97610 + if (pax_find_mirror_vma(vma)) {
97611 + error = __do_munmap(mm, start_m, end_m - start_m);
97612 + if (error)
97613 + goto fail;
97614 + } else {
97615 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
97616 + if (!vma_m) {
97617 + error = -ENOMEM;
97618 + goto fail;
97619 + }
97620 + vma->vm_flags = newflags;
97621 + error = pax_mirror_vma(vma_m, vma);
97622 + if (error) {
97623 + vma->vm_flags = oldflags;
97624 + goto fail;
97625 + }
97626 + }
97627 + }
97628 +#endif
97629 +
97630 /*
97631 * First try to merge with previous and/or next vma.
97632 */
97633 @@ -314,7 +418,19 @@ success:
97634 * vm_flags and vm_page_prot are protected by the mmap_sem
97635 * held in write mode.
97636 */
97637 +
97638 +#ifdef CONFIG_PAX_SEGMEXEC
97639 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
97640 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
97641 +#endif
97642 +
97643 vma->vm_flags = newflags;
97644 +
97645 +#ifdef CONFIG_PAX_MPROTECT
97646 + if (mm->binfmt && mm->binfmt->handle_mprotect)
97647 + mm->binfmt->handle_mprotect(vma, newflags);
97648 +#endif
97649 +
97650 dirty_accountable = vma_wants_writenotify(vma);
97651 vma_set_page_prot(vma);
97652
97653 @@ -350,6 +466,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
97654 end = start + len;
97655 if (end <= start)
97656 return -ENOMEM;
97657 +
97658 +#ifdef CONFIG_PAX_SEGMEXEC
97659 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
97660 + if (end > SEGMEXEC_TASK_SIZE)
97661 + return -EINVAL;
97662 + } else
97663 +#endif
97664 +
97665 + if (end > TASK_SIZE)
97666 + return -EINVAL;
97667 +
97668 if (!arch_validate_prot(prot))
97669 return -EINVAL;
97670
97671 @@ -357,7 +484,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
97672 /*
97673 * Does the application expect PROT_READ to imply PROT_EXEC:
97674 */
97675 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
97676 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
97677 prot |= PROT_EXEC;
97678
97679 vm_flags = calc_vm_prot_bits(prot);
97680 @@ -389,6 +516,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
97681 if (start > vma->vm_start)
97682 prev = vma;
97683
97684 +#ifdef CONFIG_PAX_MPROTECT
97685 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
97686 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
97687 +#endif
97688 +
97689 for (nstart = start ; ; ) {
97690 unsigned long newflags;
97691
97692 @@ -399,6 +531,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
97693
97694 /* newflags >> 4 shift VM_MAY% in place of VM_% */
97695 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
97696 + if (prot & (PROT_WRITE | PROT_EXEC))
97697 + gr_log_rwxmprotect(vma);
97698 +
97699 + error = -EACCES;
97700 + goto out;
97701 + }
97702 +
97703 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
97704 error = -EACCES;
97705 goto out;
97706 }
97707 @@ -413,6 +553,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
97708 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
97709 if (error)
97710 goto out;
97711 +
97712 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
97713 +
97714 nstart = tmp;
97715
97716 if (nstart < prev->vm_end)
97717 diff --git a/mm/mremap.c b/mm/mremap.c
97718 index b147f66..98a695a 100644
97719 --- a/mm/mremap.c
97720 +++ b/mm/mremap.c
97721 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
97722 continue;
97723 pte = ptep_get_and_clear(mm, old_addr, old_pte);
97724 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
97725 +
97726 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
97727 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
97728 + pte = pte_exprotect(pte);
97729 +#endif
97730 +
97731 pte = move_soft_dirty_pte(pte);
97732 set_pte_at(mm, new_addr, new_pte, pte);
97733 }
97734 @@ -345,6 +351,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
97735 if (is_vm_hugetlb_page(vma))
97736 goto Einval;
97737
97738 +#ifdef CONFIG_PAX_SEGMEXEC
97739 + if (pax_find_mirror_vma(vma))
97740 + goto Einval;
97741 +#endif
97742 +
97743 /* We can't remap across vm area boundaries */
97744 if (old_len > vma->vm_end - addr)
97745 goto Efault;
97746 @@ -400,20 +411,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
97747 unsigned long ret = -EINVAL;
97748 unsigned long charged = 0;
97749 unsigned long map_flags;
97750 + unsigned long pax_task_size = TASK_SIZE;
97751
97752 if (new_addr & ~PAGE_MASK)
97753 goto out;
97754
97755 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
97756 +#ifdef CONFIG_PAX_SEGMEXEC
97757 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
97758 + pax_task_size = SEGMEXEC_TASK_SIZE;
97759 +#endif
97760 +
97761 + pax_task_size -= PAGE_SIZE;
97762 +
97763 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
97764 goto out;
97765
97766 /* Check if the location we're moving into overlaps the
97767 * old location at all, and fail if it does.
97768 */
97769 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
97770 - goto out;
97771 -
97772 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
97773 + if (addr + old_len > new_addr && new_addr + new_len > addr)
97774 goto out;
97775
97776 ret = do_munmap(mm, new_addr, new_len);
97777 @@ -482,6 +498,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
97778 unsigned long ret = -EINVAL;
97779 unsigned long charged = 0;
97780 bool locked = false;
97781 + unsigned long pax_task_size = TASK_SIZE;
97782
97783 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
97784 return ret;
97785 @@ -503,6 +520,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
97786 if (!new_len)
97787 return ret;
97788
97789 +#ifdef CONFIG_PAX_SEGMEXEC
97790 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
97791 + pax_task_size = SEGMEXEC_TASK_SIZE;
97792 +#endif
97793 +
97794 + pax_task_size -= PAGE_SIZE;
97795 +
97796 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
97797 + old_len > pax_task_size || addr > pax_task_size-old_len)
97798 + return ret;
97799 +
97800 down_write(&current->mm->mmap_sem);
97801
97802 if (flags & MREMAP_FIXED) {
97803 @@ -553,6 +581,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
97804 new_addr = addr;
97805 }
97806 ret = addr;
97807 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
97808 goto out;
97809 }
97810 }
97811 @@ -576,7 +605,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
97812 goto out;
97813 }
97814
97815 + map_flags = vma->vm_flags;
97816 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
97817 + if (!(ret & ~PAGE_MASK)) {
97818 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
97819 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
97820 + }
97821 }
97822 out:
97823 if (ret & ~PAGE_MASK)
97824 diff --git a/mm/nommu.c b/mm/nommu.c
97825 index bd1808e..b63d87c 100644
97826 --- a/mm/nommu.c
97827 +++ b/mm/nommu.c
97828 @@ -70,7 +70,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
97829 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
97830 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
97831 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
97832 -int heap_stack_gap = 0;
97833
97834 atomic_long_t mmap_pages_allocated;
97835
97836 @@ -857,15 +856,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
97837 EXPORT_SYMBOL(find_vma);
97838
97839 /*
97840 - * find a VMA
97841 - * - we don't extend stack VMAs under NOMMU conditions
97842 - */
97843 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
97844 -{
97845 - return find_vma(mm, addr);
97846 -}
97847 -
97848 -/*
97849 * expand a stack to a given address
97850 * - not supported under NOMMU conditions
97851 */
97852 @@ -1572,6 +1562,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97853
97854 /* most fields are the same, copy all, and then fixup */
97855 *new = *vma;
97856 + INIT_LIST_HEAD(&new->anon_vma_chain);
97857 *region = *vma->vm_region;
97858 new->vm_region = region;
97859
97860 @@ -2002,8 +1993,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
97861 }
97862 EXPORT_SYMBOL(generic_file_remap_pages);
97863
97864 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
97865 - unsigned long addr, void *buf, int len, int write)
97866 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
97867 + unsigned long addr, void *buf, size_t len, int write)
97868 {
97869 struct vm_area_struct *vma;
97870
97871 @@ -2044,8 +2035,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
97872 *
97873 * The caller must hold a reference on @mm.
97874 */
97875 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
97876 - void *buf, int len, int write)
97877 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
97878 + void *buf, size_t len, int write)
97879 {
97880 return __access_remote_vm(NULL, mm, addr, buf, len, write);
97881 }
97882 @@ -2054,7 +2045,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
97883 * Access another process' address space.
97884 * - source/target buffer must be kernel space
97885 */
97886 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
97887 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
97888 {
97889 struct mm_struct *mm;
97890
97891 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
97892 index 19ceae8..70848ee 100644
97893 --- a/mm/page-writeback.c
97894 +++ b/mm/page-writeback.c
97895 @@ -664,7 +664,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
97896 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
97897 * - the bdi dirty thresh drops quickly due to change of JBOD workload
97898 */
97899 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
97900 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
97901 unsigned long thresh,
97902 unsigned long bg_thresh,
97903 unsigned long dirty,
97904 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
97905 index 616a2c9..0e755f6 100644
97906 --- a/mm/page_alloc.c
97907 +++ b/mm/page_alloc.c
97908 @@ -59,6 +59,7 @@
97909 #include <linux/page-debug-flags.h>
97910 #include <linux/hugetlb.h>
97911 #include <linux/sched/rt.h>
97912 +#include <linux/random.h>
97913
97914 #include <asm/sections.h>
97915 #include <asm/tlbflush.h>
97916 @@ -356,7 +357,7 @@ out:
97917 * This usage means that zero-order pages may not be compound.
97918 */
97919
97920 -static void free_compound_page(struct page *page)
97921 +void free_compound_page(struct page *page)
97922 {
97923 __free_pages_ok(page, compound_order(page));
97924 }
97925 @@ -741,6 +742,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
97926 int i;
97927 int bad = 0;
97928
97929 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
97930 + unsigned long index = 1UL << order;
97931 +#endif
97932 +
97933 trace_mm_page_free(page, order);
97934 kmemcheck_free_shadow(page, order);
97935
97936 @@ -757,6 +762,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
97937 debug_check_no_obj_freed(page_address(page),
97938 PAGE_SIZE << order);
97939 }
97940 +
97941 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
97942 + for (; index; --index)
97943 + sanitize_highpage(page + index - 1);
97944 +#endif
97945 +
97946 arch_free_page(page, order);
97947 kernel_map_pages(page, 1 << order, 0);
97948
97949 @@ -780,6 +791,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
97950 local_irq_restore(flags);
97951 }
97952
97953 +#ifdef CONFIG_PAX_LATENT_ENTROPY
97954 +bool __meminitdata extra_latent_entropy;
97955 +
97956 +static int __init setup_pax_extra_latent_entropy(char *str)
97957 +{
97958 + extra_latent_entropy = true;
97959 + return 0;
97960 +}
97961 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
97962 +
97963 +volatile u64 latent_entropy __latent_entropy;
97964 +EXPORT_SYMBOL(latent_entropy);
97965 +#endif
97966 +
97967 void __init __free_pages_bootmem(struct page *page, unsigned int order)
97968 {
97969 unsigned int nr_pages = 1 << order;
97970 @@ -795,6 +820,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
97971 __ClearPageReserved(p);
97972 set_page_count(p, 0);
97973
97974 +#ifdef CONFIG_PAX_LATENT_ENTROPY
97975 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
97976 + u64 hash = 0;
97977 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
97978 + const u64 *data = lowmem_page_address(page);
97979 +
97980 + for (index = 0; index < end; index++)
97981 + hash ^= hash + data[index];
97982 + latent_entropy ^= hash;
97983 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
97984 + }
97985 +#endif
97986 +
97987 page_zone(page)->managed_pages += nr_pages;
97988 set_page_refcounted(page);
97989 __free_pages(page, order);
97990 @@ -923,8 +961,10 @@ static int prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags)
97991 arch_alloc_page(page, order);
97992 kernel_map_pages(page, 1 << order, 1);
97993
97994 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
97995 if (gfp_flags & __GFP_ZERO)
97996 prep_zero_page(page, order, gfp_flags);
97997 +#endif
97998
97999 if (order && (gfp_flags & __GFP_COMP))
98000 prep_compound_page(page, order);
98001 @@ -1602,7 +1642,7 @@ again:
98002 }
98003
98004 __mod_zone_page_state(zone, NR_ALLOC_BATCH, -(1 << order));
98005 - if (atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
98006 + if (atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
98007 !test_bit(ZONE_FAIR_DEPLETED, &zone->flags))
98008 set_bit(ZONE_FAIR_DEPLETED, &zone->flags);
98009
98010 @@ -1923,7 +1963,7 @@ static void reset_alloc_batches(struct zone *preferred_zone)
98011 do {
98012 mod_zone_page_state(zone, NR_ALLOC_BATCH,
98013 high_wmark_pages(zone) - low_wmark_pages(zone) -
98014 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
98015 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
98016 clear_bit(ZONE_FAIR_DEPLETED, &zone->flags);
98017 } while (zone++ != preferred_zone);
98018 }
98019 @@ -5698,7 +5738,7 @@ static void __setup_per_zone_wmarks(void)
98020
98021 __mod_zone_page_state(zone, NR_ALLOC_BATCH,
98022 high_wmark_pages(zone) - low_wmark_pages(zone) -
98023 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
98024 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
98025
98026 setup_zone_migrate_reserve(zone);
98027 spin_unlock_irqrestore(&zone->lock, flags);
98028 diff --git a/mm/percpu.c b/mm/percpu.c
98029 index 014bab6..db5a76f 100644
98030 --- a/mm/percpu.c
98031 +++ b/mm/percpu.c
98032 @@ -131,7 +131,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
98033 static unsigned int pcpu_high_unit_cpu __read_mostly;
98034
98035 /* the address of the first chunk which starts with the kernel static area */
98036 -void *pcpu_base_addr __read_mostly;
98037 +void *pcpu_base_addr __read_only;
98038 EXPORT_SYMBOL_GPL(pcpu_base_addr);
98039
98040 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
98041 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
98042 index 5077afc..846c9ef 100644
98043 --- a/mm/process_vm_access.c
98044 +++ b/mm/process_vm_access.c
98045 @@ -13,6 +13,7 @@
98046 #include <linux/uio.h>
98047 #include <linux/sched.h>
98048 #include <linux/highmem.h>
98049 +#include <linux/security.h>
98050 #include <linux/ptrace.h>
98051 #include <linux/slab.h>
98052 #include <linux/syscalls.h>
98053 @@ -157,19 +158,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
98054 ssize_t iov_len;
98055 size_t total_len = iov_iter_count(iter);
98056
98057 + return -ENOSYS; // PaX: until properly audited
98058 +
98059 /*
98060 * Work out how many pages of struct pages we're going to need
98061 * when eventually calling get_user_pages
98062 */
98063 for (i = 0; i < riovcnt; i++) {
98064 iov_len = rvec[i].iov_len;
98065 - if (iov_len > 0) {
98066 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
98067 - + iov_len)
98068 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
98069 - / PAGE_SIZE + 1;
98070 - nr_pages = max(nr_pages, nr_pages_iov);
98071 - }
98072 + if (iov_len <= 0)
98073 + continue;
98074 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
98075 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
98076 + nr_pages = max(nr_pages, nr_pages_iov);
98077 }
98078
98079 if (nr_pages == 0)
98080 @@ -197,6 +198,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
98081 goto free_proc_pages;
98082 }
98083
98084 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
98085 + rc = -EPERM;
98086 + goto put_task_struct;
98087 + }
98088 +
98089 mm = mm_access(task, PTRACE_MODE_ATTACH);
98090 if (!mm || IS_ERR(mm)) {
98091 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
98092 diff --git a/mm/rmap.c b/mm/rmap.c
98093 index 3e4c721..a5e3e39 100644
98094 --- a/mm/rmap.c
98095 +++ b/mm/rmap.c
98096 @@ -164,6 +164,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98097 struct anon_vma *anon_vma = vma->anon_vma;
98098 struct anon_vma_chain *avc;
98099
98100 +#ifdef CONFIG_PAX_SEGMEXEC
98101 + struct anon_vma_chain *avc_m = NULL;
98102 +#endif
98103 +
98104 might_sleep();
98105 if (unlikely(!anon_vma)) {
98106 struct mm_struct *mm = vma->vm_mm;
98107 @@ -173,6 +177,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98108 if (!avc)
98109 goto out_enomem;
98110
98111 +#ifdef CONFIG_PAX_SEGMEXEC
98112 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
98113 + if (!avc_m)
98114 + goto out_enomem_free_avc;
98115 +#endif
98116 +
98117 anon_vma = find_mergeable_anon_vma(vma);
98118 allocated = NULL;
98119 if (!anon_vma) {
98120 @@ -186,6 +196,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98121 /* page_table_lock to protect against threads */
98122 spin_lock(&mm->page_table_lock);
98123 if (likely(!vma->anon_vma)) {
98124 +
98125 +#ifdef CONFIG_PAX_SEGMEXEC
98126 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
98127 +
98128 + if (vma_m) {
98129 + BUG_ON(vma_m->anon_vma);
98130 + vma_m->anon_vma = anon_vma;
98131 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
98132 + avc_m = NULL;
98133 + }
98134 +#endif
98135 +
98136 vma->anon_vma = anon_vma;
98137 anon_vma_chain_link(vma, avc, anon_vma);
98138 allocated = NULL;
98139 @@ -196,12 +218,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98140
98141 if (unlikely(allocated))
98142 put_anon_vma(allocated);
98143 +
98144 +#ifdef CONFIG_PAX_SEGMEXEC
98145 + if (unlikely(avc_m))
98146 + anon_vma_chain_free(avc_m);
98147 +#endif
98148 +
98149 if (unlikely(avc))
98150 anon_vma_chain_free(avc);
98151 }
98152 return 0;
98153
98154 out_enomem_free_avc:
98155 +
98156 +#ifdef CONFIG_PAX_SEGMEXEC
98157 + if (avc_m)
98158 + anon_vma_chain_free(avc_m);
98159 +#endif
98160 +
98161 anon_vma_chain_free(avc);
98162 out_enomem:
98163 return -ENOMEM;
98164 @@ -237,7 +271,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
98165 * Attach the anon_vmas from src to dst.
98166 * Returns 0 on success, -ENOMEM on failure.
98167 */
98168 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
98169 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
98170 {
98171 struct anon_vma_chain *avc, *pavc;
98172 struct anon_vma *root = NULL;
98173 @@ -270,7 +304,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
98174 * the corresponding VMA in the parent process is attached to.
98175 * Returns 0 on success, non-zero on failure.
98176 */
98177 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
98178 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
98179 {
98180 struct anon_vma_chain *avc;
98181 struct anon_vma *anon_vma;
98182 @@ -376,8 +410,10 @@ static void anon_vma_ctor(void *data)
98183 void __init anon_vma_init(void)
98184 {
98185 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
98186 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
98187 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
98188 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
98189 + anon_vma_ctor);
98190 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
98191 + SLAB_PANIC|SLAB_NO_SANITIZE);
98192 }
98193
98194 /*
98195 diff --git a/mm/shmem.c b/mm/shmem.c
98196 index 185836b..d7255a1 100644
98197 --- a/mm/shmem.c
98198 +++ b/mm/shmem.c
98199 @@ -33,7 +33,7 @@
98200 #include <linux/swap.h>
98201 #include <linux/aio.h>
98202
98203 -static struct vfsmount *shm_mnt;
98204 +struct vfsmount *shm_mnt;
98205
98206 #ifdef CONFIG_SHMEM
98207 /*
98208 @@ -80,7 +80,7 @@ static struct vfsmount *shm_mnt;
98209 #define BOGO_DIRENT_SIZE 20
98210
98211 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
98212 -#define SHORT_SYMLINK_LEN 128
98213 +#define SHORT_SYMLINK_LEN 64
98214
98215 /*
98216 * shmem_fallocate communicates with shmem_fault or shmem_writepage via
98217 @@ -2558,6 +2558,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
98218 static int shmem_xattr_validate(const char *name)
98219 {
98220 struct { const char *prefix; size_t len; } arr[] = {
98221 +
98222 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
98223 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
98224 +#endif
98225 +
98226 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
98227 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
98228 };
98229 @@ -2613,6 +2618,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
98230 if (err)
98231 return err;
98232
98233 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
98234 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
98235 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
98236 + return -EOPNOTSUPP;
98237 + if (size > 8)
98238 + return -EINVAL;
98239 + }
98240 +#endif
98241 +
98242 return simple_xattr_set(&info->xattrs, name, value, size, flags);
98243 }
98244
98245 @@ -2996,8 +3010,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
98246 int err = -ENOMEM;
98247
98248 /* Round up to L1_CACHE_BYTES to resist false sharing */
98249 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
98250 - L1_CACHE_BYTES), GFP_KERNEL);
98251 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
98252 if (!sbinfo)
98253 return -ENOMEM;
98254
98255 diff --git a/mm/slab.c b/mm/slab.c
98256 index f34e053..78a3839 100644
98257 --- a/mm/slab.c
98258 +++ b/mm/slab.c
98259 @@ -314,10 +314,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
98260 if ((x)->max_freeable < i) \
98261 (x)->max_freeable = i; \
98262 } while (0)
98263 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
98264 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
98265 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
98266 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
98267 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
98268 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
98269 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
98270 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
98271 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
98272 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
98273 #else
98274 #define STATS_INC_ACTIVE(x) do { } while (0)
98275 #define STATS_DEC_ACTIVE(x) do { } while (0)
98276 @@ -334,6 +336,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
98277 #define STATS_INC_ALLOCMISS(x) do { } while (0)
98278 #define STATS_INC_FREEHIT(x) do { } while (0)
98279 #define STATS_INC_FREEMISS(x) do { } while (0)
98280 +#define STATS_INC_SANITIZED(x) do { } while (0)
98281 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
98282 #endif
98283
98284 #if DEBUG
98285 @@ -450,7 +454,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
98286 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
98287 */
98288 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
98289 - const struct page *page, void *obj)
98290 + const struct page *page, const void *obj)
98291 {
98292 u32 offset = (obj - page->s_mem);
98293 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
98294 @@ -1438,7 +1442,7 @@ void __init kmem_cache_init(void)
98295 * structures first. Without this, further allocations will bug.
98296 */
98297 kmalloc_caches[INDEX_NODE] = create_kmalloc_cache("kmalloc-node",
98298 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
98299 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
98300 slab_state = PARTIAL_NODE;
98301
98302 slab_early_init = 0;
98303 @@ -2059,7 +2063,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
98304
98305 cachep = find_mergeable(size, align, flags, name, ctor);
98306 if (cachep) {
98307 - cachep->refcount++;
98308 + atomic_inc(&cachep->refcount);
98309
98310 /*
98311 * Adjust the object sizes so that we clear
98312 @@ -3352,6 +3356,20 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
98313 struct array_cache *ac = cpu_cache_get(cachep);
98314
98315 check_irq_off();
98316 +
98317 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98318 + if (cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))
98319 + STATS_INC_NOT_SANITIZED(cachep);
98320 + else {
98321 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
98322 +
98323 + if (cachep->ctor)
98324 + cachep->ctor(objp);
98325 +
98326 + STATS_INC_SANITIZED(cachep);
98327 + }
98328 +#endif
98329 +
98330 kmemleak_free_recursive(objp, cachep->flags);
98331 objp = cache_free_debugcheck(cachep, objp, caller);
98332
98333 @@ -3557,6 +3575,7 @@ void kfree(const void *objp)
98334
98335 if (unlikely(ZERO_OR_NULL_PTR(objp)))
98336 return;
98337 + VM_BUG_ON(!virt_addr_valid(objp));
98338 local_irq_save(flags);
98339 kfree_debugcheck(objp);
98340 c = virt_to_cache(objp);
98341 @@ -3979,14 +3998,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
98342 }
98343 /* cpu stats */
98344 {
98345 - unsigned long allochit = atomic_read(&cachep->allochit);
98346 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
98347 - unsigned long freehit = atomic_read(&cachep->freehit);
98348 - unsigned long freemiss = atomic_read(&cachep->freemiss);
98349 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
98350 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
98351 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
98352 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
98353
98354 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
98355 allochit, allocmiss, freehit, freemiss);
98356 }
98357 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98358 + {
98359 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
98360 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
98361 +
98362 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
98363 + }
98364 +#endif
98365 #endif
98366 }
98367
98368 @@ -4200,13 +4227,69 @@ static const struct file_operations proc_slabstats_operations = {
98369 static int __init slab_proc_init(void)
98370 {
98371 #ifdef CONFIG_DEBUG_SLAB_LEAK
98372 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
98373 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
98374 #endif
98375 return 0;
98376 }
98377 module_init(slab_proc_init);
98378 #endif
98379
98380 +bool is_usercopy_object(const void *ptr)
98381 +{
98382 + struct page *page;
98383 + struct kmem_cache *cachep;
98384 +
98385 + if (ZERO_OR_NULL_PTR(ptr))
98386 + return false;
98387 +
98388 + if (!slab_is_available())
98389 + return false;
98390 +
98391 + if (!virt_addr_valid(ptr))
98392 + return false;
98393 +
98394 + page = virt_to_head_page(ptr);
98395 +
98396 + if (!PageSlab(page))
98397 + return false;
98398 +
98399 + cachep = page->slab_cache;
98400 + return cachep->flags & SLAB_USERCOPY;
98401 +}
98402 +
98403 +#ifdef CONFIG_PAX_USERCOPY
98404 +const char *check_heap_object(const void *ptr, unsigned long n)
98405 +{
98406 + struct page *page;
98407 + struct kmem_cache *cachep;
98408 + unsigned int objnr;
98409 + unsigned long offset;
98410 +
98411 + if (ZERO_OR_NULL_PTR(ptr))
98412 + return "<null>";
98413 +
98414 + if (!virt_addr_valid(ptr))
98415 + return NULL;
98416 +
98417 + page = virt_to_head_page(ptr);
98418 +
98419 + if (!PageSlab(page))
98420 + return NULL;
98421 +
98422 + cachep = page->slab_cache;
98423 + if (!(cachep->flags & SLAB_USERCOPY))
98424 + return cachep->name;
98425 +
98426 + objnr = obj_to_index(cachep, page, ptr);
98427 + BUG_ON(objnr >= cachep->num);
98428 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
98429 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
98430 + return NULL;
98431 +
98432 + return cachep->name;
98433 +}
98434 +#endif
98435 +
98436 /**
98437 * ksize - get the actual amount of memory allocated for a given object
98438 * @objp: Pointer to the object
98439 diff --git a/mm/slab.h b/mm/slab.h
98440 index ab019e6..fbcac34 100644
98441 --- a/mm/slab.h
98442 +++ b/mm/slab.h
98443 @@ -22,7 +22,7 @@ struct kmem_cache {
98444 unsigned int align; /* Alignment as calculated */
98445 unsigned long flags; /* Active flags on the slab */
98446 const char *name; /* Slab name for sysfs */
98447 - int refcount; /* Use counter */
98448 + atomic_t refcount; /* Use counter */
98449 void (*ctor)(void *); /* Called on object slot creation */
98450 struct list_head list; /* List of all slab caches on the system */
98451 };
98452 @@ -66,6 +66,20 @@ extern struct list_head slab_caches;
98453 /* The slab cache that manages slab cache information */
98454 extern struct kmem_cache *kmem_cache;
98455
98456 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98457 +#ifdef CONFIG_X86_64
98458 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
98459 +#else
98460 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
98461 +#endif
98462 +enum pax_sanitize_mode {
98463 + PAX_SANITIZE_SLAB_OFF = 0,
98464 + PAX_SANITIZE_SLAB_FAST,
98465 + PAX_SANITIZE_SLAB_FULL,
98466 +};
98467 +extern enum pax_sanitize_mode pax_sanitize_slab;
98468 +#endif
98469 +
98470 unsigned long calculate_alignment(unsigned long flags,
98471 unsigned long align, unsigned long size);
98472
98473 @@ -116,7 +130,8 @@ static inline unsigned long kmem_cache_flags(unsigned long object_size,
98474
98475 /* Legal flag mask for kmem_cache_create(), for various configurations */
98476 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
98477 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
98478 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
98479 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
98480
98481 #if defined(CONFIG_DEBUG_SLAB)
98482 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
98483 @@ -300,6 +315,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
98484 return s;
98485
98486 page = virt_to_head_page(x);
98487 +
98488 + BUG_ON(!PageSlab(page));
98489 +
98490 cachep = page->slab_cache;
98491 if (slab_equal_or_root(cachep, s))
98492 return cachep;
98493 diff --git a/mm/slab_common.c b/mm/slab_common.c
98494 index dcdab81..3576646 100644
98495 --- a/mm/slab_common.c
98496 +++ b/mm/slab_common.c
98497 @@ -25,11 +25,35 @@
98498
98499 #include "slab.h"
98500
98501 -enum slab_state slab_state;
98502 +enum slab_state slab_state __read_only;
98503 LIST_HEAD(slab_caches);
98504 DEFINE_MUTEX(slab_mutex);
98505 struct kmem_cache *kmem_cache;
98506
98507 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98508 +enum pax_sanitize_mode pax_sanitize_slab __read_only = PAX_SANITIZE_SLAB_FAST;
98509 +static int __init pax_sanitize_slab_setup(char *str)
98510 +{
98511 + if (!str)
98512 + return 0;
98513 +
98514 + if (!strcmp(str, "0") || !strcmp(str, "off")) {
98515 + pr_info("PaX slab sanitization: %s\n", "disabled");
98516 + pax_sanitize_slab = PAX_SANITIZE_SLAB_OFF;
98517 + } else if (!strcmp(str, "1") || !strcmp(str, "fast")) {
98518 + pr_info("PaX slab sanitization: %s\n", "fast");
98519 + pax_sanitize_slab = PAX_SANITIZE_SLAB_FAST;
98520 + } else if (!strcmp(str, "full")) {
98521 + pr_info("PaX slab sanitization: %s\n", "full");
98522 + pax_sanitize_slab = PAX_SANITIZE_SLAB_FULL;
98523 + } else
98524 + pr_err("PaX slab sanitization: unsupported option '%s'\n", str);
98525 +
98526 + return 0;
98527 +}
98528 +early_param("pax_sanitize_slab", pax_sanitize_slab_setup);
98529 +#endif
98530 +
98531 /*
98532 * Set of flags that will prevent slab merging
98533 */
98534 @@ -44,7 +68,7 @@ struct kmem_cache *kmem_cache;
98535 * Merge control. If this is set then no merging of slab caches will occur.
98536 * (Could be removed. This was introduced to pacify the merge skeptics.)
98537 */
98538 -static int slab_nomerge;
98539 +static int slab_nomerge = 1;
98540
98541 static int __init setup_slab_nomerge(char *str)
98542 {
98543 @@ -218,7 +242,7 @@ int slab_unmergeable(struct kmem_cache *s)
98544 /*
98545 * We may have set a slab to be unmergeable during bootstrap.
98546 */
98547 - if (s->refcount < 0)
98548 + if (atomic_read(&s->refcount) < 0)
98549 return 1;
98550
98551 return 0;
98552 @@ -322,7 +346,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
98553 if (err)
98554 goto out_free_cache;
98555
98556 - s->refcount = 1;
98557 + atomic_set(&s->refcount, 1);
98558 list_add(&s->list, &slab_caches);
98559 out:
98560 if (err)
98561 @@ -386,6 +410,13 @@ kmem_cache_create(const char *name, size_t size, size_t align,
98562 */
98563 flags &= CACHE_CREATE_MASK;
98564
98565 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98566 + if (pax_sanitize_slab == PAX_SANITIZE_SLAB_OFF || (flags & SLAB_DESTROY_BY_RCU))
98567 + flags |= SLAB_NO_SANITIZE;
98568 + else if (pax_sanitize_slab == PAX_SANITIZE_SLAB_FULL)
98569 + flags &= ~SLAB_NO_SANITIZE;
98570 +#endif
98571 +
98572 s = __kmem_cache_alias(name, size, align, flags, ctor);
98573 if (s)
98574 goto out_unlock;
98575 @@ -505,8 +536,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
98576
98577 mutex_lock(&slab_mutex);
98578
98579 - s->refcount--;
98580 - if (s->refcount)
98581 + if (!atomic_dec_and_test(&s->refcount))
98582 goto out_unlock;
98583
98584 if (memcg_cleanup_cache_params(s) != 0)
98585 @@ -526,7 +556,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
98586 rcu_barrier();
98587
98588 memcg_free_cache_params(s);
98589 -#ifdef SLAB_SUPPORTS_SYSFS
98590 +#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
98591 sysfs_slab_remove(s);
98592 #else
98593 slab_kmem_cache_release(s);
98594 @@ -582,7 +612,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
98595 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
98596 name, size, err);
98597
98598 - s->refcount = -1; /* Exempt from merging for now */
98599 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
98600 }
98601
98602 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
98603 @@ -595,7 +625,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
98604
98605 create_boot_cache(s, name, size, flags);
98606 list_add(&s->list, &slab_caches);
98607 - s->refcount = 1;
98608 + atomic_set(&s->refcount, 1);
98609 return s;
98610 }
98611
98612 @@ -607,6 +637,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
98613 EXPORT_SYMBOL(kmalloc_dma_caches);
98614 #endif
98615
98616 +#ifdef CONFIG_PAX_USERCOPY_SLABS
98617 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
98618 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
98619 +#endif
98620 +
98621 /*
98622 * Conversion table for small slabs sizes / 8 to the index in the
98623 * kmalloc array. This is necessary for slabs < 192 since we have non power
98624 @@ -671,6 +706,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
98625 return kmalloc_dma_caches[index];
98626
98627 #endif
98628 +
98629 +#ifdef CONFIG_PAX_USERCOPY_SLABS
98630 + if (unlikely((flags & GFP_USERCOPY)))
98631 + return kmalloc_usercopy_caches[index];
98632 +
98633 +#endif
98634 +
98635 return kmalloc_caches[index];
98636 }
98637
98638 @@ -727,7 +769,7 @@ void __init create_kmalloc_caches(unsigned long flags)
98639 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
98640 if (!kmalloc_caches[i]) {
98641 kmalloc_caches[i] = create_kmalloc_cache(NULL,
98642 - 1 << i, flags);
98643 + 1 << i, SLAB_USERCOPY | flags);
98644 }
98645
98646 /*
98647 @@ -736,10 +778,10 @@ void __init create_kmalloc_caches(unsigned long flags)
98648 * earlier power of two caches
98649 */
98650 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
98651 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
98652 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
98653
98654 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
98655 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
98656 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
98657 }
98658
98659 /* Kmalloc array is now usable */
98660 @@ -772,6 +814,23 @@ void __init create_kmalloc_caches(unsigned long flags)
98661 }
98662 }
98663 #endif
98664 +
98665 +#ifdef CONFIG_PAX_USERCOPY_SLABS
98666 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
98667 + struct kmem_cache *s = kmalloc_caches[i];
98668 +
98669 + if (s) {
98670 + int size = kmalloc_size(i);
98671 + char *n = kasprintf(GFP_NOWAIT,
98672 + "usercopy-kmalloc-%d", size);
98673 +
98674 + BUG_ON(!n);
98675 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
98676 + size, SLAB_USERCOPY | flags);
98677 + }
98678 + }
98679 +#endif
98680 +
98681 }
98682 #endif /* !CONFIG_SLOB */
98683
98684 @@ -830,6 +889,9 @@ void print_slabinfo_header(struct seq_file *m)
98685 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
98686 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
98687 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
98688 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98689 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
98690 +#endif
98691 #endif
98692 seq_putc(m, '\n');
98693 }
98694 diff --git a/mm/slob.c b/mm/slob.c
98695 index 96a8620..3e7e663 100644
98696 --- a/mm/slob.c
98697 +++ b/mm/slob.c
98698 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
98699 /*
98700 * Return the size of a slob block.
98701 */
98702 -static slobidx_t slob_units(slob_t *s)
98703 +static slobidx_t slob_units(const slob_t *s)
98704 {
98705 if (s->units > 0)
98706 return s->units;
98707 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
98708 /*
98709 * Return the next free slob block pointer after this one.
98710 */
98711 -static slob_t *slob_next(slob_t *s)
98712 +static slob_t *slob_next(const slob_t *s)
98713 {
98714 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
98715 slobidx_t next;
98716 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
98717 /*
98718 * Returns true if s is the last free block in its page.
98719 */
98720 -static int slob_last(slob_t *s)
98721 +static int slob_last(const slob_t *s)
98722 {
98723 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
98724 }
98725
98726 -static void *slob_new_pages(gfp_t gfp, int order, int node)
98727 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
98728 {
98729 - void *page;
98730 + struct page *page;
98731
98732 #ifdef CONFIG_NUMA
98733 if (node != NUMA_NO_NODE)
98734 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
98735 if (!page)
98736 return NULL;
98737
98738 - return page_address(page);
98739 + __SetPageSlab(page);
98740 + return page;
98741 }
98742
98743 -static void slob_free_pages(void *b, int order)
98744 +static void slob_free_pages(struct page *sp, int order)
98745 {
98746 if (current->reclaim_state)
98747 current->reclaim_state->reclaimed_slab += 1 << order;
98748 - free_pages((unsigned long)b, order);
98749 + __ClearPageSlab(sp);
98750 + page_mapcount_reset(sp);
98751 + sp->private = 0;
98752 + __free_pages(sp, order);
98753 }
98754
98755 /*
98756 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
98757
98758 /* Not enough space: must allocate a new page */
98759 if (!b) {
98760 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
98761 - if (!b)
98762 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
98763 + if (!sp)
98764 return NULL;
98765 - sp = virt_to_page(b);
98766 - __SetPageSlab(sp);
98767 + b = page_address(sp);
98768
98769 spin_lock_irqsave(&slob_lock, flags);
98770 sp->units = SLOB_UNITS(PAGE_SIZE);
98771 sp->freelist = b;
98772 + sp->private = 0;
98773 INIT_LIST_HEAD(&sp->lru);
98774 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
98775 set_slob_page_free(sp, slob_list);
98776 @@ -337,7 +341,7 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
98777 /*
98778 * slob_free: entry point into the slob allocator.
98779 */
98780 -static void slob_free(void *block, int size)
98781 +static void slob_free(struct kmem_cache *c, void *block, int size)
98782 {
98783 struct page *sp;
98784 slob_t *prev, *next, *b = (slob_t *)block;
98785 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
98786 if (slob_page_free(sp))
98787 clear_slob_page_free(sp);
98788 spin_unlock_irqrestore(&slob_lock, flags);
98789 - __ClearPageSlab(sp);
98790 - page_mapcount_reset(sp);
98791 - slob_free_pages(b, 0);
98792 + slob_free_pages(sp, 0);
98793 return;
98794 }
98795
98796 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98797 + if (pax_sanitize_slab && !(c && (c->flags & SLAB_NO_SANITIZE)))
98798 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
98799 +#endif
98800 +
98801 if (!slob_page_free(sp)) {
98802 /* This slob page is about to become partially free. Easy! */
98803 sp->units = units;
98804 @@ -424,11 +431,10 @@ out:
98805 */
98806
98807 static __always_inline void *
98808 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
98809 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
98810 {
98811 - unsigned int *m;
98812 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
98813 - void *ret;
98814 + slob_t *m;
98815 + void *ret = NULL;
98816
98817 gfp &= gfp_allowed_mask;
98818
98819 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
98820
98821 if (!m)
98822 return NULL;
98823 - *m = size;
98824 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
98825 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
98826 + m[0].units = size;
98827 + m[1].units = align;
98828 ret = (void *)m + align;
98829
98830 trace_kmalloc_node(caller, ret,
98831 size, size + align, gfp, node);
98832 } else {
98833 unsigned int order = get_order(size);
98834 + struct page *page;
98835
98836 if (likely(order))
98837 gfp |= __GFP_COMP;
98838 - ret = slob_new_pages(gfp, order, node);
98839 + page = slob_new_pages(gfp, order, node);
98840 + if (page) {
98841 + ret = page_address(page);
98842 + page->private = size;
98843 + }
98844
98845 trace_kmalloc_node(caller, ret,
98846 size, PAGE_SIZE << order, gfp, node);
98847 }
98848
98849 - kmemleak_alloc(ret, size, 1, gfp);
98850 + return ret;
98851 +}
98852 +
98853 +static __always_inline void *
98854 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
98855 +{
98856 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
98857 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
98858 +
98859 + if (!ZERO_OR_NULL_PTR(ret))
98860 + kmemleak_alloc(ret, size, 1, gfp);
98861 return ret;
98862 }
98863
98864 @@ -491,34 +515,112 @@ void kfree(const void *block)
98865 return;
98866 kmemleak_free(block);
98867
98868 + VM_BUG_ON(!virt_addr_valid(block));
98869 sp = virt_to_page(block);
98870 - if (PageSlab(sp)) {
98871 + VM_BUG_ON(!PageSlab(sp));
98872 + if (!sp->private) {
98873 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
98874 - unsigned int *m = (unsigned int *)(block - align);
98875 - slob_free(m, *m + align);
98876 - } else
98877 + slob_t *m = (slob_t *)(block - align);
98878 + slob_free(NULL, m, m[0].units + align);
98879 + } else {
98880 + __ClearPageSlab(sp);
98881 + page_mapcount_reset(sp);
98882 + sp->private = 0;
98883 __free_pages(sp, compound_order(sp));
98884 + }
98885 }
98886 EXPORT_SYMBOL(kfree);
98887
98888 +bool is_usercopy_object(const void *ptr)
98889 +{
98890 + if (!slab_is_available())
98891 + return false;
98892 +
98893 + // PAX: TODO
98894 +
98895 + return false;
98896 +}
98897 +
98898 +#ifdef CONFIG_PAX_USERCOPY
98899 +const char *check_heap_object(const void *ptr, unsigned long n)
98900 +{
98901 + struct page *page;
98902 + const slob_t *free;
98903 + const void *base;
98904 + unsigned long flags;
98905 +
98906 + if (ZERO_OR_NULL_PTR(ptr))
98907 + return "<null>";
98908 +
98909 + if (!virt_addr_valid(ptr))
98910 + return NULL;
98911 +
98912 + page = virt_to_head_page(ptr);
98913 + if (!PageSlab(page))
98914 + return NULL;
98915 +
98916 + if (page->private) {
98917 + base = page;
98918 + if (base <= ptr && n <= page->private - (ptr - base))
98919 + return NULL;
98920 + return "<slob>";
98921 + }
98922 +
98923 + /* some tricky double walking to find the chunk */
98924 + spin_lock_irqsave(&slob_lock, flags);
98925 + base = (void *)((unsigned long)ptr & PAGE_MASK);
98926 + free = page->freelist;
98927 +
98928 + while (!slob_last(free) && (void *)free <= ptr) {
98929 + base = free + slob_units(free);
98930 + free = slob_next(free);
98931 + }
98932 +
98933 + while (base < (void *)free) {
98934 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
98935 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
98936 + int offset;
98937 +
98938 + if (ptr < base + align)
98939 + break;
98940 +
98941 + offset = ptr - base - align;
98942 + if (offset >= m) {
98943 + base += size;
98944 + continue;
98945 + }
98946 +
98947 + if (n > m - offset)
98948 + break;
98949 +
98950 + spin_unlock_irqrestore(&slob_lock, flags);
98951 + return NULL;
98952 + }
98953 +
98954 + spin_unlock_irqrestore(&slob_lock, flags);
98955 + return "<slob>";
98956 +}
98957 +#endif
98958 +
98959 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
98960 size_t ksize(const void *block)
98961 {
98962 struct page *sp;
98963 int align;
98964 - unsigned int *m;
98965 + slob_t *m;
98966
98967 BUG_ON(!block);
98968 if (unlikely(block == ZERO_SIZE_PTR))
98969 return 0;
98970
98971 sp = virt_to_page(block);
98972 - if (unlikely(!PageSlab(sp)))
98973 - return PAGE_SIZE << compound_order(sp);
98974 + VM_BUG_ON(!PageSlab(sp));
98975 + if (sp->private)
98976 + return sp->private;
98977
98978 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
98979 - m = (unsigned int *)(block - align);
98980 - return SLOB_UNITS(*m) * SLOB_UNIT;
98981 + m = (slob_t *)(block - align);
98982 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
98983 }
98984 EXPORT_SYMBOL(ksize);
98985
98986 @@ -534,23 +636,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
98987
98988 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
98989 {
98990 - void *b;
98991 + void *b = NULL;
98992
98993 flags &= gfp_allowed_mask;
98994
98995 lockdep_trace_alloc(flags);
98996
98997 +#ifdef CONFIG_PAX_USERCOPY_SLABS
98998 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
98999 +#else
99000 if (c->size < PAGE_SIZE) {
99001 b = slob_alloc(c->size, flags, c->align, node);
99002 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
99003 SLOB_UNITS(c->size) * SLOB_UNIT,
99004 flags, node);
99005 } else {
99006 - b = slob_new_pages(flags, get_order(c->size), node);
99007 + struct page *sp;
99008 +
99009 + sp = slob_new_pages(flags, get_order(c->size), node);
99010 + if (sp) {
99011 + b = page_address(sp);
99012 + sp->private = c->size;
99013 + }
99014 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
99015 PAGE_SIZE << get_order(c->size),
99016 flags, node);
99017 }
99018 +#endif
99019
99020 if (b && c->ctor)
99021 c->ctor(b);
99022 @@ -580,12 +692,16 @@ void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t gfp, int node)
99023 EXPORT_SYMBOL(kmem_cache_alloc_node);
99024 #endif
99025
99026 -static void __kmem_cache_free(void *b, int size)
99027 +static void __kmem_cache_free(struct kmem_cache *c, void *b, int size)
99028 {
99029 - if (size < PAGE_SIZE)
99030 - slob_free(b, size);
99031 + struct page *sp;
99032 +
99033 + sp = virt_to_page(b);
99034 + BUG_ON(!PageSlab(sp));
99035 + if (!sp->private)
99036 + slob_free(c, b, size);
99037 else
99038 - slob_free_pages(b, get_order(size));
99039 + slob_free_pages(sp, get_order(size));
99040 }
99041
99042 static void kmem_rcu_free(struct rcu_head *head)
99043 @@ -593,22 +709,36 @@ static void kmem_rcu_free(struct rcu_head *head)
99044 struct slob_rcu *slob_rcu = (struct slob_rcu *)head;
99045 void *b = (void *)slob_rcu - (slob_rcu->size - sizeof(struct slob_rcu));
99046
99047 - __kmem_cache_free(b, slob_rcu->size);
99048 + __kmem_cache_free(NULL, b, slob_rcu->size);
99049 }
99050
99051 void kmem_cache_free(struct kmem_cache *c, void *b)
99052 {
99053 + int size = c->size;
99054 +
99055 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99056 + if (size + c->align < PAGE_SIZE) {
99057 + size += c->align;
99058 + b -= c->align;
99059 + }
99060 +#endif
99061 +
99062 kmemleak_free_recursive(b, c->flags);
99063 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
99064 struct slob_rcu *slob_rcu;
99065 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
99066 - slob_rcu->size = c->size;
99067 + slob_rcu = b + (size - sizeof(struct slob_rcu));
99068 + slob_rcu->size = size;
99069 call_rcu(&slob_rcu->head, kmem_rcu_free);
99070 } else {
99071 - __kmem_cache_free(b, c->size);
99072 + __kmem_cache_free(c, b, size);
99073 }
99074
99075 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99076 + trace_kfree(_RET_IP_, b);
99077 +#else
99078 trace_kmem_cache_free(_RET_IP_, b);
99079 +#endif
99080 +
99081 }
99082 EXPORT_SYMBOL(kmem_cache_free);
99083
99084 diff --git a/mm/slub.c b/mm/slub.c
99085 index ae7b9f1..7b3fdbe 100644
99086 --- a/mm/slub.c
99087 +++ b/mm/slub.c
99088 @@ -197,7 +197,7 @@ struct track {
99089
99090 enum track_item { TRACK_ALLOC, TRACK_FREE };
99091
99092 -#ifdef CONFIG_SYSFS
99093 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99094 static int sysfs_slab_add(struct kmem_cache *);
99095 static int sysfs_slab_alias(struct kmem_cache *, const char *);
99096 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
99097 @@ -535,7 +535,7 @@ static void print_track(const char *s, struct track *t)
99098 if (!t->addr)
99099 return;
99100
99101 - pr_err("INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
99102 + pr_err("INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
99103 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
99104 #ifdef CONFIG_STACKTRACE
99105 {
99106 @@ -2645,6 +2645,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
99107
99108 slab_free_hook(s, x);
99109
99110 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99111 + if (!(s->flags & SLAB_NO_SANITIZE)) {
99112 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
99113 + if (s->ctor)
99114 + s->ctor(x);
99115 + }
99116 +#endif
99117 +
99118 redo:
99119 /*
99120 * Determine the currently cpus per cpu slab.
99121 @@ -2982,6 +2990,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
99122 s->inuse = size;
99123
99124 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
99125 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99126 + (!(flags & SLAB_NO_SANITIZE)) ||
99127 +#endif
99128 s->ctor)) {
99129 /*
99130 * Relocate free pointer after the object if it is not
99131 @@ -3301,6 +3312,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
99132 EXPORT_SYMBOL(__kmalloc_node);
99133 #endif
99134
99135 +bool is_usercopy_object(const void *ptr)
99136 +{
99137 + struct page *page;
99138 + struct kmem_cache *s;
99139 +
99140 + if (ZERO_OR_NULL_PTR(ptr))
99141 + return false;
99142 +
99143 + if (!slab_is_available())
99144 + return false;
99145 +
99146 + if (!virt_addr_valid(ptr))
99147 + return false;
99148 +
99149 + page = virt_to_head_page(ptr);
99150 +
99151 + if (!PageSlab(page))
99152 + return false;
99153 +
99154 + s = page->slab_cache;
99155 + return s->flags & SLAB_USERCOPY;
99156 +}
99157 +
99158 +#ifdef CONFIG_PAX_USERCOPY
99159 +const char *check_heap_object(const void *ptr, unsigned long n)
99160 +{
99161 + struct page *page;
99162 + struct kmem_cache *s;
99163 + unsigned long offset;
99164 +
99165 + if (ZERO_OR_NULL_PTR(ptr))
99166 + return "<null>";
99167 +
99168 + if (!virt_addr_valid(ptr))
99169 + return NULL;
99170 +
99171 + page = virt_to_head_page(ptr);
99172 +
99173 + if (!PageSlab(page))
99174 + return NULL;
99175 +
99176 + s = page->slab_cache;
99177 + if (!(s->flags & SLAB_USERCOPY))
99178 + return s->name;
99179 +
99180 + offset = (ptr - page_address(page)) % s->size;
99181 + if (offset <= s->object_size && n <= s->object_size - offset)
99182 + return NULL;
99183 +
99184 + return s->name;
99185 +}
99186 +#endif
99187 +
99188 size_t ksize(const void *object)
99189 {
99190 struct page *page;
99191 @@ -3329,6 +3393,7 @@ void kfree(const void *x)
99192 if (unlikely(ZERO_OR_NULL_PTR(x)))
99193 return;
99194
99195 + VM_BUG_ON(!virt_addr_valid(x));
99196 page = virt_to_head_page(x);
99197 if (unlikely(!PageSlab(page))) {
99198 BUG_ON(!PageCompound(page));
99199 @@ -3624,7 +3689,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
99200 int i;
99201 struct kmem_cache *c;
99202
99203 - s->refcount++;
99204 + atomic_inc(&s->refcount);
99205
99206 /*
99207 * Adjust the object sizes so that we clear
99208 @@ -3643,7 +3708,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
99209 }
99210
99211 if (sysfs_slab_alias(s, name)) {
99212 - s->refcount--;
99213 + atomic_dec(&s->refcount);
99214 s = NULL;
99215 }
99216 }
99217 @@ -3760,7 +3825,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
99218 }
99219 #endif
99220
99221 -#ifdef CONFIG_SYSFS
99222 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99223 static int count_inuse(struct page *page)
99224 {
99225 return page->inuse;
99226 @@ -4041,7 +4106,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
99227 len += sprintf(buf + len, "%7ld ", l->count);
99228
99229 if (l->addr)
99230 +#ifdef CONFIG_GRKERNSEC_HIDESYM
99231 + len += sprintf(buf + len, "%pS", NULL);
99232 +#else
99233 len += sprintf(buf + len, "%pS", (void *)l->addr);
99234 +#endif
99235 else
99236 len += sprintf(buf + len, "<not-available>");
99237
99238 @@ -4143,12 +4212,12 @@ static void __init resiliency_test(void)
99239 validate_slab_cache(kmalloc_caches[9]);
99240 }
99241 #else
99242 -#ifdef CONFIG_SYSFS
99243 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99244 static void resiliency_test(void) {};
99245 #endif
99246 #endif
99247
99248 -#ifdef CONFIG_SYSFS
99249 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99250 enum slab_stat_type {
99251 SL_ALL, /* All slabs */
99252 SL_PARTIAL, /* Only partially allocated slabs */
99253 @@ -4385,13 +4454,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
99254 {
99255 if (!s->ctor)
99256 return 0;
99257 +#ifdef CONFIG_GRKERNSEC_HIDESYM
99258 + return sprintf(buf, "%pS\n", NULL);
99259 +#else
99260 return sprintf(buf, "%pS\n", s->ctor);
99261 +#endif
99262 }
99263 SLAB_ATTR_RO(ctor);
99264
99265 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
99266 {
99267 - return sprintf(buf, "%d\n", s->refcount < 0 ? 0 : s->refcount - 1);
99268 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) < 0 ? 0 : atomic_read(&s->refcount) - 1);
99269 }
99270 SLAB_ATTR_RO(aliases);
99271
99272 @@ -4479,6 +4552,22 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
99273 SLAB_ATTR_RO(cache_dma);
99274 #endif
99275
99276 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99277 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
99278 +{
99279 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
99280 +}
99281 +SLAB_ATTR_RO(usercopy);
99282 +#endif
99283 +
99284 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99285 +static ssize_t sanitize_show(struct kmem_cache *s, char *buf)
99286 +{
99287 + return sprintf(buf, "%d\n", !(s->flags & SLAB_NO_SANITIZE));
99288 +}
99289 +SLAB_ATTR_RO(sanitize);
99290 +#endif
99291 +
99292 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
99293 {
99294 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
99295 @@ -4534,7 +4623,7 @@ static ssize_t trace_store(struct kmem_cache *s, const char *buf,
99296 * as well as cause other issues like converting a mergeable
99297 * cache into an umergeable one.
99298 */
99299 - if (s->refcount > 1)
99300 + if (atomic_read(&s->refcount) > 1)
99301 return -EINVAL;
99302
99303 s->flags &= ~SLAB_TRACE;
99304 @@ -4654,7 +4743,7 @@ static ssize_t failslab_show(struct kmem_cache *s, char *buf)
99305 static ssize_t failslab_store(struct kmem_cache *s, const char *buf,
99306 size_t length)
99307 {
99308 - if (s->refcount > 1)
99309 + if (atomic_read(&s->refcount) > 1)
99310 return -EINVAL;
99311
99312 s->flags &= ~SLAB_FAILSLAB;
99313 @@ -4824,6 +4913,12 @@ static struct attribute *slab_attrs[] = {
99314 #ifdef CONFIG_ZONE_DMA
99315 &cache_dma_attr.attr,
99316 #endif
99317 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99318 + &usercopy_attr.attr,
99319 +#endif
99320 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99321 + &sanitize_attr.attr,
99322 +#endif
99323 #ifdef CONFIG_NUMA
99324 &remote_node_defrag_ratio_attr.attr,
99325 #endif
99326 @@ -5068,6 +5163,7 @@ static char *create_unique_id(struct kmem_cache *s)
99327 return name;
99328 }
99329
99330 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99331 static int sysfs_slab_add(struct kmem_cache *s)
99332 {
99333 int err;
99334 @@ -5141,6 +5237,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
99335 kobject_del(&s->kobj);
99336 kobject_put(&s->kobj);
99337 }
99338 +#endif
99339
99340 /*
99341 * Need to buffer aliases during bootup until sysfs becomes
99342 @@ -5154,6 +5251,7 @@ struct saved_alias {
99343
99344 static struct saved_alias *alias_list;
99345
99346 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99347 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
99348 {
99349 struct saved_alias *al;
99350 @@ -5176,6 +5274,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
99351 alias_list = al;
99352 return 0;
99353 }
99354 +#endif
99355
99356 static int __init slab_sysfs_init(void)
99357 {
99358 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
99359 index 4cba9c2..b4f9fcc 100644
99360 --- a/mm/sparse-vmemmap.c
99361 +++ b/mm/sparse-vmemmap.c
99362 @@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
99363 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
99364 if (!p)
99365 return NULL;
99366 - pud_populate(&init_mm, pud, p);
99367 + pud_populate_kernel(&init_mm, pud, p);
99368 }
99369 return pud;
99370 }
99371 @@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
99372 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
99373 if (!p)
99374 return NULL;
99375 - pgd_populate(&init_mm, pgd, p);
99376 + pgd_populate_kernel(&init_mm, pgd, p);
99377 }
99378 return pgd;
99379 }
99380 diff --git a/mm/sparse.c b/mm/sparse.c
99381 index d1b48b6..6e8590e 100644
99382 --- a/mm/sparse.c
99383 +++ b/mm/sparse.c
99384 @@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
99385
99386 for (i = 0; i < PAGES_PER_SECTION; i++) {
99387 if (PageHWPoison(&memmap[i])) {
99388 - atomic_long_sub(1, &num_poisoned_pages);
99389 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
99390 ClearPageHWPoison(&memmap[i]);
99391 }
99392 }
99393 diff --git a/mm/swap.c b/mm/swap.c
99394 index 8a12b33..7068e78 100644
99395 --- a/mm/swap.c
99396 +++ b/mm/swap.c
99397 @@ -31,6 +31,7 @@
99398 #include <linux/memcontrol.h>
99399 #include <linux/gfp.h>
99400 #include <linux/uio.h>
99401 +#include <linux/hugetlb.h>
99402
99403 #include "internal.h"
99404
99405 @@ -77,6 +78,8 @@ static void __put_compound_page(struct page *page)
99406
99407 __page_cache_release(page);
99408 dtor = get_compound_page_dtor(page);
99409 + if (!PageHuge(page))
99410 + BUG_ON(dtor != free_compound_page);
99411 (*dtor)(page);
99412 }
99413
99414 diff --git a/mm/swapfile.c b/mm/swapfile.c
99415 index 8798b2e..348f9dd 100644
99416 --- a/mm/swapfile.c
99417 +++ b/mm/swapfile.c
99418 @@ -84,7 +84,7 @@ static DEFINE_MUTEX(swapon_mutex);
99419
99420 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
99421 /* Activity counter to indicate that a swapon or swapoff has occurred */
99422 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
99423 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
99424
99425 static inline unsigned char swap_count(unsigned char ent)
99426 {
99427 @@ -1944,7 +1944,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
99428 spin_unlock(&swap_lock);
99429
99430 err = 0;
99431 - atomic_inc(&proc_poll_event);
99432 + atomic_inc_unchecked(&proc_poll_event);
99433 wake_up_interruptible(&proc_poll_wait);
99434
99435 out_dput:
99436 @@ -1961,8 +1961,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
99437
99438 poll_wait(file, &proc_poll_wait, wait);
99439
99440 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
99441 - seq->poll_event = atomic_read(&proc_poll_event);
99442 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
99443 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
99444 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
99445 }
99446
99447 @@ -2060,7 +2060,7 @@ static int swaps_open(struct inode *inode, struct file *file)
99448 return ret;
99449
99450 seq = file->private_data;
99451 - seq->poll_event = atomic_read(&proc_poll_event);
99452 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
99453 return 0;
99454 }
99455
99456 @@ -2520,7 +2520,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
99457 (frontswap_map) ? "FS" : "");
99458
99459 mutex_unlock(&swapon_mutex);
99460 - atomic_inc(&proc_poll_event);
99461 + atomic_inc_unchecked(&proc_poll_event);
99462 wake_up_interruptible(&proc_poll_wait);
99463
99464 if (S_ISREG(inode->i_mode))
99465 diff --git a/mm/util.c b/mm/util.c
99466 index fec39d4..3e60325 100644
99467 --- a/mm/util.c
99468 +++ b/mm/util.c
99469 @@ -195,6 +195,12 @@ struct task_struct *task_of_stack(struct task_struct *task,
99470 void arch_pick_mmap_layout(struct mm_struct *mm)
99471 {
99472 mm->mmap_base = TASK_UNMAPPED_BASE;
99473 +
99474 +#ifdef CONFIG_PAX_RANDMMAP
99475 + if (mm->pax_flags & MF_PAX_RANDMMAP)
99476 + mm->mmap_base += mm->delta_mmap;
99477 +#endif
99478 +
99479 mm->get_unmapped_area = arch_get_unmapped_area;
99480 }
99481 #endif
99482 @@ -371,6 +377,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
99483 if (!mm->arg_end)
99484 goto out_mm; /* Shh! No looking before we're done */
99485
99486 + if (gr_acl_handle_procpidmem(task))
99487 + goto out_mm;
99488 +
99489 len = mm->arg_end - mm->arg_start;
99490
99491 if (len > buflen)
99492 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
99493 index 90520af..24231aa 100644
99494 --- a/mm/vmalloc.c
99495 +++ b/mm/vmalloc.c
99496 @@ -40,6 +40,21 @@ struct vfree_deferred {
99497 };
99498 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
99499
99500 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
99501 +struct stack_deferred_llist {
99502 + struct llist_head list;
99503 + void *stack;
99504 + void *lowmem_stack;
99505 +};
99506 +
99507 +struct stack_deferred {
99508 + struct stack_deferred_llist list;
99509 + struct work_struct wq;
99510 +};
99511 +
99512 +static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
99513 +#endif
99514 +
99515 static void __vunmap(const void *, int);
99516
99517 static void free_work(struct work_struct *w)
99518 @@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
99519 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
99520 struct llist_node *llnode = llist_del_all(&p->list);
99521 while (llnode) {
99522 - void *p = llnode;
99523 + void *x = llnode;
99524 llnode = llist_next(llnode);
99525 - __vunmap(p, 1);
99526 + __vunmap(x, 1);
99527 }
99528 }
99529
99530 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
99531 +static void unmap_work(struct work_struct *w)
99532 +{
99533 + struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
99534 + struct llist_node *llnode = llist_del_all(&p->list.list);
99535 + while (llnode) {
99536 + struct stack_deferred_llist *x =
99537 + llist_entry((struct llist_head *)llnode,
99538 + struct stack_deferred_llist, list);
99539 + void *stack = ACCESS_ONCE(x->stack);
99540 + void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
99541 + llnode = llist_next(llnode);
99542 + __vunmap(stack, 0);
99543 + free_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
99544 + }
99545 +}
99546 +#endif
99547 +
99548 /*** Page table manipulation functions ***/
99549
99550 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
99551 @@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
99552
99553 pte = pte_offset_kernel(pmd, addr);
99554 do {
99555 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
99556 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
99557 +
99558 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
99559 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
99560 + BUG_ON(!pte_exec(*pte));
99561 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
99562 + continue;
99563 + }
99564 +#endif
99565 +
99566 + {
99567 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
99568 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
99569 + }
99570 } while (pte++, addr += PAGE_SIZE, addr != end);
99571 }
99572
99573 @@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
99574 pte = pte_alloc_kernel(pmd, addr);
99575 if (!pte)
99576 return -ENOMEM;
99577 +
99578 + pax_open_kernel();
99579 do {
99580 struct page *page = pages[*nr];
99581
99582 - if (WARN_ON(!pte_none(*pte)))
99583 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
99584 + if (pgprot_val(prot) & _PAGE_NX)
99585 +#endif
99586 +
99587 + if (!pte_none(*pte)) {
99588 + pax_close_kernel();
99589 + WARN_ON(1);
99590 return -EBUSY;
99591 - if (WARN_ON(!page))
99592 + }
99593 + if (!page) {
99594 + pax_close_kernel();
99595 + WARN_ON(1);
99596 return -ENOMEM;
99597 + }
99598 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
99599 (*nr)++;
99600 } while (pte++, addr += PAGE_SIZE, addr != end);
99601 + pax_close_kernel();
99602 return 0;
99603 }
99604
99605 @@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
99606 pmd_t *pmd;
99607 unsigned long next;
99608
99609 - pmd = pmd_alloc(&init_mm, pud, addr);
99610 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
99611 if (!pmd)
99612 return -ENOMEM;
99613 do {
99614 @@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
99615 pud_t *pud;
99616 unsigned long next;
99617
99618 - pud = pud_alloc(&init_mm, pgd, addr);
99619 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
99620 if (!pud)
99621 return -ENOMEM;
99622 do {
99623 @@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
99624 if (addr >= MODULES_VADDR && addr < MODULES_END)
99625 return 1;
99626 #endif
99627 +
99628 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
99629 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
99630 + return 1;
99631 +#endif
99632 +
99633 return is_vmalloc_addr(x);
99634 }
99635
99636 @@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
99637
99638 if (!pgd_none(*pgd)) {
99639 pud_t *pud = pud_offset(pgd, addr);
99640 +#ifdef CONFIG_X86
99641 + if (!pud_large(*pud))
99642 +#endif
99643 if (!pud_none(*pud)) {
99644 pmd_t *pmd = pmd_offset(pud, addr);
99645 +#ifdef CONFIG_X86
99646 + if (!pmd_large(*pmd))
99647 +#endif
99648 if (!pmd_none(*pmd)) {
99649 pte_t *ptep, pte;
99650
99651 @@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
99652 for_each_possible_cpu(i) {
99653 struct vmap_block_queue *vbq;
99654 struct vfree_deferred *p;
99655 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
99656 + struct stack_deferred *p2;
99657 +#endif
99658
99659 vbq = &per_cpu(vmap_block_queue, i);
99660 spin_lock_init(&vbq->lock);
99661 INIT_LIST_HEAD(&vbq->free);
99662 +
99663 p = &per_cpu(vfree_deferred, i);
99664 init_llist_head(&p->list);
99665 INIT_WORK(&p->wq, free_work);
99666 +
99667 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
99668 + p2 = &per_cpu(stack_deferred, i);
99669 + init_llist_head(&p2->list.list);
99670 + INIT_WORK(&p2->wq, unmap_work);
99671 +#endif
99672 }
99673
99674 /* Import existing vmlist entries. */
99675 @@ -1314,6 +1393,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
99676 struct vm_struct *area;
99677
99678 BUG_ON(in_interrupt());
99679 +
99680 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
99681 + if (flags & VM_KERNEXEC) {
99682 + if (start != VMALLOC_START || end != VMALLOC_END)
99683 + return NULL;
99684 + start = (unsigned long)MODULES_EXEC_VADDR;
99685 + end = (unsigned long)MODULES_EXEC_END;
99686 + }
99687 +#endif
99688 +
99689 if (flags & VM_IOREMAP)
99690 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
99691
99692 @@ -1519,6 +1608,23 @@ void vunmap(const void *addr)
99693 }
99694 EXPORT_SYMBOL(vunmap);
99695
99696 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
99697 +void unmap_process_stacks(struct task_struct *task)
99698 +{
99699 + if (unlikely(in_interrupt())) {
99700 + struct stack_deferred *p = &__get_cpu_var(stack_deferred);
99701 + struct stack_deferred_llist *list = task->stack;
99702 + list->stack = task->stack;
99703 + list->lowmem_stack = task->lowmem_stack;
99704 + if (llist_add((struct llist_node *)&list->list, &p->list.list))
99705 + schedule_work(&p->wq);
99706 + } else {
99707 + __vunmap(task->stack, 0);
99708 + free_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
99709 + }
99710 +}
99711 +#endif
99712 +
99713 /**
99714 * vmap - map an array of pages into virtually contiguous space
99715 * @pages: array of page pointers
99716 @@ -1539,6 +1645,11 @@ void *vmap(struct page **pages, unsigned int count,
99717 if (count > totalram_pages)
99718 return NULL;
99719
99720 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
99721 + if (!(pgprot_val(prot) & _PAGE_NX))
99722 + flags |= VM_KERNEXEC;
99723 +#endif
99724 +
99725 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
99726 __builtin_return_address(0));
99727 if (!area)
99728 @@ -1641,6 +1752,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
99729 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
99730 goto fail;
99731
99732 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
99733 + if (!(pgprot_val(prot) & _PAGE_NX))
99734 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
99735 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
99736 + else
99737 +#endif
99738 +
99739 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
99740 start, end, node, gfp_mask, caller);
99741 if (!area)
99742 @@ -1817,10 +1935,9 @@ EXPORT_SYMBOL(vzalloc_node);
99743 * For tight control over page level allocator and protection flags
99744 * use __vmalloc() instead.
99745 */
99746 -
99747 void *vmalloc_exec(unsigned long size)
99748 {
99749 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
99750 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
99751 NUMA_NO_NODE, __builtin_return_address(0));
99752 }
99753
99754 @@ -2127,6 +2244,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
99755 {
99756 struct vm_struct *area;
99757
99758 + BUG_ON(vma->vm_mirror);
99759 +
99760 size = PAGE_ALIGN(size);
99761
99762 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
99763 @@ -2609,7 +2728,11 @@ static int s_show(struct seq_file *m, void *p)
99764 v->addr, v->addr + v->size, v->size);
99765
99766 if (v->caller)
99767 +#ifdef CONFIG_GRKERNSEC_HIDESYM
99768 + seq_printf(m, " %pK", v->caller);
99769 +#else
99770 seq_printf(m, " %pS", v->caller);
99771 +#endif
99772
99773 if (v->nr_pages)
99774 seq_printf(m, " pages=%d", v->nr_pages);
99775 diff --git a/mm/vmstat.c b/mm/vmstat.c
99776 index 1b12d39..57b29b2 100644
99777 --- a/mm/vmstat.c
99778 +++ b/mm/vmstat.c
99779 @@ -22,6 +22,7 @@
99780 #include <linux/writeback.h>
99781 #include <linux/compaction.h>
99782 #include <linux/mm_inline.h>
99783 +#include <linux/grsecurity.h>
99784
99785 #include "internal.h"
99786
99787 @@ -81,7 +82,7 @@ void vm_events_fold_cpu(int cpu)
99788 *
99789 * vm_stat contains the global counters
99790 */
99791 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
99792 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
99793 EXPORT_SYMBOL(vm_stat);
99794
99795 #ifdef CONFIG_SMP
99796 @@ -433,7 +434,7 @@ static int fold_diff(int *diff)
99797
99798 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
99799 if (diff[i]) {
99800 - atomic_long_add(diff[i], &vm_stat[i]);
99801 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
99802 changes++;
99803 }
99804 return changes;
99805 @@ -471,7 +472,7 @@ static int refresh_cpu_vm_stats(void)
99806 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
99807 if (v) {
99808
99809 - atomic_long_add(v, &zone->vm_stat[i]);
99810 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
99811 global_diff[i] += v;
99812 #ifdef CONFIG_NUMA
99813 /* 3 seconds idle till flush */
99814 @@ -535,7 +536,7 @@ void cpu_vm_stats_fold(int cpu)
99815
99816 v = p->vm_stat_diff[i];
99817 p->vm_stat_diff[i] = 0;
99818 - atomic_long_add(v, &zone->vm_stat[i]);
99819 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
99820 global_diff[i] += v;
99821 }
99822 }
99823 @@ -555,8 +556,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
99824 if (pset->vm_stat_diff[i]) {
99825 int v = pset->vm_stat_diff[i];
99826 pset->vm_stat_diff[i] = 0;
99827 - atomic_long_add(v, &zone->vm_stat[i]);
99828 - atomic_long_add(v, &vm_stat[i]);
99829 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
99830 + atomic_long_add_unchecked(v, &vm_stat[i]);
99831 }
99832 }
99833 #endif
99834 @@ -1189,10 +1190,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
99835 stat_items_size += sizeof(struct vm_event_state);
99836 #endif
99837
99838 - v = kmalloc(stat_items_size, GFP_KERNEL);
99839 + v = kzalloc(stat_items_size, GFP_KERNEL);
99840 m->private = v;
99841 if (!v)
99842 return ERR_PTR(-ENOMEM);
99843 +
99844 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
99845 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
99846 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
99847 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
99848 + && !in_group_p(grsec_proc_gid)
99849 +#endif
99850 + )
99851 + return (unsigned long *)m->private + *pos;
99852 +#endif
99853 +#endif
99854 +
99855 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
99856 v[i] = global_page_state(i);
99857 v += NR_VM_ZONE_STAT_ITEMS;
99858 @@ -1424,10 +1437,16 @@ static int __init setup_vmstat(void)
99859 cpu_notifier_register_done();
99860 #endif
99861 #ifdef CONFIG_PROC_FS
99862 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
99863 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
99864 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
99865 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
99866 + {
99867 + mode_t gr_mode = S_IRUGO;
99868 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
99869 + gr_mode = S_IRUSR;
99870 +#endif
99871 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
99872 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
99873 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
99874 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
99875 + }
99876 #endif
99877 return 0;
99878 }
99879 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
99880 index 64c6bed..b79a5de 100644
99881 --- a/net/8021q/vlan.c
99882 +++ b/net/8021q/vlan.c
99883 @@ -481,7 +481,7 @@ out:
99884 return NOTIFY_DONE;
99885 }
99886
99887 -static struct notifier_block vlan_notifier_block __read_mostly = {
99888 +static struct notifier_block vlan_notifier_block = {
99889 .notifier_call = vlan_device_event,
99890 };
99891
99892 @@ -556,8 +556,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
99893 err = -EPERM;
99894 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
99895 break;
99896 - if ((args.u.name_type >= 0) &&
99897 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
99898 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
99899 struct vlan_net *vn;
99900
99901 vn = net_generic(net, vlan_net_id);
99902 diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c
99903 index 8ac8a5c..991defc 100644
99904 --- a/net/8021q/vlan_netlink.c
99905 +++ b/net/8021q/vlan_netlink.c
99906 @@ -238,7 +238,7 @@ nla_put_failure:
99907 return -EMSGSIZE;
99908 }
99909
99910 -struct rtnl_link_ops vlan_link_ops __read_mostly = {
99911 +struct rtnl_link_ops vlan_link_ops = {
99912 .kind = "vlan",
99913 .maxtype = IFLA_VLAN_MAX,
99914 .policy = vlan_policy,
99915 diff --git a/net/9p/client.c b/net/9p/client.c
99916 index e86a9bea..e91f70e 100644
99917 --- a/net/9p/client.c
99918 +++ b/net/9p/client.c
99919 @@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
99920 len - inline_len);
99921 } else {
99922 err = copy_from_user(ename + inline_len,
99923 - uidata, len - inline_len);
99924 + (char __force_user *)uidata, len - inline_len);
99925 if (err) {
99926 err = -EFAULT;
99927 goto out_err;
99928 @@ -1570,7 +1570,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
99929 kernel_buf = 1;
99930 indata = data;
99931 } else
99932 - indata = (__force char *)udata;
99933 + indata = (__force_kernel char *)udata;
99934 /*
99935 * response header len is 11
99936 * PDU Header(7) + IO Size (4)
99937 @@ -1645,7 +1645,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
99938 kernel_buf = 1;
99939 odata = data;
99940 } else
99941 - odata = (char *)udata;
99942 + odata = (char __force_kernel *)udata;
99943 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
99944 P9_ZC_HDR_SZ, kernel_buf, "dqd",
99945 fid->fid, offset, rsize);
99946 diff --git a/net/9p/mod.c b/net/9p/mod.c
99947 index 6ab36ae..6f1841b 100644
99948 --- a/net/9p/mod.c
99949 +++ b/net/9p/mod.c
99950 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
99951 void v9fs_register_trans(struct p9_trans_module *m)
99952 {
99953 spin_lock(&v9fs_trans_lock);
99954 - list_add_tail(&m->list, &v9fs_trans_list);
99955 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
99956 spin_unlock(&v9fs_trans_lock);
99957 }
99958 EXPORT_SYMBOL(v9fs_register_trans);
99959 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
99960 void v9fs_unregister_trans(struct p9_trans_module *m)
99961 {
99962 spin_lock(&v9fs_trans_lock);
99963 - list_del_init(&m->list);
99964 + pax_list_del_init((struct list_head *)&m->list);
99965 spin_unlock(&v9fs_trans_lock);
99966 }
99967 EXPORT_SYMBOL(v9fs_unregister_trans);
99968 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
99969 index 80d08f6..de63fd1 100644
99970 --- a/net/9p/trans_fd.c
99971 +++ b/net/9p/trans_fd.c
99972 @@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
99973 oldfs = get_fs();
99974 set_fs(get_ds());
99975 /* The cast to a user pointer is valid due to the set_fs() */
99976 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
99977 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
99978 set_fs(oldfs);
99979
99980 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
99981 diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
99982 index af46bc4..f9adfcd 100644
99983 --- a/net/appletalk/atalk_proc.c
99984 +++ b/net/appletalk/atalk_proc.c
99985 @@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
99986 struct proc_dir_entry *p;
99987 int rc = -ENOMEM;
99988
99989 - atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
99990 + atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
99991 if (!atalk_proc_dir)
99992 goto out;
99993
99994 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
99995 index 876fbe8..8bbea9f 100644
99996 --- a/net/atm/atm_misc.c
99997 +++ b/net/atm/atm_misc.c
99998 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
99999 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
100000 return 1;
100001 atm_return(vcc, truesize);
100002 - atomic_inc(&vcc->stats->rx_drop);
100003 + atomic_inc_unchecked(&vcc->stats->rx_drop);
100004 return 0;
100005 }
100006 EXPORT_SYMBOL(atm_charge);
100007 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
100008 }
100009 }
100010 atm_return(vcc, guess);
100011 - atomic_inc(&vcc->stats->rx_drop);
100012 + atomic_inc_unchecked(&vcc->stats->rx_drop);
100013 return NULL;
100014 }
100015 EXPORT_SYMBOL(atm_alloc_charge);
100016 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
100017
100018 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
100019 {
100020 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
100021 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
100022 __SONET_ITEMS
100023 #undef __HANDLE_ITEM
100024 }
100025 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
100026
100027 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
100028 {
100029 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
100030 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
100031 __SONET_ITEMS
100032 #undef __HANDLE_ITEM
100033 }
100034 diff --git a/net/atm/lec.c b/net/atm/lec.c
100035 index 4b98f89..5a2f6cb 100644
100036 --- a/net/atm/lec.c
100037 +++ b/net/atm/lec.c
100038 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
100039 }
100040
100041 static struct lane2_ops lane2_ops = {
100042 - lane2_resolve, /* resolve, spec 3.1.3 */
100043 - lane2_associate_req, /* associate_req, spec 3.1.4 */
100044 - NULL /* associate indicator, spec 3.1.5 */
100045 + .resolve = lane2_resolve,
100046 + .associate_req = lane2_associate_req,
100047 + .associate_indicator = NULL
100048 };
100049
100050 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
100051 diff --git a/net/atm/lec.h b/net/atm/lec.h
100052 index 4149db1..f2ab682 100644
100053 --- a/net/atm/lec.h
100054 +++ b/net/atm/lec.h
100055 @@ -48,7 +48,7 @@ struct lane2_ops {
100056 const u8 *tlvs, u32 sizeoftlvs);
100057 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
100058 const u8 *tlvs, u32 sizeoftlvs);
100059 -};
100060 +} __no_const;
100061
100062 /*
100063 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
100064 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
100065 index d1b2d9a..d549f7f 100644
100066 --- a/net/atm/mpoa_caches.c
100067 +++ b/net/atm/mpoa_caches.c
100068 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
100069
100070
100071 static struct in_cache_ops ingress_ops = {
100072 - in_cache_add_entry, /* add_entry */
100073 - in_cache_get, /* get */
100074 - in_cache_get_with_mask, /* get_with_mask */
100075 - in_cache_get_by_vcc, /* get_by_vcc */
100076 - in_cache_put, /* put */
100077 - in_cache_remove_entry, /* remove_entry */
100078 - cache_hit, /* cache_hit */
100079 - clear_count_and_expired, /* clear_count */
100080 - check_resolving_entries, /* check_resolving */
100081 - refresh_entries, /* refresh */
100082 - in_destroy_cache /* destroy_cache */
100083 + .add_entry = in_cache_add_entry,
100084 + .get = in_cache_get,
100085 + .get_with_mask = in_cache_get_with_mask,
100086 + .get_by_vcc = in_cache_get_by_vcc,
100087 + .put = in_cache_put,
100088 + .remove_entry = in_cache_remove_entry,
100089 + .cache_hit = cache_hit,
100090 + .clear_count = clear_count_and_expired,
100091 + .check_resolving = check_resolving_entries,
100092 + .refresh = refresh_entries,
100093 + .destroy_cache = in_destroy_cache
100094 };
100095
100096 static struct eg_cache_ops egress_ops = {
100097 - eg_cache_add_entry, /* add_entry */
100098 - eg_cache_get_by_cache_id, /* get_by_cache_id */
100099 - eg_cache_get_by_tag, /* get_by_tag */
100100 - eg_cache_get_by_vcc, /* get_by_vcc */
100101 - eg_cache_get_by_src_ip, /* get_by_src_ip */
100102 - eg_cache_put, /* put */
100103 - eg_cache_remove_entry, /* remove_entry */
100104 - update_eg_cache_entry, /* update */
100105 - clear_expired, /* clear_expired */
100106 - eg_destroy_cache /* destroy_cache */
100107 + .add_entry = eg_cache_add_entry,
100108 + .get_by_cache_id = eg_cache_get_by_cache_id,
100109 + .get_by_tag = eg_cache_get_by_tag,
100110 + .get_by_vcc = eg_cache_get_by_vcc,
100111 + .get_by_src_ip = eg_cache_get_by_src_ip,
100112 + .put = eg_cache_put,
100113 + .remove_entry = eg_cache_remove_entry,
100114 + .update = update_eg_cache_entry,
100115 + .clear_expired = clear_expired,
100116 + .destroy_cache = eg_destroy_cache
100117 };
100118
100119
100120 diff --git a/net/atm/proc.c b/net/atm/proc.c
100121 index bbb6461..cf04016 100644
100122 --- a/net/atm/proc.c
100123 +++ b/net/atm/proc.c
100124 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
100125 const struct k_atm_aal_stats *stats)
100126 {
100127 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
100128 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
100129 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
100130 - atomic_read(&stats->rx_drop));
100131 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
100132 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
100133 + atomic_read_unchecked(&stats->rx_drop));
100134 }
100135
100136 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
100137 diff --git a/net/atm/resources.c b/net/atm/resources.c
100138 index 0447d5d..3cf4728 100644
100139 --- a/net/atm/resources.c
100140 +++ b/net/atm/resources.c
100141 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
100142 static void copy_aal_stats(struct k_atm_aal_stats *from,
100143 struct atm_aal_stats *to)
100144 {
100145 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
100146 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
100147 __AAL_STAT_ITEMS
100148 #undef __HANDLE_ITEM
100149 }
100150 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
100151 static void subtract_aal_stats(struct k_atm_aal_stats *from,
100152 struct atm_aal_stats *to)
100153 {
100154 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
100155 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
100156 __AAL_STAT_ITEMS
100157 #undef __HANDLE_ITEM
100158 }
100159 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
100160 index 919a5ce..cc6b444 100644
100161 --- a/net/ax25/sysctl_net_ax25.c
100162 +++ b/net/ax25/sysctl_net_ax25.c
100163 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
100164 {
100165 char path[sizeof("net/ax25/") + IFNAMSIZ];
100166 int k;
100167 - struct ctl_table *table;
100168 + ctl_table_no_const *table;
100169
100170 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
100171 if (!table)
100172 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
100173 index 1e80539..676c37a 100644
100174 --- a/net/batman-adv/bat_iv_ogm.c
100175 +++ b/net/batman-adv/bat_iv_ogm.c
100176 @@ -313,7 +313,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
100177
100178 /* randomize initial seqno to avoid collision */
100179 get_random_bytes(&random_seqno, sizeof(random_seqno));
100180 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
100181 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
100182
100183 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
100184 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
100185 @@ -918,9 +918,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
100186 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
100187
100188 /* change sequence number to network order */
100189 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
100190 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
100191 batadv_ogm_packet->seqno = htonl(seqno);
100192 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
100193 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
100194
100195 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
100196
100197 @@ -1597,7 +1597,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
100198 return;
100199
100200 /* could be changed by schedule_own_packet() */
100201 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
100202 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
100203
100204 if (ogm_packet->flags & BATADV_DIRECTLINK)
100205 has_directlink_flag = true;
100206 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
100207 index fc1835c..eead856 100644
100208 --- a/net/batman-adv/fragmentation.c
100209 +++ b/net/batman-adv/fragmentation.c
100210 @@ -450,7 +450,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
100211 frag_header.packet_type = BATADV_UNICAST_FRAG;
100212 frag_header.version = BATADV_COMPAT_VERSION;
100213 frag_header.ttl = BATADV_TTL;
100214 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
100215 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
100216 frag_header.reserved = 0;
100217 frag_header.no = 0;
100218 frag_header.total_size = htons(skb->len);
100219 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
100220 index 5467955..75ad4e3 100644
100221 --- a/net/batman-adv/soft-interface.c
100222 +++ b/net/batman-adv/soft-interface.c
100223 @@ -296,7 +296,7 @@ send:
100224 primary_if->net_dev->dev_addr);
100225
100226 /* set broadcast sequence number */
100227 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
100228 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
100229 bcast_packet->seqno = htonl(seqno);
100230
100231 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
100232 @@ -761,7 +761,7 @@ static int batadv_softif_init_late(struct net_device *dev)
100233 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
100234
100235 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
100236 - atomic_set(&bat_priv->bcast_seqno, 1);
100237 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
100238 atomic_set(&bat_priv->tt.vn, 0);
100239 atomic_set(&bat_priv->tt.local_changes, 0);
100240 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
100241 @@ -775,7 +775,7 @@ static int batadv_softif_init_late(struct net_device *dev)
100242
100243 /* randomize initial seqno to avoid collision */
100244 get_random_bytes(&random_seqno, sizeof(random_seqno));
100245 - atomic_set(&bat_priv->frag_seqno, random_seqno);
100246 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
100247
100248 bat_priv->primary_if = NULL;
100249 bat_priv->num_ifaces = 0;
100250 @@ -983,7 +983,7 @@ int batadv_softif_is_valid(const struct net_device *net_dev)
100251 return 0;
100252 }
100253
100254 -struct rtnl_link_ops batadv_link_ops __read_mostly = {
100255 +struct rtnl_link_ops batadv_link_ops = {
100256 .kind = "batadv",
100257 .priv_size = sizeof(struct batadv_priv),
100258 .setup = batadv_softif_init_early,
100259 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
100260 index 8854c05..ee5d5497 100644
100261 --- a/net/batman-adv/types.h
100262 +++ b/net/batman-adv/types.h
100263 @@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
100264 struct batadv_hard_iface_bat_iv {
100265 unsigned char *ogm_buff;
100266 int ogm_buff_len;
100267 - atomic_t ogm_seqno;
100268 + atomic_unchecked_t ogm_seqno;
100269 };
100270
100271 /**
100272 @@ -768,7 +768,7 @@ struct batadv_priv {
100273 atomic_t bonding;
100274 atomic_t fragmentation;
100275 atomic_t packet_size_max;
100276 - atomic_t frag_seqno;
100277 + atomic_unchecked_t frag_seqno;
100278 #ifdef CONFIG_BATMAN_ADV_BLA
100279 atomic_t bridge_loop_avoidance;
100280 #endif
100281 @@ -787,7 +787,7 @@ struct batadv_priv {
100282 #endif
100283 uint32_t isolation_mark;
100284 uint32_t isolation_mark_mask;
100285 - atomic_t bcast_seqno;
100286 + atomic_unchecked_t bcast_seqno;
100287 atomic_t bcast_queue_left;
100288 atomic_t batman_queue_left;
100289 char num_ifaces;
100290 diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
100291 index c2e0d14..bfa852b 100644
100292 --- a/net/bluetooth/6lowpan.c
100293 +++ b/net/bluetooth/6lowpan.c
100294 @@ -367,7 +367,6 @@ static int recv_pkt(struct sk_buff *skb, struct net_device *dev,
100295
100296 drop:
100297 dev->stats.rx_dropped++;
100298 - kfree_skb(skb);
100299 return NET_RX_DROP;
100300 }
100301
100302 diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c
100303 index 85bcc21..ce82722d 100644
100304 --- a/net/bluetooth/bnep/core.c
100305 +++ b/net/bluetooth/bnep/core.c
100306 @@ -533,6 +533,9 @@ int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock)
100307
100308 BT_DBG("");
100309
100310 + if (!l2cap_is_socket(sock))
100311 + return -EBADFD;
100312 +
100313 baswap((void *) dst, &l2cap_pi(sock->sk)->chan->dst);
100314 baswap((void *) src, &l2cap_pi(sock->sk)->chan->src);
100315
100316 diff --git a/net/bluetooth/cmtp/core.c b/net/bluetooth/cmtp/core.c
100317 index 67fe5e8..278a194 100644
100318 --- a/net/bluetooth/cmtp/core.c
100319 +++ b/net/bluetooth/cmtp/core.c
100320 @@ -334,6 +334,9 @@ int cmtp_add_connection(struct cmtp_connadd_req *req, struct socket *sock)
100321
100322 BT_DBG("");
100323
100324 + if (!l2cap_is_socket(sock))
100325 + return -EBADFD;
100326 +
100327 session = kzalloc(sizeof(struct cmtp_session), GFP_KERNEL);
100328 if (!session)
100329 return -ENOMEM;
100330 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
100331 index 115f149..f0ba286 100644
100332 --- a/net/bluetooth/hci_sock.c
100333 +++ b/net/bluetooth/hci_sock.c
100334 @@ -1067,7 +1067,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
100335 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
100336 }
100337
100338 - len = min_t(unsigned int, len, sizeof(uf));
100339 + len = min((size_t)len, sizeof(uf));
100340 if (copy_from_user(&uf, optval, len)) {
100341 err = -EFAULT;
100342 break;
100343 diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
100344 index 1b7d605..02ebd10 100644
100345 --- a/net/bluetooth/hidp/core.c
100346 +++ b/net/bluetooth/hidp/core.c
100347 @@ -1318,13 +1318,14 @@ int hidp_connection_add(struct hidp_connadd_req *req,
100348 {
100349 struct hidp_session *session;
100350 struct l2cap_conn *conn;
100351 - struct l2cap_chan *chan = l2cap_pi(ctrl_sock->sk)->chan;
100352 + struct l2cap_chan *chan;
100353 int ret;
100354
100355 ret = hidp_verify_sockets(ctrl_sock, intr_sock);
100356 if (ret)
100357 return ret;
100358
100359 + chan = l2cap_pi(ctrl_sock->sk)->chan;
100360 conn = NULL;
100361 l2cap_chan_lock(chan);
100362 if (chan->conn)
100363 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
100364 index b6f9777..36d3039 100644
100365 --- a/net/bluetooth/l2cap_core.c
100366 +++ b/net/bluetooth/l2cap_core.c
100367 @@ -3512,8 +3512,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
100368 break;
100369
100370 case L2CAP_CONF_RFC:
100371 - if (olen == sizeof(rfc))
100372 - memcpy(&rfc, (void *)val, olen);
100373 + if (olen != sizeof(rfc))
100374 + break;
100375 +
100376 + memcpy(&rfc, (void *)val, olen);
100377
100378 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
100379 rfc.mode != chan->mode)
100380 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
100381 index 31f106e..323f606 100644
100382 --- a/net/bluetooth/l2cap_sock.c
100383 +++ b/net/bluetooth/l2cap_sock.c
100384 @@ -628,7 +628,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
100385 struct sock *sk = sock->sk;
100386 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
100387 struct l2cap_options opts;
100388 - int len, err = 0;
100389 + int err = 0;
100390 + size_t len = optlen;
100391 u32 opt;
100392
100393 BT_DBG("sk %p", sk);
100394 @@ -655,7 +656,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
100395 opts.max_tx = chan->max_tx;
100396 opts.txwin_size = chan->tx_win;
100397
100398 - len = min_t(unsigned int, sizeof(opts), optlen);
100399 + len = min(sizeof(opts), len);
100400 if (copy_from_user((char *) &opts, optval, len)) {
100401 err = -EFAULT;
100402 break;
100403 @@ -742,7 +743,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
100404 struct bt_security sec;
100405 struct bt_power pwr;
100406 struct l2cap_conn *conn;
100407 - int len, err = 0;
100408 + int err = 0;
100409 + size_t len = optlen;
100410 u32 opt;
100411
100412 BT_DBG("sk %p", sk);
100413 @@ -766,7 +768,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
100414
100415 sec.level = BT_SECURITY_LOW;
100416
100417 - len = min_t(unsigned int, sizeof(sec), optlen);
100418 + len = min(sizeof(sec), len);
100419 if (copy_from_user((char *) &sec, optval, len)) {
100420 err = -EFAULT;
100421 break;
100422 @@ -862,7 +864,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
100423
100424 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
100425
100426 - len = min_t(unsigned int, sizeof(pwr), optlen);
100427 + len = min(sizeof(pwr), len);
100428 if (copy_from_user((char *) &pwr, optval, len)) {
100429 err = -EFAULT;
100430 break;
100431 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
100432 index 8bbbb5e..6fc0950 100644
100433 --- a/net/bluetooth/rfcomm/sock.c
100434 +++ b/net/bluetooth/rfcomm/sock.c
100435 @@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
100436 struct sock *sk = sock->sk;
100437 struct bt_security sec;
100438 int err = 0;
100439 - size_t len;
100440 + size_t len = optlen;
100441 u32 opt;
100442
100443 BT_DBG("sk %p", sk);
100444 @@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
100445
100446 sec.level = BT_SECURITY_LOW;
100447
100448 - len = min_t(unsigned int, sizeof(sec), optlen);
100449 + len = min(sizeof(sec), len);
100450 if (copy_from_user((char *) &sec, optval, len)) {
100451 err = -EFAULT;
100452 break;
100453 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
100454 index 8e385a0..a5bdd8e 100644
100455 --- a/net/bluetooth/rfcomm/tty.c
100456 +++ b/net/bluetooth/rfcomm/tty.c
100457 @@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
100458 BT_DBG("tty %p id %d", tty, tty->index);
100459
100460 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
100461 - dev->channel, dev->port.count);
100462 + dev->channel, atomic_read(&dev->port.count));
100463
100464 err = tty_port_open(&dev->port, tty, filp);
100465 if (err)
100466 @@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
100467 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
100468
100469 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
100470 - dev->port.count);
100471 + atomic_read(&dev->port.count));
100472
100473 tty_port_close(&dev->port, tty, filp);
100474 }
100475 diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
100476 index e5ec470..cbfabd1 100644
100477 --- a/net/bridge/br_netlink.c
100478 +++ b/net/bridge/br_netlink.c
100479 @@ -564,7 +564,7 @@ static struct rtnl_af_ops br_af_ops = {
100480 .get_link_af_size = br_get_link_af_size,
100481 };
100482
100483 -struct rtnl_link_ops br_link_ops __read_mostly = {
100484 +struct rtnl_link_ops br_link_ops = {
100485 .kind = "bridge",
100486 .priv_size = sizeof(struct net_bridge),
100487 .setup = br_dev_setup,
100488 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
100489 index d9a8c05..8dadc6c6 100644
100490 --- a/net/bridge/netfilter/ebtables.c
100491 +++ b/net/bridge/netfilter/ebtables.c
100492 @@ -1533,7 +1533,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100493 tmp.valid_hooks = t->table->valid_hooks;
100494 }
100495 mutex_unlock(&ebt_mutex);
100496 - if (copy_to_user(user, &tmp, *len) != 0) {
100497 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
100498 BUGPRINT("c2u Didn't work\n");
100499 ret = -EFAULT;
100500 break;
100501 @@ -2339,7 +2339,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
100502 goto out;
100503 tmp.valid_hooks = t->valid_hooks;
100504
100505 - if (copy_to_user(user, &tmp, *len) != 0) {
100506 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
100507 ret = -EFAULT;
100508 break;
100509 }
100510 @@ -2350,7 +2350,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
100511 tmp.entries_size = t->table->entries_size;
100512 tmp.valid_hooks = t->table->valid_hooks;
100513
100514 - if (copy_to_user(user, &tmp, *len) != 0) {
100515 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
100516 ret = -EFAULT;
100517 break;
100518 }
100519 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
100520 index f5afda1..dcf770a 100644
100521 --- a/net/caif/cfctrl.c
100522 +++ b/net/caif/cfctrl.c
100523 @@ -10,6 +10,7 @@
100524 #include <linux/spinlock.h>
100525 #include <linux/slab.h>
100526 #include <linux/pkt_sched.h>
100527 +#include <linux/sched.h>
100528 #include <net/caif/caif_layer.h>
100529 #include <net/caif/cfpkt.h>
100530 #include <net/caif/cfctrl.h>
100531 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
100532 memset(&dev_info, 0, sizeof(dev_info));
100533 dev_info.id = 0xff;
100534 cfsrvl_init(&this->serv, 0, &dev_info, false);
100535 - atomic_set(&this->req_seq_no, 1);
100536 - atomic_set(&this->rsp_seq_no, 1);
100537 + atomic_set_unchecked(&this->req_seq_no, 1);
100538 + atomic_set_unchecked(&this->rsp_seq_no, 1);
100539 this->serv.layer.receive = cfctrl_recv;
100540 sprintf(this->serv.layer.name, "ctrl");
100541 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
100542 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
100543 struct cfctrl_request_info *req)
100544 {
100545 spin_lock_bh(&ctrl->info_list_lock);
100546 - atomic_inc(&ctrl->req_seq_no);
100547 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
100548 + atomic_inc_unchecked(&ctrl->req_seq_no);
100549 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
100550 list_add_tail(&req->list, &ctrl->list);
100551 spin_unlock_bh(&ctrl->info_list_lock);
100552 }
100553 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
100554 if (p != first)
100555 pr_warn("Requests are not received in order\n");
100556
100557 - atomic_set(&ctrl->rsp_seq_no,
100558 + atomic_set_unchecked(&ctrl->rsp_seq_no,
100559 p->sequence_no);
100560 list_del(&p->list);
100561 goto out;
100562 diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c
100563 index 4589ff67..46d6b8f 100644
100564 --- a/net/caif/chnl_net.c
100565 +++ b/net/caif/chnl_net.c
100566 @@ -516,7 +516,7 @@ static const struct nla_policy ipcaif_policy[IFLA_CAIF_MAX + 1] = {
100567 };
100568
100569
100570 -static struct rtnl_link_ops ipcaif_link_ops __read_mostly = {
100571 +static struct rtnl_link_ops ipcaif_link_ops = {
100572 .kind = "caif",
100573 .priv_size = sizeof(struct chnl_net),
100574 .setup = ipcaif_net_setup,
100575 diff --git a/net/can/af_can.c b/net/can/af_can.c
100576 index ce82337..5d17b4d 100644
100577 --- a/net/can/af_can.c
100578 +++ b/net/can/af_can.c
100579 @@ -884,7 +884,7 @@ static const struct net_proto_family can_family_ops = {
100580 };
100581
100582 /* notifier block for netdevice event */
100583 -static struct notifier_block can_netdev_notifier __read_mostly = {
100584 +static struct notifier_block can_netdev_notifier = {
100585 .notifier_call = can_notifier,
100586 };
100587
100588 diff --git a/net/can/bcm.c b/net/can/bcm.c
100589 index dcb75c0..24b1b43 100644
100590 --- a/net/can/bcm.c
100591 +++ b/net/can/bcm.c
100592 @@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
100593 }
100594
100595 /* create /proc/net/can-bcm directory */
100596 - proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
100597 + proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
100598 return 0;
100599 }
100600
100601 diff --git a/net/can/gw.c b/net/can/gw.c
100602 index 050a211..bb9fe33 100644
100603 --- a/net/can/gw.c
100604 +++ b/net/can/gw.c
100605 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
100606 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
100607
100608 static HLIST_HEAD(cgw_list);
100609 -static struct notifier_block notifier;
100610
100611 static struct kmem_cache *cgw_cache __read_mostly;
100612
100613 @@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
100614 return err;
100615 }
100616
100617 +static struct notifier_block notifier = {
100618 + .notifier_call = cgw_notifier
100619 +};
100620 +
100621 static __init int cgw_module_init(void)
100622 {
100623 /* sanitize given module parameter */
100624 @@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
100625 return -ENOMEM;
100626
100627 /* set notifier */
100628 - notifier.notifier_call = cgw_notifier;
100629 register_netdevice_notifier(&notifier);
100630
100631 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
100632 diff --git a/net/can/proc.c b/net/can/proc.c
100633 index 1a19b98..df2b4ec 100644
100634 --- a/net/can/proc.c
100635 +++ b/net/can/proc.c
100636 @@ -514,7 +514,7 @@ static void can_remove_proc_readentry(const char *name)
100637 void can_init_proc(void)
100638 {
100639 /* create /proc/net/can directory */
100640 - can_dir = proc_mkdir("can", init_net.proc_net);
100641 + can_dir = proc_mkdir_restrict("can", init_net.proc_net);
100642
100643 if (!can_dir) {
100644 printk(KERN_INFO "can: failed to create /proc/net/can . "
100645 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
100646 index 8d1653c..77ad145 100644
100647 --- a/net/ceph/messenger.c
100648 +++ b/net/ceph/messenger.c
100649 @@ -188,7 +188,7 @@ static void con_fault(struct ceph_connection *con);
100650 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
100651
100652 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
100653 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
100654 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
100655
100656 static struct page *zero_page; /* used in certain error cases */
100657
100658 @@ -199,7 +199,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
100659 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
100660 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
100661
100662 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
100663 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
100664 s = addr_str[i];
100665
100666 switch (ss->ss_family) {
100667 diff --git a/net/compat.c b/net/compat.c
100668 index bc8aeef..f9c070c 100644
100669 --- a/net/compat.c
100670 +++ b/net/compat.c
100671 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
100672 return -EFAULT;
100673 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
100674 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
100675 - kmsg->msg_name = compat_ptr(tmp1);
100676 - kmsg->msg_iov = compat_ptr(tmp2);
100677 - kmsg->msg_control = compat_ptr(tmp3);
100678 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
100679 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
100680 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
100681 return 0;
100682 }
100683
100684 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
100685
100686 if (kern_msg->msg_name && kern_msg->msg_namelen) {
100687 if (mode == VERIFY_READ) {
100688 - int err = move_addr_to_kernel(kern_msg->msg_name,
100689 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
100690 kern_msg->msg_namelen,
100691 kern_address);
100692 if (err < 0)
100693 @@ -100,7 +100,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
100694 }
100695
100696 tot_len = iov_from_user_compat_to_kern(kern_iov,
100697 - (struct compat_iovec __user *)kern_msg->msg_iov,
100698 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
100699 kern_msg->msg_iovlen);
100700 if (tot_len >= 0)
100701 kern_msg->msg_iov = kern_iov;
100702 @@ -120,20 +120,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
100703
100704 #define CMSG_COMPAT_FIRSTHDR(msg) \
100705 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
100706 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
100707 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
100708 (struct compat_cmsghdr __user *)NULL)
100709
100710 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
100711 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
100712 (ucmlen) <= (unsigned long) \
100713 ((mhdr)->msg_controllen - \
100714 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
100715 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
100716
100717 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
100718 struct compat_cmsghdr __user *cmsg, int cmsg_len)
100719 {
100720 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
100721 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
100722 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
100723 msg->msg_controllen)
100724 return NULL;
100725 return (struct compat_cmsghdr __user *)ptr;
100726 @@ -223,7 +223,7 @@ Efault:
100727
100728 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
100729 {
100730 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
100731 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
100732 struct compat_cmsghdr cmhdr;
100733 struct compat_timeval ctv;
100734 struct compat_timespec cts[3];
100735 @@ -279,7 +279,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
100736
100737 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
100738 {
100739 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
100740 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
100741 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
100742 int fdnum = scm->fp->count;
100743 struct file **fp = scm->fp->fp;
100744 @@ -367,7 +367,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
100745 return -EFAULT;
100746 old_fs = get_fs();
100747 set_fs(KERNEL_DS);
100748 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
100749 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
100750 set_fs(old_fs);
100751
100752 return err;
100753 @@ -428,7 +428,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
100754 len = sizeof(ktime);
100755 old_fs = get_fs();
100756 set_fs(KERNEL_DS);
100757 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
100758 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
100759 set_fs(old_fs);
100760
100761 if (!err) {
100762 @@ -571,7 +571,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
100763 case MCAST_JOIN_GROUP:
100764 case MCAST_LEAVE_GROUP:
100765 {
100766 - struct compat_group_req __user *gr32 = (void *)optval;
100767 + struct compat_group_req __user *gr32 = (void __user *)optval;
100768 struct group_req __user *kgr =
100769 compat_alloc_user_space(sizeof(struct group_req));
100770 u32 interface;
100771 @@ -592,7 +592,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
100772 case MCAST_BLOCK_SOURCE:
100773 case MCAST_UNBLOCK_SOURCE:
100774 {
100775 - struct compat_group_source_req __user *gsr32 = (void *)optval;
100776 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
100777 struct group_source_req __user *kgsr = compat_alloc_user_space(
100778 sizeof(struct group_source_req));
100779 u32 interface;
100780 @@ -613,7 +613,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
100781 }
100782 case MCAST_MSFILTER:
100783 {
100784 - struct compat_group_filter __user *gf32 = (void *)optval;
100785 + struct compat_group_filter __user *gf32 = (void __user *)optval;
100786 struct group_filter __user *kgf;
100787 u32 interface, fmode, numsrc;
100788
100789 @@ -651,7 +651,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
100790 char __user *optval, int __user *optlen,
100791 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
100792 {
100793 - struct compat_group_filter __user *gf32 = (void *)optval;
100794 + struct compat_group_filter __user *gf32 = (void __user *)optval;
100795 struct group_filter __user *kgf;
100796 int __user *koptlen;
100797 u32 interface, fmode, numsrc;
100798 @@ -804,7 +804,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
100799
100800 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
100801 return -EINVAL;
100802 - if (copy_from_user(a, args, nas[call]))
100803 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
100804 return -EFAULT;
100805 a0 = a[0];
100806 a1 = a[1];
100807 diff --git a/net/core/datagram.c b/net/core/datagram.c
100808 index fdbc9a8..cd6972c 100644
100809 --- a/net/core/datagram.c
100810 +++ b/net/core/datagram.c
100811 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
100812 }
100813
100814 kfree_skb(skb);
100815 - atomic_inc(&sk->sk_drops);
100816 + atomic_inc_unchecked(&sk->sk_drops);
100817 sk_mem_reclaim_partial(sk);
100818
100819 return err;
100820 diff --git a/net/core/dev.c b/net/core/dev.c
100821 index 945bbd0..8b1a370 100644
100822 --- a/net/core/dev.c
100823 +++ b/net/core/dev.c
100824 @@ -1683,14 +1683,14 @@ int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
100825 {
100826 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
100827 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
100828 - atomic_long_inc(&dev->rx_dropped);
100829 + atomic_long_inc_unchecked(&dev->rx_dropped);
100830 kfree_skb(skb);
100831 return NET_RX_DROP;
100832 }
100833 }
100834
100835 if (unlikely(!is_skb_forwardable(dev, skb))) {
100836 - atomic_long_inc(&dev->rx_dropped);
100837 + atomic_long_inc_unchecked(&dev->rx_dropped);
100838 kfree_skb(skb);
100839 return NET_RX_DROP;
100840 }
100841 @@ -2985,7 +2985,7 @@ recursion_alert:
100842 drop:
100843 rcu_read_unlock_bh();
100844
100845 - atomic_long_inc(&dev->tx_dropped);
100846 + atomic_long_inc_unchecked(&dev->tx_dropped);
100847 kfree_skb_list(skb);
100848 return rc;
100849 out:
100850 @@ -3328,7 +3328,7 @@ enqueue:
100851
100852 local_irq_restore(flags);
100853
100854 - atomic_long_inc(&skb->dev->rx_dropped);
100855 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
100856 kfree_skb(skb);
100857 return NET_RX_DROP;
100858 }
100859 @@ -3405,7 +3405,7 @@ int netif_rx_ni(struct sk_buff *skb)
100860 }
100861 EXPORT_SYMBOL(netif_rx_ni);
100862
100863 -static void net_tx_action(struct softirq_action *h)
100864 +static __latent_entropy void net_tx_action(void)
100865 {
100866 struct softnet_data *sd = this_cpu_ptr(&softnet_data);
100867
100868 @@ -3738,7 +3738,7 @@ ncls:
100869 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
100870 } else {
100871 drop:
100872 - atomic_long_inc(&skb->dev->rx_dropped);
100873 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
100874 kfree_skb(skb);
100875 /* Jamal, now you will not able to escape explaining
100876 * me how you were going to use this. :-)
100877 @@ -4502,7 +4502,7 @@ void netif_napi_del(struct napi_struct *napi)
100878 }
100879 EXPORT_SYMBOL(netif_napi_del);
100880
100881 -static void net_rx_action(struct softirq_action *h)
100882 +static __latent_entropy void net_rx_action(void)
100883 {
100884 struct softnet_data *sd = this_cpu_ptr(&softnet_data);
100885 unsigned long time_limit = jiffies + 2;
100886 @@ -6548,8 +6548,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
100887 } else {
100888 netdev_stats_to_stats64(storage, &dev->stats);
100889 }
100890 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
100891 - storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
100892 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
100893 + storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
100894 return storage;
100895 }
100896 EXPORT_SYMBOL(dev_get_stats);
100897 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
100898 index 72e899a..79a9409 100644
100899 --- a/net/core/dev_ioctl.c
100900 +++ b/net/core/dev_ioctl.c
100901 @@ -365,8 +365,13 @@ void dev_load(struct net *net, const char *name)
100902 no_module = !dev;
100903 if (no_module && capable(CAP_NET_ADMIN))
100904 no_module = request_module("netdev-%s", name);
100905 - if (no_module && capable(CAP_SYS_MODULE))
100906 + if (no_module && capable(CAP_SYS_MODULE)) {
100907 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
100908 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
100909 +#else
100910 request_module("%s", name);
100911 +#endif
100912 + }
100913 }
100914 EXPORT_SYMBOL(dev_load);
100915
100916 diff --git a/net/core/filter.c b/net/core/filter.c
100917 index 647b122..18a7ff6 100644
100918 --- a/net/core/filter.c
100919 +++ b/net/core/filter.c
100920 @@ -532,7 +532,11 @@ do_pass:
100921
100922 /* Unkown instruction. */
100923 default:
100924 - goto err;
100925 + WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
100926 + fp->code, fp->jt, fp->jf, fp->k);
100927 + kfree(addrs);
100928 + BUG();
100929 + return -EINVAL;
100930 }
100931
100932 insn++;
100933 @@ -576,7 +580,7 @@ static int check_load_and_stores(const struct sock_filter *filter, int flen)
100934 u16 *masks, memvalid = 0; /* One bit per cell, 16 cells */
100935 int pc, ret = 0;
100936
100937 - BUILD_BUG_ON(BPF_MEMWORDS > 16);
100938 + BUILD_BUG_ON(BPF_MEMWORDS != 16);
100939
100940 masks = kmalloc_array(flen, sizeof(*masks), GFP_KERNEL);
100941 if (!masks)
100942 @@ -987,7 +991,7 @@ int bpf_prog_create(struct bpf_prog **pfp, struct sock_fprog_kern *fprog)
100943 if (!fp)
100944 return -ENOMEM;
100945
100946 - memcpy(fp->insns, fprog->filter, fsize);
100947 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
100948
100949 fp->len = fprog->len;
100950 /* Since unattached filters are not copied back to user
100951 diff --git a/net/core/flow.c b/net/core/flow.c
100952 index a0348fd..6951c76 100644
100953 --- a/net/core/flow.c
100954 +++ b/net/core/flow.c
100955 @@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
100956 static int flow_entry_valid(struct flow_cache_entry *fle,
100957 struct netns_xfrm *xfrm)
100958 {
100959 - if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
100960 + if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
100961 return 0;
100962 if (fle->object && !fle->object->ops->check(fle->object))
100963 return 0;
100964 @@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
100965 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
100966 fcp->hash_count++;
100967 }
100968 - } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
100969 + } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
100970 flo = fle->object;
100971 if (!flo)
100972 goto ret_object;
100973 @@ -263,7 +263,7 @@ nocache:
100974 }
100975 flo = resolver(net, key, family, dir, flo, ctx);
100976 if (fle) {
100977 - fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
100978 + fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
100979 if (!IS_ERR(flo))
100980 fle->object = flo;
100981 else
100982 diff --git a/net/core/iovec.c b/net/core/iovec.c
100983 index e1ec45a..e5c6f16 100644
100984 --- a/net/core/iovec.c
100985 +++ b/net/core/iovec.c
100986 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
100987 if (m->msg_name && m->msg_namelen) {
100988 if (mode == VERIFY_READ) {
100989 void __user *namep;
100990 - namep = (void __user __force *) m->msg_name;
100991 + namep = (void __force_user *) m->msg_name;
100992 err = move_addr_to_kernel(namep, m->msg_namelen,
100993 address);
100994 if (err < 0)
100995 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
100996 }
100997
100998 size = m->msg_iovlen * sizeof(struct iovec);
100999 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
101000 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
101001 return -EFAULT;
101002
101003 m->msg_iov = iov;
101004 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
101005 index ef31fef..8be66d9 100644
101006 --- a/net/core/neighbour.c
101007 +++ b/net/core/neighbour.c
101008 @@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
101009 void __user *buffer, size_t *lenp, loff_t *ppos)
101010 {
101011 int size, ret;
101012 - struct ctl_table tmp = *ctl;
101013 + ctl_table_no_const tmp = *ctl;
101014
101015 tmp.extra1 = &zero;
101016 tmp.extra2 = &unres_qlen_max;
101017 @@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
101018 void __user *buffer,
101019 size_t *lenp, loff_t *ppos)
101020 {
101021 - struct ctl_table tmp = *ctl;
101022 + ctl_table_no_const tmp = *ctl;
101023 int ret;
101024
101025 tmp.extra1 = &zero;
101026 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
101027 index 2bf8329..2eb1423 100644
101028 --- a/net/core/net-procfs.c
101029 +++ b/net/core/net-procfs.c
101030 @@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
101031 struct rtnl_link_stats64 temp;
101032 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
101033
101034 - seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101035 + if (gr_proc_is_restricted())
101036 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101037 + "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
101038 + dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
101039 + 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
101040 + else
101041 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101042 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
101043 dev->name, stats->rx_bytes, stats->rx_packets,
101044 stats->rx_errors,
101045 @@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
101046 return 0;
101047 }
101048
101049 -static const struct seq_operations dev_seq_ops = {
101050 +const struct seq_operations dev_seq_ops = {
101051 .start = dev_seq_start,
101052 .next = dev_seq_next,
101053 .stop = dev_seq_stop,
101054 @@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
101055
101056 static int softnet_seq_open(struct inode *inode, struct file *file)
101057 {
101058 - return seq_open(file, &softnet_seq_ops);
101059 + return seq_open_restrict(file, &softnet_seq_ops);
101060 }
101061
101062 static const struct file_operations softnet_seq_fops = {
101063 @@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
101064 else
101065 seq_printf(seq, "%04x", ntohs(pt->type));
101066
101067 +#ifdef CONFIG_GRKERNSEC_HIDESYM
101068 + seq_printf(seq, " %-8s %pf\n",
101069 + pt->dev ? pt->dev->name : "", NULL);
101070 +#else
101071 seq_printf(seq, " %-8s %pf\n",
101072 pt->dev ? pt->dev->name : "", pt->func);
101073 +#endif
101074 }
101075
101076 return 0;
101077 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
101078 index 9dd0669..c52fb1b 100644
101079 --- a/net/core/net-sysfs.c
101080 +++ b/net/core/net-sysfs.c
101081 @@ -278,7 +278,7 @@ static ssize_t carrier_changes_show(struct device *dev,
101082 {
101083 struct net_device *netdev = to_net_dev(dev);
101084 return sprintf(buf, fmt_dec,
101085 - atomic_read(&netdev->carrier_changes));
101086 + atomic_read_unchecked(&netdev->carrier_changes));
101087 }
101088 static DEVICE_ATTR_RO(carrier_changes);
101089
101090 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
101091 index 7f15517..f7d65c0 100644
101092 --- a/net/core/net_namespace.c
101093 +++ b/net/core/net_namespace.c
101094 @@ -445,7 +445,7 @@ static int __register_pernet_operations(struct list_head *list,
101095 int error;
101096 LIST_HEAD(net_exit_list);
101097
101098 - list_add_tail(&ops->list, list);
101099 + pax_list_add_tail((struct list_head *)&ops->list, list);
101100 if (ops->init || (ops->id && ops->size)) {
101101 for_each_net(net) {
101102 error = ops_init(ops, net);
101103 @@ -458,7 +458,7 @@ static int __register_pernet_operations(struct list_head *list,
101104
101105 out_undo:
101106 /* If I have an error cleanup all namespaces I initialized */
101107 - list_del(&ops->list);
101108 + pax_list_del((struct list_head *)&ops->list);
101109 ops_exit_list(ops, &net_exit_list);
101110 ops_free_list(ops, &net_exit_list);
101111 return error;
101112 @@ -469,7 +469,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
101113 struct net *net;
101114 LIST_HEAD(net_exit_list);
101115
101116 - list_del(&ops->list);
101117 + pax_list_del((struct list_head *)&ops->list);
101118 for_each_net(net)
101119 list_add_tail(&net->exit_list, &net_exit_list);
101120 ops_exit_list(ops, &net_exit_list);
101121 @@ -603,7 +603,7 @@ int register_pernet_device(struct pernet_operations *ops)
101122 mutex_lock(&net_mutex);
101123 error = register_pernet_operations(&pernet_list, ops);
101124 if (!error && (first_device == &pernet_list))
101125 - first_device = &ops->list;
101126 + first_device = (struct list_head *)&ops->list;
101127 mutex_unlock(&net_mutex);
101128 return error;
101129 }
101130 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
101131 index e6645b4..43e1af9 100644
101132 --- a/net/core/netpoll.c
101133 +++ b/net/core/netpoll.c
101134 @@ -379,7 +379,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
101135 struct udphdr *udph;
101136 struct iphdr *iph;
101137 struct ethhdr *eth;
101138 - static atomic_t ip_ident;
101139 + static atomic_unchecked_t ip_ident;
101140 struct ipv6hdr *ip6h;
101141
101142 udp_len = len + sizeof(*udph);
101143 @@ -450,7 +450,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
101144 put_unaligned(0x45, (unsigned char *)iph);
101145 iph->tos = 0;
101146 put_unaligned(htons(ip_len), &(iph->tot_len));
101147 - iph->id = htons(atomic_inc_return(&ip_ident));
101148 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
101149 iph->frag_off = 0;
101150 iph->ttl = 64;
101151 iph->protocol = IPPROTO_UDP;
101152 diff --git a/net/core/pktgen.c b/net/core/pktgen.c
101153 index 443256b..bbff424 100644
101154 --- a/net/core/pktgen.c
101155 +++ b/net/core/pktgen.c
101156 @@ -3753,7 +3753,7 @@ static int __net_init pg_net_init(struct net *net)
101157 pn->net = net;
101158 INIT_LIST_HEAD(&pn->pktgen_threads);
101159 pn->pktgen_exiting = false;
101160 - pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
101161 + pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
101162 if (!pn->proc_dir) {
101163 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
101164 return -ENODEV;
101165 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
101166 index 76321ea..3129bd6 100644
101167 --- a/net/core/rtnetlink.c
101168 +++ b/net/core/rtnetlink.c
101169 @@ -58,7 +58,7 @@ struct rtnl_link {
101170 rtnl_doit_func doit;
101171 rtnl_dumpit_func dumpit;
101172 rtnl_calcit_func calcit;
101173 -};
101174 +} __no_const;
101175
101176 static DEFINE_MUTEX(rtnl_mutex);
101177
101178 @@ -304,10 +304,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
101179 * to use the ops for creating device. So do not
101180 * fill up dellink as well. That disables rtnl_dellink.
101181 */
101182 - if (ops->setup && !ops->dellink)
101183 - ops->dellink = unregister_netdevice_queue;
101184 + if (ops->setup && !ops->dellink) {
101185 + pax_open_kernel();
101186 + *(void **)&ops->dellink = unregister_netdevice_queue;
101187 + pax_close_kernel();
101188 + }
101189
101190 - list_add_tail(&ops->list, &link_ops);
101191 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
101192 return 0;
101193 }
101194 EXPORT_SYMBOL_GPL(__rtnl_link_register);
101195 @@ -354,7 +357,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
101196 for_each_net(net) {
101197 __rtnl_kill_links(net, ops);
101198 }
101199 - list_del(&ops->list);
101200 + pax_list_del((struct list_head *)&ops->list);
101201 }
101202 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
101203
101204 @@ -1014,7 +1017,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
101205 (dev->ifalias &&
101206 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
101207 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
101208 - atomic_read(&dev->carrier_changes)))
101209 + atomic_read_unchecked(&dev->carrier_changes)))
101210 goto nla_put_failure;
101211
101212 if (1) {
101213 diff --git a/net/core/scm.c b/net/core/scm.c
101214 index b442e7e..6f5b5a2 100644
101215 --- a/net/core/scm.c
101216 +++ b/net/core/scm.c
101217 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
101218 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
101219 {
101220 struct cmsghdr __user *cm
101221 - = (__force struct cmsghdr __user *)msg->msg_control;
101222 + = (struct cmsghdr __force_user *)msg->msg_control;
101223 struct cmsghdr cmhdr;
101224 int cmlen = CMSG_LEN(len);
101225 int err;
101226 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
101227 err = -EFAULT;
101228 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
101229 goto out;
101230 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
101231 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
101232 goto out;
101233 cmlen = CMSG_SPACE(len);
101234 if (msg->msg_controllen < cmlen)
101235 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
101236 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
101237 {
101238 struct cmsghdr __user *cm
101239 - = (__force struct cmsghdr __user*)msg->msg_control;
101240 + = (struct cmsghdr __force_user *)msg->msg_control;
101241
101242 int fdmax = 0;
101243 int fdnum = scm->fp->count;
101244 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
101245 if (fdnum < fdmax)
101246 fdmax = fdnum;
101247
101248 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
101249 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
101250 i++, cmfptr++)
101251 {
101252 struct socket *sock;
101253 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
101254 index 32e31c2..e981248 100644
101255 --- a/net/core/skbuff.c
101256 +++ b/net/core/skbuff.c
101257 @@ -2025,7 +2025,7 @@ EXPORT_SYMBOL(__skb_checksum);
101258 __wsum skb_checksum(const struct sk_buff *skb, int offset,
101259 int len, __wsum csum)
101260 {
101261 - const struct skb_checksum_ops ops = {
101262 + static const struct skb_checksum_ops ops = {
101263 .update = csum_partial_ext,
101264 .combine = csum_block_add_ext,
101265 };
101266 @@ -3255,12 +3255,14 @@ void __init skb_init(void)
101267 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
101268 sizeof(struct sk_buff),
101269 0,
101270 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
101271 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
101272 + SLAB_NO_SANITIZE,
101273 NULL);
101274 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
101275 sizeof(struct sk_buff_fclones),
101276 0,
101277 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
101278 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
101279 + SLAB_NO_SANITIZE,
101280 NULL);
101281 }
101282
101283 diff --git a/net/core/sock.c b/net/core/sock.c
101284 index 15e0c67..0310f4a 100644
101285 --- a/net/core/sock.c
101286 +++ b/net/core/sock.c
101287 @@ -441,7 +441,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
101288 struct sk_buff_head *list = &sk->sk_receive_queue;
101289
101290 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
101291 - atomic_inc(&sk->sk_drops);
101292 + atomic_inc_unchecked(&sk->sk_drops);
101293 trace_sock_rcvqueue_full(sk, skb);
101294 return -ENOMEM;
101295 }
101296 @@ -451,7 +451,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
101297 return err;
101298
101299 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
101300 - atomic_inc(&sk->sk_drops);
101301 + atomic_inc_unchecked(&sk->sk_drops);
101302 return -ENOBUFS;
101303 }
101304
101305 @@ -464,7 +464,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
101306 skb_dst_force(skb);
101307
101308 spin_lock_irqsave(&list->lock, flags);
101309 - skb->dropcount = atomic_read(&sk->sk_drops);
101310 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
101311 __skb_queue_tail(list, skb);
101312 spin_unlock_irqrestore(&list->lock, flags);
101313
101314 @@ -484,7 +484,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
101315 skb->dev = NULL;
101316
101317 if (sk_rcvqueues_full(sk, sk->sk_rcvbuf)) {
101318 - atomic_inc(&sk->sk_drops);
101319 + atomic_inc_unchecked(&sk->sk_drops);
101320 goto discard_and_relse;
101321 }
101322 if (nested)
101323 @@ -502,7 +502,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
101324 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
101325 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
101326 bh_unlock_sock(sk);
101327 - atomic_inc(&sk->sk_drops);
101328 + atomic_inc_unchecked(&sk->sk_drops);
101329 goto discard_and_relse;
101330 }
101331
101332 @@ -991,12 +991,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
101333 struct timeval tm;
101334 } v;
101335
101336 - int lv = sizeof(int);
101337 - int len;
101338 + unsigned int lv = sizeof(int);
101339 + unsigned int len;
101340
101341 if (get_user(len, optlen))
101342 return -EFAULT;
101343 - if (len < 0)
101344 + if (len > INT_MAX)
101345 return -EINVAL;
101346
101347 memset(&v, 0, sizeof(v));
101348 @@ -1134,11 +1134,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
101349
101350 case SO_PEERNAME:
101351 {
101352 - char address[128];
101353 + char address[_K_SS_MAXSIZE];
101354
101355 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
101356 return -ENOTCONN;
101357 - if (lv < len)
101358 + if (lv < len || sizeof address < len)
101359 return -EINVAL;
101360 if (copy_to_user(optval, address, len))
101361 return -EFAULT;
101362 @@ -1219,7 +1219,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
101363
101364 if (len > lv)
101365 len = lv;
101366 - if (copy_to_user(optval, &v, len))
101367 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
101368 return -EFAULT;
101369 lenout:
101370 if (put_user(len, optlen))
101371 @@ -2315,7 +2315,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
101372 */
101373 smp_wmb();
101374 atomic_set(&sk->sk_refcnt, 1);
101375 - atomic_set(&sk->sk_drops, 0);
101376 + atomic_set_unchecked(&sk->sk_drops, 0);
101377 }
101378 EXPORT_SYMBOL(sock_init_data);
101379
101380 @@ -2443,6 +2443,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
101381 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
101382 int level, int type)
101383 {
101384 + struct sock_extended_err ee;
101385 struct sock_exterr_skb *serr;
101386 struct sk_buff *skb;
101387 int copied, err;
101388 @@ -2464,7 +2465,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
101389 sock_recv_timestamp(msg, sk, skb);
101390
101391 serr = SKB_EXT_ERR(skb);
101392 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
101393 + ee = serr->ee;
101394 + put_cmsg(msg, level, type, sizeof ee, &ee);
101395
101396 msg->msg_flags |= MSG_ERRQUEUE;
101397 err = copied;
101398 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
101399 index ad704c7..ca48aff 100644
101400 --- a/net/core/sock_diag.c
101401 +++ b/net/core/sock_diag.c
101402 @@ -9,26 +9,33 @@
101403 #include <linux/inet_diag.h>
101404 #include <linux/sock_diag.h>
101405
101406 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
101407 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
101408 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
101409 static DEFINE_MUTEX(sock_diag_table_mutex);
101410
101411 int sock_diag_check_cookie(void *sk, __u32 *cookie)
101412 {
101413 +#ifndef CONFIG_GRKERNSEC_HIDESYM
101414 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
101415 cookie[1] != INET_DIAG_NOCOOKIE) &&
101416 ((u32)(unsigned long)sk != cookie[0] ||
101417 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
101418 return -ESTALE;
101419 else
101420 +#endif
101421 return 0;
101422 }
101423 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
101424
101425 void sock_diag_save_cookie(void *sk, __u32 *cookie)
101426 {
101427 +#ifdef CONFIG_GRKERNSEC_HIDESYM
101428 + cookie[0] = 0;
101429 + cookie[1] = 0;
101430 +#else
101431 cookie[0] = (u32)(unsigned long)sk;
101432 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
101433 +#endif
101434 }
101435 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
101436
101437 @@ -110,8 +117,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
101438 mutex_lock(&sock_diag_table_mutex);
101439 if (sock_diag_handlers[hndl->family])
101440 err = -EBUSY;
101441 - else
101442 + else {
101443 + pax_open_kernel();
101444 sock_diag_handlers[hndl->family] = hndl;
101445 + pax_close_kernel();
101446 + }
101447 mutex_unlock(&sock_diag_table_mutex);
101448
101449 return err;
101450 @@ -127,7 +137,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
101451
101452 mutex_lock(&sock_diag_table_mutex);
101453 BUG_ON(sock_diag_handlers[family] != hnld);
101454 + pax_open_kernel();
101455 sock_diag_handlers[family] = NULL;
101456 + pax_close_kernel();
101457 mutex_unlock(&sock_diag_table_mutex);
101458 }
101459 EXPORT_SYMBOL_GPL(sock_diag_unregister);
101460 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
101461 index cf9cd13..50683950 100644
101462 --- a/net/core/sysctl_net_core.c
101463 +++ b/net/core/sysctl_net_core.c
101464 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
101465 {
101466 unsigned int orig_size, size;
101467 int ret, i;
101468 - struct ctl_table tmp = {
101469 + ctl_table_no_const tmp = {
101470 .data = &size,
101471 .maxlen = sizeof(size),
101472 .mode = table->mode
101473 @@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
101474 void __user *buffer, size_t *lenp, loff_t *ppos)
101475 {
101476 char id[IFNAMSIZ];
101477 - struct ctl_table tbl = {
101478 + ctl_table_no_const tbl = {
101479 .data = id,
101480 .maxlen = IFNAMSIZ,
101481 };
101482 @@ -263,7 +263,7 @@ static struct ctl_table net_core_table[] = {
101483 .mode = 0644,
101484 .proc_handler = proc_dointvec
101485 },
101486 -#ifdef CONFIG_BPF_JIT
101487 +#if defined(CONFIG_BPF_JIT) && !defined(CONFIG_GRKERNSEC_BPF_HARDEN)
101488 {
101489 .procname = "bpf_jit_enable",
101490 .data = &bpf_jit_enable,
101491 @@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
101492
101493 static __net_init int sysctl_core_net_init(struct net *net)
101494 {
101495 - struct ctl_table *tbl;
101496 + ctl_table_no_const *tbl = NULL;
101497
101498 net->core.sysctl_somaxconn = SOMAXCONN;
101499
101500 - tbl = netns_core_table;
101501 if (!net_eq(net, &init_net)) {
101502 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
101503 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
101504 if (tbl == NULL)
101505 goto err_dup;
101506
101507 @@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
101508 if (net->user_ns != &init_user_ns) {
101509 tbl[0].procname = NULL;
101510 }
101511 - }
101512 -
101513 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
101514 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
101515 + } else
101516 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
101517 if (net->core.sysctl_hdr == NULL)
101518 goto err_reg;
101519
101520 return 0;
101521
101522 err_reg:
101523 - if (tbl != netns_core_table)
101524 - kfree(tbl);
101525 + kfree(tbl);
101526 err_dup:
101527 return -ENOMEM;
101528 }
101529 @@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
101530 kfree(tbl);
101531 }
101532
101533 -static __net_initdata struct pernet_operations sysctl_core_ops = {
101534 +static __net_initconst struct pernet_operations sysctl_core_ops = {
101535 .init = sysctl_core_net_init,
101536 .exit = sysctl_core_net_exit,
101537 };
101538 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
101539 index 25733d5..b9360f0 100644
101540 --- a/net/decnet/af_decnet.c
101541 +++ b/net/decnet/af_decnet.c
101542 @@ -466,6 +466,7 @@ static struct proto dn_proto = {
101543 .sysctl_rmem = sysctl_decnet_rmem,
101544 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
101545 .obj_size = sizeof(struct dn_sock),
101546 + .slab_flags = SLAB_USERCOPY,
101547 };
101548
101549 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
101550 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
101551 index 4400da7..3429972 100644
101552 --- a/net/decnet/dn_dev.c
101553 +++ b/net/decnet/dn_dev.c
101554 @@ -201,7 +201,7 @@ static struct dn_dev_sysctl_table {
101555 .extra1 = &min_t3,
101556 .extra2 = &max_t3
101557 },
101558 - {0}
101559 + { }
101560 },
101561 };
101562
101563 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
101564 index 5325b54..a0d4d69 100644
101565 --- a/net/decnet/sysctl_net_decnet.c
101566 +++ b/net/decnet/sysctl_net_decnet.c
101567 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
101568
101569 if (len > *lenp) len = *lenp;
101570
101571 - if (copy_to_user(buffer, addr, len))
101572 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
101573 return -EFAULT;
101574
101575 *lenp = len;
101576 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
101577
101578 if (len > *lenp) len = *lenp;
101579
101580 - if (copy_to_user(buffer, devname, len))
101581 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
101582 return -EFAULT;
101583
101584 *lenp = len;
101585 diff --git a/net/hsr/hsr_netlink.c b/net/hsr/hsr_netlink.c
101586 index a2c7e4c..3dc9f67 100644
101587 --- a/net/hsr/hsr_netlink.c
101588 +++ b/net/hsr/hsr_netlink.c
101589 @@ -102,7 +102,7 @@ nla_put_failure:
101590 return -EMSGSIZE;
101591 }
101592
101593 -static struct rtnl_link_ops hsr_link_ops __read_mostly = {
101594 +static struct rtnl_link_ops hsr_link_ops = {
101595 .kind = "hsr",
101596 .maxtype = IFLA_HSR_MAX,
101597 .policy = hsr_policy,
101598 diff --git a/net/ieee802154/6lowpan_rtnl.c b/net/ieee802154/6lowpan_rtnl.c
101599 index 4413629..dea596a 100644
101600 --- a/net/ieee802154/6lowpan_rtnl.c
101601 +++ b/net/ieee802154/6lowpan_rtnl.c
101602 @@ -635,7 +635,7 @@ static void lowpan_dellink(struct net_device *dev, struct list_head *head)
101603 dev_put(real_dev);
101604 }
101605
101606 -static struct rtnl_link_ops lowpan_link_ops __read_mostly = {
101607 +static struct rtnl_link_ops lowpan_link_ops = {
101608 .kind = "lowpan",
101609 .priv_size = sizeof(struct lowpan_dev_info),
101610 .setup = lowpan_setup,
101611 diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
101612 index 7cfcd68..84ca5b7 100644
101613 --- a/net/ieee802154/reassembly.c
101614 +++ b/net/ieee802154/reassembly.c
101615 @@ -433,14 +433,13 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
101616
101617 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
101618 {
101619 - struct ctl_table *table;
101620 + ctl_table_no_const *table = NULL;
101621 struct ctl_table_header *hdr;
101622 struct netns_ieee802154_lowpan *ieee802154_lowpan =
101623 net_ieee802154_lowpan(net);
101624
101625 - table = lowpan_frags_ns_ctl_table;
101626 if (!net_eq(net, &init_net)) {
101627 - table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
101628 + table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
101629 GFP_KERNEL);
101630 if (table == NULL)
101631 goto err_alloc;
101632 @@ -455,9 +454,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
101633 /* Don't export sysctls to unprivileged users */
101634 if (net->user_ns != &init_user_ns)
101635 table[0].procname = NULL;
101636 - }
101637 -
101638 - hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
101639 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
101640 + } else
101641 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
101642 if (hdr == NULL)
101643 goto err_reg;
101644
101645 @@ -465,8 +464,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
101646 return 0;
101647
101648 err_reg:
101649 - if (!net_eq(net, &init_net))
101650 - kfree(table);
101651 + kfree(table);
101652 err_alloc:
101653 return -ENOMEM;
101654 }
101655 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
101656 index e67da4e..da217942 100644
101657 --- a/net/ipv4/af_inet.c
101658 +++ b/net/ipv4/af_inet.c
101659 @@ -1392,7 +1392,7 @@ int inet_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
101660 return ip_recv_error(sk, msg, len, addr_len);
101661 #if IS_ENABLED(CONFIG_IPV6)
101662 if (sk->sk_family == AF_INET6)
101663 - return pingv6_ops.ipv6_recv_error(sk, msg, len, addr_len);
101664 + return pingv6_ops->ipv6_recv_error(sk, msg, len, addr_len);
101665 #endif
101666 return -EINVAL;
101667 }
101668 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
101669 index 214882e..ec032f6 100644
101670 --- a/net/ipv4/devinet.c
101671 +++ b/net/ipv4/devinet.c
101672 @@ -69,7 +69,8 @@
101673
101674 static struct ipv4_devconf ipv4_devconf = {
101675 .data = {
101676 - [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
101677 + [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 0,
101678 + [IPV4_DEVCONF_RP_FILTER - 1] = 1,
101679 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
101680 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
101681 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
101682 @@ -80,7 +81,8 @@ static struct ipv4_devconf ipv4_devconf = {
101683
101684 static struct ipv4_devconf ipv4_devconf_dflt = {
101685 .data = {
101686 - [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
101687 + [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 0,
101688 + [IPV4_DEVCONF_RP_FILTER - 1] = 1,
101689 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
101690 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
101691 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
101692 @@ -1548,7 +1550,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
101693 idx = 0;
101694 head = &net->dev_index_head[h];
101695 rcu_read_lock();
101696 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
101697 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
101698 net->dev_base_seq;
101699 hlist_for_each_entry_rcu(dev, head, index_hlist) {
101700 if (idx < s_idx)
101701 @@ -1866,7 +1868,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
101702 idx = 0;
101703 head = &net->dev_index_head[h];
101704 rcu_read_lock();
101705 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
101706 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
101707 net->dev_base_seq;
101708 hlist_for_each_entry_rcu(dev, head, index_hlist) {
101709 if (idx < s_idx)
101710 @@ -2101,7 +2103,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
101711 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
101712 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
101713
101714 -static struct devinet_sysctl_table {
101715 +static const struct devinet_sysctl_table {
101716 struct ctl_table_header *sysctl_header;
101717 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
101718 } devinet_sysctl = {
101719 @@ -2233,7 +2235,7 @@ static __net_init int devinet_init_net(struct net *net)
101720 int err;
101721 struct ipv4_devconf *all, *dflt;
101722 #ifdef CONFIG_SYSCTL
101723 - struct ctl_table *tbl = ctl_forward_entry;
101724 + ctl_table_no_const *tbl = NULL;
101725 struct ctl_table_header *forw_hdr;
101726 #endif
101727
101728 @@ -2251,7 +2253,7 @@ static __net_init int devinet_init_net(struct net *net)
101729 goto err_alloc_dflt;
101730
101731 #ifdef CONFIG_SYSCTL
101732 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
101733 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
101734 if (tbl == NULL)
101735 goto err_alloc_ctl;
101736
101737 @@ -2271,7 +2273,10 @@ static __net_init int devinet_init_net(struct net *net)
101738 goto err_reg_dflt;
101739
101740 err = -ENOMEM;
101741 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
101742 + if (!net_eq(net, &init_net))
101743 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
101744 + else
101745 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
101746 if (forw_hdr == NULL)
101747 goto err_reg_ctl;
101748 net->ipv4.forw_hdr = forw_hdr;
101749 @@ -2287,8 +2292,7 @@ err_reg_ctl:
101750 err_reg_dflt:
101751 __devinet_sysctl_unregister(all);
101752 err_reg_all:
101753 - if (tbl != ctl_forward_entry)
101754 - kfree(tbl);
101755 + kfree(tbl);
101756 err_alloc_ctl:
101757 #endif
101758 if (dflt != &ipv4_devconf_dflt)
101759 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
101760 index 23104a3..9f5570b 100644
101761 --- a/net/ipv4/fib_frontend.c
101762 +++ b/net/ipv4/fib_frontend.c
101763 @@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
101764 #ifdef CONFIG_IP_ROUTE_MULTIPATH
101765 fib_sync_up(dev);
101766 #endif
101767 - atomic_inc(&net->ipv4.dev_addr_genid);
101768 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
101769 rt_cache_flush(dev_net(dev));
101770 break;
101771 case NETDEV_DOWN:
101772 fib_del_ifaddr(ifa, NULL);
101773 - atomic_inc(&net->ipv4.dev_addr_genid);
101774 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
101775 if (ifa->ifa_dev->ifa_list == NULL) {
101776 /* Last address was deleted from this interface.
101777 * Disable IP.
101778 @@ -1060,7 +1060,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
101779 #ifdef CONFIG_IP_ROUTE_MULTIPATH
101780 fib_sync_up(dev);
101781 #endif
101782 - atomic_inc(&net->ipv4.dev_addr_genid);
101783 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
101784 rt_cache_flush(net);
101785 break;
101786 case NETDEV_DOWN:
101787 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
101788 index f99f41b..1879da9 100644
101789 --- a/net/ipv4/fib_semantics.c
101790 +++ b/net/ipv4/fib_semantics.c
101791 @@ -770,7 +770,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
101792 nh->nh_saddr = inet_select_addr(nh->nh_dev,
101793 nh->nh_gw,
101794 nh->nh_parent->fib_scope);
101795 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
101796 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
101797
101798 return nh->nh_saddr;
101799 }
101800 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
101801 index 9111a4e..3576905 100644
101802 --- a/net/ipv4/inet_hashtables.c
101803 +++ b/net/ipv4/inet_hashtables.c
101804 @@ -18,6 +18,7 @@
101805 #include <linux/sched.h>
101806 #include <linux/slab.h>
101807 #include <linux/wait.h>
101808 +#include <linux/security.h>
101809
101810 #include <net/inet_connection_sock.h>
101811 #include <net/inet_hashtables.h>
101812 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
101813 return inet_ehashfn(net, laddr, lport, faddr, fport);
101814 }
101815
101816 +extern void gr_update_task_in_ip_table(const struct inet_sock *inet);
101817 +
101818 /*
101819 * Allocate and initialize a new local port bind bucket.
101820 * The bindhash mutex for snum's hash chain must be held here.
101821 @@ -554,6 +557,8 @@ ok:
101822 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
101823 spin_unlock(&head->lock);
101824
101825 + gr_update_task_in_ip_table(inet_sk(sk));
101826 +
101827 if (tw) {
101828 inet_twsk_deschedule(tw, death_row);
101829 while (twrefcnt) {
101830 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
101831 index 241afd7..31b95d5 100644
101832 --- a/net/ipv4/inetpeer.c
101833 +++ b/net/ipv4/inetpeer.c
101834 @@ -461,7 +461,7 @@ relookup:
101835 if (p) {
101836 p->daddr = *daddr;
101837 atomic_set(&p->refcnt, 1);
101838 - atomic_set(&p->rid, 0);
101839 + atomic_set_unchecked(&p->rid, 0);
101840 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
101841 p->rate_tokens = 0;
101842 /* 60*HZ is arbitrary, but chosen enough high so that the first
101843 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
101844 index 2811cc1..ad5a534 100644
101845 --- a/net/ipv4/ip_fragment.c
101846 +++ b/net/ipv4/ip_fragment.c
101847 @@ -268,7 +268,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
101848 return 0;
101849
101850 start = qp->rid;
101851 - end = atomic_inc_return(&peer->rid);
101852 + end = atomic_inc_return_unchecked(&peer->rid);
101853 qp->rid = end;
101854
101855 rc = qp->q.fragments && (end - start) > max;
101856 @@ -746,12 +746,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
101857
101858 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
101859 {
101860 - struct ctl_table *table;
101861 + ctl_table_no_const *table = NULL;
101862 struct ctl_table_header *hdr;
101863
101864 - table = ip4_frags_ns_ctl_table;
101865 if (!net_eq(net, &init_net)) {
101866 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
101867 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
101868 if (table == NULL)
101869 goto err_alloc;
101870
101871 @@ -765,9 +764,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
101872 /* Don't export sysctls to unprivileged users */
101873 if (net->user_ns != &init_user_ns)
101874 table[0].procname = NULL;
101875 - }
101876 + hdr = register_net_sysctl(net, "net/ipv4", table);
101877 + } else
101878 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
101879
101880 - hdr = register_net_sysctl(net, "net/ipv4", table);
101881 if (hdr == NULL)
101882 goto err_reg;
101883
101884 @@ -775,8 +775,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
101885 return 0;
101886
101887 err_reg:
101888 - if (!net_eq(net, &init_net))
101889 - kfree(table);
101890 + kfree(table);
101891 err_alloc:
101892 return -ENOMEM;
101893 }
101894 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
101895 index 12055fd..df852c4 100644
101896 --- a/net/ipv4/ip_gre.c
101897 +++ b/net/ipv4/ip_gre.c
101898 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
101899 module_param(log_ecn_error, bool, 0644);
101900 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
101901
101902 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
101903 +static struct rtnl_link_ops ipgre_link_ops;
101904 static int ipgre_tunnel_init(struct net_device *dev);
101905
101906 static int ipgre_net_id __read_mostly;
101907 @@ -815,7 +815,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
101908 [IFLA_GRE_ENCAP_DPORT] = { .type = NLA_U16 },
101909 };
101910
101911 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
101912 +static struct rtnl_link_ops ipgre_link_ops = {
101913 .kind = "gre",
101914 .maxtype = IFLA_GRE_MAX,
101915 .policy = ipgre_policy,
101916 @@ -829,7 +829,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
101917 .fill_info = ipgre_fill_info,
101918 };
101919
101920 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
101921 +static struct rtnl_link_ops ipgre_tap_ops = {
101922 .kind = "gretap",
101923 .maxtype = IFLA_GRE_MAX,
101924 .policy = ipgre_policy,
101925 diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
101926 index 3d4da2c..40f9c29 100644
101927 --- a/net/ipv4/ip_input.c
101928 +++ b/net/ipv4/ip_input.c
101929 @@ -147,6 +147,10 @@
101930 #include <linux/mroute.h>
101931 #include <linux/netlink.h>
101932
101933 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101934 +extern int grsec_enable_blackhole;
101935 +#endif
101936 +
101937 /*
101938 * Process Router Attention IP option (RFC 2113)
101939 */
101940 @@ -223,6 +227,9 @@ static int ip_local_deliver_finish(struct sk_buff *skb)
101941 if (!raw) {
101942 if (xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
101943 IP_INC_STATS_BH(net, IPSTATS_MIB_INUNKNOWNPROTOS);
101944 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101945 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
101946 +#endif
101947 icmp_send(skb, ICMP_DEST_UNREACH,
101948 ICMP_PROT_UNREACH, 0);
101949 }
101950 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
101951 index 9daf217..dc6972d 100644
101952 --- a/net/ipv4/ip_sockglue.c
101953 +++ b/net/ipv4/ip_sockglue.c
101954 @@ -1177,7 +1177,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
101955 len = min_t(unsigned int, len, opt->optlen);
101956 if (put_user(len, optlen))
101957 return -EFAULT;
101958 - if (copy_to_user(optval, opt->__data, len))
101959 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
101960 + copy_to_user(optval, opt->__data, len))
101961 return -EFAULT;
101962 return 0;
101963 }
101964 @@ -1308,7 +1309,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
101965 if (sk->sk_type != SOCK_STREAM)
101966 return -ENOPROTOOPT;
101967
101968 - msg.msg_control = (__force void *) optval;
101969 + msg.msg_control = (__force_kernel void *) optval;
101970 msg.msg_controllen = len;
101971 msg.msg_flags = flags;
101972
101973 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
101974 index 1a7e979..fd05aa4 100644
101975 --- a/net/ipv4/ip_vti.c
101976 +++ b/net/ipv4/ip_vti.c
101977 @@ -45,7 +45,7 @@
101978 #include <net/net_namespace.h>
101979 #include <net/netns/generic.h>
101980
101981 -static struct rtnl_link_ops vti_link_ops __read_mostly;
101982 +static struct rtnl_link_ops vti_link_ops;
101983
101984 static int vti_net_id __read_mostly;
101985 static int vti_tunnel_init(struct net_device *dev);
101986 @@ -519,7 +519,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
101987 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
101988 };
101989
101990 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
101991 +static struct rtnl_link_ops vti_link_ops = {
101992 .kind = "vti",
101993 .maxtype = IFLA_VTI_MAX,
101994 .policy = vti_policy,
101995 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
101996 index 648fa14..97864d0 100644
101997 --- a/net/ipv4/ipconfig.c
101998 +++ b/net/ipv4/ipconfig.c
101999 @@ -333,7 +333,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
102000
102001 mm_segment_t oldfs = get_fs();
102002 set_fs(get_ds());
102003 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
102004 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
102005 set_fs(oldfs);
102006 return res;
102007 }
102008 @@ -344,7 +344,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
102009
102010 mm_segment_t oldfs = get_fs();
102011 set_fs(get_ds());
102012 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
102013 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
102014 set_fs(oldfs);
102015 return res;
102016 }
102017 @@ -355,7 +355,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
102018
102019 mm_segment_t oldfs = get_fs();
102020 set_fs(get_ds());
102021 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
102022 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
102023 set_fs(oldfs);
102024 return res;
102025 }
102026 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
102027 index 37096d6..86abb03 100644
102028 --- a/net/ipv4/ipip.c
102029 +++ b/net/ipv4/ipip.c
102030 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
102031 static int ipip_net_id __read_mostly;
102032
102033 static int ipip_tunnel_init(struct net_device *dev);
102034 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
102035 +static struct rtnl_link_ops ipip_link_ops;
102036
102037 static int ipip_err(struct sk_buff *skb, u32 info)
102038 {
102039 @@ -487,7 +487,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
102040 [IFLA_IPTUN_ENCAP_DPORT] = { .type = NLA_U16 },
102041 };
102042
102043 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
102044 +static struct rtnl_link_ops ipip_link_ops = {
102045 .kind = "ipip",
102046 .maxtype = IFLA_IPTUN_MAX,
102047 .policy = ipip_policy,
102048 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
102049 index f95b6f9..2ee2097 100644
102050 --- a/net/ipv4/netfilter/arp_tables.c
102051 +++ b/net/ipv4/netfilter/arp_tables.c
102052 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
102053 #endif
102054
102055 static int get_info(struct net *net, void __user *user,
102056 - const int *len, int compat)
102057 + int len, int compat)
102058 {
102059 char name[XT_TABLE_MAXNAMELEN];
102060 struct xt_table *t;
102061 int ret;
102062
102063 - if (*len != sizeof(struct arpt_getinfo)) {
102064 - duprintf("length %u != %Zu\n", *len,
102065 + if (len != sizeof(struct arpt_getinfo)) {
102066 + duprintf("length %u != %Zu\n", len,
102067 sizeof(struct arpt_getinfo));
102068 return -EINVAL;
102069 }
102070 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
102071 info.size = private->size;
102072 strcpy(info.name, name);
102073
102074 - if (copy_to_user(user, &info, *len) != 0)
102075 + if (copy_to_user(user, &info, len) != 0)
102076 ret = -EFAULT;
102077 else
102078 ret = 0;
102079 @@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
102080
102081 switch (cmd) {
102082 case ARPT_SO_GET_INFO:
102083 - ret = get_info(sock_net(sk), user, len, 1);
102084 + ret = get_info(sock_net(sk), user, *len, 1);
102085 break;
102086 case ARPT_SO_GET_ENTRIES:
102087 ret = compat_get_entries(sock_net(sk), user, len);
102088 @@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
102089
102090 switch (cmd) {
102091 case ARPT_SO_GET_INFO:
102092 - ret = get_info(sock_net(sk), user, len, 0);
102093 + ret = get_info(sock_net(sk), user, *len, 0);
102094 break;
102095
102096 case ARPT_SO_GET_ENTRIES:
102097 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
102098 index 99e810f..3711b81 100644
102099 --- a/net/ipv4/netfilter/ip_tables.c
102100 +++ b/net/ipv4/netfilter/ip_tables.c
102101 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
102102 #endif
102103
102104 static int get_info(struct net *net, void __user *user,
102105 - const int *len, int compat)
102106 + int len, int compat)
102107 {
102108 char name[XT_TABLE_MAXNAMELEN];
102109 struct xt_table *t;
102110 int ret;
102111
102112 - if (*len != sizeof(struct ipt_getinfo)) {
102113 - duprintf("length %u != %zu\n", *len,
102114 + if (len != sizeof(struct ipt_getinfo)) {
102115 + duprintf("length %u != %zu\n", len,
102116 sizeof(struct ipt_getinfo));
102117 return -EINVAL;
102118 }
102119 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
102120 info.size = private->size;
102121 strcpy(info.name, name);
102122
102123 - if (copy_to_user(user, &info, *len) != 0)
102124 + if (copy_to_user(user, &info, len) != 0)
102125 ret = -EFAULT;
102126 else
102127 ret = 0;
102128 @@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
102129
102130 switch (cmd) {
102131 case IPT_SO_GET_INFO:
102132 - ret = get_info(sock_net(sk), user, len, 1);
102133 + ret = get_info(sock_net(sk), user, *len, 1);
102134 break;
102135 case IPT_SO_GET_ENTRIES:
102136 ret = compat_get_entries(sock_net(sk), user, len);
102137 @@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
102138
102139 switch (cmd) {
102140 case IPT_SO_GET_INFO:
102141 - ret = get_info(sock_net(sk), user, len, 0);
102142 + ret = get_info(sock_net(sk), user, *len, 0);
102143 break;
102144
102145 case IPT_SO_GET_ENTRIES:
102146 diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
102147 index e90f83a..3e6acca 100644
102148 --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
102149 +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
102150 @@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
102151 spin_lock_init(&cn->lock);
102152
102153 #ifdef CONFIG_PROC_FS
102154 - cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
102155 + cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
102156 if (!cn->procdir) {
102157 pr_err("Unable to proc dir entry\n");
102158 return -ENOMEM;
102159 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
102160 index 5d740cc..b2842b9 100644
102161 --- a/net/ipv4/ping.c
102162 +++ b/net/ipv4/ping.c
102163 @@ -59,7 +59,7 @@ struct ping_table {
102164 };
102165
102166 static struct ping_table ping_table;
102167 -struct pingv6_ops pingv6_ops;
102168 +struct pingv6_ops *pingv6_ops;
102169 EXPORT_SYMBOL_GPL(pingv6_ops);
102170
102171 static u16 ping_port_rover;
102172 @@ -350,7 +350,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
102173 return -ENODEV;
102174 }
102175 }
102176 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
102177 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
102178 scoped);
102179 rcu_read_unlock();
102180
102181 @@ -558,7 +558,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
102182 }
102183 #if IS_ENABLED(CONFIG_IPV6)
102184 } else if (skb->protocol == htons(ETH_P_IPV6)) {
102185 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
102186 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
102187 #endif
102188 }
102189
102190 @@ -576,7 +576,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
102191 info, (u8 *)icmph);
102192 #if IS_ENABLED(CONFIG_IPV6)
102193 } else if (family == AF_INET6) {
102194 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
102195 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
102196 info, (u8 *)icmph);
102197 #endif
102198 }
102199 @@ -910,10 +910,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
102200 }
102201
102202 if (inet6_sk(sk)->rxopt.all)
102203 - pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
102204 + pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
102205 if (skb->protocol == htons(ETH_P_IPV6) &&
102206 inet6_sk(sk)->rxopt.all)
102207 - pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
102208 + pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
102209 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
102210 ip_cmsg_recv(msg, skb);
102211 #endif
102212 @@ -1105,7 +1105,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
102213 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
102214 0, sock_i_ino(sp),
102215 atomic_read(&sp->sk_refcnt), sp,
102216 - atomic_read(&sp->sk_drops));
102217 + atomic_read_unchecked(&sp->sk_drops));
102218 }
102219
102220 static int ping_v4_seq_show(struct seq_file *seq, void *v)
102221 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
102222 index 739db31..74f0210 100644
102223 --- a/net/ipv4/raw.c
102224 +++ b/net/ipv4/raw.c
102225 @@ -314,7 +314,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
102226 int raw_rcv(struct sock *sk, struct sk_buff *skb)
102227 {
102228 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
102229 - atomic_inc(&sk->sk_drops);
102230 + atomic_inc_unchecked(&sk->sk_drops);
102231 kfree_skb(skb);
102232 return NET_RX_DROP;
102233 }
102234 @@ -755,16 +755,20 @@ static int raw_init(struct sock *sk)
102235
102236 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
102237 {
102238 + struct icmp_filter filter;
102239 +
102240 if (optlen > sizeof(struct icmp_filter))
102241 optlen = sizeof(struct icmp_filter);
102242 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
102243 + if (copy_from_user(&filter, optval, optlen))
102244 return -EFAULT;
102245 + raw_sk(sk)->filter = filter;
102246 return 0;
102247 }
102248
102249 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
102250 {
102251 int len, ret = -EFAULT;
102252 + struct icmp_filter filter;
102253
102254 if (get_user(len, optlen))
102255 goto out;
102256 @@ -774,8 +778,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
102257 if (len > sizeof(struct icmp_filter))
102258 len = sizeof(struct icmp_filter);
102259 ret = -EFAULT;
102260 - if (put_user(len, optlen) ||
102261 - copy_to_user(optval, &raw_sk(sk)->filter, len))
102262 + filter = raw_sk(sk)->filter;
102263 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
102264 goto out;
102265 ret = 0;
102266 out: return ret;
102267 @@ -1004,7 +1008,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
102268 0, 0L, 0,
102269 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
102270 0, sock_i_ino(sp),
102271 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
102272 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
102273 }
102274
102275 static int raw_seq_show(struct seq_file *seq, void *v)
102276 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
102277 index 6a2155b..d426880 100644
102278 --- a/net/ipv4/route.c
102279 +++ b/net/ipv4/route.c
102280 @@ -228,7 +228,7 @@ static const struct seq_operations rt_cache_seq_ops = {
102281
102282 static int rt_cache_seq_open(struct inode *inode, struct file *file)
102283 {
102284 - return seq_open(file, &rt_cache_seq_ops);
102285 + return seq_open_restrict(file, &rt_cache_seq_ops);
102286 }
102287
102288 static const struct file_operations rt_cache_seq_fops = {
102289 @@ -319,7 +319,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
102290
102291 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
102292 {
102293 - return seq_open(file, &rt_cpu_seq_ops);
102294 + return seq_open_restrict(file, &rt_cpu_seq_ops);
102295 }
102296
102297 static const struct file_operations rt_cpu_seq_fops = {
102298 @@ -357,7 +357,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
102299
102300 static int rt_acct_proc_open(struct inode *inode, struct file *file)
102301 {
102302 - return single_open(file, rt_acct_proc_show, NULL);
102303 + return single_open_restrict(file, rt_acct_proc_show, NULL);
102304 }
102305
102306 static const struct file_operations rt_acct_proc_fops = {
102307 @@ -459,11 +459,11 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
102308
102309 #define IP_IDENTS_SZ 2048u
102310 struct ip_ident_bucket {
102311 - atomic_t id;
102312 + atomic_unchecked_t id;
102313 u32 stamp32;
102314 };
102315
102316 -static struct ip_ident_bucket *ip_idents __read_mostly;
102317 +static struct ip_ident_bucket ip_idents[IP_IDENTS_SZ] __read_mostly;
102318
102319 /* In order to protect privacy, we add a perturbation to identifiers
102320 * if one generator is seldom used. This makes hard for an attacker
102321 @@ -479,7 +479,7 @@ u32 ip_idents_reserve(u32 hash, int segs)
102322 if (old != now && cmpxchg(&bucket->stamp32, old, now) == old)
102323 delta = prandom_u32_max(now - old);
102324
102325 - return atomic_add_return(segs + delta, &bucket->id) - segs;
102326 + return atomic_add_return_unchecked(segs + delta, &bucket->id) - segs;
102327 }
102328 EXPORT_SYMBOL(ip_idents_reserve);
102329
102330 @@ -2624,34 +2624,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
102331 .maxlen = sizeof(int),
102332 .mode = 0200,
102333 .proc_handler = ipv4_sysctl_rtcache_flush,
102334 + .extra1 = &init_net,
102335 },
102336 { },
102337 };
102338
102339 static __net_init int sysctl_route_net_init(struct net *net)
102340 {
102341 - struct ctl_table *tbl;
102342 + ctl_table_no_const *tbl = NULL;
102343
102344 - tbl = ipv4_route_flush_table;
102345 if (!net_eq(net, &init_net)) {
102346 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
102347 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
102348 if (tbl == NULL)
102349 goto err_dup;
102350
102351 /* Don't export sysctls to unprivileged users */
102352 if (net->user_ns != &init_user_ns)
102353 tbl[0].procname = NULL;
102354 - }
102355 - tbl[0].extra1 = net;
102356 + tbl[0].extra1 = net;
102357 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
102358 + } else
102359 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
102360
102361 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
102362 if (net->ipv4.route_hdr == NULL)
102363 goto err_reg;
102364 return 0;
102365
102366 err_reg:
102367 - if (tbl != ipv4_route_flush_table)
102368 - kfree(tbl);
102369 + kfree(tbl);
102370 err_dup:
102371 return -ENOMEM;
102372 }
102373 @@ -2674,8 +2674,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
102374
102375 static __net_init int rt_genid_init(struct net *net)
102376 {
102377 - atomic_set(&net->ipv4.rt_genid, 0);
102378 - atomic_set(&net->fnhe_genid, 0);
102379 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
102380 + atomic_set_unchecked(&net->fnhe_genid, 0);
102381 get_random_bytes(&net->ipv4.dev_addr_genid,
102382 sizeof(net->ipv4.dev_addr_genid));
102383 return 0;
102384 @@ -2718,11 +2718,7 @@ int __init ip_rt_init(void)
102385 {
102386 int rc = 0;
102387
102388 - ip_idents = kmalloc(IP_IDENTS_SZ * sizeof(*ip_idents), GFP_KERNEL);
102389 - if (!ip_idents)
102390 - panic("IP: failed to allocate ip_idents\n");
102391 -
102392 - prandom_bytes(ip_idents, IP_IDENTS_SZ * sizeof(*ip_idents));
102393 + prandom_bytes(ip_idents, sizeof(ip_idents));
102394
102395 #ifdef CONFIG_IP_ROUTE_CLASSID
102396 ip_rt_acct = __alloc_percpu(256 * sizeof(struct ip_rt_acct), __alignof__(struct ip_rt_acct));
102397 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
102398 index b3c53c8..35cc18d 100644
102399 --- a/net/ipv4/sysctl_net_ipv4.c
102400 +++ b/net/ipv4/sysctl_net_ipv4.c
102401 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
102402 container_of(table->data, struct net, ipv4.ip_local_ports.range);
102403 int ret;
102404 int range[2];
102405 - struct ctl_table tmp = {
102406 + ctl_table_no_const tmp = {
102407 .data = &range,
102408 .maxlen = sizeof(range),
102409 .mode = table->mode,
102410 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
102411 int ret;
102412 gid_t urange[2];
102413 kgid_t low, high;
102414 - struct ctl_table tmp = {
102415 + ctl_table_no_const tmp = {
102416 .data = &urange,
102417 .maxlen = sizeof(urange),
102418 .mode = table->mode,
102419 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
102420 void __user *buffer, size_t *lenp, loff_t *ppos)
102421 {
102422 char val[TCP_CA_NAME_MAX];
102423 - struct ctl_table tbl = {
102424 + ctl_table_no_const tbl = {
102425 .data = val,
102426 .maxlen = TCP_CA_NAME_MAX,
102427 };
102428 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
102429 void __user *buffer, size_t *lenp,
102430 loff_t *ppos)
102431 {
102432 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
102433 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
102434 int ret;
102435
102436 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
102437 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
102438 void __user *buffer, size_t *lenp,
102439 loff_t *ppos)
102440 {
102441 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
102442 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
102443 int ret;
102444
102445 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
102446 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
102447 void __user *buffer, size_t *lenp,
102448 loff_t *ppos)
102449 {
102450 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
102451 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
102452 struct tcp_fastopen_context *ctxt;
102453 int ret;
102454 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
102455 @@ -874,13 +874,12 @@ static struct ctl_table ipv4_net_table[] = {
102456
102457 static __net_init int ipv4_sysctl_init_net(struct net *net)
102458 {
102459 - struct ctl_table *table;
102460 + ctl_table_no_const *table = NULL;
102461
102462 - table = ipv4_net_table;
102463 if (!net_eq(net, &init_net)) {
102464 int i;
102465
102466 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
102467 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
102468 if (table == NULL)
102469 goto err_alloc;
102470
102471 @@ -889,7 +888,10 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
102472 table[i].data += (void *)net - (void *)&init_net;
102473 }
102474
102475 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
102476 + if (!net_eq(net, &init_net))
102477 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
102478 + else
102479 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
102480 if (net->ipv4.ipv4_hdr == NULL)
102481 goto err_reg;
102482
102483 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
102484 index d107ee2..bcebf11 100644
102485 --- a/net/ipv4/tcp_input.c
102486 +++ b/net/ipv4/tcp_input.c
102487 @@ -765,7 +765,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
102488 * without any lock. We want to make sure compiler wont store
102489 * intermediate values in this location.
102490 */
102491 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
102492 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
102493 sk->sk_max_pacing_rate);
102494 }
102495
102496 @@ -4527,7 +4527,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
102497 * simplifies code)
102498 */
102499 static void
102500 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
102501 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
102502 struct sk_buff *head, struct sk_buff *tail,
102503 u32 start, u32 end)
102504 {
102505 @@ -5506,6 +5506,7 @@ discard:
102506 tcp_paws_reject(&tp->rx_opt, 0))
102507 goto discard_and_undo;
102508
102509 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
102510 if (th->syn) {
102511 /* We see SYN without ACK. It is attempt of
102512 * simultaneous connect with crossed SYNs.
102513 @@ -5556,6 +5557,7 @@ discard:
102514 goto discard;
102515 #endif
102516 }
102517 +#endif
102518 /* "fifth, if neither of the SYN or RST bits is set then
102519 * drop the segment and return."
102520 */
102521 @@ -5602,7 +5604,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
102522 goto discard;
102523
102524 if (th->syn) {
102525 - if (th->fin)
102526 + if (th->fin || th->urg || th->psh)
102527 goto discard;
102528 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
102529 return 1;
102530 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
102531 index ef7089c..a3e65fb 100644
102532 --- a/net/ipv4/tcp_ipv4.c
102533 +++ b/net/ipv4/tcp_ipv4.c
102534 @@ -89,6 +89,10 @@ int sysctl_tcp_tw_reuse __read_mostly;
102535 int sysctl_tcp_low_latency __read_mostly;
102536 EXPORT_SYMBOL(sysctl_tcp_low_latency);
102537
102538 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102539 +extern int grsec_enable_blackhole;
102540 +#endif
102541 +
102542 #ifdef CONFIG_TCP_MD5SIG
102543 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
102544 __be32 daddr, __be32 saddr, const struct tcphdr *th);
102545 @@ -1469,6 +1473,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
102546 return 0;
102547
102548 reset:
102549 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102550 + if (!grsec_enable_blackhole)
102551 +#endif
102552 tcp_v4_send_reset(rsk, skb);
102553 discard:
102554 kfree_skb(skb);
102555 @@ -1633,12 +1640,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
102556 TCP_SKB_CB(skb)->sacked = 0;
102557
102558 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
102559 - if (!sk)
102560 + if (!sk) {
102561 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102562 + ret = 1;
102563 +#endif
102564 goto no_tcp_socket;
102565 -
102566 + }
102567 process:
102568 - if (sk->sk_state == TCP_TIME_WAIT)
102569 + if (sk->sk_state == TCP_TIME_WAIT) {
102570 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102571 + ret = 2;
102572 +#endif
102573 goto do_time_wait;
102574 + }
102575
102576 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
102577 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
102578 @@ -1694,6 +1708,10 @@ csum_error:
102579 bad_packet:
102580 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
102581 } else {
102582 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102583 + if (!grsec_enable_blackhole || (ret == 1 &&
102584 + (skb->dev->flags & IFF_LOOPBACK)))
102585 +#endif
102586 tcp_v4_send_reset(NULL, skb);
102587 }
102588
102589 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
102590 index 63d2680..2db9d6b 100644
102591 --- a/net/ipv4/tcp_minisocks.c
102592 +++ b/net/ipv4/tcp_minisocks.c
102593 @@ -27,6 +27,10 @@
102594 #include <net/inet_common.h>
102595 #include <net/xfrm.h>
102596
102597 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102598 +extern int grsec_enable_blackhole;
102599 +#endif
102600 +
102601 int sysctl_tcp_syncookies __read_mostly = 1;
102602 EXPORT_SYMBOL(sysctl_tcp_syncookies);
102603
102604 @@ -739,7 +743,10 @@ embryonic_reset:
102605 * avoid becoming vulnerable to outside attack aiming at
102606 * resetting legit local connections.
102607 */
102608 - req->rsk_ops->send_reset(sk, skb);
102609 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102610 + if (!grsec_enable_blackhole)
102611 +#endif
102612 + req->rsk_ops->send_reset(sk, skb);
102613 } else if (fastopen) { /* received a valid RST pkt */
102614 reqsk_fastopen_remove(sk, req, true);
102615 tcp_reset(sk);
102616 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
102617 index ebf5ff5..4d1ff32 100644
102618 --- a/net/ipv4/tcp_probe.c
102619 +++ b/net/ipv4/tcp_probe.c
102620 @@ -236,7 +236,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
102621 if (cnt + width >= len)
102622 break;
102623
102624 - if (copy_to_user(buf + cnt, tbuf, width))
102625 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
102626 return -EFAULT;
102627 cnt += width;
102628 }
102629 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
102630 index 9b21ae8..4eb67df 100644
102631 --- a/net/ipv4/tcp_timer.c
102632 +++ b/net/ipv4/tcp_timer.c
102633 @@ -22,6 +22,10 @@
102634 #include <linux/gfp.h>
102635 #include <net/tcp.h>
102636
102637 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102638 +extern int grsec_lastack_retries;
102639 +#endif
102640 +
102641 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
102642 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
102643 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
102644 @@ -191,6 +195,13 @@ static int tcp_write_timeout(struct sock *sk)
102645 }
102646 }
102647
102648 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102649 + if ((sk->sk_state == TCP_LAST_ACK) &&
102650 + (grsec_lastack_retries > 0) &&
102651 + (grsec_lastack_retries < retry_until))
102652 + retry_until = grsec_lastack_retries;
102653 +#endif
102654 +
102655 if (retransmits_timed_out(sk, retry_until,
102656 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
102657 /* Has it gone just too far? */
102658 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
102659 index cd0db54..93a6518 100644
102660 --- a/net/ipv4/udp.c
102661 +++ b/net/ipv4/udp.c
102662 @@ -87,6 +87,7 @@
102663 #include <linux/types.h>
102664 #include <linux/fcntl.h>
102665 #include <linux/module.h>
102666 +#include <linux/security.h>
102667 #include <linux/socket.h>
102668 #include <linux/sockios.h>
102669 #include <linux/igmp.h>
102670 @@ -114,6 +115,10 @@
102671 #include <net/busy_poll.h>
102672 #include "udp_impl.h"
102673
102674 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102675 +extern int grsec_enable_blackhole;
102676 +#endif
102677 +
102678 struct udp_table udp_table __read_mostly;
102679 EXPORT_SYMBOL(udp_table);
102680
102681 @@ -595,6 +600,9 @@ static inline bool __udp_is_mcast_sock(struct net *net, struct sock *sk,
102682 return true;
102683 }
102684
102685 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
102686 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
102687 +
102688 /*
102689 * This routine is called by the ICMP module when it gets some
102690 * sort of error condition. If err < 0 then the socket should
102691 @@ -932,9 +940,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
102692 dport = usin->sin_port;
102693 if (dport == 0)
102694 return -EINVAL;
102695 +
102696 + err = gr_search_udp_sendmsg(sk, usin);
102697 + if (err)
102698 + return err;
102699 } else {
102700 if (sk->sk_state != TCP_ESTABLISHED)
102701 return -EDESTADDRREQ;
102702 +
102703 + err = gr_search_udp_sendmsg(sk, NULL);
102704 + if (err)
102705 + return err;
102706 +
102707 daddr = inet->inet_daddr;
102708 dport = inet->inet_dport;
102709 /* Open fast path for connected socket.
102710 @@ -1182,7 +1199,7 @@ static unsigned int first_packet_length(struct sock *sk)
102711 IS_UDPLITE(sk));
102712 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
102713 IS_UDPLITE(sk));
102714 - atomic_inc(&sk->sk_drops);
102715 + atomic_inc_unchecked(&sk->sk_drops);
102716 __skb_unlink(skb, rcvq);
102717 __skb_queue_tail(&list_kill, skb);
102718 }
102719 @@ -1262,6 +1279,10 @@ try_again:
102720 if (!skb)
102721 goto out;
102722
102723 + err = gr_search_udp_recvmsg(sk, skb);
102724 + if (err)
102725 + goto out_free;
102726 +
102727 ulen = skb->len - sizeof(struct udphdr);
102728 copied = len;
102729 if (copied > ulen)
102730 @@ -1295,7 +1316,7 @@ try_again:
102731 if (unlikely(err)) {
102732 trace_kfree_skb(skb, udp_recvmsg);
102733 if (!peeked) {
102734 - atomic_inc(&sk->sk_drops);
102735 + atomic_inc_unchecked(&sk->sk_drops);
102736 UDP_INC_STATS_USER(sock_net(sk),
102737 UDP_MIB_INERRORS, is_udplite);
102738 }
102739 @@ -1592,7 +1613,7 @@ csum_error:
102740 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
102741 drop:
102742 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
102743 - atomic_inc(&sk->sk_drops);
102744 + atomic_inc_unchecked(&sk->sk_drops);
102745 kfree_skb(skb);
102746 return -1;
102747 }
102748 @@ -1611,7 +1632,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
102749 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
102750
102751 if (!skb1) {
102752 - atomic_inc(&sk->sk_drops);
102753 + atomic_inc_unchecked(&sk->sk_drops);
102754 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
102755 IS_UDPLITE(sk));
102756 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
102757 @@ -1812,6 +1833,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
102758 goto csum_error;
102759
102760 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
102761 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102762 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
102763 +#endif
102764 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
102765
102766 /*
102767 @@ -2398,7 +2422,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
102768 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
102769 0, sock_i_ino(sp),
102770 atomic_read(&sp->sk_refcnt), sp,
102771 - atomic_read(&sp->sk_drops));
102772 + atomic_read_unchecked(&sp->sk_drops));
102773 }
102774
102775 int udp4_seq_show(struct seq_file *seq, void *v)
102776 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
102777 index 6156f68..d6ab46d 100644
102778 --- a/net/ipv4/xfrm4_policy.c
102779 +++ b/net/ipv4/xfrm4_policy.c
102780 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
102781 fl4->flowi4_tos = iph->tos;
102782 }
102783
102784 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
102785 +static int xfrm4_garbage_collect(struct dst_ops *ops)
102786 {
102787 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
102788
102789 - xfrm4_policy_afinfo.garbage_collect(net);
102790 + xfrm_garbage_collect_deferred(net);
102791 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
102792 }
102793
102794 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
102795
102796 static int __net_init xfrm4_net_init(struct net *net)
102797 {
102798 - struct ctl_table *table;
102799 + ctl_table_no_const *table = NULL;
102800 struct ctl_table_header *hdr;
102801
102802 - table = xfrm4_policy_table;
102803 if (!net_eq(net, &init_net)) {
102804 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
102805 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
102806 if (!table)
102807 goto err_alloc;
102808
102809 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
102810 - }
102811 -
102812 - hdr = register_net_sysctl(net, "net/ipv4", table);
102813 + hdr = register_net_sysctl(net, "net/ipv4", table);
102814 + } else
102815 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
102816 if (!hdr)
102817 goto err_reg;
102818
102819 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
102820 return 0;
102821
102822 err_reg:
102823 - if (!net_eq(net, &init_net))
102824 - kfree(table);
102825 + kfree(table);
102826 err_alloc:
102827 return -ENOMEM;
102828 }
102829 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
102830 index 0169ccf..50d7b04 100644
102831 --- a/net/ipv6/addrconf.c
102832 +++ b/net/ipv6/addrconf.c
102833 @@ -171,7 +171,7 @@ static struct ipv6_devconf ipv6_devconf __read_mostly = {
102834 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
102835 .mtu6 = IPV6_MIN_MTU,
102836 .accept_ra = 1,
102837 - .accept_redirects = 1,
102838 + .accept_redirects = 0,
102839 .autoconf = 1,
102840 .force_mld_version = 0,
102841 .mldv1_unsolicited_report_interval = 10 * HZ,
102842 @@ -208,7 +208,7 @@ static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
102843 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
102844 .mtu6 = IPV6_MIN_MTU,
102845 .accept_ra = 1,
102846 - .accept_redirects = 1,
102847 + .accept_redirects = 0,
102848 .autoconf = 1,
102849 .force_mld_version = 0,
102850 .mldv1_unsolicited_report_interval = 10 * HZ,
102851 @@ -604,7 +604,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
102852 idx = 0;
102853 head = &net->dev_index_head[h];
102854 rcu_read_lock();
102855 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
102856 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
102857 net->dev_base_seq;
102858 hlist_for_each_entry_rcu(dev, head, index_hlist) {
102859 if (idx < s_idx)
102860 @@ -2396,7 +2396,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
102861 p.iph.ihl = 5;
102862 p.iph.protocol = IPPROTO_IPV6;
102863 p.iph.ttl = 64;
102864 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
102865 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
102866
102867 if (ops->ndo_do_ioctl) {
102868 mm_segment_t oldfs = get_fs();
102869 @@ -3534,16 +3534,23 @@ static const struct file_operations if6_fops = {
102870 .release = seq_release_net,
102871 };
102872
102873 +extern void register_ipv6_seq_ops_addr(struct seq_operations *addr);
102874 +extern void unregister_ipv6_seq_ops_addr(void);
102875 +
102876 static int __net_init if6_proc_net_init(struct net *net)
102877 {
102878 - if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops))
102879 + register_ipv6_seq_ops_addr(&if6_seq_ops);
102880 + if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops)) {
102881 + unregister_ipv6_seq_ops_addr();
102882 return -ENOMEM;
102883 + }
102884 return 0;
102885 }
102886
102887 static void __net_exit if6_proc_net_exit(struct net *net)
102888 {
102889 remove_proc_entry("if_inet6", net->proc_net);
102890 + unregister_ipv6_seq_ops_addr();
102891 }
102892
102893 static struct pernet_operations if6_proc_net_ops = {
102894 @@ -4159,7 +4166,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
102895 s_ip_idx = ip_idx = cb->args[2];
102896
102897 rcu_read_lock();
102898 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
102899 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
102900 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
102901 idx = 0;
102902 head = &net->dev_index_head[h];
102903 @@ -4788,7 +4795,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
102904 rt_genid_bump_ipv6(net);
102905 break;
102906 }
102907 - atomic_inc(&net->ipv6.dev_addr_genid);
102908 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
102909 }
102910
102911 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
102912 @@ -4808,7 +4815,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
102913 int *valp = ctl->data;
102914 int val = *valp;
102915 loff_t pos = *ppos;
102916 - struct ctl_table lctl;
102917 + ctl_table_no_const lctl;
102918 int ret;
102919
102920 /*
102921 @@ -4893,7 +4900,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
102922 int *valp = ctl->data;
102923 int val = *valp;
102924 loff_t pos = *ppos;
102925 - struct ctl_table lctl;
102926 + ctl_table_no_const lctl;
102927 int ret;
102928
102929 /*
102930 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
102931 index e8c4400..a4cd5da 100644
102932 --- a/net/ipv6/af_inet6.c
102933 +++ b/net/ipv6/af_inet6.c
102934 @@ -766,7 +766,7 @@ static int __net_init inet6_net_init(struct net *net)
102935 net->ipv6.sysctl.icmpv6_time = 1*HZ;
102936 net->ipv6.sysctl.flowlabel_consistency = 1;
102937 net->ipv6.sysctl.auto_flowlabels = 0;
102938 - atomic_set(&net->ipv6.fib6_sernum, 1);
102939 + atomic_set_unchecked(&net->ipv6.fib6_sernum, 1);
102940
102941 err = ipv6_init_mibs(net);
102942 if (err)
102943 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
102944 index 2cdc383..09cffb8 100644
102945 --- a/net/ipv6/datagram.c
102946 +++ b/net/ipv6/datagram.c
102947 @@ -928,5 +928,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
102948 0,
102949 sock_i_ino(sp),
102950 atomic_read(&sp->sk_refcnt), sp,
102951 - atomic_read(&sp->sk_drops));
102952 + atomic_read_unchecked(&sp->sk_drops));
102953 }
102954 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
102955 index 97ae700..18dcae0 100644
102956 --- a/net/ipv6/icmp.c
102957 +++ b/net/ipv6/icmp.c
102958 @@ -997,7 +997,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
102959
102960 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
102961 {
102962 - struct ctl_table *table;
102963 + ctl_table_no_const *table;
102964
102965 table = kmemdup(ipv6_icmp_table_template,
102966 sizeof(ipv6_icmp_table_template),
102967 diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
102968 index b2d1838..0194c04 100644
102969 --- a/net/ipv6/ip6_fib.c
102970 +++ b/net/ipv6/ip6_fib.c
102971 @@ -99,9 +99,9 @@ static int fib6_new_sernum(struct net *net)
102972 int new, old;
102973
102974 do {
102975 - old = atomic_read(&net->ipv6.fib6_sernum);
102976 + old = atomic_read_unchecked(&net->ipv6.fib6_sernum);
102977 new = old < INT_MAX ? old + 1 : 1;
102978 - } while (atomic_cmpxchg(&net->ipv6.fib6_sernum,
102979 + } while (atomic_cmpxchg_unchecked(&net->ipv6.fib6_sernum,
102980 old, new) != old);
102981 return new;
102982 }
102983 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
102984 index 0e32d2e..98cbe65 100644
102985 --- a/net/ipv6/ip6_gre.c
102986 +++ b/net/ipv6/ip6_gre.c
102987 @@ -71,8 +71,8 @@ struct ip6gre_net {
102988 struct net_device *fb_tunnel_dev;
102989 };
102990
102991 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
102992 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly;
102993 +static struct rtnl_link_ops ip6gre_link_ops;
102994 +static struct rtnl_link_ops ip6gre_tap_ops;
102995 static int ip6gre_tunnel_init(struct net_device *dev);
102996 static void ip6gre_tunnel_setup(struct net_device *dev);
102997 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
102998 @@ -1289,7 +1289,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
102999 }
103000
103001
103002 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
103003 +static struct inet6_protocol ip6gre_protocol = {
103004 .handler = ip6gre_rcv,
103005 .err_handler = ip6gre_err,
103006 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
103007 @@ -1650,7 +1650,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
103008 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
103009 };
103010
103011 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
103012 +static struct rtnl_link_ops ip6gre_link_ops = {
103013 .kind = "ip6gre",
103014 .maxtype = IFLA_GRE_MAX,
103015 .policy = ip6gre_policy,
103016 @@ -1664,7 +1664,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
103017 .fill_info = ip6gre_fill_info,
103018 };
103019
103020 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
103021 +static struct rtnl_link_ops ip6gre_tap_ops = {
103022 .kind = "ip6gretap",
103023 .maxtype = IFLA_GRE_MAX,
103024 .policy = ip6gre_policy,
103025 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
103026 index 9cb94cf..5678108 100644
103027 --- a/net/ipv6/ip6_tunnel.c
103028 +++ b/net/ipv6/ip6_tunnel.c
103029 @@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
103030
103031 static int ip6_tnl_dev_init(struct net_device *dev);
103032 static void ip6_tnl_dev_setup(struct net_device *dev);
103033 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
103034 +static struct rtnl_link_ops ip6_link_ops;
103035
103036 static int ip6_tnl_net_id __read_mostly;
103037 struct ip6_tnl_net {
103038 @@ -1706,7 +1706,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
103039 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
103040 };
103041
103042 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
103043 +static struct rtnl_link_ops ip6_link_ops = {
103044 .kind = "ip6tnl",
103045 .maxtype = IFLA_IPTUN_MAX,
103046 .policy = ip6_tnl_policy,
103047 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
103048 index bcda14d..49378c9 100644
103049 --- a/net/ipv6/ip6_vti.c
103050 +++ b/net/ipv6/ip6_vti.c
103051 @@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
103052
103053 static int vti6_dev_init(struct net_device *dev);
103054 static void vti6_dev_setup(struct net_device *dev);
103055 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
103056 +static struct rtnl_link_ops vti6_link_ops;
103057
103058 static int vti6_net_id __read_mostly;
103059 struct vti6_net {
103060 @@ -981,7 +981,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
103061 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
103062 };
103063
103064 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
103065 +static struct rtnl_link_ops vti6_link_ops = {
103066 .kind = "vti6",
103067 .maxtype = IFLA_VTI_MAX,
103068 .policy = vti6_policy,
103069 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
103070 index e1a9583..7dd8f4d 100644
103071 --- a/net/ipv6/ipv6_sockglue.c
103072 +++ b/net/ipv6/ipv6_sockglue.c
103073 @@ -993,7 +993,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
103074 if (sk->sk_type != SOCK_STREAM)
103075 return -ENOPROTOOPT;
103076
103077 - msg.msg_control = optval;
103078 + msg.msg_control = (void __force_kernel *)optval;
103079 msg.msg_controllen = len;
103080 msg.msg_flags = flags;
103081
103082 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
103083 index e080fbb..412b3cf 100644
103084 --- a/net/ipv6/netfilter/ip6_tables.c
103085 +++ b/net/ipv6/netfilter/ip6_tables.c
103086 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
103087 #endif
103088
103089 static int get_info(struct net *net, void __user *user,
103090 - const int *len, int compat)
103091 + int len, int compat)
103092 {
103093 char name[XT_TABLE_MAXNAMELEN];
103094 struct xt_table *t;
103095 int ret;
103096
103097 - if (*len != sizeof(struct ip6t_getinfo)) {
103098 - duprintf("length %u != %zu\n", *len,
103099 + if (len != sizeof(struct ip6t_getinfo)) {
103100 + duprintf("length %u != %zu\n", len,
103101 sizeof(struct ip6t_getinfo));
103102 return -EINVAL;
103103 }
103104 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
103105 info.size = private->size;
103106 strcpy(info.name, name);
103107
103108 - if (copy_to_user(user, &info, *len) != 0)
103109 + if (copy_to_user(user, &info, len) != 0)
103110 ret = -EFAULT;
103111 else
103112 ret = 0;
103113 @@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103114
103115 switch (cmd) {
103116 case IP6T_SO_GET_INFO:
103117 - ret = get_info(sock_net(sk), user, len, 1);
103118 + ret = get_info(sock_net(sk), user, *len, 1);
103119 break;
103120 case IP6T_SO_GET_ENTRIES:
103121 ret = compat_get_entries(sock_net(sk), user, len);
103122 @@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103123
103124 switch (cmd) {
103125 case IP6T_SO_GET_INFO:
103126 - ret = get_info(sock_net(sk), user, len, 0);
103127 + ret = get_info(sock_net(sk), user, *len, 0);
103128 break;
103129
103130 case IP6T_SO_GET_ENTRIES:
103131 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
103132 index 6f187c8..34b367f 100644
103133 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
103134 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
103135 @@ -96,12 +96,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
103136
103137 static int nf_ct_frag6_sysctl_register(struct net *net)
103138 {
103139 - struct ctl_table *table;
103140 + ctl_table_no_const *table = NULL;
103141 struct ctl_table_header *hdr;
103142
103143 - table = nf_ct_frag6_sysctl_table;
103144 if (!net_eq(net, &init_net)) {
103145 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
103146 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
103147 GFP_KERNEL);
103148 if (table == NULL)
103149 goto err_alloc;
103150 @@ -112,9 +111,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
103151 table[2].data = &net->nf_frag.frags.high_thresh;
103152 table[2].extra1 = &net->nf_frag.frags.low_thresh;
103153 table[2].extra2 = &init_net.nf_frag.frags.high_thresh;
103154 - }
103155 -
103156 - hdr = register_net_sysctl(net, "net/netfilter", table);
103157 + hdr = register_net_sysctl(net, "net/netfilter", table);
103158 + } else
103159 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
103160 if (hdr == NULL)
103161 goto err_reg;
103162
103163 @@ -122,8 +121,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
103164 return 0;
103165
103166 err_reg:
103167 - if (!net_eq(net, &init_net))
103168 - kfree(table);
103169 + kfree(table);
103170 err_alloc:
103171 return -ENOMEM;
103172 }
103173 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
103174 index 5b7a1ed..d9da205 100644
103175 --- a/net/ipv6/ping.c
103176 +++ b/net/ipv6/ping.c
103177 @@ -240,6 +240,24 @@ static struct pernet_operations ping_v6_net_ops = {
103178 };
103179 #endif
103180
103181 +static struct pingv6_ops real_pingv6_ops = {
103182 + .ipv6_recv_error = ipv6_recv_error,
103183 + .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
103184 + .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
103185 + .icmpv6_err_convert = icmpv6_err_convert,
103186 + .ipv6_icmp_error = ipv6_icmp_error,
103187 + .ipv6_chk_addr = ipv6_chk_addr,
103188 +};
103189 +
103190 +static struct pingv6_ops dummy_pingv6_ops = {
103191 + .ipv6_recv_error = dummy_ipv6_recv_error,
103192 + .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
103193 + .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
103194 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
103195 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
103196 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
103197 +};
103198 +
103199 int __init pingv6_init(void)
103200 {
103201 #ifdef CONFIG_PROC_FS
103202 @@ -247,13 +265,7 @@ int __init pingv6_init(void)
103203 if (ret)
103204 return ret;
103205 #endif
103206 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
103207 - pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
103208 - pingv6_ops.ip6_datagram_recv_specific_ctl =
103209 - ip6_datagram_recv_specific_ctl;
103210 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
103211 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
103212 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
103213 + pingv6_ops = &real_pingv6_ops;
103214 return inet6_register_protosw(&pingv6_protosw);
103215 }
103216
103217 @@ -262,14 +274,9 @@ int __init pingv6_init(void)
103218 */
103219 void pingv6_exit(void)
103220 {
103221 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
103222 - pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
103223 - pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
103224 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
103225 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
103226 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
103227 #ifdef CONFIG_PROC_FS
103228 unregister_pernet_subsys(&ping_v6_net_ops);
103229 #endif
103230 + pingv6_ops = &dummy_pingv6_ops;
103231 inet6_unregister_protosw(&pingv6_protosw);
103232 }
103233 diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
103234 index 1752cd0..3c6af41 100644
103235 --- a/net/ipv6/proc.c
103236 +++ b/net/ipv6/proc.c
103237 @@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
103238 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
103239 goto proc_snmp6_fail;
103240
103241 - net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
103242 + net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
103243 if (!net->mib.proc_net_devsnmp6)
103244 goto proc_dev_snmp6_fail;
103245 return 0;
103246 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
103247 index 896af88..6e2ba628 100644
103248 --- a/net/ipv6/raw.c
103249 +++ b/net/ipv6/raw.c
103250 @@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
103251 {
103252 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
103253 skb_checksum_complete(skb)) {
103254 - atomic_inc(&sk->sk_drops);
103255 + atomic_inc_unchecked(&sk->sk_drops);
103256 kfree_skb(skb);
103257 return NET_RX_DROP;
103258 }
103259 @@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
103260 struct raw6_sock *rp = raw6_sk(sk);
103261
103262 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
103263 - atomic_inc(&sk->sk_drops);
103264 + atomic_inc_unchecked(&sk->sk_drops);
103265 kfree_skb(skb);
103266 return NET_RX_DROP;
103267 }
103268 @@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
103269
103270 if (inet->hdrincl) {
103271 if (skb_checksum_complete(skb)) {
103272 - atomic_inc(&sk->sk_drops);
103273 + atomic_inc_unchecked(&sk->sk_drops);
103274 kfree_skb(skb);
103275 return NET_RX_DROP;
103276 }
103277 @@ -608,7 +608,7 @@ out:
103278 return err;
103279 }
103280
103281 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
103282 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
103283 struct flowi6 *fl6, struct dst_entry **dstp,
103284 unsigned int flags)
103285 {
103286 @@ -914,12 +914,15 @@ do_confirm:
103287 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
103288 char __user *optval, int optlen)
103289 {
103290 + struct icmp6_filter filter;
103291 +
103292 switch (optname) {
103293 case ICMPV6_FILTER:
103294 if (optlen > sizeof(struct icmp6_filter))
103295 optlen = sizeof(struct icmp6_filter);
103296 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
103297 + if (copy_from_user(&filter, optval, optlen))
103298 return -EFAULT;
103299 + raw6_sk(sk)->filter = filter;
103300 return 0;
103301 default:
103302 return -ENOPROTOOPT;
103303 @@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
103304 char __user *optval, int __user *optlen)
103305 {
103306 int len;
103307 + struct icmp6_filter filter;
103308
103309 switch (optname) {
103310 case ICMPV6_FILTER:
103311 @@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
103312 len = sizeof(struct icmp6_filter);
103313 if (put_user(len, optlen))
103314 return -EFAULT;
103315 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
103316 + filter = raw6_sk(sk)->filter;
103317 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
103318 return -EFAULT;
103319 return 0;
103320 default:
103321 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
103322 index 1a157ca..9fc05f4 100644
103323 --- a/net/ipv6/reassembly.c
103324 +++ b/net/ipv6/reassembly.c
103325 @@ -625,12 +625,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
103326
103327 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
103328 {
103329 - struct ctl_table *table;
103330 + ctl_table_no_const *table = NULL;
103331 struct ctl_table_header *hdr;
103332
103333 - table = ip6_frags_ns_ctl_table;
103334 if (!net_eq(net, &init_net)) {
103335 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
103336 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
103337 if (table == NULL)
103338 goto err_alloc;
103339
103340 @@ -644,9 +643,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
103341 /* Don't export sysctls to unprivileged users */
103342 if (net->user_ns != &init_user_ns)
103343 table[0].procname = NULL;
103344 - }
103345 + hdr = register_net_sysctl(net, "net/ipv6", table);
103346 + } else
103347 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
103348
103349 - hdr = register_net_sysctl(net, "net/ipv6", table);
103350 if (hdr == NULL)
103351 goto err_reg;
103352
103353 @@ -654,8 +654,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
103354 return 0;
103355
103356 err_reg:
103357 - if (!net_eq(net, &init_net))
103358 - kfree(table);
103359 + kfree(table);
103360 err_alloc:
103361 return -ENOMEM;
103362 }
103363 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
103364 index a318dd89..7ecfea6 100644
103365 --- a/net/ipv6/route.c
103366 +++ b/net/ipv6/route.c
103367 @@ -2965,7 +2965,7 @@ struct ctl_table ipv6_route_table_template[] = {
103368
103369 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
103370 {
103371 - struct ctl_table *table;
103372 + ctl_table_no_const *table;
103373
103374 table = kmemdup(ipv6_route_table_template,
103375 sizeof(ipv6_route_table_template),
103376 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
103377 index a24557a..00a9ed1 100644
103378 --- a/net/ipv6/sit.c
103379 +++ b/net/ipv6/sit.c
103380 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
103381 static void ipip6_dev_free(struct net_device *dev);
103382 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
103383 __be32 *v4dst);
103384 -static struct rtnl_link_ops sit_link_ops __read_mostly;
103385 +static struct rtnl_link_ops sit_link_ops;
103386
103387 static int sit_net_id __read_mostly;
103388 struct sit_net {
103389 @@ -1750,7 +1750,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
103390 unregister_netdevice_queue(dev, head);
103391 }
103392
103393 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
103394 +static struct rtnl_link_ops sit_link_ops = {
103395 .kind = "sit",
103396 .maxtype = IFLA_IPTUN_MAX,
103397 .policy = ipip6_policy,
103398 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
103399 index c5c10fa..2577d51 100644
103400 --- a/net/ipv6/sysctl_net_ipv6.c
103401 +++ b/net/ipv6/sysctl_net_ipv6.c
103402 @@ -78,7 +78,7 @@ static struct ctl_table ipv6_rotable[] = {
103403
103404 static int __net_init ipv6_sysctl_net_init(struct net *net)
103405 {
103406 - struct ctl_table *ipv6_table;
103407 + ctl_table_no_const *ipv6_table;
103408 struct ctl_table *ipv6_route_table;
103409 struct ctl_table *ipv6_icmp_table;
103410 int err;
103411 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
103412 index c277951..c7ee5bf 100644
103413 --- a/net/ipv6/tcp_ipv6.c
103414 +++ b/net/ipv6/tcp_ipv6.c
103415 @@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
103416 }
103417 }
103418
103419 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103420 +extern int grsec_enable_blackhole;
103421 +#endif
103422 +
103423 static void tcp_v6_hash(struct sock *sk)
103424 {
103425 if (sk->sk_state != TCP_CLOSE) {
103426 @@ -1341,6 +1345,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
103427 return 0;
103428
103429 reset:
103430 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103431 + if (!grsec_enable_blackhole)
103432 +#endif
103433 tcp_v6_send_reset(sk, skb);
103434 discard:
103435 if (opt_skb)
103436 @@ -1434,12 +1441,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
103437
103438 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest,
103439 tcp_v6_iif(skb));
103440 - if (!sk)
103441 + if (!sk) {
103442 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103443 + ret = 1;
103444 +#endif
103445 goto no_tcp_socket;
103446 + }
103447
103448 process:
103449 - if (sk->sk_state == TCP_TIME_WAIT)
103450 + if (sk->sk_state == TCP_TIME_WAIT) {
103451 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103452 + ret = 2;
103453 +#endif
103454 goto do_time_wait;
103455 + }
103456
103457 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
103458 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
103459 @@ -1486,6 +1501,10 @@ csum_error:
103460 bad_packet:
103461 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
103462 } else {
103463 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103464 + if (!grsec_enable_blackhole || (ret == 1 &&
103465 + (skb->dev->flags & IFF_LOOPBACK)))
103466 +#endif
103467 tcp_v6_send_reset(NULL, skb);
103468 }
103469
103470 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
103471 index f6ba535..b41033f 100644
103472 --- a/net/ipv6/udp.c
103473 +++ b/net/ipv6/udp.c
103474 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
103475 udp_ipv6_hash_secret + net_hash_mix(net));
103476 }
103477
103478 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103479 +extern int grsec_enable_blackhole;
103480 +#endif
103481 +
103482 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
103483 {
103484 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
103485 @@ -434,7 +438,7 @@ try_again:
103486 if (unlikely(err)) {
103487 trace_kfree_skb(skb, udpv6_recvmsg);
103488 if (!peeked) {
103489 - atomic_inc(&sk->sk_drops);
103490 + atomic_inc_unchecked(&sk->sk_drops);
103491 if (is_udp4)
103492 UDP_INC_STATS_USER(sock_net(sk),
103493 UDP_MIB_INERRORS,
103494 @@ -701,7 +705,7 @@ csum_error:
103495 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
103496 drop:
103497 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
103498 - atomic_inc(&sk->sk_drops);
103499 + atomic_inc_unchecked(&sk->sk_drops);
103500 kfree_skb(skb);
103501 return -1;
103502 }
103503 @@ -740,7 +744,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
103504 if (likely(skb1 == NULL))
103505 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
103506 if (!skb1) {
103507 - atomic_inc(&sk->sk_drops);
103508 + atomic_inc_unchecked(&sk->sk_drops);
103509 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
103510 IS_UDPLITE(sk));
103511 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103512 @@ -919,6 +923,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
103513 goto csum_error;
103514
103515 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
103516 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103517 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
103518 +#endif
103519 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
103520
103521 kfree_skb(skb);
103522 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
103523 index 5f98364..5ca982a 100644
103524 --- a/net/ipv6/xfrm6_policy.c
103525 +++ b/net/ipv6/xfrm6_policy.c
103526 @@ -130,8 +130,8 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
103527 {
103528 struct flowi6 *fl6 = &fl->u.ip6;
103529 int onlyproto = 0;
103530 - u16 offset = skb_network_header_len(skb);
103531 const struct ipv6hdr *hdr = ipv6_hdr(skb);
103532 + u16 offset = sizeof(*hdr);
103533 struct ipv6_opt_hdr *exthdr;
103534 const unsigned char *nh = skb_network_header(skb);
103535 u8 nexthdr = nh[IP6CB(skb)->nhoff];
103536 @@ -217,11 +217,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
103537 }
103538 }
103539
103540 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
103541 +static int xfrm6_garbage_collect(struct dst_ops *ops)
103542 {
103543 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
103544
103545 - xfrm6_policy_afinfo.garbage_collect(net);
103546 + xfrm_garbage_collect_deferred(net);
103547 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
103548 }
103549
103550 @@ -334,19 +334,19 @@ static struct ctl_table xfrm6_policy_table[] = {
103551
103552 static int __net_init xfrm6_net_init(struct net *net)
103553 {
103554 - struct ctl_table *table;
103555 + ctl_table_no_const *table = NULL;
103556 struct ctl_table_header *hdr;
103557
103558 - table = xfrm6_policy_table;
103559 if (!net_eq(net, &init_net)) {
103560 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
103561 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
103562 if (!table)
103563 goto err_alloc;
103564
103565 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
103566 - }
103567 + hdr = register_net_sysctl(net, "net/ipv6", table);
103568 + } else
103569 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
103570
103571 - hdr = register_net_sysctl(net, "net/ipv6", table);
103572 if (!hdr)
103573 goto err_reg;
103574
103575 @@ -354,8 +354,7 @@ static int __net_init xfrm6_net_init(struct net *net)
103576 return 0;
103577
103578 err_reg:
103579 - if (!net_eq(net, &init_net))
103580 - kfree(table);
103581 + kfree(table);
103582 err_alloc:
103583 return -ENOMEM;
103584 }
103585 diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
103586 index e15c16a..7cf07aa 100644
103587 --- a/net/ipx/ipx_proc.c
103588 +++ b/net/ipx/ipx_proc.c
103589 @@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
103590 struct proc_dir_entry *p;
103591 int rc = -ENOMEM;
103592
103593 - ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
103594 + ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
103595
103596 if (!ipx_proc_dir)
103597 goto out;
103598 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
103599 index 61ceb4c..e788eb8 100644
103600 --- a/net/irda/ircomm/ircomm_tty.c
103601 +++ b/net/irda/ircomm/ircomm_tty.c
103602 @@ -317,10 +317,10 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
103603 add_wait_queue(&port->open_wait, &wait);
103604
103605 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
103606 - __FILE__, __LINE__, tty->driver->name, port->count);
103607 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
103608
103609 spin_lock_irqsave(&port->lock, flags);
103610 - port->count--;
103611 + atomic_dec(&port->count);
103612 port->blocked_open++;
103613 spin_unlock_irqrestore(&port->lock, flags);
103614
103615 @@ -355,7 +355,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
103616 }
103617
103618 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
103619 - __FILE__, __LINE__, tty->driver->name, port->count);
103620 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
103621
103622 schedule();
103623 }
103624 @@ -365,12 +365,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
103625
103626 spin_lock_irqsave(&port->lock, flags);
103627 if (!tty_hung_up_p(filp))
103628 - port->count++;
103629 + atomic_inc(&port->count);
103630 port->blocked_open--;
103631 spin_unlock_irqrestore(&port->lock, flags);
103632
103633 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
103634 - __FILE__, __LINE__, tty->driver->name, port->count);
103635 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
103636
103637 if (!retval)
103638 port->flags |= ASYNC_NORMAL_ACTIVE;
103639 @@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
103640
103641 /* ++ is not atomic, so this should be protected - Jean II */
103642 spin_lock_irqsave(&self->port.lock, flags);
103643 - self->port.count++;
103644 + atomic_inc(&self->port.count);
103645 spin_unlock_irqrestore(&self->port.lock, flags);
103646 tty_port_tty_set(&self->port, tty);
103647
103648 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
103649 - self->line, self->port.count);
103650 + self->line, atomic_read(&self->port.count));
103651
103652 /* Not really used by us, but lets do it anyway */
103653 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
103654 @@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
103655 tty_kref_put(port->tty);
103656 }
103657 port->tty = NULL;
103658 - port->count = 0;
103659 + atomic_set(&port->count, 0);
103660 spin_unlock_irqrestore(&port->lock, flags);
103661
103662 wake_up_interruptible(&port->open_wait);
103663 @@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
103664 seq_putc(m, '\n');
103665
103666 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
103667 - seq_printf(m, "Open count: %d\n", self->port.count);
103668 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
103669 seq_printf(m, "Max data size: %d\n", self->max_data_size);
103670 seq_printf(m, "Max header size: %d\n", self->max_header_size);
103671
103672 diff --git a/net/irda/irproc.c b/net/irda/irproc.c
103673 index b9ac598..f88cc56 100644
103674 --- a/net/irda/irproc.c
103675 +++ b/net/irda/irproc.c
103676 @@ -66,7 +66,7 @@ void __init irda_proc_register(void)
103677 {
103678 int i;
103679
103680 - proc_irda = proc_mkdir("irda", init_net.proc_net);
103681 + proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
103682 if (proc_irda == NULL)
103683 return;
103684
103685 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
103686 index a089b6b..3ca3b60 100644
103687 --- a/net/iucv/af_iucv.c
103688 +++ b/net/iucv/af_iucv.c
103689 @@ -686,10 +686,10 @@ static void __iucv_auto_name(struct iucv_sock *iucv)
103690 {
103691 char name[12];
103692
103693 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
103694 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
103695 while (__iucv_get_sock_by_name(name)) {
103696 sprintf(name, "%08x",
103697 - atomic_inc_return(&iucv_sk_list.autobind_name));
103698 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
103699 }
103700 memcpy(iucv->src_name, name, 8);
103701 }
103702 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
103703 index 2a6a1fd..6c112b0 100644
103704 --- a/net/iucv/iucv.c
103705 +++ b/net/iucv/iucv.c
103706 @@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
103707 return NOTIFY_OK;
103708 }
103709
103710 -static struct notifier_block __refdata iucv_cpu_notifier = {
103711 +static struct notifier_block iucv_cpu_notifier = {
103712 .notifier_call = iucv_cpu_notify,
103713 };
103714
103715 diff --git a/net/key/af_key.c b/net/key/af_key.c
103716 index 1847ec4..26ef732 100644
103717 --- a/net/key/af_key.c
103718 +++ b/net/key/af_key.c
103719 @@ -3049,10 +3049,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
103720 static u32 get_acqseq(void)
103721 {
103722 u32 res;
103723 - static atomic_t acqseq;
103724 + static atomic_unchecked_t acqseq;
103725
103726 do {
103727 - res = atomic_inc_return(&acqseq);
103728 + res = atomic_inc_return_unchecked(&acqseq);
103729 } while (!res);
103730 return res;
103731 }
103732 diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
103733 index edb78e6..8dc654a 100644
103734 --- a/net/l2tp/l2tp_eth.c
103735 +++ b/net/l2tp/l2tp_eth.c
103736 @@ -42,12 +42,12 @@ struct l2tp_eth {
103737 struct sock *tunnel_sock;
103738 struct l2tp_session *session;
103739 struct list_head list;
103740 - atomic_long_t tx_bytes;
103741 - atomic_long_t tx_packets;
103742 - atomic_long_t tx_dropped;
103743 - atomic_long_t rx_bytes;
103744 - atomic_long_t rx_packets;
103745 - atomic_long_t rx_errors;
103746 + atomic_long_unchecked_t tx_bytes;
103747 + atomic_long_unchecked_t tx_packets;
103748 + atomic_long_unchecked_t tx_dropped;
103749 + atomic_long_unchecked_t rx_bytes;
103750 + atomic_long_unchecked_t rx_packets;
103751 + atomic_long_unchecked_t rx_errors;
103752 };
103753
103754 /* via l2tp_session_priv() */
103755 @@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
103756 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
103757
103758 if (likely(ret == NET_XMIT_SUCCESS)) {
103759 - atomic_long_add(len, &priv->tx_bytes);
103760 - atomic_long_inc(&priv->tx_packets);
103761 + atomic_long_add_unchecked(len, &priv->tx_bytes);
103762 + atomic_long_inc_unchecked(&priv->tx_packets);
103763 } else {
103764 - atomic_long_inc(&priv->tx_dropped);
103765 + atomic_long_inc_unchecked(&priv->tx_dropped);
103766 }
103767 return NETDEV_TX_OK;
103768 }
103769 @@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
103770 {
103771 struct l2tp_eth *priv = netdev_priv(dev);
103772
103773 - stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
103774 - stats->tx_packets = atomic_long_read(&priv->tx_packets);
103775 - stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
103776 - stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
103777 - stats->rx_packets = atomic_long_read(&priv->rx_packets);
103778 - stats->rx_errors = atomic_long_read(&priv->rx_errors);
103779 + stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
103780 + stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
103781 + stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
103782 + stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
103783 + stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
103784 + stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
103785 return stats;
103786 }
103787
103788 @@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
103789 nf_reset(skb);
103790
103791 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
103792 - atomic_long_inc(&priv->rx_packets);
103793 - atomic_long_add(data_len, &priv->rx_bytes);
103794 + atomic_long_inc_unchecked(&priv->rx_packets);
103795 + atomic_long_add_unchecked(data_len, &priv->rx_bytes);
103796 } else {
103797 - atomic_long_inc(&priv->rx_errors);
103798 + atomic_long_inc_unchecked(&priv->rx_errors);
103799 }
103800 return;
103801
103802 error:
103803 - atomic_long_inc(&priv->rx_errors);
103804 + atomic_long_inc_unchecked(&priv->rx_errors);
103805 kfree_skb(skb);
103806 }
103807
103808 diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
103809 index 1a3c7e0..80f8b0c 100644
103810 --- a/net/llc/llc_proc.c
103811 +++ b/net/llc/llc_proc.c
103812 @@ -247,7 +247,7 @@ int __init llc_proc_init(void)
103813 int rc = -ENOMEM;
103814 struct proc_dir_entry *p;
103815
103816 - llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
103817 + llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
103818 if (!llc_proc_dir)
103819 goto out;
103820
103821 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
103822 index 343da1e..509873f 100644
103823 --- a/net/mac80211/cfg.c
103824 +++ b/net/mac80211/cfg.c
103825 @@ -541,7 +541,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
103826 ret = ieee80211_vif_use_channel(sdata, chandef,
103827 IEEE80211_CHANCTX_EXCLUSIVE);
103828 }
103829 - } else if (local->open_count == local->monitors) {
103830 + } else if (local_read(&local->open_count) == local->monitors) {
103831 local->_oper_chandef = *chandef;
103832 ieee80211_hw_config(local, 0);
103833 }
103834 @@ -3326,7 +3326,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
103835 else
103836 local->probe_req_reg--;
103837
103838 - if (!local->open_count)
103839 + if (!local_read(&local->open_count))
103840 break;
103841
103842 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
103843 @@ -3460,8 +3460,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
103844 if (chanctx_conf) {
103845 *chandef = sdata->vif.bss_conf.chandef;
103846 ret = 0;
103847 - } else if (local->open_count > 0 &&
103848 - local->open_count == local->monitors &&
103849 + } else if (local_read(&local->open_count) > 0 &&
103850 + local_read(&local->open_count) == local->monitors &&
103851 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
103852 if (local->use_chanctx)
103853 *chandef = local->monitor_chandef;
103854 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
103855 index 8c68da3..0695016 100644
103856 --- a/net/mac80211/ieee80211_i.h
103857 +++ b/net/mac80211/ieee80211_i.h
103858 @@ -29,6 +29,7 @@
103859 #include <net/ieee80211_radiotap.h>
103860 #include <net/cfg80211.h>
103861 #include <net/mac80211.h>
103862 +#include <asm/local.h>
103863 #include "key.h"
103864 #include "sta_info.h"
103865 #include "debug.h"
103866 @@ -1057,7 +1058,7 @@ struct ieee80211_local {
103867 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
103868 spinlock_t queue_stop_reason_lock;
103869
103870 - int open_count;
103871 + local_t open_count;
103872 int monitors, cooked_mntrs;
103873 /* number of interfaces with corresponding FIF_ flags */
103874 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
103875 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
103876 index 653f5eb..02994ee 100644
103877 --- a/net/mac80211/iface.c
103878 +++ b/net/mac80211/iface.c
103879 @@ -532,7 +532,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
103880 break;
103881 }
103882
103883 - if (local->open_count == 0) {
103884 + if (local_read(&local->open_count) == 0) {
103885 res = drv_start(local);
103886 if (res)
103887 goto err_del_bss;
103888 @@ -579,7 +579,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
103889 res = drv_add_interface(local, sdata);
103890 if (res)
103891 goto err_stop;
103892 - } else if (local->monitors == 0 && local->open_count == 0) {
103893 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
103894 res = ieee80211_add_virtual_monitor(local);
103895 if (res)
103896 goto err_stop;
103897 @@ -688,7 +688,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
103898 atomic_inc(&local->iff_promiscs);
103899
103900 if (coming_up)
103901 - local->open_count++;
103902 + local_inc(&local->open_count);
103903
103904 if (hw_reconf_flags)
103905 ieee80211_hw_config(local, hw_reconf_flags);
103906 @@ -726,7 +726,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
103907 err_del_interface:
103908 drv_remove_interface(local, sdata);
103909 err_stop:
103910 - if (!local->open_count)
103911 + if (!local_read(&local->open_count))
103912 drv_stop(local);
103913 err_del_bss:
103914 sdata->bss = NULL;
103915 @@ -892,7 +892,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
103916 }
103917
103918 if (going_down)
103919 - local->open_count--;
103920 + local_dec(&local->open_count);
103921
103922 switch (sdata->vif.type) {
103923 case NL80211_IFTYPE_AP_VLAN:
103924 @@ -954,7 +954,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
103925 }
103926 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
103927
103928 - if (local->open_count == 0)
103929 + if (local_read(&local->open_count) == 0)
103930 ieee80211_clear_tx_pending(local);
103931
103932 /*
103933 @@ -997,7 +997,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
103934 if (cancel_scan)
103935 flush_delayed_work(&local->scan_work);
103936
103937 - if (local->open_count == 0) {
103938 + if (local_read(&local->open_count) == 0) {
103939 ieee80211_stop_device(local);
103940
103941 /* no reconfiguring after stop! */
103942 @@ -1008,7 +1008,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
103943 ieee80211_configure_filter(local);
103944 ieee80211_hw_config(local, hw_reconf_flags);
103945
103946 - if (local->monitors == local->open_count)
103947 + if (local->monitors == local_read(&local->open_count))
103948 ieee80211_add_virtual_monitor(local);
103949 }
103950
103951 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
103952 index 0de7c93..884b2ca 100644
103953 --- a/net/mac80211/main.c
103954 +++ b/net/mac80211/main.c
103955 @@ -175,7 +175,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
103956 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
103957 IEEE80211_CONF_CHANGE_POWER);
103958
103959 - if (changed && local->open_count) {
103960 + if (changed && local_read(&local->open_count)) {
103961 ret = drv_config(local, changed);
103962 /*
103963 * Goal:
103964 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
103965 index 4c5192e..04cc0d8 100644
103966 --- a/net/mac80211/pm.c
103967 +++ b/net/mac80211/pm.c
103968 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
103969 struct ieee80211_sub_if_data *sdata;
103970 struct sta_info *sta;
103971
103972 - if (!local->open_count)
103973 + if (!local_read(&local->open_count))
103974 goto suspend;
103975
103976 ieee80211_scan_cancel(local);
103977 @@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
103978 cancel_work_sync(&local->dynamic_ps_enable_work);
103979 del_timer_sync(&local->dynamic_ps_timer);
103980
103981 - local->wowlan = wowlan && local->open_count;
103982 + local->wowlan = wowlan && local_read(&local->open_count);
103983 if (local->wowlan) {
103984 int err = drv_suspend(local, wowlan);
103985 if (err < 0) {
103986 @@ -125,7 +125,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
103987 WARN_ON(!list_empty(&local->chanctx_list));
103988
103989 /* stop hardware - this must stop RX */
103990 - if (local->open_count)
103991 + if (local_read(&local->open_count))
103992 ieee80211_stop_device(local);
103993
103994 suspend:
103995 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
103996 index 6081329..ab23834 100644
103997 --- a/net/mac80211/rate.c
103998 +++ b/net/mac80211/rate.c
103999 @@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
104000
104001 ASSERT_RTNL();
104002
104003 - if (local->open_count)
104004 + if (local_read(&local->open_count))
104005 return -EBUSY;
104006
104007 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
104008 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
104009 index 3c61060..7bed2e3 100644
104010 --- a/net/mac80211/util.c
104011 +++ b/net/mac80211/util.c
104012 @@ -1669,7 +1669,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
104013 }
104014 #endif
104015 /* everything else happens only if HW was up & running */
104016 - if (!local->open_count)
104017 + if (!local_read(&local->open_count))
104018 goto wake_up;
104019
104020 /*
104021 @@ -1895,7 +1895,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
104022 local->in_reconfig = false;
104023 barrier();
104024
104025 - if (local->monitors == local->open_count && local->monitors > 0)
104026 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
104027 ieee80211_add_virtual_monitor(local);
104028
104029 /*
104030 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
104031 index ae5096ab..e5aa70a 100644
104032 --- a/net/netfilter/Kconfig
104033 +++ b/net/netfilter/Kconfig
104034 @@ -1105,6 +1105,16 @@ config NETFILTER_XT_MATCH_ESP
104035
104036 To compile it as a module, choose M here. If unsure, say N.
104037
104038 +config NETFILTER_XT_MATCH_GRADM
104039 + tristate '"gradm" match support'
104040 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
104041 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
104042 + ---help---
104043 + The gradm match allows to match on grsecurity RBAC being enabled.
104044 + It is useful when iptables rules are applied early on bootup to
104045 + prevent connections to the machine (except from a trusted host)
104046 + while the RBAC system is disabled.
104047 +
104048 config NETFILTER_XT_MATCH_HASHLIMIT
104049 tristate '"hashlimit" match support'
104050 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
104051 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
104052 index a9571be..c59e173 100644
104053 --- a/net/netfilter/Makefile
104054 +++ b/net/netfilter/Makefile
104055 @@ -137,6 +137,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
104056 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
104057 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
104058 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
104059 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
104060 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
104061 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
104062 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
104063 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
104064 index d259da3..6a32b2c 100644
104065 --- a/net/netfilter/ipset/ip_set_core.c
104066 +++ b/net/netfilter/ipset/ip_set_core.c
104067 @@ -1952,7 +1952,7 @@ done:
104068 return ret;
104069 }
104070
104071 -static struct nf_sockopt_ops so_set __read_mostly = {
104072 +static struct nf_sockopt_ops so_set = {
104073 .pf = PF_INET,
104074 .get_optmin = SO_IP_SET,
104075 .get_optmax = SO_IP_SET + 1,
104076 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
104077 index b0f7b62..0541842 100644
104078 --- a/net/netfilter/ipvs/ip_vs_conn.c
104079 +++ b/net/netfilter/ipvs/ip_vs_conn.c
104080 @@ -572,7 +572,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
104081 /* Increase the refcnt counter of the dest */
104082 ip_vs_dest_hold(dest);
104083
104084 - conn_flags = atomic_read(&dest->conn_flags);
104085 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
104086 if (cp->protocol != IPPROTO_UDP)
104087 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
104088 flags = cp->flags;
104089 @@ -922,7 +922,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af,
104090
104091 cp->control = NULL;
104092 atomic_set(&cp->n_control, 0);
104093 - atomic_set(&cp->in_pkts, 0);
104094 + atomic_set_unchecked(&cp->in_pkts, 0);
104095
104096 cp->packet_xmit = NULL;
104097 cp->app = NULL;
104098 @@ -1229,7 +1229,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
104099
104100 /* Don't drop the entry if its number of incoming packets is not
104101 located in [0, 8] */
104102 - i = atomic_read(&cp->in_pkts);
104103 + i = atomic_read_unchecked(&cp->in_pkts);
104104 if (i > 8 || i < 0) return 0;
104105
104106 if (!todrop_rate[i]) return 0;
104107 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
104108 index 990decb..5075248 100644
104109 --- a/net/netfilter/ipvs/ip_vs_core.c
104110 +++ b/net/netfilter/ipvs/ip_vs_core.c
104111 @@ -568,7 +568,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
104112 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
104113 /* do not touch skb anymore */
104114
104115 - atomic_inc(&cp->in_pkts);
104116 + atomic_inc_unchecked(&cp->in_pkts);
104117 ip_vs_conn_put(cp);
104118 return ret;
104119 }
104120 @@ -1712,7 +1712,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
104121 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
104122 pkts = sysctl_sync_threshold(ipvs);
104123 else
104124 - pkts = atomic_add_return(1, &cp->in_pkts);
104125 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
104126
104127 if (ipvs->sync_state & IP_VS_STATE_MASTER)
104128 ip_vs_sync_conn(net, cp, pkts);
104129 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
104130 index ac7ba68..9735acb9 100644
104131 --- a/net/netfilter/ipvs/ip_vs_ctl.c
104132 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
104133 @@ -800,7 +800,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
104134 */
104135 ip_vs_rs_hash(ipvs, dest);
104136 }
104137 - atomic_set(&dest->conn_flags, conn_flags);
104138 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
104139
104140 /* bind the service */
104141 old_svc = rcu_dereference_protected(dest->svc, 1);
104142 @@ -1665,7 +1665,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
104143 * align with netns init in ip_vs_control_net_init()
104144 */
104145
104146 -static struct ctl_table vs_vars[] = {
104147 +static ctl_table_no_const vs_vars[] __read_only = {
104148 {
104149 .procname = "amemthresh",
104150 .maxlen = sizeof(int),
104151 @@ -2000,7 +2000,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
104152 " %-7s %-6d %-10d %-10d\n",
104153 &dest->addr.in6,
104154 ntohs(dest->port),
104155 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
104156 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
104157 atomic_read(&dest->weight),
104158 atomic_read(&dest->activeconns),
104159 atomic_read(&dest->inactconns));
104160 @@ -2011,7 +2011,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
104161 "%-7s %-6d %-10d %-10d\n",
104162 ntohl(dest->addr.ip),
104163 ntohs(dest->port),
104164 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
104165 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
104166 atomic_read(&dest->weight),
104167 atomic_read(&dest->activeconns),
104168 atomic_read(&dest->inactconns));
104169 @@ -2500,7 +2500,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
104170
104171 entry.addr = dest->addr.ip;
104172 entry.port = dest->port;
104173 - entry.conn_flags = atomic_read(&dest->conn_flags);
104174 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
104175 entry.weight = atomic_read(&dest->weight);
104176 entry.u_threshold = dest->u_threshold;
104177 entry.l_threshold = dest->l_threshold;
104178 @@ -3040,7 +3040,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
104179 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
104180 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
104181 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
104182 - (atomic_read(&dest->conn_flags) &
104183 + (atomic_read_unchecked(&dest->conn_flags) &
104184 IP_VS_CONN_F_FWD_MASK)) ||
104185 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
104186 atomic_read(&dest->weight)) ||
104187 @@ -3673,7 +3673,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
104188 {
104189 int idx;
104190 struct netns_ipvs *ipvs = net_ipvs(net);
104191 - struct ctl_table *tbl;
104192 + ctl_table_no_const *tbl;
104193
104194 atomic_set(&ipvs->dropentry, 0);
104195 spin_lock_init(&ipvs->dropentry_lock);
104196 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
104197 index 127f140..553d652 100644
104198 --- a/net/netfilter/ipvs/ip_vs_lblc.c
104199 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
104200 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
104201 * IPVS LBLC sysctl table
104202 */
104203 #ifdef CONFIG_SYSCTL
104204 -static struct ctl_table vs_vars_table[] = {
104205 +static ctl_table_no_const vs_vars_table[] __read_only = {
104206 {
104207 .procname = "lblc_expiration",
104208 .data = NULL,
104209 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
104210 index 2229d2d..b32b785 100644
104211 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
104212 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
104213 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
104214 * IPVS LBLCR sysctl table
104215 */
104216
104217 -static struct ctl_table vs_vars_table[] = {
104218 +static ctl_table_no_const vs_vars_table[] __read_only = {
104219 {
104220 .procname = "lblcr_expiration",
104221 .data = NULL,
104222 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
104223 index 7162c86..9eeb60e 100644
104224 --- a/net/netfilter/ipvs/ip_vs_sync.c
104225 +++ b/net/netfilter/ipvs/ip_vs_sync.c
104226 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
104227 cp = cp->control;
104228 if (cp) {
104229 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
104230 - pkts = atomic_add_return(1, &cp->in_pkts);
104231 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
104232 else
104233 pkts = sysctl_sync_threshold(ipvs);
104234 ip_vs_sync_conn(net, cp->control, pkts);
104235 @@ -771,7 +771,7 @@ control:
104236 if (!cp)
104237 return;
104238 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
104239 - pkts = atomic_add_return(1, &cp->in_pkts);
104240 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
104241 else
104242 pkts = sysctl_sync_threshold(ipvs);
104243 goto sloop;
104244 @@ -901,7 +901,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
104245
104246 if (opt)
104247 memcpy(&cp->in_seq, opt, sizeof(*opt));
104248 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
104249 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
104250 cp->state = state;
104251 cp->old_state = cp->state;
104252 /*
104253 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
104254 index bd90bf8..816a020d 100644
104255 --- a/net/netfilter/ipvs/ip_vs_xmit.c
104256 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
104257 @@ -1215,7 +1215,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
104258 else
104259 rc = NF_ACCEPT;
104260 /* do not touch skb anymore */
104261 - atomic_inc(&cp->in_pkts);
104262 + atomic_inc_unchecked(&cp->in_pkts);
104263 goto out;
104264 }
104265
104266 @@ -1308,7 +1308,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
104267 else
104268 rc = NF_ACCEPT;
104269 /* do not touch skb anymore */
104270 - atomic_inc(&cp->in_pkts);
104271 + atomic_inc_unchecked(&cp->in_pkts);
104272 goto out;
104273 }
104274
104275 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
104276 index a4b5e2a..13b1de3 100644
104277 --- a/net/netfilter/nf_conntrack_acct.c
104278 +++ b/net/netfilter/nf_conntrack_acct.c
104279 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
104280 #ifdef CONFIG_SYSCTL
104281 static int nf_conntrack_acct_init_sysctl(struct net *net)
104282 {
104283 - struct ctl_table *table;
104284 + ctl_table_no_const *table;
104285
104286 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
104287 GFP_KERNEL);
104288 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
104289 index 5016a69..594f8e9 100644
104290 --- a/net/netfilter/nf_conntrack_core.c
104291 +++ b/net/netfilter/nf_conntrack_core.c
104292 @@ -1739,6 +1739,10 @@ void nf_conntrack_init_end(void)
104293 #define DYING_NULLS_VAL ((1<<30)+1)
104294 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
104295
104296 +#ifdef CONFIG_GRKERNSEC_HIDESYM
104297 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
104298 +#endif
104299 +
104300 int nf_conntrack_init_net(struct net *net)
104301 {
104302 int ret = -ENOMEM;
104303 @@ -1764,7 +1768,11 @@ int nf_conntrack_init_net(struct net *net)
104304 if (!net->ct.stat)
104305 goto err_pcpu_lists;
104306
104307 +#ifdef CONFIG_GRKERNSEC_HIDESYM
104308 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08x", atomic_inc_return_unchecked(&conntrack_cache_id));
104309 +#else
104310 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
104311 +#endif
104312 if (!net->ct.slabname)
104313 goto err_slabname;
104314
104315 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
104316 index 4e78c57..ec8fb74 100644
104317 --- a/net/netfilter/nf_conntrack_ecache.c
104318 +++ b/net/netfilter/nf_conntrack_ecache.c
104319 @@ -264,7 +264,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
104320 #ifdef CONFIG_SYSCTL
104321 static int nf_conntrack_event_init_sysctl(struct net *net)
104322 {
104323 - struct ctl_table *table;
104324 + ctl_table_no_const *table;
104325
104326 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
104327 GFP_KERNEL);
104328 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
104329 index 5b3eae7..dd4b8fe 100644
104330 --- a/net/netfilter/nf_conntrack_helper.c
104331 +++ b/net/netfilter/nf_conntrack_helper.c
104332 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
104333
104334 static int nf_conntrack_helper_init_sysctl(struct net *net)
104335 {
104336 - struct ctl_table *table;
104337 + ctl_table_no_const *table;
104338
104339 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
104340 GFP_KERNEL);
104341 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
104342 index b65d586..beec902 100644
104343 --- a/net/netfilter/nf_conntrack_proto.c
104344 +++ b/net/netfilter/nf_conntrack_proto.c
104345 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
104346
104347 static void
104348 nf_ct_unregister_sysctl(struct ctl_table_header **header,
104349 - struct ctl_table **table,
104350 + ctl_table_no_const **table,
104351 unsigned int users)
104352 {
104353 if (users > 0)
104354 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
104355 index cf65a1e..2f291e9 100644
104356 --- a/net/netfilter/nf_conntrack_standalone.c
104357 +++ b/net/netfilter/nf_conntrack_standalone.c
104358 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
104359
104360 static int nf_conntrack_standalone_init_sysctl(struct net *net)
104361 {
104362 - struct ctl_table *table;
104363 + ctl_table_no_const *table;
104364
104365 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
104366 GFP_KERNEL);
104367 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
104368 index 7a394df..bd91a8a 100644
104369 --- a/net/netfilter/nf_conntrack_timestamp.c
104370 +++ b/net/netfilter/nf_conntrack_timestamp.c
104371 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
104372 #ifdef CONFIG_SYSCTL
104373 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
104374 {
104375 - struct ctl_table *table;
104376 + ctl_table_no_const *table;
104377
104378 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
104379 GFP_KERNEL);
104380 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
104381 index d719764..311bc60 100644
104382 --- a/net/netfilter/nf_log.c
104383 +++ b/net/netfilter/nf_log.c
104384 @@ -353,7 +353,7 @@ static const struct file_operations nflog_file_ops = {
104385
104386 #ifdef CONFIG_SYSCTL
104387 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
104388 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
104389 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
104390
104391 static int nf_log_proc_dostring(struct ctl_table *table, int write,
104392 void __user *buffer, size_t *lenp, loff_t *ppos)
104393 @@ -384,14 +384,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
104394 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
104395 mutex_unlock(&nf_log_mutex);
104396 } else {
104397 + ctl_table_no_const nf_log_table = *table;
104398 +
104399 mutex_lock(&nf_log_mutex);
104400 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
104401 lockdep_is_held(&nf_log_mutex));
104402 if (!logger)
104403 - table->data = "NONE";
104404 + nf_log_table.data = "NONE";
104405 else
104406 - table->data = logger->name;
104407 - r = proc_dostring(table, write, buffer, lenp, ppos);
104408 + nf_log_table.data = logger->name;
104409 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
104410 mutex_unlock(&nf_log_mutex);
104411 }
104412
104413 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
104414 index c68c1e5..8b5d670 100644
104415 --- a/net/netfilter/nf_sockopt.c
104416 +++ b/net/netfilter/nf_sockopt.c
104417 @@ -43,7 +43,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
104418 }
104419 }
104420
104421 - list_add(&reg->list, &nf_sockopts);
104422 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
104423 out:
104424 mutex_unlock(&nf_sockopt_mutex);
104425 return ret;
104426 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
104427 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
104428 {
104429 mutex_lock(&nf_sockopt_mutex);
104430 - list_del(&reg->list);
104431 + pax_list_del((struct list_head *)&reg->list);
104432 mutex_unlock(&nf_sockopt_mutex);
104433 }
104434 EXPORT_SYMBOL(nf_unregister_sockopt);
104435 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
104436 index 5f1be5b..2cba8cd 100644
104437 --- a/net/netfilter/nfnetlink_log.c
104438 +++ b/net/netfilter/nfnetlink_log.c
104439 @@ -80,7 +80,7 @@ static int nfnl_log_net_id __read_mostly;
104440 struct nfnl_log_net {
104441 spinlock_t instances_lock;
104442 struct hlist_head instance_table[INSTANCE_BUCKETS];
104443 - atomic_t global_seq;
104444 + atomic_unchecked_t global_seq;
104445 };
104446
104447 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
104448 @@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
104449 /* global sequence number */
104450 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
104451 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
104452 - htonl(atomic_inc_return(&log->global_seq))))
104453 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
104454 goto nla_put_failure;
104455
104456 if (data_len) {
104457 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
104458 new file mode 100644
104459 index 0000000..c566332
104460 --- /dev/null
104461 +++ b/net/netfilter/xt_gradm.c
104462 @@ -0,0 +1,51 @@
104463 +/*
104464 + * gradm match for netfilter
104465 + * Copyright © Zbigniew Krzystolik, 2010
104466 + *
104467 + * This program is free software; you can redistribute it and/or modify
104468 + * it under the terms of the GNU General Public License; either version
104469 + * 2 or 3 as published by the Free Software Foundation.
104470 + */
104471 +#include <linux/module.h>
104472 +#include <linux/moduleparam.h>
104473 +#include <linux/skbuff.h>
104474 +#include <linux/netfilter/x_tables.h>
104475 +#include <linux/grsecurity.h>
104476 +#include <linux/netfilter/xt_gradm.h>
104477 +
104478 +static bool
104479 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
104480 +{
104481 + const struct xt_gradm_mtinfo *info = par->matchinfo;
104482 + bool retval = false;
104483 + if (gr_acl_is_enabled())
104484 + retval = true;
104485 + return retval ^ info->invflags;
104486 +}
104487 +
104488 +static struct xt_match gradm_mt_reg __read_mostly = {
104489 + .name = "gradm",
104490 + .revision = 0,
104491 + .family = NFPROTO_UNSPEC,
104492 + .match = gradm_mt,
104493 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
104494 + .me = THIS_MODULE,
104495 +};
104496 +
104497 +static int __init gradm_mt_init(void)
104498 +{
104499 + return xt_register_match(&gradm_mt_reg);
104500 +}
104501 +
104502 +static void __exit gradm_mt_exit(void)
104503 +{
104504 + xt_unregister_match(&gradm_mt_reg);
104505 +}
104506 +
104507 +module_init(gradm_mt_init);
104508 +module_exit(gradm_mt_exit);
104509 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
104510 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
104511 +MODULE_LICENSE("GPL");
104512 +MODULE_ALIAS("ipt_gradm");
104513 +MODULE_ALIAS("ip6t_gradm");
104514 diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
104515 index 05fbc2a..4424b5c 100644
104516 --- a/net/netfilter/xt_hashlimit.c
104517 +++ b/net/netfilter/xt_hashlimit.c
104518 @@ -871,11 +871,11 @@ static int __net_init hashlimit_proc_net_init(struct net *net)
104519 {
104520 struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
104521
104522 - hashlimit_net->ipt_hashlimit = proc_mkdir("ipt_hashlimit", net->proc_net);
104523 + hashlimit_net->ipt_hashlimit = proc_mkdir_restrict("ipt_hashlimit", net->proc_net);
104524 if (!hashlimit_net->ipt_hashlimit)
104525 return -ENOMEM;
104526 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
104527 - hashlimit_net->ip6t_hashlimit = proc_mkdir("ip6t_hashlimit", net->proc_net);
104528 + hashlimit_net->ip6t_hashlimit = proc_mkdir_restrict("ip6t_hashlimit", net->proc_net);
104529 if (!hashlimit_net->ip6t_hashlimit) {
104530 remove_proc_entry("ipt_hashlimit", net->proc_net);
104531 return -ENOMEM;
104532 diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
104533 index a9faae8..1ea30e0 100644
104534 --- a/net/netfilter/xt_recent.c
104535 +++ b/net/netfilter/xt_recent.c
104536 @@ -615,7 +615,7 @@ static int __net_init recent_proc_net_init(struct net *net)
104537 {
104538 struct recent_net *recent_net = recent_pernet(net);
104539
104540 - recent_net->xt_recent = proc_mkdir("xt_recent", net->proc_net);
104541 + recent_net->xt_recent = proc_mkdir_restrict("xt_recent", net->proc_net);
104542 if (!recent_net->xt_recent)
104543 return -ENOMEM;
104544 return 0;
104545 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
104546 index 11de55e..f25e448 100644
104547 --- a/net/netfilter/xt_statistic.c
104548 +++ b/net/netfilter/xt_statistic.c
104549 @@ -19,7 +19,7 @@
104550 #include <linux/module.h>
104551
104552 struct xt_statistic_priv {
104553 - atomic_t count;
104554 + atomic_unchecked_t count;
104555 } ____cacheline_aligned_in_smp;
104556
104557 MODULE_LICENSE("GPL");
104558 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
104559 break;
104560 case XT_STATISTIC_MODE_NTH:
104561 do {
104562 - oval = atomic_read(&info->master->count);
104563 + oval = atomic_read_unchecked(&info->master->count);
104564 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
104565 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
104566 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
104567 if (nval == 0)
104568 ret = !ret;
104569 break;
104570 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
104571 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
104572 if (info->master == NULL)
104573 return -ENOMEM;
104574 - atomic_set(&info->master->count, info->u.nth.count);
104575 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
104576
104577 return 0;
104578 }
104579 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
104580 index b6bf8e8..7884ddf 100644
104581 --- a/net/netlink/af_netlink.c
104582 +++ b/net/netlink/af_netlink.c
104583 @@ -273,7 +273,7 @@ static void netlink_overrun(struct sock *sk)
104584 sk->sk_error_report(sk);
104585 }
104586 }
104587 - atomic_inc(&sk->sk_drops);
104588 + atomic_inc_unchecked(&sk->sk_drops);
104589 }
104590
104591 static void netlink_rcv_wake(struct sock *sk)
104592 @@ -3010,7 +3010,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
104593 sk_wmem_alloc_get(s),
104594 nlk->cb_running,
104595 atomic_read(&s->sk_refcnt),
104596 - atomic_read(&s->sk_drops),
104597 + atomic_read_unchecked(&s->sk_drops),
104598 sock_i_ino(s)
104599 );
104600
104601 diff --git a/net/openvswitch/vport-internal_dev.c b/net/openvswitch/vport-internal_dev.c
104602 index 8451612..c8872bc 100644
104603 --- a/net/openvswitch/vport-internal_dev.c
104604 +++ b/net/openvswitch/vport-internal_dev.c
104605 @@ -122,7 +122,7 @@ static const struct net_device_ops internal_dev_netdev_ops = {
104606 .ndo_get_stats64 = internal_dev_get_stats,
104607 };
104608
104609 -static struct rtnl_link_ops internal_dev_link_ops __read_mostly = {
104610 +static struct rtnl_link_ops internal_dev_link_ops = {
104611 .kind = "openvswitch",
104612 };
104613
104614 diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c
104615 index 6015802..e81e8bf 100644
104616 --- a/net/openvswitch/vport.c
104617 +++ b/net/openvswitch/vport.c
104618 @@ -269,10 +269,10 @@ void ovs_vport_get_stats(struct vport *vport, struct ovs_vport_stats *stats)
104619 * netdev-stats can be directly read over netlink-ioctl.
104620 */
104621
104622 - stats->rx_errors = atomic_long_read(&vport->err_stats.rx_errors);
104623 - stats->tx_errors = atomic_long_read(&vport->err_stats.tx_errors);
104624 - stats->tx_dropped = atomic_long_read(&vport->err_stats.tx_dropped);
104625 - stats->rx_dropped = atomic_long_read(&vport->err_stats.rx_dropped);
104626 + stats->rx_errors = atomic_long_read_unchecked(&vport->err_stats.rx_errors);
104627 + stats->tx_errors = atomic_long_read_unchecked(&vport->err_stats.tx_errors);
104628 + stats->tx_dropped = atomic_long_read_unchecked(&vport->err_stats.tx_dropped);
104629 + stats->rx_dropped = atomic_long_read_unchecked(&vport->err_stats.rx_dropped);
104630
104631 for_each_possible_cpu(i) {
104632 const struct pcpu_sw_netstats *percpu_stats;
104633 @@ -503,19 +503,19 @@ static void ovs_vport_record_error(struct vport *vport,
104634 {
104635 switch (err_type) {
104636 case VPORT_E_RX_DROPPED:
104637 - atomic_long_inc(&vport->err_stats.rx_dropped);
104638 + atomic_long_inc_unchecked(&vport->err_stats.rx_dropped);
104639 break;
104640
104641 case VPORT_E_RX_ERROR:
104642 - atomic_long_inc(&vport->err_stats.rx_errors);
104643 + atomic_long_inc_unchecked(&vport->err_stats.rx_errors);
104644 break;
104645
104646 case VPORT_E_TX_DROPPED:
104647 - atomic_long_inc(&vport->err_stats.tx_dropped);
104648 + atomic_long_inc_unchecked(&vport->err_stats.tx_dropped);
104649 break;
104650
104651 case VPORT_E_TX_ERROR:
104652 - atomic_long_inc(&vport->err_stats.tx_errors);
104653 + atomic_long_inc_unchecked(&vport->err_stats.tx_errors);
104654 break;
104655 }
104656
104657 diff --git a/net/openvswitch/vport.h b/net/openvswitch/vport.h
104658 index 8942125..03ed887 100644
104659 --- a/net/openvswitch/vport.h
104660 +++ b/net/openvswitch/vport.h
104661 @@ -61,10 +61,10 @@ int ovs_vport_send(struct vport *, struct sk_buff *);
104662 /* The following definitions are for implementers of vport devices: */
104663
104664 struct vport_err_stats {
104665 - atomic_long_t rx_dropped;
104666 - atomic_long_t rx_errors;
104667 - atomic_long_t tx_dropped;
104668 - atomic_long_t tx_errors;
104669 + atomic_long_unchecked_t rx_dropped;
104670 + atomic_long_unchecked_t rx_errors;
104671 + atomic_long_unchecked_t tx_dropped;
104672 + atomic_long_unchecked_t tx_errors;
104673 };
104674 /**
104675 * struct vport_portids - array of netlink portids of a vport.
104676 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
104677 index 07c04a8..3ca11eb 100644
104678 --- a/net/packet/af_packet.c
104679 +++ b/net/packet/af_packet.c
104680 @@ -269,7 +269,7 @@ static int packet_direct_xmit(struct sk_buff *skb)
104681
104682 return ret;
104683 drop:
104684 - atomic_long_inc(&dev->tx_dropped);
104685 + atomic_long_inc_unchecked(&dev->tx_dropped);
104686 kfree_skb(skb);
104687 return NET_XMIT_DROP;
104688 }
104689 @@ -1836,7 +1836,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
104690
104691 spin_lock(&sk->sk_receive_queue.lock);
104692 po->stats.stats1.tp_packets++;
104693 - skb->dropcount = atomic_read(&sk->sk_drops);
104694 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
104695 __skb_queue_tail(&sk->sk_receive_queue, skb);
104696 spin_unlock(&sk->sk_receive_queue.lock);
104697 sk->sk_data_ready(sk);
104698 @@ -1845,7 +1845,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
104699 drop_n_acct:
104700 spin_lock(&sk->sk_receive_queue.lock);
104701 po->stats.stats1.tp_drops++;
104702 - atomic_inc(&sk->sk_drops);
104703 + atomic_inc_unchecked(&sk->sk_drops);
104704 spin_unlock(&sk->sk_receive_queue.lock);
104705
104706 drop_n_restore:
104707 @@ -3460,7 +3460,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
104708 case PACKET_HDRLEN:
104709 if (len > sizeof(int))
104710 len = sizeof(int);
104711 - if (copy_from_user(&val, optval, len))
104712 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
104713 return -EFAULT;
104714 switch (val) {
104715 case TPACKET_V1:
104716 @@ -3506,7 +3506,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
104717 len = lv;
104718 if (put_user(len, optlen))
104719 return -EFAULT;
104720 - if (copy_to_user(optval, data, len))
104721 + if (len > sizeof(st) || copy_to_user(optval, data, len))
104722 return -EFAULT;
104723 return 0;
104724 }
104725 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
104726 index 70a547e..23477fe 100644
104727 --- a/net/phonet/pep.c
104728 +++ b/net/phonet/pep.c
104729 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
104730
104731 case PNS_PEP_CTRL_REQ:
104732 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
104733 - atomic_inc(&sk->sk_drops);
104734 + atomic_inc_unchecked(&sk->sk_drops);
104735 break;
104736 }
104737 __skb_pull(skb, 4);
104738 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
104739 }
104740
104741 if (pn->rx_credits == 0) {
104742 - atomic_inc(&sk->sk_drops);
104743 + atomic_inc_unchecked(&sk->sk_drops);
104744 err = -ENOBUFS;
104745 break;
104746 }
104747 @@ -579,7 +579,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
104748 }
104749
104750 if (pn->rx_credits == 0) {
104751 - atomic_inc(&sk->sk_drops);
104752 + atomic_inc_unchecked(&sk->sk_drops);
104753 err = NET_RX_DROP;
104754 break;
104755 }
104756 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
104757 index 008214a..bb68240 100644
104758 --- a/net/phonet/socket.c
104759 +++ b/net/phonet/socket.c
104760 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
104761 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
104762 sock_i_ino(sk),
104763 atomic_read(&sk->sk_refcnt), sk,
104764 - atomic_read(&sk->sk_drops));
104765 + atomic_read_unchecked(&sk->sk_drops));
104766 }
104767 seq_pad(seq, '\n');
104768 return 0;
104769 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
104770 index c02a8c4..3c5b600 100644
104771 --- a/net/phonet/sysctl.c
104772 +++ b/net/phonet/sysctl.c
104773 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
104774 {
104775 int ret;
104776 int range[2] = {local_port_range[0], local_port_range[1]};
104777 - struct ctl_table tmp = {
104778 + ctl_table_no_const tmp = {
104779 .data = &range,
104780 .maxlen = sizeof(range),
104781 .mode = table->mode,
104782 diff --git a/net/rds/cong.c b/net/rds/cong.c
104783 index e5b65ac..f3b6fb7 100644
104784 --- a/net/rds/cong.c
104785 +++ b/net/rds/cong.c
104786 @@ -78,7 +78,7 @@
104787 * finds that the saved generation number is smaller than the global generation
104788 * number, it wakes up the process.
104789 */
104790 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
104791 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
104792
104793 /*
104794 * Congestion monitoring
104795 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
104796 rdsdebug("waking map %p for %pI4\n",
104797 map, &map->m_addr);
104798 rds_stats_inc(s_cong_update_received);
104799 - atomic_inc(&rds_cong_generation);
104800 + atomic_inc_unchecked(&rds_cong_generation);
104801 if (waitqueue_active(&map->m_waitq))
104802 wake_up(&map->m_waitq);
104803 if (waitqueue_active(&rds_poll_waitq))
104804 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
104805
104806 int rds_cong_updated_since(unsigned long *recent)
104807 {
104808 - unsigned long gen = atomic_read(&rds_cong_generation);
104809 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
104810
104811 if (likely(*recent == gen))
104812 return 0;
104813 diff --git a/net/rds/ib.h b/net/rds/ib.h
104814 index 7280ab8..e04f4ea 100644
104815 --- a/net/rds/ib.h
104816 +++ b/net/rds/ib.h
104817 @@ -128,7 +128,7 @@ struct rds_ib_connection {
104818 /* sending acks */
104819 unsigned long i_ack_flags;
104820 #ifdef KERNEL_HAS_ATOMIC64
104821 - atomic64_t i_ack_next; /* next ACK to send */
104822 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
104823 #else
104824 spinlock_t i_ack_lock; /* protect i_ack_next */
104825 u64 i_ack_next; /* next ACK to send */
104826 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
104827 index 31b74f5..dc1fbfa 100644
104828 --- a/net/rds/ib_cm.c
104829 +++ b/net/rds/ib_cm.c
104830 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
104831 /* Clear the ACK state */
104832 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
104833 #ifdef KERNEL_HAS_ATOMIC64
104834 - atomic64_set(&ic->i_ack_next, 0);
104835 + atomic64_set_unchecked(&ic->i_ack_next, 0);
104836 #else
104837 ic->i_ack_next = 0;
104838 #endif
104839 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
104840 index d67de45..73dbf51 100644
104841 --- a/net/rds/ib_recv.c
104842 +++ b/net/rds/ib_recv.c
104843 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
104844 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
104845 int ack_required)
104846 {
104847 - atomic64_set(&ic->i_ack_next, seq);
104848 + atomic64_set_unchecked(&ic->i_ack_next, seq);
104849 if (ack_required) {
104850 smp_mb__before_atomic();
104851 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
104852 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
104853 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
104854 smp_mb__after_atomic();
104855
104856 - return atomic64_read(&ic->i_ack_next);
104857 + return atomic64_read_unchecked(&ic->i_ack_next);
104858 }
104859 #endif
104860
104861 diff --git a/net/rds/iw.h b/net/rds/iw.h
104862 index 04ce3b1..48119a6 100644
104863 --- a/net/rds/iw.h
104864 +++ b/net/rds/iw.h
104865 @@ -134,7 +134,7 @@ struct rds_iw_connection {
104866 /* sending acks */
104867 unsigned long i_ack_flags;
104868 #ifdef KERNEL_HAS_ATOMIC64
104869 - atomic64_t i_ack_next; /* next ACK to send */
104870 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
104871 #else
104872 spinlock_t i_ack_lock; /* protect i_ack_next */
104873 u64 i_ack_next; /* next ACK to send */
104874 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
104875 index a91e1db..cf3053f 100644
104876 --- a/net/rds/iw_cm.c
104877 +++ b/net/rds/iw_cm.c
104878 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
104879 /* Clear the ACK state */
104880 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
104881 #ifdef KERNEL_HAS_ATOMIC64
104882 - atomic64_set(&ic->i_ack_next, 0);
104883 + atomic64_set_unchecked(&ic->i_ack_next, 0);
104884 #else
104885 ic->i_ack_next = 0;
104886 #endif
104887 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
104888 index aa8bf67..b70133c 100644
104889 --- a/net/rds/iw_recv.c
104890 +++ b/net/rds/iw_recv.c
104891 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
104892 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
104893 int ack_required)
104894 {
104895 - atomic64_set(&ic->i_ack_next, seq);
104896 + atomic64_set_unchecked(&ic->i_ack_next, seq);
104897 if (ack_required) {
104898 smp_mb__before_atomic();
104899 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
104900 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
104901 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
104902 smp_mb__after_atomic();
104903
104904 - return atomic64_read(&ic->i_ack_next);
104905 + return atomic64_read_unchecked(&ic->i_ack_next);
104906 }
104907 #endif
104908
104909 diff --git a/net/rds/rds.h b/net/rds/rds.h
104910 index 48f8ffc..0ef3eec 100644
104911 --- a/net/rds/rds.h
104912 +++ b/net/rds/rds.h
104913 @@ -449,7 +449,7 @@ struct rds_transport {
104914 void (*sync_mr)(void *trans_private, int direction);
104915 void (*free_mr)(void *trans_private, int invalidate);
104916 void (*flush_mrs)(void);
104917 -};
104918 +} __do_const;
104919
104920 struct rds_sock {
104921 struct sock rs_sk;
104922 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
104923 index edac9ef..16bcb98 100644
104924 --- a/net/rds/tcp.c
104925 +++ b/net/rds/tcp.c
104926 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
104927 int val = 1;
104928
104929 set_fs(KERNEL_DS);
104930 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
104931 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
104932 sizeof(val));
104933 set_fs(oldfs);
104934 }
104935 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
104936 index 53b17ca..45463e7 100644
104937 --- a/net/rds/tcp_send.c
104938 +++ b/net/rds/tcp_send.c
104939 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
104940
104941 oldfs = get_fs();
104942 set_fs(KERNEL_DS);
104943 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
104944 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
104945 sizeof(val));
104946 set_fs(oldfs);
104947 }
104948 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
104949 index 7b16704..9628ec6 100644
104950 --- a/net/rxrpc/af_rxrpc.c
104951 +++ b/net/rxrpc/af_rxrpc.c
104952 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
104953 __be32 rxrpc_epoch;
104954
104955 /* current debugging ID */
104956 -atomic_t rxrpc_debug_id;
104957 +atomic_unchecked_t rxrpc_debug_id;
104958
104959 /* count of skbs currently in use */
104960 atomic_t rxrpc_n_skbs;
104961 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
104962 index c6be17a..2a6200a 100644
104963 --- a/net/rxrpc/ar-ack.c
104964 +++ b/net/rxrpc/ar-ack.c
104965 @@ -223,7 +223,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
104966
104967 _enter("{%d,%d,%d,%d},",
104968 call->acks_hard, call->acks_unacked,
104969 - atomic_read(&call->sequence),
104970 + atomic_read_unchecked(&call->sequence),
104971 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
104972
104973 stop = 0;
104974 @@ -247,7 +247,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
104975
104976 /* each Tx packet has a new serial number */
104977 sp->hdr.serial =
104978 - htonl(atomic_inc_return(&call->conn->serial));
104979 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
104980
104981 hdr = (struct rxrpc_header *) txb->head;
104982 hdr->serial = sp->hdr.serial;
104983 @@ -451,7 +451,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
104984 */
104985 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
104986 {
104987 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
104988 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
104989 }
104990
104991 /*
104992 @@ -677,7 +677,7 @@ process_further:
104993
104994 latest = ntohl(sp->hdr.serial);
104995 hard = ntohl(ack.firstPacket);
104996 - tx = atomic_read(&call->sequence);
104997 + tx = atomic_read_unchecked(&call->sequence);
104998
104999 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
105000 latest,
105001 @@ -1209,7 +1209,7 @@ void rxrpc_process_call(struct work_struct *work)
105002 goto maybe_reschedule;
105003
105004 send_ACK_with_skew:
105005 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
105006 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
105007 ntohl(ack.serial));
105008 send_ACK:
105009 mtu = call->conn->trans->peer->if_mtu;
105010 @@ -1221,7 +1221,7 @@ send_ACK:
105011 ackinfo.rxMTU = htonl(rxrpc_rx_mtu);
105012 ackinfo.jumbo_max = htonl(rxrpc_rx_jumbo_max);
105013
105014 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
105015 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
105016 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
105017 ntohl(hdr.serial),
105018 ntohs(ack.maxSkew),
105019 @@ -1239,7 +1239,7 @@ send_ACK:
105020 send_message:
105021 _debug("send message");
105022
105023 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
105024 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
105025 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
105026 send_message_2:
105027
105028 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
105029 index a9e05db..194e793 100644
105030 --- a/net/rxrpc/ar-call.c
105031 +++ b/net/rxrpc/ar-call.c
105032 @@ -232,7 +232,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
105033 spin_lock_init(&call->lock);
105034 rwlock_init(&call->state_lock);
105035 atomic_set(&call->usage, 1);
105036 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
105037 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
105038 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
105039
105040 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
105041 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
105042 index 6631f4f..bfdf056 100644
105043 --- a/net/rxrpc/ar-connection.c
105044 +++ b/net/rxrpc/ar-connection.c
105045 @@ -210,7 +210,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
105046 rwlock_init(&conn->lock);
105047 spin_lock_init(&conn->state_lock);
105048 atomic_set(&conn->usage, 1);
105049 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
105050 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
105051 conn->avail_calls = RXRPC_MAXCALLS;
105052 conn->size_align = 4;
105053 conn->header_size = sizeof(struct rxrpc_header);
105054 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
105055 index e7ed43a..6afa140 100644
105056 --- a/net/rxrpc/ar-connevent.c
105057 +++ b/net/rxrpc/ar-connevent.c
105058 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
105059
105060 len = iov[0].iov_len + iov[1].iov_len;
105061
105062 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
105063 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
105064 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
105065
105066 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
105067 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
105068 index 481f89f..ceeaf8d 100644
105069 --- a/net/rxrpc/ar-input.c
105070 +++ b/net/rxrpc/ar-input.c
105071 @@ -331,9 +331,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
105072 /* track the latest serial number on this connection for ACK packet
105073 * information */
105074 serial = ntohl(sp->hdr.serial);
105075 - hi_serial = atomic_read(&call->conn->hi_serial);
105076 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
105077 while (serial > hi_serial)
105078 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
105079 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
105080 serial);
105081
105082 /* request ACK generation for any ACK or DATA packet that requests
105083 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
105084 index ba9fd36..9bbfe01 100644
105085 --- a/net/rxrpc/ar-internal.h
105086 +++ b/net/rxrpc/ar-internal.h
105087 @@ -272,8 +272,8 @@ struct rxrpc_connection {
105088 int error; /* error code for local abort */
105089 int debug_id; /* debug ID for printks */
105090 unsigned int call_counter; /* call ID counter */
105091 - atomic_t serial; /* packet serial number counter */
105092 - atomic_t hi_serial; /* highest serial number received */
105093 + atomic_unchecked_t serial; /* packet serial number counter */
105094 + atomic_unchecked_t hi_serial; /* highest serial number received */
105095 u8 avail_calls; /* number of calls available */
105096 u8 size_align; /* data size alignment (for security) */
105097 u8 header_size; /* rxrpc + security header size */
105098 @@ -346,7 +346,7 @@ struct rxrpc_call {
105099 spinlock_t lock;
105100 rwlock_t state_lock; /* lock for state transition */
105101 atomic_t usage;
105102 - atomic_t sequence; /* Tx data packet sequence counter */
105103 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
105104 u32 abort_code; /* local/remote abort code */
105105 enum { /* current state of call */
105106 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
105107 @@ -431,7 +431,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
105108 */
105109 extern atomic_t rxrpc_n_skbs;
105110 extern __be32 rxrpc_epoch;
105111 -extern atomic_t rxrpc_debug_id;
105112 +extern atomic_unchecked_t rxrpc_debug_id;
105113 extern struct workqueue_struct *rxrpc_workqueue;
105114
105115 /*
105116 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
105117 index 87f7135..74d3703 100644
105118 --- a/net/rxrpc/ar-local.c
105119 +++ b/net/rxrpc/ar-local.c
105120 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
105121 spin_lock_init(&local->lock);
105122 rwlock_init(&local->services_lock);
105123 atomic_set(&local->usage, 1);
105124 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
105125 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
105126 memcpy(&local->srx, srx, sizeof(*srx));
105127 }
105128
105129 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
105130 index 0b4b9a7..966ffbb 100644
105131 --- a/net/rxrpc/ar-output.c
105132 +++ b/net/rxrpc/ar-output.c
105133 @@ -682,14 +682,14 @@ static int rxrpc_send_data(struct kiocb *iocb,
105134 memset(skb_put(skb, pad), 0, pad);
105135 }
105136
105137 - seq = atomic_inc_return(&call->sequence);
105138 + seq = atomic_inc_return_unchecked(&call->sequence);
105139
105140 sp->hdr.epoch = conn->epoch;
105141 sp->hdr.cid = call->cid;
105142 sp->hdr.callNumber = call->call_id;
105143 sp->hdr.seq = htonl(seq);
105144 sp->hdr.serial =
105145 - htonl(atomic_inc_return(&conn->serial));
105146 + htonl(atomic_inc_return_unchecked(&conn->serial));
105147 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
105148 sp->hdr.userStatus = 0;
105149 sp->hdr.securityIndex = conn->security_ix;
105150 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
105151 index bebaa43..2644591 100644
105152 --- a/net/rxrpc/ar-peer.c
105153 +++ b/net/rxrpc/ar-peer.c
105154 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
105155 INIT_LIST_HEAD(&peer->error_targets);
105156 spin_lock_init(&peer->lock);
105157 atomic_set(&peer->usage, 1);
105158 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
105159 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
105160 memcpy(&peer->srx, srx, sizeof(*srx));
105161
105162 rxrpc_assess_MTU_size(peer);
105163 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
105164 index 38047f7..9f48511 100644
105165 --- a/net/rxrpc/ar-proc.c
105166 +++ b/net/rxrpc/ar-proc.c
105167 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
105168 atomic_read(&conn->usage),
105169 rxrpc_conn_states[conn->state],
105170 key_serial(conn->key),
105171 - atomic_read(&conn->serial),
105172 - atomic_read(&conn->hi_serial));
105173 + atomic_read_unchecked(&conn->serial),
105174 + atomic_read_unchecked(&conn->hi_serial));
105175
105176 return 0;
105177 }
105178 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
105179 index 1976dec..aa70be5 100644
105180 --- a/net/rxrpc/ar-transport.c
105181 +++ b/net/rxrpc/ar-transport.c
105182 @@ -51,7 +51,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
105183 spin_lock_init(&trans->client_lock);
105184 rwlock_init(&trans->conn_lock);
105185 atomic_set(&trans->usage, 1);
105186 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
105187 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
105188
105189 if (peer->srx.transport.family == AF_INET) {
105190 switch (peer->srx.transport_type) {
105191 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
105192 index f226709..0e735a8 100644
105193 --- a/net/rxrpc/rxkad.c
105194 +++ b/net/rxrpc/rxkad.c
105195 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
105196
105197 len = iov[0].iov_len + iov[1].iov_len;
105198
105199 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
105200 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
105201 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
105202
105203 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
105204 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
105205
105206 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
105207
105208 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
105209 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
105210 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
105211
105212 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
105213 diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
105214 index 6efca30..1259f82 100644
105215 --- a/net/sched/sch_generic.c
105216 +++ b/net/sched/sch_generic.c
105217 @@ -349,7 +349,7 @@ void netif_carrier_on(struct net_device *dev)
105218 if (test_and_clear_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
105219 if (dev->reg_state == NETREG_UNINITIALIZED)
105220 return;
105221 - atomic_inc(&dev->carrier_changes);
105222 + atomic_inc_unchecked(&dev->carrier_changes);
105223 linkwatch_fire_event(dev);
105224 if (netif_running(dev))
105225 __netdev_watchdog_up(dev);
105226 @@ -368,7 +368,7 @@ void netif_carrier_off(struct net_device *dev)
105227 if (!test_and_set_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
105228 if (dev->reg_state == NETREG_UNINITIALIZED)
105229 return;
105230 - atomic_inc(&dev->carrier_changes);
105231 + atomic_inc_unchecked(&dev->carrier_changes);
105232 linkwatch_fire_event(dev);
105233 }
105234 }
105235 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
105236 index 0e4198e..f94193e 100644
105237 --- a/net/sctp/ipv6.c
105238 +++ b/net/sctp/ipv6.c
105239 @@ -972,7 +972,7 @@ static const struct inet6_protocol sctpv6_protocol = {
105240 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
105241 };
105242
105243 -static struct sctp_af sctp_af_inet6 = {
105244 +static struct sctp_af sctp_af_inet6 __read_only = {
105245 .sa_family = AF_INET6,
105246 .sctp_xmit = sctp_v6_xmit,
105247 .setsockopt = ipv6_setsockopt,
105248 @@ -1002,7 +1002,7 @@ static struct sctp_af sctp_af_inet6 = {
105249 #endif
105250 };
105251
105252 -static struct sctp_pf sctp_pf_inet6 = {
105253 +static struct sctp_pf sctp_pf_inet6 __read_only = {
105254 .event_msgname = sctp_inet6_event_msgname,
105255 .skb_msgname = sctp_inet6_skb_msgname,
105256 .af_supported = sctp_inet6_af_supported,
105257 @@ -1029,7 +1029,7 @@ void sctp_v6_pf_init(void)
105258
105259 void sctp_v6_pf_exit(void)
105260 {
105261 - list_del(&sctp_af_inet6.list);
105262 + pax_list_del(&sctp_af_inet6.list);
105263 }
105264
105265 /* Initialize IPv6 support and register with socket layer. */
105266 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
105267 index 8f34b27..b105385 100644
105268 --- a/net/sctp/protocol.c
105269 +++ b/net/sctp/protocol.c
105270 @@ -836,8 +836,10 @@ int sctp_register_af(struct sctp_af *af)
105271 return 0;
105272 }
105273
105274 + pax_open_kernel();
105275 INIT_LIST_HEAD(&af->list);
105276 - list_add_tail(&af->list, &sctp_address_families);
105277 + pax_close_kernel();
105278 + pax_list_add_tail(&af->list, &sctp_address_families);
105279 return 1;
105280 }
105281
105282 @@ -967,7 +969,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
105283
105284 static struct sctp_af sctp_af_inet;
105285
105286 -static struct sctp_pf sctp_pf_inet = {
105287 +static struct sctp_pf sctp_pf_inet __read_only = {
105288 .event_msgname = sctp_inet_event_msgname,
105289 .skb_msgname = sctp_inet_skb_msgname,
105290 .af_supported = sctp_inet_af_supported,
105291 @@ -1039,7 +1041,7 @@ static const struct net_protocol sctp_protocol = {
105292 };
105293
105294 /* IPv4 address related functions. */
105295 -static struct sctp_af sctp_af_inet = {
105296 +static struct sctp_af sctp_af_inet __read_only = {
105297 .sa_family = AF_INET,
105298 .sctp_xmit = sctp_v4_xmit,
105299 .setsockopt = ip_setsockopt,
105300 @@ -1123,7 +1125,7 @@ static void sctp_v4_pf_init(void)
105301
105302 static void sctp_v4_pf_exit(void)
105303 {
105304 - list_del(&sctp_af_inet.list);
105305 + pax_list_del(&sctp_af_inet.list);
105306 }
105307
105308 static int sctp_v4_protosw_init(void)
105309 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
105310 index fef2acd..c705c4f 100644
105311 --- a/net/sctp/sm_sideeffect.c
105312 +++ b/net/sctp/sm_sideeffect.c
105313 @@ -439,7 +439,7 @@ static void sctp_generate_sack_event(unsigned long data)
105314 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
105315 }
105316
105317 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
105318 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
105319 NULL,
105320 sctp_generate_t1_cookie_event,
105321 sctp_generate_t1_init_event,
105322 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
105323 index 634a2ab..8e93929 100644
105324 --- a/net/sctp/socket.c
105325 +++ b/net/sctp/socket.c
105326 @@ -2199,11 +2199,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
105327 {
105328 struct sctp_association *asoc;
105329 struct sctp_ulpevent *event;
105330 + struct sctp_event_subscribe subscribe;
105331
105332 if (optlen > sizeof(struct sctp_event_subscribe))
105333 return -EINVAL;
105334 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
105335 + if (copy_from_user(&subscribe, optval, optlen))
105336 return -EFAULT;
105337 + sctp_sk(sk)->subscribe = subscribe;
105338
105339 if (sctp_sk(sk)->subscribe.sctp_data_io_event)
105340 pr_warn_ratelimited(DEPRECATED "%s (pid %d) "
105341 @@ -4372,13 +4374,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
105342 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
105343 int __user *optlen)
105344 {
105345 + struct sctp_event_subscribe subscribe;
105346 +
105347 if (len <= 0)
105348 return -EINVAL;
105349 if (len > sizeof(struct sctp_event_subscribe))
105350 len = sizeof(struct sctp_event_subscribe);
105351 if (put_user(len, optlen))
105352 return -EFAULT;
105353 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
105354 + subscribe = sctp_sk(sk)->subscribe;
105355 + if (copy_to_user(optval, &subscribe, len))
105356 return -EFAULT;
105357 return 0;
105358 }
105359 @@ -4396,6 +4401,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
105360 */
105361 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
105362 {
105363 + __u32 autoclose;
105364 +
105365 /* Applicable to UDP-style socket only */
105366 if (sctp_style(sk, TCP))
105367 return -EOPNOTSUPP;
105368 @@ -4404,7 +4411,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
105369 len = sizeof(int);
105370 if (put_user(len, optlen))
105371 return -EFAULT;
105372 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
105373 + autoclose = sctp_sk(sk)->autoclose;
105374 + if (copy_to_user(optval, &autoclose, sizeof(int)))
105375 return -EFAULT;
105376 return 0;
105377 }
105378 @@ -4778,12 +4786,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
105379 */
105380 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
105381 {
105382 + struct sctp_initmsg initmsg;
105383 +
105384 if (len < sizeof(struct sctp_initmsg))
105385 return -EINVAL;
105386 len = sizeof(struct sctp_initmsg);
105387 if (put_user(len, optlen))
105388 return -EFAULT;
105389 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
105390 + initmsg = sctp_sk(sk)->initmsg;
105391 + if (copy_to_user(optval, &initmsg, len))
105392 return -EFAULT;
105393 return 0;
105394 }
105395 @@ -4824,6 +4835,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
105396 ->addr_to_user(sp, &temp);
105397 if (space_left < addrlen)
105398 return -ENOMEM;
105399 + if (addrlen > sizeof(temp) || addrlen < 0)
105400 + return -EFAULT;
105401 if (copy_to_user(to, &temp, addrlen))
105402 return -EFAULT;
105403 to += addrlen;
105404 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
105405 index 2e9ada1..40f425d 100644
105406 --- a/net/sctp/sysctl.c
105407 +++ b/net/sctp/sysctl.c
105408 @@ -321,7 +321,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
105409 loff_t *ppos)
105410 {
105411 struct net *net = current->nsproxy->net_ns;
105412 - struct ctl_table tbl;
105413 + ctl_table_no_const tbl;
105414 bool changed = false;
105415 char *none = "none";
105416 char tmp[8];
105417 @@ -369,7 +369,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
105418 struct net *net = current->nsproxy->net_ns;
105419 unsigned int min = *(unsigned int *) ctl->extra1;
105420 unsigned int max = *(unsigned int *) ctl->extra2;
105421 - struct ctl_table tbl;
105422 + ctl_table_no_const tbl;
105423 int ret, new_value;
105424
105425 memset(&tbl, 0, sizeof(struct ctl_table));
105426 @@ -398,7 +398,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
105427 struct net *net = current->nsproxy->net_ns;
105428 unsigned int min = *(unsigned int *) ctl->extra1;
105429 unsigned int max = *(unsigned int *) ctl->extra2;
105430 - struct ctl_table tbl;
105431 + ctl_table_no_const tbl;
105432 int ret, new_value;
105433
105434 memset(&tbl, 0, sizeof(struct ctl_table));
105435 @@ -436,7 +436,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
105436 loff_t *ppos)
105437 {
105438 struct net *net = current->nsproxy->net_ns;
105439 - struct ctl_table tbl;
105440 + ctl_table_no_const tbl;
105441 int new_value, ret;
105442
105443 memset(&tbl, 0, sizeof(struct ctl_table));
105444 @@ -463,7 +463,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
105445
105446 int sctp_sysctl_net_register(struct net *net)
105447 {
105448 - struct ctl_table *table;
105449 + ctl_table_no_const *table;
105450 int i;
105451
105452 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
105453 diff --git a/net/socket.c b/net/socket.c
105454 index fe20c31..83a0ed6 100644
105455 --- a/net/socket.c
105456 +++ b/net/socket.c
105457 @@ -89,6 +89,7 @@
105458 #include <linux/magic.h>
105459 #include <linux/slab.h>
105460 #include <linux/xattr.h>
105461 +#include <linux/in.h>
105462
105463 #include <asm/uaccess.h>
105464 #include <asm/unistd.h>
105465 @@ -113,6 +114,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
105466 unsigned int sysctl_net_busy_poll __read_mostly;
105467 #endif
105468
105469 +#include <linux/grsock.h>
105470 +
105471 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
105472 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
105473 unsigned long nr_segs, loff_t pos);
105474 @@ -164,7 +167,7 @@ static const struct file_operations socket_file_ops = {
105475 */
105476
105477 static DEFINE_SPINLOCK(net_family_lock);
105478 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
105479 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
105480
105481 /*
105482 * Statistics counters of the socket lists
105483 @@ -330,7 +333,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
105484 &sockfs_dentry_operations, SOCKFS_MAGIC);
105485 }
105486
105487 -static struct vfsmount *sock_mnt __read_mostly;
105488 +struct vfsmount *sock_mnt __read_mostly;
105489
105490 static struct file_system_type sock_fs_type = {
105491 .name = "sockfs",
105492 @@ -1263,6 +1266,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
105493 return -EAFNOSUPPORT;
105494 if (type < 0 || type >= SOCK_MAX)
105495 return -EINVAL;
105496 + if (protocol < 0)
105497 + return -EINVAL;
105498
105499 /* Compatibility.
105500
105501 @@ -1283,6 +1288,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
105502 if (err)
105503 return err;
105504
105505 + if(!kern && !gr_search_socket(family, type, protocol)) {
105506 + if (rcu_access_pointer(net_families[family]) == NULL)
105507 + return -EAFNOSUPPORT;
105508 + else
105509 + return -EACCES;
105510 + }
105511 +
105512 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
105513 + if (rcu_access_pointer(net_families[family]) == NULL)
105514 + return -EAFNOSUPPORT;
105515 + else
105516 + return -EACCES;
105517 + }
105518 +
105519 /*
105520 * Allocate the socket and allow the family to set things up. if
105521 * the protocol is 0, the family is instructed to select an appropriate
105522 @@ -1534,6 +1553,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
105523 if (sock) {
105524 err = move_addr_to_kernel(umyaddr, addrlen, &address);
105525 if (err >= 0) {
105526 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
105527 + err = -EACCES;
105528 + goto error;
105529 + }
105530 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
105531 + if (err)
105532 + goto error;
105533 +
105534 err = security_socket_bind(sock,
105535 (struct sockaddr *)&address,
105536 addrlen);
105537 @@ -1542,6 +1569,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
105538 (struct sockaddr *)
105539 &address, addrlen);
105540 }
105541 +error:
105542 fput_light(sock->file, fput_needed);
105543 }
105544 return err;
105545 @@ -1565,10 +1593,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
105546 if ((unsigned int)backlog > somaxconn)
105547 backlog = somaxconn;
105548
105549 + if (gr_handle_sock_server_other(sock->sk)) {
105550 + err = -EPERM;
105551 + goto error;
105552 + }
105553 +
105554 + err = gr_search_listen(sock);
105555 + if (err)
105556 + goto error;
105557 +
105558 err = security_socket_listen(sock, backlog);
105559 if (!err)
105560 err = sock->ops->listen(sock, backlog);
105561
105562 +error:
105563 fput_light(sock->file, fput_needed);
105564 }
105565 return err;
105566 @@ -1612,6 +1650,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
105567 newsock->type = sock->type;
105568 newsock->ops = sock->ops;
105569
105570 + if (gr_handle_sock_server_other(sock->sk)) {
105571 + err = -EPERM;
105572 + sock_release(newsock);
105573 + goto out_put;
105574 + }
105575 +
105576 + err = gr_search_accept(sock);
105577 + if (err) {
105578 + sock_release(newsock);
105579 + goto out_put;
105580 + }
105581 +
105582 /*
105583 * We don't need try_module_get here, as the listening socket (sock)
105584 * has the protocol module (sock->ops->owner) held.
105585 @@ -1657,6 +1707,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
105586 fd_install(newfd, newfile);
105587 err = newfd;
105588
105589 + gr_attach_curr_ip(newsock->sk);
105590 +
105591 out_put:
105592 fput_light(sock->file, fput_needed);
105593 out:
105594 @@ -1689,6 +1741,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
105595 int, addrlen)
105596 {
105597 struct socket *sock;
105598 + struct sockaddr *sck;
105599 struct sockaddr_storage address;
105600 int err, fput_needed;
105601
105602 @@ -1699,6 +1752,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
105603 if (err < 0)
105604 goto out_put;
105605
105606 + sck = (struct sockaddr *)&address;
105607 +
105608 + if (gr_handle_sock_client(sck)) {
105609 + err = -EACCES;
105610 + goto out_put;
105611 + }
105612 +
105613 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
105614 + if (err)
105615 + goto out_put;
105616 +
105617 err =
105618 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
105619 if (err)
105620 @@ -1780,6 +1844,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
105621 * the protocol.
105622 */
105623
105624 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
105625 +
105626 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
105627 unsigned int, flags, struct sockaddr __user *, addr,
105628 int, addr_len)
105629 @@ -1846,7 +1912,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
105630 struct socket *sock;
105631 struct iovec iov;
105632 struct msghdr msg;
105633 - struct sockaddr_storage address;
105634 + struct sockaddr_storage address = { };
105635 int err, err2;
105636 int fput_needed;
105637
105638 @@ -2075,7 +2141,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
105639 * checking falls down on this.
105640 */
105641 if (copy_from_user(ctl_buf,
105642 - (void __user __force *)msg_sys->msg_control,
105643 + (void __force_user *)msg_sys->msg_control,
105644 ctl_len))
105645 goto out_freectl;
105646 msg_sys->msg_control = ctl_buf;
105647 @@ -2226,7 +2292,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
105648 int err, total_len, len;
105649
105650 /* kernel mode address */
105651 - struct sockaddr_storage addr;
105652 + struct sockaddr_storage addr = { };
105653
105654 /* user mode address pointers */
105655 struct sockaddr __user *uaddr;
105656 @@ -2255,7 +2321,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
105657 /* Save the user-mode address (verify_iovec will change the
105658 * kernel msghdr to use the kernel address space)
105659 */
105660 - uaddr = (__force void __user *)msg_sys->msg_name;
105661 + uaddr = (void __force_user *)msg_sys->msg_name;
105662 uaddr_len = COMPAT_NAMELEN(msg);
105663 if (MSG_CMSG_COMPAT & flags)
105664 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
105665 @@ -2896,7 +2962,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
105666 ifr = compat_alloc_user_space(buf_size);
105667 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
105668
105669 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
105670 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
105671 return -EFAULT;
105672
105673 if (put_user(convert_in ? rxnfc : compat_ptr(data),
105674 @@ -3007,7 +3073,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
105675 old_fs = get_fs();
105676 set_fs(KERNEL_DS);
105677 err = dev_ioctl(net, cmd,
105678 - (struct ifreq __user __force *) &kifr);
105679 + (struct ifreq __force_user *) &kifr);
105680 set_fs(old_fs);
105681
105682 return err;
105683 @@ -3100,7 +3166,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
105684
105685 old_fs = get_fs();
105686 set_fs(KERNEL_DS);
105687 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
105688 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
105689 set_fs(old_fs);
105690
105691 if (cmd == SIOCGIFMAP && !err) {
105692 @@ -3184,7 +3250,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
105693 ret |= get_user(rtdev, &(ur4->rt_dev));
105694 if (rtdev) {
105695 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
105696 - r4.rt_dev = (char __user __force *)devname;
105697 + r4.rt_dev = (char __force_user *)devname;
105698 devname[15] = 0;
105699 } else
105700 r4.rt_dev = NULL;
105701 @@ -3411,8 +3477,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
105702 int __user *uoptlen;
105703 int err;
105704
105705 - uoptval = (char __user __force *) optval;
105706 - uoptlen = (int __user __force *) optlen;
105707 + uoptval = (char __force_user *) optval;
105708 + uoptlen = (int __force_user *) optlen;
105709
105710 set_fs(KERNEL_DS);
105711 if (level == SOL_SOCKET)
105712 @@ -3432,7 +3498,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
105713 char __user *uoptval;
105714 int err;
105715
105716 - uoptval = (char __user __force *) optval;
105717 + uoptval = (char __force_user *) optval;
105718
105719 set_fs(KERNEL_DS);
105720 if (level == SOL_SOCKET)
105721 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
105722 index c548ab2..4e1b68b 100644
105723 --- a/net/sunrpc/auth_gss/svcauth_gss.c
105724 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
105725 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
105726 uint64_t *handle)
105727 {
105728 struct rsc rsci, *rscp = NULL;
105729 - static atomic64_t ctxhctr;
105730 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
105731 long long ctxh;
105732 struct gss_api_mech *gm = NULL;
105733 time_t expiry;
105734 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
105735 status = -ENOMEM;
105736 /* the handle needs to be just a unique id,
105737 * use a static counter */
105738 - ctxh = atomic64_inc_return(&ctxhctr);
105739 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
105740
105741 /* make a copy for the caller */
105742 *handle = ctxh;
105743 diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
105744 index 0663621..c4928d4 100644
105745 --- a/net/sunrpc/cache.c
105746 +++ b/net/sunrpc/cache.c
105747 @@ -1609,7 +1609,7 @@ static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
105748 struct sunrpc_net *sn;
105749
105750 sn = net_generic(net, sunrpc_net_id);
105751 - cd->u.procfs.proc_ent = proc_mkdir(cd->name, sn->proc_net_rpc);
105752 + cd->u.procfs.proc_ent = proc_mkdir_restrict(cd->name, sn->proc_net_rpc);
105753 if (cd->u.procfs.proc_ent == NULL)
105754 goto out_nomem;
105755 cd->u.procfs.channel_ent = NULL;
105756 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
105757 index 9acd6ce..4353a72 100644
105758 --- a/net/sunrpc/clnt.c
105759 +++ b/net/sunrpc/clnt.c
105760 @@ -1428,7 +1428,9 @@ call_start(struct rpc_task *task)
105761 (RPC_IS_ASYNC(task) ? "async" : "sync"));
105762
105763 /* Increment call count */
105764 - task->tk_msg.rpc_proc->p_count++;
105765 + pax_open_kernel();
105766 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
105767 + pax_close_kernel();
105768 clnt->cl_stats->rpccnt++;
105769 task->tk_action = call_reserve;
105770 }
105771 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
105772 index fe3441a..922c29e 100644
105773 --- a/net/sunrpc/sched.c
105774 +++ b/net/sunrpc/sched.c
105775 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(struct wait_bit_key *key)
105776 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
105777 static void rpc_task_set_debuginfo(struct rpc_task *task)
105778 {
105779 - static atomic_t rpc_pid;
105780 + static atomic_unchecked_t rpc_pid;
105781
105782 - task->tk_pid = atomic_inc_return(&rpc_pid);
105783 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
105784 }
105785 #else
105786 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
105787 diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c
105788 index 5453049..465669a 100644
105789 --- a/net/sunrpc/stats.c
105790 +++ b/net/sunrpc/stats.c
105791 @@ -267,7 +267,7 @@ int rpc_proc_init(struct net *net)
105792
105793 dprintk("RPC: registering /proc/net/rpc\n");
105794 sn = net_generic(net, sunrpc_net_id);
105795 - sn->proc_net_rpc = proc_mkdir("rpc", net->proc_net);
105796 + sn->proc_net_rpc = proc_mkdir_restrict("rpc", net->proc_net);
105797 if (sn->proc_net_rpc == NULL)
105798 return -ENOMEM;
105799
105800 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
105801 index ca8a795..ddfc41b 100644
105802 --- a/net/sunrpc/svc.c
105803 +++ b/net/sunrpc/svc.c
105804 @@ -1165,7 +1165,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
105805 svc_putnl(resv, RPC_SUCCESS);
105806
105807 /* Bump per-procedure stats counter */
105808 - procp->pc_count++;
105809 + pax_open_kernel();
105810 + (*(unsigned int *)&procp->pc_count)++;
105811 + pax_close_kernel();
105812
105813 /* Initialize storage for argp and resp */
105814 memset(rqstp->rq_argp, 0, procp->pc_argsize);
105815 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
105816 index 621ca7b..59421dd 100644
105817 --- a/net/sunrpc/svcauth_unix.c
105818 +++ b/net/sunrpc/svcauth_unix.c
105819 @@ -414,7 +414,7 @@ struct unix_gid {
105820 struct group_info *gi;
105821 };
105822
105823 -static int unix_gid_hash(kuid_t uid)
105824 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
105825 {
105826 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
105827 }
105828 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
105829 (*bpp)[-1] = '\n';
105830 }
105831
105832 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
105833 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
105834
105835 static int unix_gid_parse(struct cache_detail *cd,
105836 char *mesg, int mlen)
105837 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
105838 index c1b6270..05089c1 100644
105839 --- a/net/sunrpc/xprtrdma/svc_rdma.c
105840 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
105841 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
105842 static unsigned int min_max_inline = 4096;
105843 static unsigned int max_max_inline = 65536;
105844
105845 -atomic_t rdma_stat_recv;
105846 -atomic_t rdma_stat_read;
105847 -atomic_t rdma_stat_write;
105848 -atomic_t rdma_stat_sq_starve;
105849 -atomic_t rdma_stat_rq_starve;
105850 -atomic_t rdma_stat_rq_poll;
105851 -atomic_t rdma_stat_rq_prod;
105852 -atomic_t rdma_stat_sq_poll;
105853 -atomic_t rdma_stat_sq_prod;
105854 +atomic_unchecked_t rdma_stat_recv;
105855 +atomic_unchecked_t rdma_stat_read;
105856 +atomic_unchecked_t rdma_stat_write;
105857 +atomic_unchecked_t rdma_stat_sq_starve;
105858 +atomic_unchecked_t rdma_stat_rq_starve;
105859 +atomic_unchecked_t rdma_stat_rq_poll;
105860 +atomic_unchecked_t rdma_stat_rq_prod;
105861 +atomic_unchecked_t rdma_stat_sq_poll;
105862 +atomic_unchecked_t rdma_stat_sq_prod;
105863
105864 /* Temporary NFS request map and context caches */
105865 struct kmem_cache *svc_rdma_map_cachep;
105866 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
105867 len -= *ppos;
105868 if (len > *lenp)
105869 len = *lenp;
105870 - if (len && copy_to_user(buffer, str_buf, len))
105871 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
105872 return -EFAULT;
105873 *lenp = len;
105874 *ppos += len;
105875 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
105876 {
105877 .procname = "rdma_stat_read",
105878 .data = &rdma_stat_read,
105879 - .maxlen = sizeof(atomic_t),
105880 + .maxlen = sizeof(atomic_unchecked_t),
105881 .mode = 0644,
105882 .proc_handler = read_reset_stat,
105883 },
105884 {
105885 .procname = "rdma_stat_recv",
105886 .data = &rdma_stat_recv,
105887 - .maxlen = sizeof(atomic_t),
105888 + .maxlen = sizeof(atomic_unchecked_t),
105889 .mode = 0644,
105890 .proc_handler = read_reset_stat,
105891 },
105892 {
105893 .procname = "rdma_stat_write",
105894 .data = &rdma_stat_write,
105895 - .maxlen = sizeof(atomic_t),
105896 + .maxlen = sizeof(atomic_unchecked_t),
105897 .mode = 0644,
105898 .proc_handler = read_reset_stat,
105899 },
105900 {
105901 .procname = "rdma_stat_sq_starve",
105902 .data = &rdma_stat_sq_starve,
105903 - .maxlen = sizeof(atomic_t),
105904 + .maxlen = sizeof(atomic_unchecked_t),
105905 .mode = 0644,
105906 .proc_handler = read_reset_stat,
105907 },
105908 {
105909 .procname = "rdma_stat_rq_starve",
105910 .data = &rdma_stat_rq_starve,
105911 - .maxlen = sizeof(atomic_t),
105912 + .maxlen = sizeof(atomic_unchecked_t),
105913 .mode = 0644,
105914 .proc_handler = read_reset_stat,
105915 },
105916 {
105917 .procname = "rdma_stat_rq_poll",
105918 .data = &rdma_stat_rq_poll,
105919 - .maxlen = sizeof(atomic_t),
105920 + .maxlen = sizeof(atomic_unchecked_t),
105921 .mode = 0644,
105922 .proc_handler = read_reset_stat,
105923 },
105924 {
105925 .procname = "rdma_stat_rq_prod",
105926 .data = &rdma_stat_rq_prod,
105927 - .maxlen = sizeof(atomic_t),
105928 + .maxlen = sizeof(atomic_unchecked_t),
105929 .mode = 0644,
105930 .proc_handler = read_reset_stat,
105931 },
105932 {
105933 .procname = "rdma_stat_sq_poll",
105934 .data = &rdma_stat_sq_poll,
105935 - .maxlen = sizeof(atomic_t),
105936 + .maxlen = sizeof(atomic_unchecked_t),
105937 .mode = 0644,
105938 .proc_handler = read_reset_stat,
105939 },
105940 {
105941 .procname = "rdma_stat_sq_prod",
105942 .data = &rdma_stat_sq_prod,
105943 - .maxlen = sizeof(atomic_t),
105944 + .maxlen = sizeof(atomic_unchecked_t),
105945 .mode = 0644,
105946 .proc_handler = read_reset_stat,
105947 },
105948 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
105949 index e011027..9d3c4e1 100644
105950 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
105951 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
105952 @@ -220,7 +220,7 @@ static int rdma_read_chunk_lcl(struct svcxprt_rdma *xprt,
105953 *page_no = pg_no;
105954 *page_offset = pg_off;
105955 ret = read;
105956 - atomic_inc(&rdma_stat_read);
105957 + atomic_inc_unchecked(&rdma_stat_read);
105958 return ret;
105959 err:
105960 svc_rdma_unmap_dma(ctxt);
105961 @@ -356,7 +356,7 @@ static int rdma_read_chunk_frmr(struct svcxprt_rdma *xprt,
105962 *page_no = pg_no;
105963 *page_offset = pg_off;
105964 ret = read;
105965 - atomic_inc(&rdma_stat_read);
105966 + atomic_inc_unchecked(&rdma_stat_read);
105967 return ret;
105968 err:
105969 svc_rdma_unmap_dma(ctxt);
105970 @@ -540,7 +540,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
105971 dto_q);
105972 list_del_init(&ctxt->dto_q);
105973 } else {
105974 - atomic_inc(&rdma_stat_rq_starve);
105975 + atomic_inc_unchecked(&rdma_stat_rq_starve);
105976 clear_bit(XPT_DATA, &xprt->xpt_flags);
105977 ctxt = NULL;
105978 }
105979 @@ -559,7 +559,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
105980 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
105981 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
105982 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
105983 - atomic_inc(&rdma_stat_recv);
105984 + atomic_inc_unchecked(&rdma_stat_recv);
105985
105986 /* Build up the XDR from the receive buffers. */
105987 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
105988 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
105989 index 9f1b506..2e0b321 100644
105990 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
105991 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
105992 @@ -208,7 +208,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
105993 write_wr.wr.rdma.remote_addr = to;
105994
105995 /* Post It */
105996 - atomic_inc(&rdma_stat_write);
105997 + atomic_inc_unchecked(&rdma_stat_write);
105998 if (svc_rdma_send(xprt, &write_wr))
105999 goto err;
106000 return write_len - bc;
106001 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
106002 index 4e61880..1f0d963 100644
106003 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
106004 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
106005 @@ -295,7 +295,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
106006 return;
106007
106008 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
106009 - atomic_inc(&rdma_stat_rq_poll);
106010 + atomic_inc_unchecked(&rdma_stat_rq_poll);
106011
106012 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
106013 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
106014 @@ -317,7 +317,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
106015 }
106016
106017 if (ctxt)
106018 - atomic_inc(&rdma_stat_rq_prod);
106019 + atomic_inc_unchecked(&rdma_stat_rq_prod);
106020
106021 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
106022 /*
106023 @@ -392,7 +392,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
106024 return;
106025
106026 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
106027 - atomic_inc(&rdma_stat_sq_poll);
106028 + atomic_inc_unchecked(&rdma_stat_sq_poll);
106029 while ((ret = ib_poll_cq(cq, ARRAY_SIZE(wc_a), wc_a)) > 0) {
106030 int i;
106031
106032 @@ -420,7 +420,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
106033 }
106034
106035 if (ctxt)
106036 - atomic_inc(&rdma_stat_sq_prod);
106037 + atomic_inc_unchecked(&rdma_stat_sq_prod);
106038 }
106039
106040 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
106041 @@ -1264,7 +1264,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
106042 spin_lock_bh(&xprt->sc_lock);
106043 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
106044 spin_unlock_bh(&xprt->sc_lock);
106045 - atomic_inc(&rdma_stat_sq_starve);
106046 + atomic_inc_unchecked(&rdma_stat_sq_starve);
106047
106048 /* See if we can opportunistically reap SQ WR to make room */
106049 sq_cq_reap(xprt);
106050 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
106051 index e7000be..e3b0ba7 100644
106052 --- a/net/sysctl_net.c
106053 +++ b/net/sysctl_net.c
106054 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
106055 kgid_t root_gid = make_kgid(net->user_ns, 0);
106056
106057 /* Allow network administrator to have same access as root. */
106058 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
106059 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
106060 uid_eq(root_uid, current_euid())) {
106061 int mode = (table->mode >> 6) & 7;
106062 return (mode << 6) | (mode << 3) | mode;
106063 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
106064 index 31b5cb2..566ff01 100644
106065 --- a/net/tipc/subscr.c
106066 +++ b/net/tipc/subscr.c
106067 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
106068 struct tipc_subscriber *subscriber = sub->subscriber;
106069 struct kvec msg_sect;
106070
106071 - msg_sect.iov_base = (void *)&sub->evt;
106072 + msg_sect.iov_base = &sub->evt;
106073 msg_sect.iov_len = sizeof(struct tipc_event);
106074 sub->evt.event = htohl(event, sub->swap);
106075 sub->evt.found_lower = htohl(found_lower, sub->swap);
106076 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
106077 index e968843..bc95776 100644
106078 --- a/net/unix/af_unix.c
106079 +++ b/net/unix/af_unix.c
106080 @@ -791,6 +791,12 @@ static struct sock *unix_find_other(struct net *net,
106081 err = -ECONNREFUSED;
106082 if (!S_ISSOCK(inode->i_mode))
106083 goto put_fail;
106084 +
106085 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
106086 + err = -EACCES;
106087 + goto put_fail;
106088 + }
106089 +
106090 u = unix_find_socket_byinode(inode);
106091 if (!u)
106092 goto put_fail;
106093 @@ -811,6 +817,13 @@ static struct sock *unix_find_other(struct net *net,
106094 if (u) {
106095 struct dentry *dentry;
106096 dentry = unix_sk(u)->path.dentry;
106097 +
106098 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
106099 + err = -EPERM;
106100 + sock_put(u);
106101 + goto fail;
106102 + }
106103 +
106104 if (dentry)
106105 touch_atime(&unix_sk(u)->path);
106106 } else
106107 @@ -844,12 +857,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
106108 */
106109 err = security_path_mknod(&path, dentry, mode, 0);
106110 if (!err) {
106111 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
106112 + err = -EACCES;
106113 + goto out;
106114 + }
106115 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
106116 if (!err) {
106117 res->mnt = mntget(path.mnt);
106118 res->dentry = dget(dentry);
106119 + gr_handle_create(dentry, path.mnt);
106120 }
106121 }
106122 +out:
106123 done_path_create(&path, dentry);
106124 return err;
106125 }
106126 @@ -2350,9 +2369,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
106127 seq_puts(seq, "Num RefCount Protocol Flags Type St "
106128 "Inode Path\n");
106129 else {
106130 - struct sock *s = v;
106131 + struct sock *s = v, *peer;
106132 struct unix_sock *u = unix_sk(s);
106133 unix_state_lock(s);
106134 + peer = unix_peer(s);
106135 + unix_state_unlock(s);
106136 +
106137 + unix_state_double_lock(s, peer);
106138
106139 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
106140 s,
106141 @@ -2379,8 +2402,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
106142 }
106143 for ( ; i < len; i++)
106144 seq_putc(seq, u->addr->name->sun_path[i]);
106145 - }
106146 - unix_state_unlock(s);
106147 + } else if (peer)
106148 + seq_printf(seq, " P%lu", sock_i_ino(peer));
106149 +
106150 + unix_state_double_unlock(s, peer);
106151 seq_putc(seq, '\n');
106152 }
106153
106154 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
106155 index b3d5150..ff3a837 100644
106156 --- a/net/unix/sysctl_net_unix.c
106157 +++ b/net/unix/sysctl_net_unix.c
106158 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
106159
106160 int __net_init unix_sysctl_register(struct net *net)
106161 {
106162 - struct ctl_table *table;
106163 + ctl_table_no_const *table;
106164
106165 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
106166 if (table == NULL)
106167 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
106168 index 9b7f207..2596621 100644
106169 --- a/net/vmw_vsock/vmci_transport_notify.c
106170 +++ b/net/vmw_vsock/vmci_transport_notify.c
106171 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
106172
106173 /* Socket control packet based operations. */
106174 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
106175 - vmci_transport_notify_pkt_socket_init,
106176 - vmci_transport_notify_pkt_socket_destruct,
106177 - vmci_transport_notify_pkt_poll_in,
106178 - vmci_transport_notify_pkt_poll_out,
106179 - vmci_transport_notify_pkt_handle_pkt,
106180 - vmci_transport_notify_pkt_recv_init,
106181 - vmci_transport_notify_pkt_recv_pre_block,
106182 - vmci_transport_notify_pkt_recv_pre_dequeue,
106183 - vmci_transport_notify_pkt_recv_post_dequeue,
106184 - vmci_transport_notify_pkt_send_init,
106185 - vmci_transport_notify_pkt_send_pre_block,
106186 - vmci_transport_notify_pkt_send_pre_enqueue,
106187 - vmci_transport_notify_pkt_send_post_enqueue,
106188 - vmci_transport_notify_pkt_process_request,
106189 - vmci_transport_notify_pkt_process_negotiate,
106190 + .socket_init = vmci_transport_notify_pkt_socket_init,
106191 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
106192 + .poll_in = vmci_transport_notify_pkt_poll_in,
106193 + .poll_out = vmci_transport_notify_pkt_poll_out,
106194 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
106195 + .recv_init = vmci_transport_notify_pkt_recv_init,
106196 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
106197 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
106198 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
106199 + .send_init = vmci_transport_notify_pkt_send_init,
106200 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
106201 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
106202 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
106203 + .process_request = vmci_transport_notify_pkt_process_request,
106204 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
106205 };
106206 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
106207 index dc9c792..3089de0 100644
106208 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
106209 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
106210 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
106211
106212 /* Socket always on control packet based operations. */
106213 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
106214 - vmci_transport_notify_pkt_socket_init,
106215 - vmci_transport_notify_pkt_socket_destruct,
106216 - vmci_transport_notify_pkt_poll_in,
106217 - vmci_transport_notify_pkt_poll_out,
106218 - vmci_transport_notify_pkt_handle_pkt,
106219 - vmci_transport_notify_pkt_recv_init,
106220 - vmci_transport_notify_pkt_recv_pre_block,
106221 - vmci_transport_notify_pkt_recv_pre_dequeue,
106222 - vmci_transport_notify_pkt_recv_post_dequeue,
106223 - vmci_transport_notify_pkt_send_init,
106224 - vmci_transport_notify_pkt_send_pre_block,
106225 - vmci_transport_notify_pkt_send_pre_enqueue,
106226 - vmci_transport_notify_pkt_send_post_enqueue,
106227 - vmci_transport_notify_pkt_process_request,
106228 - vmci_transport_notify_pkt_process_negotiate,
106229 + .socket_init = vmci_transport_notify_pkt_socket_init,
106230 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
106231 + .poll_in = vmci_transport_notify_pkt_poll_in,
106232 + .poll_out = vmci_transport_notify_pkt_poll_out,
106233 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
106234 + .recv_init = vmci_transport_notify_pkt_recv_init,
106235 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
106236 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
106237 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
106238 + .send_init = vmci_transport_notify_pkt_send_init,
106239 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
106240 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
106241 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
106242 + .process_request = vmci_transport_notify_pkt_process_request,
106243 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
106244 };
106245 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
106246 index c8717c1..08539f5 100644
106247 --- a/net/wireless/wext-core.c
106248 +++ b/net/wireless/wext-core.c
106249 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
106250 */
106251
106252 /* Support for very large requests */
106253 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
106254 - (user_length > descr->max_tokens)) {
106255 + if (user_length > descr->max_tokens) {
106256 /* Allow userspace to GET more than max so
106257 * we can support any size GET requests.
106258 * There is still a limit : -ENOMEM.
106259 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
106260 }
106261 }
106262
106263 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
106264 - /*
106265 - * If this is a GET, but not NOMAX, it means that the extra
106266 - * data is not bounded by userspace, but by max_tokens. Thus
106267 - * set the length to max_tokens. This matches the extra data
106268 - * allocation.
106269 - * The driver should fill it with the number of tokens it
106270 - * provided, and it may check iwp->length rather than having
106271 - * knowledge of max_tokens. If the driver doesn't change the
106272 - * iwp->length, this ioctl just copies back max_token tokens
106273 - * filled with zeroes. Hopefully the driver isn't claiming
106274 - * them to be valid data.
106275 - */
106276 - iwp->length = descr->max_tokens;
106277 - }
106278 -
106279 err = handler(dev, info, (union iwreq_data *) iwp, extra);
106280
106281 iwp->length += essid_compat;
106282 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
106283 index 4323952..a06dfe1 100644
106284 --- a/net/x25/sysctl_net_x25.c
106285 +++ b/net/x25/sysctl_net_x25.c
106286 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
106287 .mode = 0644,
106288 .proc_handler = proc_dointvec,
106289 },
106290 - { 0, },
106291 + { },
106292 };
106293
106294 void __init x25_register_sysctl(void)
106295 diff --git a/net/x25/x25_proc.c b/net/x25/x25_proc.c
106296 index 0917f04..f4e3d8c 100644
106297 --- a/net/x25/x25_proc.c
106298 +++ b/net/x25/x25_proc.c
106299 @@ -209,7 +209,7 @@ static const struct file_operations x25_seq_forward_fops = {
106300
106301 int __init x25_proc_init(void)
106302 {
106303 - if (!proc_mkdir("x25", init_net.proc_net))
106304 + if (!proc_mkdir_restrict("x25", init_net.proc_net))
106305 return -ENOMEM;
106306
106307 if (!proc_create("x25/route", S_IRUGO, init_net.proc_net,
106308 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
106309 index 88bf289..7b0741b 100644
106310 --- a/net/xfrm/xfrm_policy.c
106311 +++ b/net/xfrm/xfrm_policy.c
106312 @@ -330,7 +330,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
106313 {
106314 policy->walk.dead = 1;
106315
106316 - atomic_inc(&policy->genid);
106317 + atomic_inc_unchecked(&policy->genid);
106318
106319 if (del_timer(&policy->polq.hold_timer))
106320 xfrm_pol_put(policy);
106321 @@ -781,7 +781,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
106322 hlist_add_head(&policy->bydst, chain);
106323 xfrm_pol_hold(policy);
106324 net->xfrm.policy_count[dir]++;
106325 - atomic_inc(&net->xfrm.flow_cache_genid);
106326 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
106327
106328 /* After previous checking, family can either be AF_INET or AF_INET6 */
106329 if (policy->family == AF_INET)
106330 @@ -1871,7 +1871,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
106331
106332 xdst->num_pols = num_pols;
106333 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy *) * num_pols);
106334 - xdst->policy_genid = atomic_read(&pols[0]->genid);
106335 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
106336
106337 return xdst;
106338 }
106339 @@ -2685,10 +2685,11 @@ void xfrm_garbage_collect(struct net *net)
106340 }
106341 EXPORT_SYMBOL(xfrm_garbage_collect);
106342
106343 -static void xfrm_garbage_collect_deferred(struct net *net)
106344 +void xfrm_garbage_collect_deferred(struct net *net)
106345 {
106346 flow_cache_flush_deferred(net);
106347 }
106348 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
106349
106350 static void xfrm_init_pmtu(struct dst_entry *dst)
106351 {
106352 @@ -2738,7 +2739,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
106353 if (xdst->xfrm_genid != dst->xfrm->genid)
106354 return 0;
106355 if (xdst->num_pols > 0 &&
106356 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
106357 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
106358 return 0;
106359
106360 mtu = dst_mtu(dst->child);
106361 @@ -2826,8 +2827,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
106362 dst_ops->link_failure = xfrm_link_failure;
106363 if (likely(dst_ops->neigh_lookup == NULL))
106364 dst_ops->neigh_lookup = xfrm_neigh_lookup;
106365 - if (likely(afinfo->garbage_collect == NULL))
106366 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
106367 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
106368 }
106369 spin_unlock(&xfrm_policy_afinfo_lock);
106370 @@ -2881,7 +2880,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
106371 dst_ops->check = NULL;
106372 dst_ops->negative_advice = NULL;
106373 dst_ops->link_failure = NULL;
106374 - afinfo->garbage_collect = NULL;
106375 }
106376 return err;
106377 }
106378 @@ -3277,7 +3275,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
106379 sizeof(pol->xfrm_vec[i].saddr));
106380 pol->xfrm_vec[i].encap_family = mp->new_family;
106381 /* flush bundles */
106382 - atomic_inc(&pol->genid);
106383 + atomic_inc_unchecked(&pol->genid);
106384 }
106385 }
106386
106387 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
106388 index de971b6..b843409 100644
106389 --- a/net/xfrm/xfrm_state.c
106390 +++ b/net/xfrm/xfrm_state.c
106391 @@ -166,12 +166,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
106392
106393 if (unlikely(afinfo == NULL))
106394 return -EAFNOSUPPORT;
106395 - typemap = afinfo->type_map;
106396 + typemap = (const struct xfrm_type **)afinfo->type_map;
106397 spin_lock_bh(&xfrm_type_lock);
106398
106399 - if (likely(typemap[type->proto] == NULL))
106400 + if (likely(typemap[type->proto] == NULL)) {
106401 + pax_open_kernel();
106402 typemap[type->proto] = type;
106403 - else
106404 + pax_close_kernel();
106405 + } else
106406 err = -EEXIST;
106407 spin_unlock_bh(&xfrm_type_lock);
106408 xfrm_state_put_afinfo(afinfo);
106409 @@ -187,13 +189,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
106410
106411 if (unlikely(afinfo == NULL))
106412 return -EAFNOSUPPORT;
106413 - typemap = afinfo->type_map;
106414 + typemap = (const struct xfrm_type **)afinfo->type_map;
106415 spin_lock_bh(&xfrm_type_lock);
106416
106417 if (unlikely(typemap[type->proto] != type))
106418 err = -ENOENT;
106419 - else
106420 + else {
106421 + pax_open_kernel();
106422 typemap[type->proto] = NULL;
106423 + pax_close_kernel();
106424 + }
106425 spin_unlock_bh(&xfrm_type_lock);
106426 xfrm_state_put_afinfo(afinfo);
106427 return err;
106428 @@ -203,7 +208,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
106429 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
106430 {
106431 struct xfrm_state_afinfo *afinfo;
106432 - const struct xfrm_type **typemap;
106433 const struct xfrm_type *type;
106434 int modload_attempted = 0;
106435
106436 @@ -211,9 +215,8 @@ retry:
106437 afinfo = xfrm_state_get_afinfo(family);
106438 if (unlikely(afinfo == NULL))
106439 return NULL;
106440 - typemap = afinfo->type_map;
106441
106442 - type = typemap[proto];
106443 + type = afinfo->type_map[proto];
106444 if (unlikely(type && !try_module_get(type->owner)))
106445 type = NULL;
106446 if (!type && !modload_attempted) {
106447 @@ -247,7 +250,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
106448 return -EAFNOSUPPORT;
106449
106450 err = -EEXIST;
106451 - modemap = afinfo->mode_map;
106452 + modemap = (struct xfrm_mode **)afinfo->mode_map;
106453 spin_lock_bh(&xfrm_mode_lock);
106454 if (modemap[mode->encap])
106455 goto out;
106456 @@ -256,8 +259,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
106457 if (!try_module_get(afinfo->owner))
106458 goto out;
106459
106460 - mode->afinfo = afinfo;
106461 + pax_open_kernel();
106462 + *(const void **)&mode->afinfo = afinfo;
106463 modemap[mode->encap] = mode;
106464 + pax_close_kernel();
106465 err = 0;
106466
106467 out:
106468 @@ -281,10 +286,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
106469 return -EAFNOSUPPORT;
106470
106471 err = -ENOENT;
106472 - modemap = afinfo->mode_map;
106473 + modemap = (struct xfrm_mode **)afinfo->mode_map;
106474 spin_lock_bh(&xfrm_mode_lock);
106475 if (likely(modemap[mode->encap] == mode)) {
106476 + pax_open_kernel();
106477 modemap[mode->encap] = NULL;
106478 + pax_close_kernel();
106479 module_put(mode->afinfo->owner);
106480 err = 0;
106481 }
106482 @@ -1505,10 +1512,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
106483 u32 xfrm_get_acqseq(void)
106484 {
106485 u32 res;
106486 - static atomic_t acqseq;
106487 + static atomic_unchecked_t acqseq;
106488
106489 do {
106490 - res = atomic_inc_return(&acqseq);
106491 + res = atomic_inc_return_unchecked(&acqseq);
106492 } while (!res);
106493
106494 return res;
106495 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
106496 index 05a6e3d..6716ec9 100644
106497 --- a/net/xfrm/xfrm_sysctl.c
106498 +++ b/net/xfrm/xfrm_sysctl.c
106499 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
106500
106501 int __net_init xfrm_sysctl_init(struct net *net)
106502 {
106503 - struct ctl_table *table;
106504 + ctl_table_no_const *table;
106505
106506 __xfrm_sysctl_init(net);
106507
106508 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
106509 index 649ce68..f6bc05c 100644
106510 --- a/scripts/Makefile.build
106511 +++ b/scripts/Makefile.build
106512 @@ -60,7 +60,7 @@ endif
106513 endif
106514
106515 # Do not include host rules unless needed
106516 -ifneq ($(hostprogs-y)$(hostprogs-m),)
106517 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
106518 include scripts/Makefile.host
106519 endif
106520
106521 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
106522 index b1c668d..638055f 100644
106523 --- a/scripts/Makefile.clean
106524 +++ b/scripts/Makefile.clean
106525 @@ -41,7 +41,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
106526 __clean-files := $(extra-y) $(extra-m) $(extra-) \
106527 $(always) $(targets) $(clean-files) \
106528 $(host-progs) \
106529 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
106530 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
106531 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
106532
106533 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
106534
106535 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
106536 index 133edfa..c9aa07f 100644
106537 --- a/scripts/Makefile.host
106538 +++ b/scripts/Makefile.host
106539 @@ -20,7 +20,19 @@
106540 # Will compile qconf as a C++ program, and menu as a C program.
106541 # They are linked as C++ code to the executable qconf
106542
106543 +# hostprogs-y := conf
106544 +# conf-objs := conf.o libkconfig.so
106545 +# libkconfig-objs := expr.o type.o
106546 +# Will create a shared library named libkconfig.so that consists of
106547 +# expr.o and type.o (they are both compiled as C code and the object files
106548 +# are made as position independent code).
106549 +# conf.c is compiled as a C program, and conf.o is linked together with
106550 +# libkconfig.so as the executable conf.
106551 +# Note: Shared libraries consisting of C++ files are not supported
106552 +
106553 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
106554 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
106555 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
106556
106557 # C code
106558 # Executables compiled from a single .c file
106559 @@ -42,6 +54,19 @@ host-cxxmulti := $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m)))
106560 # C++ Object (.o) files compiled from .cc files
106561 host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
106562
106563 +# Shared libaries (only .c supported)
106564 +# Shared libraries (.so) - all .so files referenced in "xxx-objs"
106565 +host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
106566 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
106567 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
106568 +# Remove .so files from "xxx-objs"
106569 +host-cobjs := $(filter-out %.so,$(host-cobjs))
106570 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
106571 +
106572 +# Object (.o) files used by the shared libaries
106573 +host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
106574 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
106575 +
106576 # output directory for programs/.o files
106577 # hostprogs-y := tools/build may have been specified.
106578 # Retrieve also directory of .o files from prog-objs or prog-cxxobjs notation
106579 @@ -56,6 +81,10 @@ host-cmulti := $(addprefix $(obj)/,$(host-cmulti))
106580 host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
106581 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
106582 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
106583 +host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
106584 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
106585 +host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
106586 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
106587 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
106588
106589 obj-dirs += $(host-objdirs)
106590 @@ -124,5 +153,37 @@ quiet_cmd_host-cxxobjs = HOSTCXX $@
106591 $(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE
106592 $(call if_changed_dep,host-cxxobjs)
106593
106594 +# Compile .c file, create position independent .o file
106595 +# host-cshobjs -> .o
106596 +quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
106597 + cmd_host-cshobjs = $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $<
106598 +$(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
106599 + $(call if_changed_dep,host-cshobjs)
106600 +
106601 +# Compile .c file, create position independent .o file
106602 +# host-cxxshobjs -> .o
106603 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
106604 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
106605 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
106606 + $(call if_changed_dep,host-cxxshobjs)
106607 +
106608 +# Link a shared library, based on position independent .o files
106609 +# *.o -> .so shared library (host-cshlib)
106610 +quiet_cmd_host-cshlib = HOSTLLD -shared $@
106611 + cmd_host-cshlib = $(HOSTCC) $(HOSTLDFLAGS) -shared -o $@ \
106612 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
106613 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
106614 +$(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
106615 + $(call if_changed,host-cshlib)
106616 +
106617 +# Link a shared library, based on position independent .o files
106618 +# *.o -> .so shared library (host-cxxshlib)
106619 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
106620 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
106621 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
106622 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
106623 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
106624 + $(call if_changed,host-cxxshlib)
106625 +
106626 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
106627 - $(host-cxxmulti) $(host-cxxobjs)
106628 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
106629 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
106630 index b304068..462d24e 100644
106631 --- a/scripts/basic/fixdep.c
106632 +++ b/scripts/basic/fixdep.c
106633 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
106634 /*
106635 * Lookup a value in the configuration string.
106636 */
106637 -static int is_defined_config(const char *name, int len, unsigned int hash)
106638 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
106639 {
106640 struct item *aux;
106641
106642 @@ -211,10 +211,10 @@ static void clear_config(void)
106643 /*
106644 * Record the use of a CONFIG_* word.
106645 */
106646 -static void use_config(const char *m, int slen)
106647 +static void use_config(const char *m, unsigned int slen)
106648 {
106649 unsigned int hash = strhash(m, slen);
106650 - int c, i;
106651 + unsigned int c, i;
106652
106653 if (is_defined_config(m, slen, hash))
106654 return;
106655 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
106656
106657 static void parse_config_file(const char *map, size_t len)
106658 {
106659 - const int *end = (const int *) (map + len);
106660 + const unsigned int *end = (const unsigned int *) (map + len);
106661 /* start at +1, so that p can never be < map */
106662 - const int *m = (const int *) map + 1;
106663 + const unsigned int *m = (const unsigned int *) map + 1;
106664 const char *p, *q;
106665
106666 for (; m < end; m++) {
106667 @@ -435,7 +435,7 @@ static void print_deps(void)
106668 static void traps(void)
106669 {
106670 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
106671 - int *p = (int *)test;
106672 + unsigned int *p = (unsigned int *)test;
106673
106674 if (*p != INT_CONF) {
106675 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
106676 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
106677 new file mode 100644
106678 index 0000000..42018ed
106679 --- /dev/null
106680 +++ b/scripts/gcc-plugin.sh
106681 @@ -0,0 +1,51 @@
106682 +#!/bin/sh
106683 +srctree=$(dirname "$0")
106684 +gccplugins_dir=$($3 -print-file-name=plugin)
106685 +plugincc=$($1 -E - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
106686 +#include "gcc-common.h"
106687 +#if BUILDING_GCC_VERSION >= 4008 || defined(ENABLE_BUILD_WITH_CXX)
106688 +#warning $2 CXX
106689 +#else
106690 +#warning $1 CC
106691 +#endif
106692 +EOF
106693 +)
106694 +
106695 +if [ $? -ne 0 ]
106696 +then
106697 + exit 1
106698 +fi
106699 +
106700 +case "$plugincc" in
106701 + *"$1 CC"*)
106702 + echo "$1"
106703 + exit 0
106704 + ;;
106705 +
106706 + *"$2 CXX"*)
106707 + # the c++ compiler needs another test, see below
106708 + ;;
106709 +
106710 + *)
106711 + exit 1
106712 + ;;
106713 +esac
106714 +
106715 +# we need a c++ compiler that supports the designated initializer GNU extension
106716 +plugincc=$($2 -c -x c++ -std=gnu++98 - -fsyntax-only -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
106717 +#include "gcc-common.h"
106718 +class test {
106719 +public:
106720 + int test;
106721 +} test = {
106722 + .test = 1
106723 +};
106724 +EOF
106725 +)
106726 +
106727 +if [ $? -eq 0 ]
106728 +then
106729 + echo "$2"
106730 + exit 0
106731 +fi
106732 +exit 1
106733 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
106734 index fdebd66..a349e33 100755
106735 --- a/scripts/headers_install.sh
106736 +++ b/scripts/headers_install.sh
106737 @@ -32,6 +32,7 @@ do
106738 FILE="$(basename "$i")"
106739 sed -r \
106740 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
106741 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
106742 -e 's/__attribute_const__([ \t]|$)/\1/g' \
106743 -e 's@^#include <linux/compiler.h>@@' \
106744 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
106745 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
106746 index 86a4fe7..99e91f9 100755
106747 --- a/scripts/link-vmlinux.sh
106748 +++ b/scripts/link-vmlinux.sh
106749 @@ -166,7 +166,7 @@ else
106750 fi;
106751
106752 # final build of init/
106753 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
106754 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
106755
106756 kallsymso=""
106757 kallsyms_vmlinux=""
106758 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
106759 index e614ef6..d9d2b01 100644
106760 --- a/scripts/mod/file2alias.c
106761 +++ b/scripts/mod/file2alias.c
106762 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
106763 unsigned long size, unsigned long id_size,
106764 void *symval)
106765 {
106766 - int i;
106767 + unsigned int i;
106768
106769 if (size % id_size || size < id_size) {
106770 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
106771 @@ -171,7 +171,7 @@ static void device_id_check(const char *modname, const char *device_id,
106772 /* USB is special because the bcdDevice can be matched against a numeric range */
106773 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
106774 static void do_usb_entry(void *symval,
106775 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
106776 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
106777 unsigned char range_lo, unsigned char range_hi,
106778 unsigned char max, struct module *mod)
106779 {
106780 @@ -281,7 +281,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
106781 {
106782 unsigned int devlo, devhi;
106783 unsigned char chi, clo, max;
106784 - int ndigits;
106785 + unsigned int ndigits;
106786
106787 DEF_FIELD(symval, usb_device_id, match_flags);
106788 DEF_FIELD(symval, usb_device_id, idVendor);
106789 @@ -534,7 +534,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
106790 for (i = 0; i < count; i++) {
106791 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
106792 char acpi_id[sizeof(*id)];
106793 - int j;
106794 + unsigned int j;
106795
106796 buf_printf(&mod->dev_table_buf,
106797 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
106798 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
106799
106800 for (j = 0; j < PNP_MAX_DEVICES; j++) {
106801 const char *id = (char *)(*devs)[j].id;
106802 - int i2, j2;
106803 + unsigned int i2, j2;
106804 int dup = 0;
106805
106806 if (!id[0])
106807 @@ -589,7 +589,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
106808 /* add an individual alias for every device entry */
106809 if (!dup) {
106810 char acpi_id[PNP_ID_LEN];
106811 - int k;
106812 + unsigned int k;
106813
106814 buf_printf(&mod->dev_table_buf,
106815 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
106816 @@ -939,7 +939,7 @@ static void dmi_ascii_filter(char *d, const char *s)
106817 static int do_dmi_entry(const char *filename, void *symval,
106818 char *alias)
106819 {
106820 - int i, j;
106821 + unsigned int i, j;
106822 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
106823 sprintf(alias, "dmi*");
106824
106825 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
106826 index d439856..10c1eac 100644
106827 --- a/scripts/mod/modpost.c
106828 +++ b/scripts/mod/modpost.c
106829 @@ -921,6 +921,7 @@ enum mismatch {
106830 ANY_INIT_TO_ANY_EXIT,
106831 ANY_EXIT_TO_ANY_INIT,
106832 EXPORT_TO_INIT_EXIT,
106833 + DATA_TO_TEXT
106834 };
106835
106836 struct sectioncheck {
106837 @@ -1007,6 +1008,12 @@ static const struct sectioncheck sectioncheck[] = {
106838 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
106839 .mismatch = EXPORT_TO_INIT_EXIT,
106840 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
106841 +},
106842 +/* Do not reference code from writable data */
106843 +{
106844 + .fromsec = { DATA_SECTIONS, NULL },
106845 + .tosec = { TEXT_SECTIONS, NULL },
106846 + .mismatch = DATA_TO_TEXT
106847 }
106848 };
106849
106850 @@ -1127,10 +1134,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
106851 continue;
106852 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
106853 continue;
106854 - if (sym->st_value == addr)
106855 - return sym;
106856 /* Find a symbol nearby - addr are maybe negative */
106857 d = sym->st_value - addr;
106858 + if (d == 0)
106859 + return sym;
106860 if (d < 0)
106861 d = addr - sym->st_value;
106862 if (d < distance) {
106863 @@ -1408,6 +1415,14 @@ static void report_sec_mismatch(const char *modname,
106864 tosym, prl_to, prl_to, tosym);
106865 free(prl_to);
106866 break;
106867 + case DATA_TO_TEXT:
106868 +#if 0
106869 + fprintf(stderr,
106870 + "The %s %s:%s references\n"
106871 + "the %s %s:%s%s\n",
106872 + from, fromsec, fromsym, to, tosec, tosym, to_p);
106873 +#endif
106874 + break;
106875 }
106876 fprintf(stderr, "\n");
106877 }
106878 @@ -1659,7 +1674,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
106879 static void check_sec_ref(struct module *mod, const char *modname,
106880 struct elf_info *elf)
106881 {
106882 - int i;
106883 + unsigned int i;
106884 Elf_Shdr *sechdrs = elf->sechdrs;
106885
106886 /* Walk through all sections */
106887 @@ -1790,7 +1805,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
106888 va_end(ap);
106889 }
106890
106891 -void buf_write(struct buffer *buf, const char *s, int len)
106892 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
106893 {
106894 if (buf->size - buf->pos < len) {
106895 buf->size += len + SZ;
106896 @@ -2009,7 +2024,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
106897 if (fstat(fileno(file), &st) < 0)
106898 goto close_write;
106899
106900 - if (st.st_size != b->pos)
106901 + if (st.st_size != (off_t)b->pos)
106902 goto close_write;
106903
106904 tmp = NOFAIL(malloc(b->pos));
106905 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
106906 index 168b43d..77914bf 100644
106907 --- a/scripts/mod/modpost.h
106908 +++ b/scripts/mod/modpost.h
106909 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
106910
106911 struct buffer {
106912 char *p;
106913 - int pos;
106914 - int size;
106915 + unsigned int pos;
106916 + unsigned int size;
106917 };
106918
106919 void __attribute__((format(printf, 2, 3)))
106920 buf_printf(struct buffer *buf, const char *fmt, ...);
106921
106922 void
106923 -buf_write(struct buffer *buf, const char *s, int len);
106924 +buf_write(struct buffer *buf, const char *s, unsigned int len);
106925
106926 struct module {
106927 struct module *next;
106928 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
106929 index 944418d..15291e4 100644
106930 --- a/scripts/mod/sumversion.c
106931 +++ b/scripts/mod/sumversion.c
106932 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
106933 goto out;
106934 }
106935
106936 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
106937 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
106938 warn("writing sum in %s failed: %s\n",
106939 filename, strerror(errno));
106940 goto out;
106941 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
106942 index 0865b3e..7235dd4 100644
106943 --- a/scripts/module-common.lds
106944 +++ b/scripts/module-common.lds
106945 @@ -6,6 +6,10 @@
106946 SECTIONS {
106947 /DISCARD/ : { *(.discard) }
106948
106949 + .rodata : {
106950 + *(.rodata) *(.rodata.*)
106951 + *(.data..read_only)
106952 + }
106953 __ksymtab : { *(SORT(___ksymtab+*)) }
106954 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
106955 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
106956 diff --git a/scripts/package/Makefile b/scripts/package/Makefile
106957 index 99ca6e7..3a1a1a1 100644
106958 --- a/scripts/package/Makefile
106959 +++ b/scripts/package/Makefile
106960 @@ -46,7 +46,7 @@ rpm-pkg rpm: FORCE
106961 ln -sf $(srctree) $(KERNELPATH)
106962 $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec
106963 $(CONFIG_SHELL) $(srctree)/scripts/setlocalversion --save-scmversion
106964 - tar -cz $(RCS_TAR_IGNORE) -f $(KERNELPATH).tar.gz $(TAR_CONTENT)
106965 + tar --owner=root --group=root -cz $(RCS_TAR_IGNORE) -f $(KERNELPATH).tar.gz $(TAR_CONTENT)
106966 rm $(KERNELPATH)
106967 rm -f $(objtree)/.scmversion
106968 $(CONFIG_SHELL) $(srctree)/scripts/mkversion > $(objtree)/.tmp_version
106969 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
106970 index 5972624..4028795 100755
106971 --- a/scripts/package/builddeb
106972 +++ b/scripts/package/builddeb
106973 @@ -293,6 +293,7 @@ fi
106974 (cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> "$objtree/debian/hdrsrcfiles"
106975 (cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> "$objtree/debian/hdrsrcfiles"
106976 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f) >> "$objtree/debian/hdrobjfiles"
106977 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
106978 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
106979 mkdir -p "$destdir"
106980 (cd $srctree; tar -c -f - -T -) < "$objtree/debian/hdrsrcfiles" | (cd $destdir; tar -xf -)
106981 diff --git a/scripts/package/mkspec b/scripts/package/mkspec
106982 index 1395760..bca2734 100755
106983 --- a/scripts/package/mkspec
106984 +++ b/scripts/package/mkspec
106985 @@ -121,29 +121,40 @@ echo 'rm -f $RPM_BUILD_ROOT'"/lib/modules/$KERNELRELEASE/{build,source}"
106986 echo "mkdir -p "'$RPM_BUILD_ROOT'"/usr/src/kernels/$KERNELRELEASE"
106987 echo "EXCLUDES=\"$RCS_TAR_IGNORE --exclude .tmp_versions --exclude=*vmlinux* --exclude=*.o --exclude=*.ko --exclude=*.cmd --exclude=Documentation --exclude=firmware --exclude .config.old --exclude .missing-syscalls.d\""
106988 echo "tar "'$EXCLUDES'" -cf- . | (cd "'$RPM_BUILD_ROOT'"/usr/src/kernels/$KERNELRELEASE;tar xvf -)"
106989 -echo 'cd $RPM_BUILD_ROOT'"/lib/modules/$KERNELRELEASE"
106990 -echo "ln -sf /usr/src/kernels/$KERNELRELEASE build"
106991 -echo "ln -sf /usr/src/kernels/$KERNELRELEASE source"
106992
106993 echo ""
106994 echo "%clean"
106995 echo 'rm -rf $RPM_BUILD_ROOT'
106996 echo ""
106997 +echo "%pre"
106998 +echo 'chmod -f 0500 /boot'
106999 +echo 'if [ -d /lib/modules ]; then'
107000 +echo 'chmod -f 0500 /lib/modules'
107001 +echo 'fi'
107002 +echo 'if [ -d /lib32/modules ]; then'
107003 +echo 'chmod -f 0500 /lib32/modules'
107004 +echo 'fi'
107005 +echo 'if [ -d /lib64/modules ]; then'
107006 +echo 'chmod -f 0500 /lib64/modules'
107007 +echo 'fi'
107008 +echo ""
107009 +echo "%post devel"
107010 +echo "ln -sf /usr/src/kernels/$KERNELRELEASE /lib/modules/$KERNELRELEASE/build"
107011 +echo "ln -sf /usr/src/kernels/$KERNELRELEASE /lib/modules/$KERNELRELEASE/source"
107012 +echo ""
107013 echo "%post"
107014 -echo "if [ -x /sbin/installkernel -a -r /boot/vmlinuz-$KERNELRELEASE -a -r /boot/System.map-$KERNELRELEASE ]; then"
107015 -echo "cp /boot/vmlinuz-$KERNELRELEASE /boot/vmlinuz-$KERNELRELEASE-rpm"
107016 -echo "cp /boot/System.map-$KERNELRELEASE /boot/System.map-$KERNELRELEASE-rpm"
107017 -echo "rm -f /boot/vmlinuz-$KERNELRELEASE /boot/System.map-$KERNELRELEASE"
107018 -echo "/sbin/installkernel $KERNELRELEASE /boot/vmlinuz-$KERNELRELEASE-rpm /boot/System.map-$KERNELRELEASE-rpm"
107019 -echo "rm -f /boot/vmlinuz-$KERNELRELEASE-rpm /boot/System.map-$KERNELRELEASE-rpm"
107020 +echo "if [ -x /sbin/dracut ]; then"
107021 +echo '/sbin/new-kernel-pkg --dracut --mkinitrd --depmod --install --make-default '"$KERNELRELEASE"' || exit $?'
107022 +echo "else"
107023 +echo '/sbin/new-kernel-pkg --mkinitrd --depmod --install --make-default '"$KERNELRELEASE"' || exit $?'
107024 echo "fi"
107025 echo ""
107026 echo "%files"
107027 -echo '%defattr (-, root, root)'
107028 +echo '%defattr (400, root, root, 500)'
107029 echo "%dir /lib/modules"
107030 -echo "/lib/modules/$KERNELRELEASE"
107031 echo "%exclude /lib/modules/$KERNELRELEASE/build"
107032 echo "%exclude /lib/modules/$KERNELRELEASE/source"
107033 +echo "/lib/modules/$KERNELRELEASE"
107034 echo "/lib/firmware/$KERNELRELEASE"
107035 echo "/boot/*"
107036 echo ""
107037 @@ -152,8 +163,7 @@ echo '%defattr (-, root, root)'
107038 echo "/usr/include"
107039 echo ""
107040 echo "%files devel"
107041 -echo '%defattr (-, root, root)'
107042 +echo '%defattr (400, root, root, 500)'
107043 +echo "%dir /lib/modules/$KERNELRELEASE"
107044 echo "/usr/src/kernels/$KERNELRELEASE"
107045 -echo "/lib/modules/$KERNELRELEASE/build"
107046 -echo "/lib/modules/$KERNELRELEASE/source"
107047 echo ""
107048 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
107049 index 4718d78..9220d58 100644
107050 --- a/scripts/pnmtologo.c
107051 +++ b/scripts/pnmtologo.c
107052 @@ -244,14 +244,14 @@ static void write_header(void)
107053 fprintf(out, " * Linux logo %s\n", logoname);
107054 fputs(" */\n\n", out);
107055 fputs("#include <linux/linux_logo.h>\n\n", out);
107056 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
107057 + fprintf(out, "static unsigned char %s_data[] = {\n",
107058 logoname);
107059 }
107060
107061 static void write_footer(void)
107062 {
107063 fputs("\n};\n\n", out);
107064 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
107065 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
107066 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
107067 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
107068 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
107069 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
107070 fputs("\n};\n\n", out);
107071
107072 /* write logo clut */
107073 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
107074 + fprintf(out, "static unsigned char %s_clut[] = {\n",
107075 logoname);
107076 write_hex_cnt = 0;
107077 for (i = 0; i < logo_clutsize; i++) {
107078 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
107079 index ba87004..3f4852c 100644
107080 --- a/scripts/sortextable.h
107081 +++ b/scripts/sortextable.h
107082 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
107083 const char *secstrtab;
107084 const char *strtab;
107085 char *extab_image;
107086 - int extab_index = 0;
107087 - int i;
107088 - int idx;
107089 + unsigned int extab_index = 0;
107090 + unsigned int i;
107091 + unsigned int idx;
107092 unsigned int num_sections;
107093 unsigned int secindex_strings;
107094
107095 diff --git a/scripts/tags.sh b/scripts/tags.sh
107096 index cdb491d..8d32bfc 100755
107097 --- a/scripts/tags.sh
107098 +++ b/scripts/tags.sh
107099 @@ -26,7 +26,7 @@ else
107100 fi
107101
107102 # ignore userspace tools
107103 -ignore="$ignore ( -path ${tree}tools ) -prune -o"
107104 +ignore="$ignore ( -path \"${tree}tools/[^g]*\" ) -prune -o"
107105
107106 # Find all available archs
107107 find_all_archs()
107108 diff --git a/security/Kconfig b/security/Kconfig
107109 index beb86b5..1a953b1 100644
107110 --- a/security/Kconfig
107111 +++ b/security/Kconfig
107112 @@ -4,6 +4,974 @@
107113
107114 menu "Security options"
107115
107116 +menu "Grsecurity"
107117 +
107118 + config ARCH_TRACK_EXEC_LIMIT
107119 + bool
107120 +
107121 + config PAX_KERNEXEC_PLUGIN
107122 + bool
107123 +
107124 + config PAX_PER_CPU_PGD
107125 + bool
107126 +
107127 + config TASK_SIZE_MAX_SHIFT
107128 + int
107129 + depends on X86_64
107130 + default 47 if !PAX_PER_CPU_PGD
107131 + default 42 if PAX_PER_CPU_PGD
107132 +
107133 + config PAX_ENABLE_PAE
107134 + bool
107135 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
107136 +
107137 + config PAX_USERCOPY_SLABS
107138 + bool
107139 +
107140 +config GRKERNSEC
107141 + bool "Grsecurity"
107142 + select CRYPTO
107143 + select CRYPTO_SHA256
107144 + select PROC_FS
107145 + select STOP_MACHINE
107146 + select TTY
107147 + select DEBUG_KERNEL
107148 + select DEBUG_LIST
107149 + help
107150 + If you say Y here, you will be able to configure many features
107151 + that will enhance the security of your system. It is highly
107152 + recommended that you say Y here and read through the help
107153 + for each option so that you fully understand the features and
107154 + can evaluate their usefulness for your machine.
107155 +
107156 +choice
107157 + prompt "Configuration Method"
107158 + depends on GRKERNSEC
107159 + default GRKERNSEC_CONFIG_CUSTOM
107160 + help
107161 +
107162 +config GRKERNSEC_CONFIG_AUTO
107163 + bool "Automatic"
107164 + help
107165 + If you choose this configuration method, you'll be able to answer a small
107166 + number of simple questions about how you plan to use this kernel.
107167 + The settings of grsecurity and PaX will be automatically configured for
107168 + the highest commonly-used settings within the provided constraints.
107169 +
107170 + If you require additional configuration, custom changes can still be made
107171 + from the "custom configuration" menu.
107172 +
107173 +config GRKERNSEC_CONFIG_CUSTOM
107174 + bool "Custom"
107175 + help
107176 + If you choose this configuration method, you'll be able to configure all
107177 + grsecurity and PaX settings manually. Via this method, no options are
107178 + automatically enabled.
107179 +
107180 +endchoice
107181 +
107182 +choice
107183 + prompt "Usage Type"
107184 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
107185 + default GRKERNSEC_CONFIG_SERVER
107186 + help
107187 +
107188 +config GRKERNSEC_CONFIG_SERVER
107189 + bool "Server"
107190 + help
107191 + Choose this option if you plan to use this kernel on a server.
107192 +
107193 +config GRKERNSEC_CONFIG_DESKTOP
107194 + bool "Desktop"
107195 + help
107196 + Choose this option if you plan to use this kernel on a desktop.
107197 +
107198 +endchoice
107199 +
107200 +choice
107201 + prompt "Virtualization Type"
107202 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
107203 + default GRKERNSEC_CONFIG_VIRT_NONE
107204 + help
107205 +
107206 +config GRKERNSEC_CONFIG_VIRT_NONE
107207 + bool "None"
107208 + help
107209 + Choose this option if this kernel will be run on bare metal.
107210 +
107211 +config GRKERNSEC_CONFIG_VIRT_GUEST
107212 + bool "Guest"
107213 + help
107214 + Choose this option if this kernel will be run as a VM guest.
107215 +
107216 +config GRKERNSEC_CONFIG_VIRT_HOST
107217 + bool "Host"
107218 + help
107219 + Choose this option if this kernel will be run as a VM host.
107220 +
107221 +endchoice
107222 +
107223 +choice
107224 + prompt "Virtualization Hardware"
107225 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
107226 + help
107227 +
107228 +config GRKERNSEC_CONFIG_VIRT_EPT
107229 + bool "EPT/RVI Processor Support"
107230 + depends on X86
107231 + help
107232 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
107233 + hardware virtualization. This allows for additional kernel hardening protections
107234 + to operate without additional performance impact.
107235 +
107236 + To see if your Intel processor supports EPT, see:
107237 + http://ark.intel.com/Products/VirtualizationTechnology
107238 + (Most Core i3/5/7 support EPT)
107239 +
107240 + To see if your AMD processor supports RVI, see:
107241 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
107242 +
107243 +config GRKERNSEC_CONFIG_VIRT_SOFT
107244 + bool "First-gen/No Hardware Virtualization"
107245 + help
107246 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
107247 + support hardware virtualization or doesn't support the EPT/RVI extensions.
107248 +
107249 +endchoice
107250 +
107251 +choice
107252 + prompt "Virtualization Software"
107253 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
107254 + help
107255 +
107256 +config GRKERNSEC_CONFIG_VIRT_XEN
107257 + bool "Xen"
107258 + help
107259 + Choose this option if this kernel is running as a Xen guest or host.
107260 +
107261 +config GRKERNSEC_CONFIG_VIRT_VMWARE
107262 + bool "VMWare"
107263 + help
107264 + Choose this option if this kernel is running as a VMWare guest or host.
107265 +
107266 +config GRKERNSEC_CONFIG_VIRT_KVM
107267 + bool "KVM"
107268 + help
107269 + Choose this option if this kernel is running as a KVM guest or host.
107270 +
107271 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
107272 + bool "VirtualBox"
107273 + help
107274 + Choose this option if this kernel is running as a VirtualBox guest or host.
107275 +
107276 +config GRKERNSEC_CONFIG_VIRT_HYPERV
107277 + bool "Hyper-V"
107278 + help
107279 + Choose this option if this kernel is running as a Hyper-V guest.
107280 +
107281 +endchoice
107282 +
107283 +choice
107284 + prompt "Required Priorities"
107285 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
107286 + default GRKERNSEC_CONFIG_PRIORITY_PERF
107287 + help
107288 +
107289 +config GRKERNSEC_CONFIG_PRIORITY_PERF
107290 + bool "Performance"
107291 + help
107292 + Choose this option if performance is of highest priority for this deployment
107293 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
107294 + clearing of structures intended for userland, and freed memory sanitizing will
107295 + be disabled.
107296 +
107297 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
107298 + bool "Security"
107299 + help
107300 + Choose this option if security is of highest priority for this deployment of
107301 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
107302 + for userland, and freed memory sanitizing will be enabled for this kernel.
107303 + In a worst-case scenario, these features can introduce a 20% performance hit
107304 + (UDEREF on x64 contributing half of this hit).
107305 +
107306 +endchoice
107307 +
107308 +menu "Default Special Groups"
107309 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
107310 +
107311 +config GRKERNSEC_PROC_GID
107312 + int "GID exempted from /proc restrictions"
107313 + default 1001
107314 + help
107315 + Setting this GID determines which group will be exempted from
107316 + grsecurity's /proc restrictions, allowing users of the specified
107317 + group to view network statistics and the existence of other users'
107318 + processes on the system. This GID may also be chosen at boot time
107319 + via "grsec_proc_gid=" on the kernel commandline.
107320 +
107321 +config GRKERNSEC_TPE_UNTRUSTED_GID
107322 + int "GID for TPE-untrusted users"
107323 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
107324 + default 1005
107325 + help
107326 + Setting this GID determines which group untrusted users should
107327 + be added to. These users will be placed under grsecurity's Trusted Path
107328 + Execution mechanism, preventing them from executing their own binaries.
107329 + The users will only be able to execute binaries in directories owned and
107330 + writable only by the root user. If the sysctl option is enabled, a sysctl
107331 + option with name "tpe_gid" is created.
107332 +
107333 +config GRKERNSEC_TPE_TRUSTED_GID
107334 + int "GID for TPE-trusted users"
107335 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
107336 + default 1005
107337 + help
107338 + Setting this GID determines what group TPE restrictions will be
107339 + *disabled* for. If the sysctl option is enabled, a sysctl option
107340 + with name "tpe_gid" is created.
107341 +
107342 +config GRKERNSEC_SYMLINKOWN_GID
107343 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
107344 + depends on GRKERNSEC_CONFIG_SERVER
107345 + default 1006
107346 + help
107347 + Setting this GID determines what group kernel-enforced
107348 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
107349 + is enabled, a sysctl option with name "symlinkown_gid" is created.
107350 +
107351 +
107352 +endmenu
107353 +
107354 +menu "Customize Configuration"
107355 +depends on GRKERNSEC
107356 +
107357 +menu "PaX"
107358 +
107359 +config PAX
107360 + bool "Enable various PaX features"
107361 + default y if GRKERNSEC_CONFIG_AUTO
107362 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
107363 + help
107364 + This allows you to enable various PaX features. PaX adds
107365 + intrusion prevention mechanisms to the kernel that reduce
107366 + the risks posed by exploitable memory corruption bugs.
107367 +
107368 +menu "PaX Control"
107369 + depends on PAX
107370 +
107371 +config PAX_SOFTMODE
107372 + bool 'Support soft mode'
107373 + help
107374 + Enabling this option will allow you to run PaX in soft mode, that
107375 + is, PaX features will not be enforced by default, only on executables
107376 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
107377 + support as they are the only way to mark executables for soft mode use.
107378 +
107379 + Soft mode can be activated by using the "pax_softmode=1" kernel command
107380 + line option on boot. Furthermore you can control various PaX features
107381 + at runtime via the entries in /proc/sys/kernel/pax.
107382 +
107383 +config PAX_EI_PAX
107384 + bool 'Use legacy ELF header marking'
107385 + default y if GRKERNSEC_CONFIG_AUTO
107386 + help
107387 + Enabling this option will allow you to control PaX features on
107388 + a per executable basis via the 'chpax' utility available at
107389 + http://pax.grsecurity.net/. The control flags will be read from
107390 + an otherwise reserved part of the ELF header. This marking has
107391 + numerous drawbacks (no support for soft-mode, toolchain does not
107392 + know about the non-standard use of the ELF header) therefore it
107393 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
107394 + support.
107395 +
107396 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
107397 + support as well, they will override the legacy EI_PAX marks.
107398 +
107399 + If you enable none of the marking options then all applications
107400 + will run with PaX enabled on them by default.
107401 +
107402 +config PAX_PT_PAX_FLAGS
107403 + bool 'Use ELF program header marking'
107404 + default y if GRKERNSEC_CONFIG_AUTO
107405 + help
107406 + Enabling this option will allow you to control PaX features on
107407 + a per executable basis via the 'paxctl' utility available at
107408 + http://pax.grsecurity.net/. The control flags will be read from
107409 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
107410 + has the benefits of supporting both soft mode and being fully
107411 + integrated into the toolchain (the binutils patch is available
107412 + from http://pax.grsecurity.net).
107413 +
107414 + Note that if you enable the legacy EI_PAX marking support as well,
107415 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
107416 +
107417 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
107418 + must make sure that the marks are the same if a binary has both marks.
107419 +
107420 + If you enable none of the marking options then all applications
107421 + will run with PaX enabled on them by default.
107422 +
107423 +config PAX_XATTR_PAX_FLAGS
107424 + bool 'Use filesystem extended attributes marking'
107425 + default y if GRKERNSEC_CONFIG_AUTO
107426 + select CIFS_XATTR if CIFS
107427 + select F2FS_FS_XATTR if F2FS_FS
107428 + select EXT2_FS_XATTR if EXT2_FS
107429 + select EXT3_FS_XATTR if EXT3_FS
107430 + select JFFS2_FS_XATTR if JFFS2_FS
107431 + select REISERFS_FS_XATTR if REISERFS_FS
107432 + select SQUASHFS_XATTR if SQUASHFS
107433 + select TMPFS_XATTR if TMPFS
107434 + help
107435 + Enabling this option will allow you to control PaX features on
107436 + a per executable basis via the 'setfattr' utility. The control
107437 + flags will be read from the user.pax.flags extended attribute of
107438 + the file. This marking has the benefit of supporting binary-only
107439 + applications that self-check themselves (e.g., skype) and would
107440 + not tolerate chpax/paxctl changes. The main drawback is that
107441 + extended attributes are not supported by some filesystems (e.g.,
107442 + isofs, udf, vfat) so copying files through such filesystems will
107443 + lose the extended attributes and these PaX markings.
107444 +
107445 + Note that if you enable the legacy EI_PAX marking support as well,
107446 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
107447 +
107448 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
107449 + must make sure that the marks are the same if a binary has both marks.
107450 +
107451 + If you enable none of the marking options then all applications
107452 + will run with PaX enabled on them by default.
107453 +
107454 +choice
107455 + prompt 'MAC system integration'
107456 + default PAX_HAVE_ACL_FLAGS
107457 + help
107458 + Mandatory Access Control systems have the option of controlling
107459 + PaX flags on a per executable basis, choose the method supported
107460 + by your particular system.
107461 +
107462 + - "none": if your MAC system does not interact with PaX,
107463 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
107464 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
107465 +
107466 + NOTE: this option is for developers/integrators only.
107467 +
107468 + config PAX_NO_ACL_FLAGS
107469 + bool 'none'
107470 +
107471 + config PAX_HAVE_ACL_FLAGS
107472 + bool 'direct'
107473 +
107474 + config PAX_HOOK_ACL_FLAGS
107475 + bool 'hook'
107476 +endchoice
107477 +
107478 +endmenu
107479 +
107480 +menu "Non-executable pages"
107481 + depends on PAX
107482 +
107483 +config PAX_NOEXEC
107484 + bool "Enforce non-executable pages"
107485 + default y if GRKERNSEC_CONFIG_AUTO
107486 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
107487 + help
107488 + By design some architectures do not allow for protecting memory
107489 + pages against execution or even if they do, Linux does not make
107490 + use of this feature. In practice this means that if a page is
107491 + readable (such as the stack or heap) it is also executable.
107492 +
107493 + There is a well known exploit technique that makes use of this
107494 + fact and a common programming mistake where an attacker can
107495 + introduce code of his choice somewhere in the attacked program's
107496 + memory (typically the stack or the heap) and then execute it.
107497 +
107498 + If the attacked program was running with different (typically
107499 + higher) privileges than that of the attacker, then he can elevate
107500 + his own privilege level (e.g. get a root shell, write to files for
107501 + which he does not have write access to, etc).
107502 +
107503 + Enabling this option will let you choose from various features
107504 + that prevent the injection and execution of 'foreign' code in
107505 + a program.
107506 +
107507 + This will also break programs that rely on the old behaviour and
107508 + expect that dynamically allocated memory via the malloc() family
107509 + of functions is executable (which it is not). Notable examples
107510 + are the XFree86 4.x server, the java runtime and wine.
107511 +
107512 +config PAX_PAGEEXEC
107513 + bool "Paging based non-executable pages"
107514 + default y if GRKERNSEC_CONFIG_AUTO
107515 + depends on PAX_NOEXEC && (!X86_32 || M586 || M586TSC || M586MMX || M686 || MPENTIUMII || MPENTIUMIII || MPENTIUMM || MCORE2 || MATOM || MPENTIUM4 || MPSC || MK7 || MK8 || MWINCHIPC6 || MWINCHIP2 || MWINCHIP3D || MVIAC3_2 || MVIAC7)
107516 + select ARCH_TRACK_EXEC_LIMIT if X86_32
107517 + help
107518 + This implementation is based on the paging feature of the CPU.
107519 + On i386 without hardware non-executable bit support there is a
107520 + variable but usually low performance impact, however on Intel's
107521 + P4 core based CPUs it is very high so you should not enable this
107522 + for kernels meant to be used on such CPUs.
107523 +
107524 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
107525 + with hardware non-executable bit support there is no performance
107526 + impact, on ppc the impact is negligible.
107527 +
107528 + Note that several architectures require various emulations due to
107529 + badly designed userland ABIs, this will cause a performance impact
107530 + but will disappear as soon as userland is fixed. For example, ppc
107531 + userland MUST have been built with secure-plt by a recent toolchain.
107532 +
107533 +config PAX_SEGMEXEC
107534 + bool "Segmentation based non-executable pages"
107535 + default y if GRKERNSEC_CONFIG_AUTO
107536 + depends on PAX_NOEXEC && X86_32
107537 + help
107538 + This implementation is based on the segmentation feature of the
107539 + CPU and has a very small performance impact, however applications
107540 + will be limited to a 1.5 GB address space instead of the normal
107541 + 3 GB.
107542 +
107543 +config PAX_EMUTRAMP
107544 + bool "Emulate trampolines"
107545 + default y if PARISC || GRKERNSEC_CONFIG_AUTO
107546 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
107547 + help
107548 + There are some programs and libraries that for one reason or
107549 + another attempt to execute special small code snippets from
107550 + non-executable memory pages. Most notable examples are the
107551 + signal handler return code generated by the kernel itself and
107552 + the GCC trampolines.
107553 +
107554 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
107555 + such programs will no longer work under your kernel.
107556 +
107557 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
107558 + utilities to enable trampoline emulation for the affected programs
107559 + yet still have the protection provided by the non-executable pages.
107560 +
107561 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
107562 + your system will not even boot.
107563 +
107564 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
107565 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
107566 + for the affected files.
107567 +
107568 + NOTE: enabling this feature *may* open up a loophole in the
107569 + protection provided by non-executable pages that an attacker
107570 + could abuse. Therefore the best solution is to not have any
107571 + files on your system that would require this option. This can
107572 + be achieved by not using libc5 (which relies on the kernel
107573 + signal handler return code) and not using or rewriting programs
107574 + that make use of the nested function implementation of GCC.
107575 + Skilled users can just fix GCC itself so that it implements
107576 + nested function calls in a way that does not interfere with PaX.
107577 +
107578 +config PAX_EMUSIGRT
107579 + bool "Automatically emulate sigreturn trampolines"
107580 + depends on PAX_EMUTRAMP && PARISC
107581 + default y
107582 + help
107583 + Enabling this option will have the kernel automatically detect
107584 + and emulate signal return trampolines executing on the stack
107585 + that would otherwise lead to task termination.
107586 +
107587 + This solution is intended as a temporary one for users with
107588 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
107589 + Modula-3 runtime, etc) or executables linked to such, basically
107590 + everything that does not specify its own SA_RESTORER function in
107591 + normal executable memory like glibc 2.1+ does.
107592 +
107593 + On parisc you MUST enable this option, otherwise your system will
107594 + not even boot.
107595 +
107596 + NOTE: this feature cannot be disabled on a per executable basis
107597 + and since it *does* open up a loophole in the protection provided
107598 + by non-executable pages, the best solution is to not have any
107599 + files on your system that would require this option.
107600 +
107601 +config PAX_MPROTECT
107602 + bool "Restrict mprotect()"
107603 + default y if GRKERNSEC_CONFIG_AUTO
107604 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
107605 + help
107606 + Enabling this option will prevent programs from
107607 + - changing the executable status of memory pages that were
107608 + not originally created as executable,
107609 + - making read-only executable pages writable again,
107610 + - creating executable pages from anonymous memory,
107611 + - making read-only-after-relocations (RELRO) data pages writable again.
107612 +
107613 + You should say Y here to complete the protection provided by
107614 + the enforcement of non-executable pages.
107615 +
107616 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
107617 + this feature on a per file basis.
107618 +
107619 +config PAX_MPROTECT_COMPAT
107620 + bool "Use legacy/compat protection demoting (read help)"
107621 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
107622 + depends on PAX_MPROTECT
107623 + help
107624 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
107625 + by sending the proper error code to the application. For some broken
107626 + userland, this can cause problems with Python or other applications. The
107627 + current implementation however allows for applications like clamav to
107628 + detect if JIT compilation/execution is allowed and to fall back gracefully
107629 + to an interpreter-based mode if it does not. While we encourage everyone
107630 + to use the current implementation as-is and push upstream to fix broken
107631 + userland (note that the RWX logging option can assist with this), in some
107632 + environments this may not be possible. Having to disable MPROTECT
107633 + completely on certain binaries reduces the security benefit of PaX,
107634 + so this option is provided for those environments to revert to the old
107635 + behavior.
107636 +
107637 +config PAX_ELFRELOCS
107638 + bool "Allow ELF text relocations (read help)"
107639 + depends on PAX_MPROTECT
107640 + default n
107641 + help
107642 + Non-executable pages and mprotect() restrictions are effective
107643 + in preventing the introduction of new executable code into an
107644 + attacked task's address space. There remain only two venues
107645 + for this kind of attack: if the attacker can execute already
107646 + existing code in the attacked task then he can either have it
107647 + create and mmap() a file containing his code or have it mmap()
107648 + an already existing ELF library that does not have position
107649 + independent code in it and use mprotect() on it to make it
107650 + writable and copy his code there. While protecting against
107651 + the former approach is beyond PaX, the latter can be prevented
107652 + by having only PIC ELF libraries on one's system (which do not
107653 + need to relocate their code). If you are sure this is your case,
107654 + as is the case with all modern Linux distributions, then leave
107655 + this option disabled. You should say 'n' here.
107656 +
107657 +config PAX_ETEXECRELOCS
107658 + bool "Allow ELF ET_EXEC text relocations"
107659 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
107660 + select PAX_ELFRELOCS
107661 + default y
107662 + help
107663 + On some architectures there are incorrectly created applications
107664 + that require text relocations and would not work without enabling
107665 + this option. If you are an alpha, ia64 or parisc user, you should
107666 + enable this option and disable it once you have made sure that
107667 + none of your applications need it.
107668 +
107669 +config PAX_EMUPLT
107670 + bool "Automatically emulate ELF PLT"
107671 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
107672 + default y
107673 + help
107674 + Enabling this option will have the kernel automatically detect
107675 + and emulate the Procedure Linkage Table entries in ELF files.
107676 + On some architectures such entries are in writable memory, and
107677 + become non-executable leading to task termination. Therefore
107678 + it is mandatory that you enable this option on alpha, parisc,
107679 + sparc and sparc64, otherwise your system would not even boot.
107680 +
107681 + NOTE: this feature *does* open up a loophole in the protection
107682 + provided by the non-executable pages, therefore the proper
107683 + solution is to modify the toolchain to produce a PLT that does
107684 + not need to be writable.
107685 +
107686 +config PAX_DLRESOLVE
107687 + bool 'Emulate old glibc resolver stub'
107688 + depends on PAX_EMUPLT && SPARC
107689 + default n
107690 + help
107691 + This option is needed if userland has an old glibc (before 2.4)
107692 + that puts a 'save' instruction into the runtime generated resolver
107693 + stub that needs special emulation.
107694 +
107695 +config PAX_KERNEXEC
107696 + bool "Enforce non-executable kernel pages"
107697 + default y if GRKERNSEC_CONFIG_AUTO && (!X86 || GRKERNSEC_CONFIG_VIRT_NONE || (GRKERNSEC_CONFIG_VIRT_EPT && GRKERNSEC_CONFIG_VIRT_GUEST) || (GRKERNSEC_CONFIG_VIRT_EPT && GRKERNSEC_CONFIG_VIRT_KVM))
107698 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
107699 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
107700 + select PAX_KERNEXEC_PLUGIN if X86_64
107701 + help
107702 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
107703 + that is, enabling this option will make it harder to inject
107704 + and execute 'foreign' code in kernel memory itself.
107705 +
107706 + Note that on amd64, CONFIG_EFI enabled with "efi=old_map" on
107707 + the kernel command-line will result in an RWX physical map.
107708 +
107709 + Likewise, the EFI runtime services are necessarily mapped as
107710 + RWX. If CONFIG_EFI is enabled on an EFI-capable system, it
107711 + is recommended that you boot with "noefi" on the kernel
107712 + command-line if possible to eliminate the mapping.
107713 +
107714 +choice
107715 + prompt "Return Address Instrumentation Method"
107716 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
107717 + depends on PAX_KERNEXEC_PLUGIN
107718 + help
107719 + Select the method used to instrument function pointer dereferences.
107720 + Note that binary modules cannot be instrumented by this approach.
107721 +
107722 + Note that the implementation requires a gcc with plugin support,
107723 + i.e., gcc 4.5 or newer. You may need to install the supporting
107724 + headers explicitly in addition to the normal gcc package.
107725 +
107726 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
107727 + bool "bts"
107728 + help
107729 + This method is compatible with binary only modules but has
107730 + a higher runtime overhead.
107731 +
107732 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
107733 + bool "or"
107734 + depends on !PARAVIRT
107735 + help
107736 + This method is incompatible with binary only modules but has
107737 + a lower runtime overhead.
107738 +endchoice
107739 +
107740 +config PAX_KERNEXEC_PLUGIN_METHOD
107741 + string
107742 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
107743 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
107744 + default ""
107745 +
107746 +config PAX_KERNEXEC_MODULE_TEXT
107747 + int "Minimum amount of memory reserved for module code"
107748 + default "8" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
107749 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
107750 + depends on PAX_KERNEXEC && X86_32
107751 + help
107752 + Due to implementation details the kernel must reserve a fixed
107753 + amount of memory for runtime allocated code (such as modules)
107754 + at compile time that cannot be changed at runtime. Here you
107755 + can specify the minimum amount in MB that will be reserved.
107756 + Due to the same implementation details this size will always
107757 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
107758 + the actually available memory for runtime allocated code will
107759 + usually be more than this minimum.
107760 +
107761 + The default 4 MB should be enough for most users but if you have
107762 + an excessive number of modules (e.g., most distribution configs
107763 + compile many drivers as modules) or use huge modules such as
107764 + nvidia's kernel driver, you will need to adjust this amount.
107765 + A good rule of thumb is to look at your currently loaded kernel
107766 + modules and add up their sizes.
107767 +
107768 +endmenu
107769 +
107770 +menu "Address Space Layout Randomization"
107771 + depends on PAX
107772 +
107773 +config PAX_ASLR
107774 + bool "Address Space Layout Randomization"
107775 + default y if GRKERNSEC_CONFIG_AUTO
107776 + help
107777 + Many if not most exploit techniques rely on the knowledge of
107778 + certain addresses in the attacked program. The following options
107779 + will allow the kernel to apply a certain amount of randomization
107780 + to specific parts of the program thereby forcing an attacker to
107781 + guess them in most cases. Any failed guess will most likely crash
107782 + the attacked program which allows the kernel to detect such attempts
107783 + and react on them. PaX itself provides no reaction mechanisms,
107784 + instead it is strongly encouraged that you make use of grsecurity's
107785 + (http://www.grsecurity.net/) built-in crash detection features or
107786 + develop one yourself.
107787 +
107788 + By saying Y here you can choose to randomize the following areas:
107789 + - top of the task's kernel stack
107790 + - top of the task's userland stack
107791 + - base address for mmap() requests that do not specify one
107792 + (this includes all libraries)
107793 + - base address of the main executable
107794 +
107795 + It is strongly recommended to say Y here as address space layout
107796 + randomization has negligible impact on performance yet it provides
107797 + a very effective protection.
107798 +
107799 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
107800 + this feature on a per file basis.
107801 +
107802 +config PAX_RANDKSTACK
107803 + bool "Randomize kernel stack base"
107804 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
107805 + depends on X86_TSC && X86
107806 + help
107807 + By saying Y here the kernel will randomize every task's kernel
107808 + stack on every system call. This will not only force an attacker
107809 + to guess it but also prevent him from making use of possible
107810 + leaked information about it.
107811 +
107812 + Since the kernel stack is a rather scarce resource, randomization
107813 + may cause unexpected stack overflows, therefore you should very
107814 + carefully test your system. Note that once enabled in the kernel
107815 + configuration, this feature cannot be disabled on a per file basis.
107816 +
107817 +config PAX_RANDUSTACK
107818 + bool
107819 +
107820 +config PAX_RANDMMAP
107821 + bool "Randomize user stack and mmap() bases"
107822 + default y if GRKERNSEC_CONFIG_AUTO
107823 + depends on PAX_ASLR
107824 + select PAX_RANDUSTACK
107825 + help
107826 + By saying Y here the kernel will randomize every task's userland
107827 + stack and use a randomized base address for mmap() requests that
107828 + do not specify one themselves.
107829 +
107830 + The stack randomization is done in two steps where the second
107831 + one may apply a big amount of shift to the top of the stack and
107832 + cause problems for programs that want to use lots of memory (more
107833 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
107834 +
107835 + As a result of mmap randomization all dynamically loaded libraries
107836 + will appear at random addresses and therefore be harder to exploit
107837 + by a technique where an attacker attempts to execute library code
107838 + for his purposes (e.g. spawn a shell from an exploited program that
107839 + is running at an elevated privilege level).
107840 +
107841 + Furthermore, if a program is relinked as a dynamic ELF file, its
107842 + base address will be randomized as well, completing the full
107843 + randomization of the address space layout. Attacking such programs
107844 + becomes a guess game. You can find an example of doing this at
107845 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
107846 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
107847 +
107848 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
107849 + feature on a per file basis.
107850 +
107851 +endmenu
107852 +
107853 +menu "Miscellaneous hardening features"
107854 +
107855 +config PAX_MEMORY_SANITIZE
107856 + bool "Sanitize all freed memory"
107857 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
107858 + help
107859 + By saying Y here the kernel will erase memory pages and slab objects
107860 + as soon as they are freed. This in turn reduces the lifetime of data
107861 + stored in them, making it less likely that sensitive information such
107862 + as passwords, cryptographic secrets, etc stay in memory for too long.
107863 +
107864 + This is especially useful for programs whose runtime is short, long
107865 + lived processes and the kernel itself benefit from this as long as
107866 + they ensure timely freeing of memory that may hold sensitive
107867 + information.
107868 +
107869 + A nice side effect of the sanitization of slab objects is the
107870 + reduction of possible info leaks caused by padding bytes within the
107871 + leaky structures. Use-after-free bugs for structures containing
107872 + pointers can also be detected as dereferencing the sanitized pointer
107873 + will generate an access violation.
107874 +
107875 + The tradeoff is performance impact, on a single CPU system kernel
107876 + compilation sees a 3% slowdown, other systems and workloads may vary
107877 + and you are advised to test this feature on your expected workload
107878 + before deploying it.
107879 +
107880 + The slab sanitization feature excludes a few slab caches per default
107881 + for performance reasons. To extend the feature to cover those as
107882 + well, pass "pax_sanitize_slab=full" as kernel command line parameter.
107883 +
107884 + To reduce the performance penalty by sanitizing pages only, albeit
107885 + limiting the effectiveness of this feature at the same time, slab
107886 + sanitization can be disabled with the kernel command line parameter
107887 + "pax_sanitize_slab=off".
107888 +
107889 + Note that this feature does not protect data stored in live pages,
107890 + e.g., process memory swapped to disk may stay there for a long time.
107891 +
107892 +config PAX_MEMORY_STACKLEAK
107893 + bool "Sanitize kernel stack"
107894 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
107895 + depends on X86
107896 + help
107897 + By saying Y here the kernel will erase the kernel stack before it
107898 + returns from a system call. This in turn reduces the information
107899 + that a kernel stack leak bug can reveal.
107900 +
107901 + Note that such a bug can still leak information that was put on
107902 + the stack by the current system call (the one eventually triggering
107903 + the bug) but traces of earlier system calls on the kernel stack
107904 + cannot leak anymore.
107905 +
107906 + The tradeoff is performance impact: on a single CPU system kernel
107907 + compilation sees a 1% slowdown, other systems and workloads may vary
107908 + and you are advised to test this feature on your expected workload
107909 + before deploying it.
107910 +
107911 + Note that the full feature requires a gcc with plugin support,
107912 + i.e., gcc 4.5 or newer. You may need to install the supporting
107913 + headers explicitly in addition to the normal gcc package. Using
107914 + older gcc versions means that functions with large enough stack
107915 + frames may leave uninitialized memory behind that may be exposed
107916 + to a later syscall leaking the stack.
107917 +
107918 +config PAX_MEMORY_STRUCTLEAK
107919 + bool "Forcibly initialize local variables copied to userland"
107920 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
107921 + help
107922 + By saying Y here the kernel will zero initialize some local
107923 + variables that are going to be copied to userland. This in
107924 + turn prevents unintended information leakage from the kernel
107925 + stack should later code forget to explicitly set all parts of
107926 + the copied variable.
107927 +
107928 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
107929 + at a much smaller coverage.
107930 +
107931 + Note that the implementation requires a gcc with plugin support,
107932 + i.e., gcc 4.5 or newer. You may need to install the supporting
107933 + headers explicitly in addition to the normal gcc package.
107934 +
107935 +config PAX_MEMORY_UDEREF
107936 + bool "Prevent invalid userland pointer dereference"
107937 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (!X86 || GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
107938 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
107939 + select PAX_PER_CPU_PGD if X86_64
107940 + help
107941 + By saying Y here the kernel will be prevented from dereferencing
107942 + userland pointers in contexts where the kernel expects only kernel
107943 + pointers. This is both a useful runtime debugging feature and a
107944 + security measure that prevents exploiting a class of kernel bugs.
107945 +
107946 + The tradeoff is that some virtualization solutions may experience
107947 + a huge slowdown and therefore you should not enable this feature
107948 + for kernels meant to run in such environments. Whether a given VM
107949 + solution is affected or not is best determined by simply trying it
107950 + out, the performance impact will be obvious right on boot as this
107951 + mechanism engages from very early on. A good rule of thumb is that
107952 + VMs running on CPUs without hardware virtualization support (i.e.,
107953 + the majority of IA-32 CPUs) will likely experience the slowdown.
107954 +
107955 + On X86_64 the kernel will make use of PCID support when available
107956 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
107957 + or performance impact. Pass pax_weakuderef on the kernel command
107958 + line to choose the latter.
107959 +
107960 +config PAX_REFCOUNT
107961 + bool "Prevent various kernel object reference counter overflows"
107962 + default y if GRKERNSEC_CONFIG_AUTO
107963 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || PPC || SPARC64 || X86)
107964 + help
107965 + By saying Y here the kernel will detect and prevent overflowing
107966 + various (but not all) kinds of object reference counters. Such
107967 + overflows can normally occur due to bugs only and are often, if
107968 + not always, exploitable.
107969 +
107970 + The tradeoff is that data structures protected by an overflowed
107971 + refcount will never be freed and therefore will leak memory. Note
107972 + that this leak also happens even without this protection but in
107973 + that case the overflow can eventually trigger the freeing of the
107974 + data structure while it is still being used elsewhere, resulting
107975 + in the exploitable situation that this feature prevents.
107976 +
107977 + Since this has a negligible performance impact, you should enable
107978 + this feature.
107979 +
107980 +config PAX_CONSTIFY_PLUGIN
107981 + bool "Automatically constify eligible structures"
107982 + default y
107983 + depends on !UML && PAX_KERNEXEC
107984 + help
107985 + By saying Y here the compiler will automatically constify a class
107986 + of types that contain only function pointers. This reduces the
107987 + kernel's attack surface and also produces a better memory layout.
107988 +
107989 + Note that the implementation requires a gcc with plugin support,
107990 + i.e., gcc 4.5 or newer. You may need to install the supporting
107991 + headers explicitly in addition to the normal gcc package.
107992 +
107993 + Note that if some code really has to modify constified variables
107994 + then the source code will have to be patched to allow it. Examples
107995 + can be found in PaX itself (the no_const attribute) and for some
107996 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
107997 +
107998 +config PAX_USERCOPY
107999 + bool "Harden heap object copies between kernel and userland"
108000 + default y if GRKERNSEC_CONFIG_AUTO
108001 + depends on ARM || IA64 || PPC || SPARC || X86
108002 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
108003 + select PAX_USERCOPY_SLABS
108004 + help
108005 + By saying Y here the kernel will enforce the size of heap objects
108006 + when they are copied in either direction between the kernel and
108007 + userland, even if only a part of the heap object is copied.
108008 +
108009 + Specifically, this checking prevents information leaking from the
108010 + kernel heap during kernel to userland copies (if the kernel heap
108011 + object is otherwise fully initialized) and prevents kernel heap
108012 + overflows during userland to kernel copies.
108013 +
108014 + Note that the current implementation provides the strictest bounds
108015 + checks for the SLUB allocator.
108016 +
108017 + Enabling this option also enables per-slab cache protection against
108018 + data in a given cache being copied into/out of via userland
108019 + accessors. Though the whitelist of regions will be reduced over
108020 + time, it notably protects important data structures like task structs.
108021 +
108022 + If frame pointers are enabled on x86, this option will also restrict
108023 + copies into and out of the kernel stack to local variables within a
108024 + single frame.
108025 +
108026 + Since this has a negligible performance impact, you should enable
108027 + this feature.
108028 +
108029 +config PAX_USERCOPY_DEBUG
108030 + bool
108031 + depends on X86 && PAX_USERCOPY
108032 + default n
108033 +
108034 +config PAX_SIZE_OVERFLOW
108035 + bool "Prevent various integer overflows in function size parameters"
108036 + default y if GRKERNSEC_CONFIG_AUTO
108037 + depends on X86
108038 + help
108039 + By saying Y here the kernel recomputes expressions of function
108040 + arguments marked by a size_overflow attribute with double integer
108041 + precision (DImode/TImode for 32/64 bit integer types).
108042 +
108043 + The recomputed argument is checked against TYPE_MAX and an event
108044 + is logged on overflow and the triggering process is killed.
108045 +
108046 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
108047 +
108048 + Note that the implementation requires a gcc with plugin support,
108049 + i.e., gcc 4.5 or newer. You may need to install the supporting
108050 + headers explicitly in addition to the normal gcc package.
108051 +
108052 +config PAX_LATENT_ENTROPY
108053 + bool "Generate some entropy during boot and runtime"
108054 + default y if GRKERNSEC_CONFIG_AUTO
108055 + help
108056 + By saying Y here the kernel will instrument some kernel code to
108057 + extract some entropy from both original and artificially created
108058 + program state. This will help especially embedded systems where
108059 + there is little 'natural' source of entropy normally. The cost
108060 + is some slowdown of the boot process and fork and irq processing.
108061 +
108062 + When pax_extra_latent_entropy is passed on the kernel command line,
108063 + entropy will be extracted from up to the first 4GB of RAM while the
108064 + runtime memory allocator is being initialized. This costs even more
108065 + slowdown of the boot process.
108066 +
108067 + Note that the implementation requires a gcc with plugin support,
108068 + i.e., gcc 4.5 or newer. You may need to install the supporting
108069 + headers explicitly in addition to the normal gcc package.
108070 +
108071 + Note that entropy extracted this way is not cryptographically
108072 + secure!
108073 +
108074 +endmenu
108075 +
108076 +endmenu
108077 +
108078 +source grsecurity/Kconfig
108079 +
108080 +endmenu
108081 +
108082 +endmenu
108083 +
108084 source security/keys/Kconfig
108085
108086 config SECURITY_DMESG_RESTRICT
108087 @@ -103,7 +1071,7 @@ config INTEL_TXT
108088 config LSM_MMAP_MIN_ADDR
108089 int "Low address space for LSM to protect from user allocation"
108090 depends on SECURITY && SECURITY_SELINUX
108091 - default 32768 if ARM || (ARM64 && COMPAT)
108092 + default 32768 if ALPHA || ARM || (ARM64 && COMPAT) || PARISC || SPARC32
108093 default 65536
108094 help
108095 This is the portion of low virtual memory which should be protected
108096 diff --git a/security/apparmor/file.c b/security/apparmor/file.c
108097 index fdaa50c..2761dcb 100644
108098 --- a/security/apparmor/file.c
108099 +++ b/security/apparmor/file.c
108100 @@ -348,8 +348,8 @@ static inline bool xindex_is_subset(u32 link, u32 target)
108101 int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
108102 struct path *new_dir, struct dentry *new_dentry)
108103 {
108104 - struct path link = { new_dir->mnt, new_dentry };
108105 - struct path target = { new_dir->mnt, old_dentry };
108106 + struct path link = { .mnt = new_dir->mnt, .dentry = new_dentry };
108107 + struct path target = { .mnt = new_dir->mnt, .dentry = old_dentry };
108108 struct path_cond cond = {
108109 old_dentry->d_inode->i_uid,
108110 old_dentry->d_inode->i_mode
108111 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
108112 index 65ca451..ad6f22d 100644
108113 --- a/security/apparmor/lsm.c
108114 +++ b/security/apparmor/lsm.c
108115 @@ -186,7 +186,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
108116 struct dentry *dentry, u32 mask,
108117 struct path_cond *cond)
108118 {
108119 - struct path path = { dir->mnt, dentry };
108120 + struct path path = { .mnt = dir->mnt, .dentry = dentry };
108121
108122 return common_perm(op, &path, mask, cond);
108123 }
108124 @@ -203,7 +203,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
108125 static int common_perm_mnt_dentry(int op, struct vfsmount *mnt,
108126 struct dentry *dentry, u32 mask)
108127 {
108128 - struct path path = { mnt, dentry };
108129 + struct path path = { .mnt = mnt, .dentry = dentry };
108130 struct path_cond cond = { dentry->d_inode->i_uid,
108131 dentry->d_inode->i_mode
108132 };
108133 @@ -325,8 +325,8 @@ static int apparmor_path_rename(struct path *old_dir, struct dentry *old_dentry,
108134
108135 profile = aa_current_profile();
108136 if (!unconfined(profile)) {
108137 - struct path old_path = { old_dir->mnt, old_dentry };
108138 - struct path new_path = { new_dir->mnt, new_dentry };
108139 + struct path old_path = { .mnt = old_dir->mnt, .dentry = old_dentry };
108140 + struct path new_path = { .mnt = new_dir->mnt, .dentry = new_dentry };
108141 struct path_cond cond = { old_dentry->d_inode->i_uid,
108142 old_dentry->d_inode->i_mode
108143 };
108144 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
108145 return error;
108146 }
108147
108148 -static struct security_operations apparmor_ops = {
108149 +static struct security_operations apparmor_ops __read_only = {
108150 .name = "apparmor",
108151
108152 .ptrace_access_check = apparmor_ptrace_access_check,
108153 diff --git a/security/commoncap.c b/security/commoncap.c
108154 index bab0611..f9a0ff5 100644
108155 --- a/security/commoncap.c
108156 +++ b/security/commoncap.c
108157 @@ -427,6 +427,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
108158 return 0;
108159 }
108160
108161 +/* returns:
108162 + 1 for suid privilege
108163 + 2 for sgid privilege
108164 + 3 for fscap privilege
108165 +*/
108166 +int is_privileged_binary(const struct dentry *dentry)
108167 +{
108168 + struct cpu_vfs_cap_data capdata;
108169 + struct inode *inode = dentry->d_inode;
108170 +
108171 + if (!inode || S_ISDIR(inode->i_mode))
108172 + return 0;
108173 +
108174 + if (inode->i_mode & S_ISUID)
108175 + return 1;
108176 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
108177 + return 2;
108178 +
108179 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
108180 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
108181 + return 3;
108182 + }
108183 +
108184 + return 0;
108185 +}
108186 +
108187 /*
108188 * Attempt to get the on-exec apply capability sets for an executable file from
108189 * its xattrs and, if present, apply them to the proposed credentials being
108190 @@ -595,6 +621,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
108191 const struct cred *cred = current_cred();
108192 kuid_t root_uid = make_kuid(cred->user_ns, 0);
108193
108194 + if (gr_acl_enable_at_secure())
108195 + return 1;
108196 +
108197 if (!uid_eq(cred->uid, root_uid)) {
108198 if (bprm->cap_effective)
108199 return 1;
108200 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
108201 index 8ee997d..24c174b 100644
108202 --- a/security/integrity/ima/ima.h
108203 +++ b/security/integrity/ima/ima.h
108204 @@ -116,8 +116,8 @@ int ima_init_template(void);
108205 extern spinlock_t ima_queue_lock;
108206
108207 struct ima_h_table {
108208 - atomic_long_t len; /* number of stored measurements in the list */
108209 - atomic_long_t violations;
108210 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
108211 + atomic_long_unchecked_t violations;
108212 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
108213 };
108214 extern struct ima_h_table ima_htable;
108215 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
108216 index 8688597..9fa80d2 100644
108217 --- a/security/integrity/ima/ima_api.c
108218 +++ b/security/integrity/ima/ima_api.c
108219 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
108220 int result;
108221
108222 /* can overflow, only indicator */
108223 - atomic_long_inc(&ima_htable.violations);
108224 + atomic_long_inc_unchecked(&ima_htable.violations);
108225
108226 result = ima_alloc_init_template(NULL, file, filename,
108227 NULL, 0, &entry);
108228 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
108229 index da92fcc..8a5d390 100644
108230 --- a/security/integrity/ima/ima_fs.c
108231 +++ b/security/integrity/ima/ima_fs.c
108232 @@ -28,12 +28,12 @@
108233 static int valid_policy = 1;
108234 #define TMPBUFLEN 12
108235 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
108236 - loff_t *ppos, atomic_long_t *val)
108237 + loff_t *ppos, atomic_long_unchecked_t *val)
108238 {
108239 char tmpbuf[TMPBUFLEN];
108240 ssize_t len;
108241
108242 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
108243 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
108244 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
108245 }
108246
108247 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
108248 index 552705d..9920f4fb 100644
108249 --- a/security/integrity/ima/ima_queue.c
108250 +++ b/security/integrity/ima/ima_queue.c
108251 @@ -83,7 +83,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
108252 INIT_LIST_HEAD(&qe->later);
108253 list_add_tail_rcu(&qe->later, &ima_measurements);
108254
108255 - atomic_long_inc(&ima_htable.len);
108256 + atomic_long_inc_unchecked(&ima_htable.len);
108257 key = ima_hash_key(entry->digest);
108258 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
108259 return 0;
108260 diff --git a/security/keys/compat.c b/security/keys/compat.c
108261 index 3478965..ec7bb9e 100644
108262 --- a/security/keys/compat.c
108263 +++ b/security/keys/compat.c
108264 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
108265 if (ret == 0)
108266 goto no_payload_free;
108267
108268 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
108269 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
108270 err:
108271 if (iov != iovstack)
108272 kfree(iov);
108273 diff --git a/security/keys/internal.h b/security/keys/internal.h
108274 index 200e378..cdc74b5 100644
108275 --- a/security/keys/internal.h
108276 +++ b/security/keys/internal.h
108277 @@ -244,7 +244,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
108278 extern long keyctl_invalidate_key(key_serial_t);
108279
108280 extern long keyctl_instantiate_key_common(key_serial_t,
108281 - const struct iovec *,
108282 + const struct iovec __user *,
108283 unsigned, size_t, key_serial_t);
108284 #ifdef CONFIG_PERSISTENT_KEYRINGS
108285 extern long keyctl_get_persistent(uid_t, key_serial_t);
108286 diff --git a/security/keys/key.c b/security/keys/key.c
108287 index e17ba6a..2cc04a6 100644
108288 --- a/security/keys/key.c
108289 +++ b/security/keys/key.c
108290 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
108291
108292 atomic_set(&key->usage, 1);
108293 init_rwsem(&key->sem);
108294 - lockdep_set_class(&key->sem, &type->lock_class);
108295 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
108296 key->index_key.type = type;
108297 key->user = user;
108298 key->quotalen = quotalen;
108299 @@ -1075,7 +1075,9 @@ int register_key_type(struct key_type *ktype)
108300 struct key_type *p;
108301 int ret;
108302
108303 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
108304 + pax_open_kernel();
108305 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
108306 + pax_close_kernel();
108307
108308 ret = -EEXIST;
108309 down_write(&key_types_sem);
108310 @@ -1087,7 +1089,7 @@ int register_key_type(struct key_type *ktype)
108311 }
108312
108313 /* store the type */
108314 - list_add(&ktype->link, &key_types_list);
108315 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
108316
108317 pr_notice("Key type %s registered\n", ktype->name);
108318 ret = 0;
108319 @@ -1109,7 +1111,7 @@ EXPORT_SYMBOL(register_key_type);
108320 void unregister_key_type(struct key_type *ktype)
108321 {
108322 down_write(&key_types_sem);
108323 - list_del_init(&ktype->link);
108324 + pax_list_del_init((struct list_head *)&ktype->link);
108325 downgrade_write(&key_types_sem);
108326 key_gc_keytype(ktype);
108327 pr_notice("Key type %s unregistered\n", ktype->name);
108328 @@ -1127,10 +1129,10 @@ void __init key_init(void)
108329 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
108330
108331 /* add the special key types */
108332 - list_add_tail(&key_type_keyring.link, &key_types_list);
108333 - list_add_tail(&key_type_dead.link, &key_types_list);
108334 - list_add_tail(&key_type_user.link, &key_types_list);
108335 - list_add_tail(&key_type_logon.link, &key_types_list);
108336 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
108337 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
108338 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
108339 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
108340
108341 /* record the root user tracking */
108342 rb_link_node(&root_key_user.node,
108343 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
108344 index 4743d71..170a185 100644
108345 --- a/security/keys/keyctl.c
108346 +++ b/security/keys/keyctl.c
108347 @@ -1000,7 +1000,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
108348 /*
108349 * Copy the iovec data from userspace
108350 */
108351 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
108352 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
108353 unsigned ioc)
108354 {
108355 for (; ioc > 0; ioc--) {
108356 @@ -1022,7 +1022,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
108357 * If successful, 0 will be returned.
108358 */
108359 long keyctl_instantiate_key_common(key_serial_t id,
108360 - const struct iovec *payload_iov,
108361 + const struct iovec __user *payload_iov,
108362 unsigned ioc,
108363 size_t plen,
108364 key_serial_t ringid)
108365 @@ -1117,7 +1117,7 @@ long keyctl_instantiate_key(key_serial_t id,
108366 [0].iov_len = plen
108367 };
108368
108369 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
108370 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
108371 }
108372
108373 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
108374 @@ -1150,7 +1150,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
108375 if (ret == 0)
108376 goto no_payload_free;
108377
108378 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
108379 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
108380 err:
108381 if (iov != iovstack)
108382 kfree(iov);
108383 diff --git a/security/min_addr.c b/security/min_addr.c
108384 index f728728..6457a0c 100644
108385 --- a/security/min_addr.c
108386 +++ b/security/min_addr.c
108387 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
108388 */
108389 static void update_mmap_min_addr(void)
108390 {
108391 +#ifndef SPARC
108392 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
108393 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
108394 mmap_min_addr = dac_mmap_min_addr;
108395 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
108396 #else
108397 mmap_min_addr = dac_mmap_min_addr;
108398 #endif
108399 +#endif
108400 }
108401
108402 /*
108403 diff --git a/security/security.c b/security/security.c
108404 index 18b35c6..c9fbc92 100644
108405 --- a/security/security.c
108406 +++ b/security/security.c
108407 @@ -33,8 +33,8 @@
108408 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
108409 CONFIG_DEFAULT_SECURITY;
108410
108411 -static struct security_operations *security_ops;
108412 -static struct security_operations default_security_ops = {
108413 +struct security_operations *security_ops __read_only;
108414 +struct security_operations default_security_ops __read_only = {
108415 .name = "default",
108416 };
108417
108418 @@ -73,11 +73,6 @@ int __init security_init(void)
108419 return 0;
108420 }
108421
108422 -void reset_security_ops(void)
108423 -{
108424 - security_ops = &default_security_ops;
108425 -}
108426 -
108427 /* Save user chosen LSM */
108428 static int __init choose_lsm(char *str)
108429 {
108430 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
108431 index a18f1fa..c9b9fc4 100644
108432 --- a/security/selinux/avc.c
108433 +++ b/security/selinux/avc.c
108434 @@ -59,7 +59,7 @@ struct avc_node {
108435 struct avc_cache {
108436 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
108437 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
108438 - atomic_t lru_hint; /* LRU hint for reclaim scan */
108439 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
108440 atomic_t active_nodes;
108441 u32 latest_notif; /* latest revocation notification */
108442 };
108443 @@ -167,7 +167,7 @@ void __init avc_init(void)
108444 spin_lock_init(&avc_cache.slots_lock[i]);
108445 }
108446 atomic_set(&avc_cache.active_nodes, 0);
108447 - atomic_set(&avc_cache.lru_hint, 0);
108448 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
108449
108450 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
108451 0, SLAB_PANIC, NULL);
108452 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
108453 spinlock_t *lock;
108454
108455 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
108456 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
108457 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
108458 head = &avc_cache.slots[hvalue];
108459 lock = &avc_cache.slots_lock[hvalue];
108460
108461 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
108462 index c603b20..8716ec9 100644
108463 --- a/security/selinux/hooks.c
108464 +++ b/security/selinux/hooks.c
108465 @@ -95,8 +95,6 @@
108466 #include "audit.h"
108467 #include "avc_ss.h"
108468
108469 -extern struct security_operations *security_ops;
108470 -
108471 /* SECMARK reference count */
108472 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
108473
108474 @@ -5809,7 +5807,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
108475
108476 #endif
108477
108478 -static struct security_operations selinux_ops = {
108479 +static struct security_operations selinux_ops __read_only = {
108480 .name = "selinux",
108481
108482 .ptrace_access_check = selinux_ptrace_access_check,
108483 @@ -6150,6 +6148,9 @@ static void selinux_nf_ip_exit(void)
108484 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
108485 static int selinux_disabled;
108486
108487 +extern struct security_operations *security_ops;
108488 +extern struct security_operations default_security_ops;
108489 +
108490 int selinux_disable(void)
108491 {
108492 if (ss_initialized) {
108493 @@ -6167,7 +6168,9 @@ int selinux_disable(void)
108494 selinux_disabled = 1;
108495 selinux_enabled = 0;
108496
108497 - reset_security_ops();
108498 + pax_open_kernel();
108499 + security_ops = &default_security_ops;
108500 + pax_close_kernel();
108501
108502 /* Try to destroy the avc node cache */
108503 avc_disable();
108504 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
108505 index 1450f85..a91e0bc 100644
108506 --- a/security/selinux/include/xfrm.h
108507 +++ b/security/selinux/include/xfrm.h
108508 @@ -48,7 +48,7 @@ static inline void selinux_xfrm_notify_policyload(void)
108509
108510 rtnl_lock();
108511 for_each_net(net) {
108512 - atomic_inc(&net->xfrm.flow_cache_genid);
108513 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
108514 rt_genid_bump_all(net);
108515 }
108516 rtnl_unlock();
108517 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
108518 index d515ec2..8a4ca71 100644
108519 --- a/security/smack/smack_lsm.c
108520 +++ b/security/smack/smack_lsm.c
108521 @@ -4079,7 +4079,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
108522 return 0;
108523 }
108524
108525 -struct security_operations smack_ops = {
108526 +struct security_operations smack_ops __read_only = {
108527 .name = "smack",
108528
108529 .ptrace_access_check = smack_ptrace_access_check,
108530 diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
108531 index 4003907..13a2b55 100644
108532 --- a/security/tomoyo/file.c
108533 +++ b/security/tomoyo/file.c
108534 @@ -692,7 +692,7 @@ int tomoyo_path_number_perm(const u8 type, struct path *path,
108535 {
108536 struct tomoyo_request_info r;
108537 struct tomoyo_obj_info obj = {
108538 - .path1 = *path,
108539 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
108540 };
108541 int error = -ENOMEM;
108542 struct tomoyo_path_info buf;
108543 @@ -740,7 +740,7 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
108544 struct tomoyo_path_info buf;
108545 struct tomoyo_request_info r;
108546 struct tomoyo_obj_info obj = {
108547 - .path1 = *path,
108548 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
108549 };
108550 int idx;
108551
108552 @@ -786,7 +786,7 @@ int tomoyo_path_perm(const u8 operation, struct path *path, const char *target)
108553 {
108554 struct tomoyo_request_info r;
108555 struct tomoyo_obj_info obj = {
108556 - .path1 = *path,
108557 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
108558 };
108559 int error;
108560 struct tomoyo_path_info buf;
108561 @@ -843,7 +843,7 @@ int tomoyo_mkdev_perm(const u8 operation, struct path *path,
108562 {
108563 struct tomoyo_request_info r;
108564 struct tomoyo_obj_info obj = {
108565 - .path1 = *path,
108566 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
108567 };
108568 int error = -ENOMEM;
108569 struct tomoyo_path_info buf;
108570 @@ -890,8 +890,8 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
108571 struct tomoyo_path_info buf2;
108572 struct tomoyo_request_info r;
108573 struct tomoyo_obj_info obj = {
108574 - .path1 = *path1,
108575 - .path2 = *path2,
108576 + .path1 = { .mnt = path1->mnt, .dentry = path1->dentry },
108577 + .path2 = { .mnt = path2->mnt, .dentry = path2->dentry }
108578 };
108579 int idx;
108580
108581 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
108582 index 390c646..f2f8db3 100644
108583 --- a/security/tomoyo/mount.c
108584 +++ b/security/tomoyo/mount.c
108585 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
108586 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
108587 need_dev = -1; /* dev_name is a directory */
108588 } else {
108589 + if (!capable(CAP_SYS_ADMIN)) {
108590 + error = -EPERM;
108591 + goto out;
108592 + }
108593 fstype = get_fs_type(type);
108594 if (!fstype) {
108595 error = -ENODEV;
108596 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
108597 index f0b756e..8aa497b 100644
108598 --- a/security/tomoyo/tomoyo.c
108599 +++ b/security/tomoyo/tomoyo.c
108600 @@ -146,7 +146,7 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
108601 */
108602 static int tomoyo_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
108603 {
108604 - struct path path = { mnt, dentry };
108605 + struct path path = { .mnt = mnt, .dentry = dentry };
108606 return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, &path, NULL);
108607 }
108608
108609 @@ -172,7 +172,7 @@ static int tomoyo_path_truncate(struct path *path)
108610 */
108611 static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
108612 {
108613 - struct path path = { parent->mnt, dentry };
108614 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
108615 return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
108616 }
108617
108618 @@ -188,7 +188,7 @@ static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
108619 static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
108620 umode_t mode)
108621 {
108622 - struct path path = { parent->mnt, dentry };
108623 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
108624 return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
108625 mode & S_IALLUGO);
108626 }
108627 @@ -203,7 +203,7 @@ static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
108628 */
108629 static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
108630 {
108631 - struct path path = { parent->mnt, dentry };
108632 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
108633 return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
108634 }
108635
108636 @@ -219,7 +219,7 @@ static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
108637 static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
108638 const char *old_name)
108639 {
108640 - struct path path = { parent->mnt, dentry };
108641 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
108642 return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
108643 }
108644
108645 @@ -236,7 +236,7 @@ static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
108646 static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
108647 umode_t mode, unsigned int dev)
108648 {
108649 - struct path path = { parent->mnt, dentry };
108650 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
108651 int type = TOMOYO_TYPE_CREATE;
108652 const unsigned int perm = mode & S_IALLUGO;
108653
108654 @@ -275,8 +275,8 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
108655 static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
108656 struct dentry *new_dentry)
108657 {
108658 - struct path path1 = { new_dir->mnt, old_dentry };
108659 - struct path path2 = { new_dir->mnt, new_dentry };
108660 + struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry };
108661 + struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry };
108662 return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
108663 }
108664
108665 @@ -295,8 +295,8 @@ static int tomoyo_path_rename(struct path *old_parent,
108666 struct path *new_parent,
108667 struct dentry *new_dentry)
108668 {
108669 - struct path path1 = { old_parent->mnt, old_dentry };
108670 - struct path path2 = { new_parent->mnt, new_dentry };
108671 + struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
108672 + struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
108673 return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
108674 }
108675
108676 @@ -424,7 +424,7 @@ static int tomoyo_sb_mount(const char *dev_name, struct path *path,
108677 */
108678 static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
108679 {
108680 - struct path path = { mnt, mnt->mnt_root };
108681 + struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
108682 return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
108683 }
108684
108685 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
108686 * tomoyo_security_ops is a "struct security_operations" which is used for
108687 * registering TOMOYO.
108688 */
108689 -static struct security_operations tomoyo_security_ops = {
108690 +static struct security_operations tomoyo_security_ops __read_only = {
108691 .name = "tomoyo",
108692 .cred_alloc_blank = tomoyo_cred_alloc_blank,
108693 .cred_prepare = tomoyo_cred_prepare,
108694 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
108695 index 20ef514..4182bed 100644
108696 --- a/security/yama/Kconfig
108697 +++ b/security/yama/Kconfig
108698 @@ -1,6 +1,6 @@
108699 config SECURITY_YAMA
108700 bool "Yama support"
108701 - depends on SECURITY
108702 + depends on SECURITY && !GRKERNSEC
108703 select SECURITYFS
108704 select SECURITY_PATH
108705 default n
108706 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
108707 index 13c88fbc..f8c115e 100644
108708 --- a/security/yama/yama_lsm.c
108709 +++ b/security/yama/yama_lsm.c
108710 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
108711 }
108712
108713 #ifndef CONFIG_SECURITY_YAMA_STACKED
108714 -static struct security_operations yama_ops = {
108715 +static struct security_operations yama_ops __read_only = {
108716 .name = "yama",
108717
108718 .ptrace_access_check = yama_ptrace_access_check,
108719 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
108720 #endif
108721
108722 #ifdef CONFIG_SYSCTL
108723 +static int zero __read_only;
108724 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
108725 +
108726 static int yama_dointvec_minmax(struct ctl_table *table, int write,
108727 void __user *buffer, size_t *lenp, loff_t *ppos)
108728 {
108729 - int rc;
108730 + ctl_table_no_const yama_table;
108731
108732 if (write && !capable(CAP_SYS_PTRACE))
108733 return -EPERM;
108734
108735 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
108736 - if (rc)
108737 - return rc;
108738 -
108739 + yama_table = *table;
108740 /* Lock the max value if it ever gets set. */
108741 - if (write && *(int *)table->data == *(int *)table->extra2)
108742 - table->extra1 = table->extra2;
108743 -
108744 - return rc;
108745 + if (ptrace_scope == max_scope)
108746 + yama_table.extra1 = &max_scope;
108747 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
108748 }
108749
108750 -static int zero;
108751 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
108752 -
108753 struct ctl_path yama_sysctl_path[] = {
108754 { .procname = "kernel", },
108755 { .procname = "yama", },
108756 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
108757 index 401107b..b9c47c6 100644
108758 --- a/sound/aoa/codecs/onyx.c
108759 +++ b/sound/aoa/codecs/onyx.c
108760 @@ -54,7 +54,7 @@ struct onyx {
108761 spdif_locked:1,
108762 analog_locked:1,
108763 original_mute:2;
108764 - int open_count;
108765 + local_t open_count;
108766 struct codec_info *codec_info;
108767
108768 /* mutex serializes concurrent access to the device
108769 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
108770 struct onyx *onyx = cii->codec_data;
108771
108772 mutex_lock(&onyx->mutex);
108773 - onyx->open_count++;
108774 + local_inc(&onyx->open_count);
108775 mutex_unlock(&onyx->mutex);
108776
108777 return 0;
108778 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
108779 struct onyx *onyx = cii->codec_data;
108780
108781 mutex_lock(&onyx->mutex);
108782 - onyx->open_count--;
108783 - if (!onyx->open_count)
108784 + if (local_dec_and_test(&onyx->open_count))
108785 onyx->spdif_locked = onyx->analog_locked = 0;
108786 mutex_unlock(&onyx->mutex);
108787
108788 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
108789 index ffd2025..df062c9 100644
108790 --- a/sound/aoa/codecs/onyx.h
108791 +++ b/sound/aoa/codecs/onyx.h
108792 @@ -11,6 +11,7 @@
108793 #include <linux/i2c.h>
108794 #include <asm/pmac_low_i2c.h>
108795 #include <asm/prom.h>
108796 +#include <asm/local.h>
108797
108798 /* PCM3052 register definitions */
108799
108800 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
108801 index ada69d7..5f65386 100644
108802 --- a/sound/core/oss/pcm_oss.c
108803 +++ b/sound/core/oss/pcm_oss.c
108804 @@ -1190,10 +1190,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
108805 if (in_kernel) {
108806 mm_segment_t fs;
108807 fs = snd_enter_user();
108808 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
108809 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
108810 snd_leave_user(fs);
108811 } else {
108812 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
108813 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
108814 }
108815 if (ret != -EPIPE && ret != -ESTRPIPE)
108816 break;
108817 @@ -1233,10 +1233,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
108818 if (in_kernel) {
108819 mm_segment_t fs;
108820 fs = snd_enter_user();
108821 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
108822 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
108823 snd_leave_user(fs);
108824 } else {
108825 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
108826 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
108827 }
108828 if (ret == -EPIPE) {
108829 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
108830 @@ -1332,7 +1332,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
108831 struct snd_pcm_plugin_channel *channels;
108832 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
108833 if (!in_kernel) {
108834 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
108835 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
108836 return -EFAULT;
108837 buf = runtime->oss.buffer;
108838 }
108839 @@ -1402,7 +1402,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
108840 }
108841 } else {
108842 tmp = snd_pcm_oss_write2(substream,
108843 - (const char __force *)buf,
108844 + (const char __force_kernel *)buf,
108845 runtime->oss.period_bytes, 0);
108846 if (tmp <= 0)
108847 goto err;
108848 @@ -1428,7 +1428,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
108849 struct snd_pcm_runtime *runtime = substream->runtime;
108850 snd_pcm_sframes_t frames, frames1;
108851 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
108852 - char __user *final_dst = (char __force __user *)buf;
108853 + char __user *final_dst = (char __force_user *)buf;
108854 if (runtime->oss.plugin_first) {
108855 struct snd_pcm_plugin_channel *channels;
108856 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
108857 @@ -1490,7 +1490,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
108858 xfer += tmp;
108859 runtime->oss.buffer_used -= tmp;
108860 } else {
108861 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
108862 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
108863 runtime->oss.period_bytes, 0);
108864 if (tmp <= 0)
108865 goto err;
108866 @@ -1659,7 +1659,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
108867 size1);
108868 size1 /= runtime->channels; /* frames */
108869 fs = snd_enter_user();
108870 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
108871 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
108872 snd_leave_user(fs);
108873 }
108874 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
108875 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
108876 index 2d957ba..fda022c 100644
108877 --- a/sound/core/pcm_compat.c
108878 +++ b/sound/core/pcm_compat.c
108879 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
108880 int err;
108881
108882 fs = snd_enter_user();
108883 - err = snd_pcm_delay(substream, &delay);
108884 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
108885 snd_leave_user(fs);
108886 if (err < 0)
108887 return err;
108888 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
108889 index 166d59c..89e3889 100644
108890 --- a/sound/core/pcm_native.c
108891 +++ b/sound/core/pcm_native.c
108892 @@ -2931,11 +2931,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
108893 switch (substream->stream) {
108894 case SNDRV_PCM_STREAM_PLAYBACK:
108895 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
108896 - (void __user *)arg);
108897 + (void __force_user *)arg);
108898 break;
108899 case SNDRV_PCM_STREAM_CAPTURE:
108900 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
108901 - (void __user *)arg);
108902 + (void __force_user *)arg);
108903 break;
108904 default:
108905 result = -EINVAL;
108906 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
108907 index 16d4267..fe8b49b 100644
108908 --- a/sound/core/seq/oss/seq_oss.c
108909 +++ b/sound/core/seq/oss/seq_oss.c
108910 @@ -69,8 +69,8 @@ static int __init alsa_seq_oss_init(void)
108911 {
108912 int rc;
108913 static struct snd_seq_dev_ops ops = {
108914 - snd_seq_oss_synth_register,
108915 - snd_seq_oss_synth_unregister,
108916 + .init_device = snd_seq_oss_synth_register,
108917 + .free_device = snd_seq_oss_synth_unregister,
108918 };
108919
108920 snd_seq_autoload_lock();
108921 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
108922 index 91a786a..4c07ed4 100644
108923 --- a/sound/core/seq/seq_device.c
108924 +++ b/sound/core/seq/seq_device.c
108925 @@ -64,7 +64,7 @@ struct ops_list {
108926 int argsize; /* argument size */
108927
108928 /* operators */
108929 - struct snd_seq_dev_ops ops;
108930 + struct snd_seq_dev_ops *ops;
108931
108932 /* registered devices */
108933 struct list_head dev_list; /* list of devices */
108934 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
108935
108936 mutex_lock(&ops->reg_mutex);
108937 /* copy driver operators */
108938 - ops->ops = *entry;
108939 + ops->ops = entry;
108940 ops->driver |= DRIVER_LOADED;
108941 ops->argsize = argsize;
108942
108943 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
108944 dev->name, ops->id, ops->argsize, dev->argsize);
108945 return -EINVAL;
108946 }
108947 - if (ops->ops.init_device(dev) >= 0) {
108948 + if (ops->ops->init_device(dev) >= 0) {
108949 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
108950 ops->num_init_devices++;
108951 } else {
108952 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
108953 dev->name, ops->id, ops->argsize, dev->argsize);
108954 return -EINVAL;
108955 }
108956 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
108957 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
108958 dev->status = SNDRV_SEQ_DEVICE_FREE;
108959 dev->driver_data = NULL;
108960 ops->num_init_devices--;
108961 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
108962 index a1fd77a..69cd659 100644
108963 --- a/sound/core/seq/seq_midi.c
108964 +++ b/sound/core/seq/seq_midi.c
108965 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
108966 static int __init alsa_seq_midi_init(void)
108967 {
108968 static struct snd_seq_dev_ops ops = {
108969 - snd_seq_midisynth_register_port,
108970 - snd_seq_midisynth_unregister_port,
108971 + .init_device = snd_seq_midisynth_register_port,
108972 + .free_device = snd_seq_midisynth_unregister_port,
108973 };
108974 memset(&synths, 0, sizeof(synths));
108975 snd_seq_autoload_lock();
108976 diff --git a/sound/core/sound.c b/sound/core/sound.c
108977 index 38ad1a0..5010a40 100644
108978 --- a/sound/core/sound.c
108979 +++ b/sound/core/sound.c
108980 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
108981 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
108982 default: return;
108983 }
108984 - request_module(str);
108985 + request_module("%s", str);
108986 }
108987
108988 #endif /* modular kernel */
108989 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
108990 index f5fd448..6ae276da 100644
108991 --- a/sound/drivers/mts64.c
108992 +++ b/sound/drivers/mts64.c
108993 @@ -29,6 +29,7 @@
108994 #include <sound/initval.h>
108995 #include <sound/rawmidi.h>
108996 #include <sound/control.h>
108997 +#include <asm/local.h>
108998
108999 #define CARD_NAME "Miditerminal 4140"
109000 #define DRIVER_NAME "MTS64"
109001 @@ -67,7 +68,7 @@ struct mts64 {
109002 struct pardevice *pardev;
109003 int pardev_claimed;
109004
109005 - int open_count;
109006 + local_t open_count;
109007 int current_midi_output_port;
109008 int current_midi_input_port;
109009 u8 mode[MTS64_NUM_INPUT_PORTS];
109010 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
109011 {
109012 struct mts64 *mts = substream->rmidi->private_data;
109013
109014 - if (mts->open_count == 0) {
109015 + if (local_read(&mts->open_count) == 0) {
109016 /* We don't need a spinlock here, because this is just called
109017 if the device has not been opened before.
109018 So there aren't any IRQs from the device */
109019 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
109020
109021 msleep(50);
109022 }
109023 - ++(mts->open_count);
109024 + local_inc(&mts->open_count);
109025
109026 return 0;
109027 }
109028 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
109029 struct mts64 *mts = substream->rmidi->private_data;
109030 unsigned long flags;
109031
109032 - --(mts->open_count);
109033 - if (mts->open_count == 0) {
109034 + if (local_dec_return(&mts->open_count) == 0) {
109035 /* We need the spinlock_irqsave here because we can still
109036 have IRQs at this point */
109037 spin_lock_irqsave(&mts->lock, flags);
109038 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
109039
109040 msleep(500);
109041
109042 - } else if (mts->open_count < 0)
109043 - mts->open_count = 0;
109044 + } else if (local_read(&mts->open_count) < 0)
109045 + local_set(&mts->open_count, 0);
109046
109047 return 0;
109048 }
109049 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
109050 index 6839953..7a0f4b9 100644
109051 --- a/sound/drivers/opl3/opl3_seq.c
109052 +++ b/sound/drivers/opl3/opl3_seq.c
109053 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
109054 {
109055 static struct snd_seq_dev_ops ops =
109056 {
109057 - snd_opl3_seq_new_device,
109058 - snd_opl3_seq_delete_device
109059 + .init_device = snd_opl3_seq_new_device,
109060 + .free_device = snd_opl3_seq_delete_device
109061 };
109062
109063 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
109064 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
109065 index b953fb4..1999c01 100644
109066 --- a/sound/drivers/opl4/opl4_lib.c
109067 +++ b/sound/drivers/opl4/opl4_lib.c
109068 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
109069 MODULE_DESCRIPTION("OPL4 driver");
109070 MODULE_LICENSE("GPL");
109071
109072 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
109073 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
109074 {
109075 int timeout = 10;
109076 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
109077 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
109078 index 9919769..d7de36c 100644
109079 --- a/sound/drivers/opl4/opl4_seq.c
109080 +++ b/sound/drivers/opl4/opl4_seq.c
109081 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
109082 static int __init alsa_opl4_synth_init(void)
109083 {
109084 static struct snd_seq_dev_ops ops = {
109085 - snd_opl4_seq_new_device,
109086 - snd_opl4_seq_delete_device
109087 + .init_device = snd_opl4_seq_new_device,
109088 + .free_device = snd_opl4_seq_delete_device
109089 };
109090
109091 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
109092 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
109093 index 78ccfa4..7a0857b 100644
109094 --- a/sound/drivers/portman2x4.c
109095 +++ b/sound/drivers/portman2x4.c
109096 @@ -48,6 +48,7 @@
109097 #include <sound/initval.h>
109098 #include <sound/rawmidi.h>
109099 #include <sound/control.h>
109100 +#include <asm/local.h>
109101
109102 #define CARD_NAME "Portman 2x4"
109103 #define DRIVER_NAME "portman"
109104 @@ -85,7 +86,7 @@ struct portman {
109105 struct pardevice *pardev;
109106 int pardev_claimed;
109107
109108 - int open_count;
109109 + local_t open_count;
109110 int mode[PORTMAN_NUM_INPUT_PORTS];
109111 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
109112 };
109113 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
109114 index 95fc2eaf..ea5d6a7 100644
109115 --- a/sound/firewire/amdtp.c
109116 +++ b/sound/firewire/amdtp.c
109117 @@ -521,7 +521,7 @@ static void update_pcm_pointers(struct amdtp_stream *s,
109118 ptr = s->pcm_buffer_pointer + frames;
109119 if (ptr >= pcm->runtime->buffer_size)
109120 ptr -= pcm->runtime->buffer_size;
109121 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
109122 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
109123
109124 s->pcm_period_pointer += frames;
109125 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
109126 @@ -961,7 +961,7 @@ EXPORT_SYMBOL(amdtp_stream_pcm_pointer);
109127 */
109128 void amdtp_stream_update(struct amdtp_stream *s)
109129 {
109130 - ACCESS_ONCE(s->source_node_id_field) =
109131 + ACCESS_ONCE_RW(s->source_node_id_field) =
109132 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
109133 }
109134 EXPORT_SYMBOL(amdtp_stream_update);
109135 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
109136 index 4823c08..47a5f7c 100644
109137 --- a/sound/firewire/amdtp.h
109138 +++ b/sound/firewire/amdtp.h
109139 @@ -212,7 +212,7 @@ static inline bool amdtp_stream_pcm_running(struct amdtp_stream *s)
109140 static inline void amdtp_stream_pcm_trigger(struct amdtp_stream *s,
109141 struct snd_pcm_substream *pcm)
109142 {
109143 - ACCESS_ONCE(s->pcm) = pcm;
109144 + ACCESS_ONCE_RW(s->pcm) = pcm;
109145 }
109146
109147 /**
109148 @@ -230,7 +230,7 @@ static inline void amdtp_stream_midi_trigger(struct amdtp_stream *s,
109149 struct snd_rawmidi_substream *midi)
109150 {
109151 if (port < s->midi_ports)
109152 - ACCESS_ONCE(s->midi[port]) = midi;
109153 + ACCESS_ONCE_RW(s->midi[port]) = midi;
109154 }
109155
109156 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
109157 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
109158 index 7ac9443..0ec6274 100644
109159 --- a/sound/firewire/isight.c
109160 +++ b/sound/firewire/isight.c
109161 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
109162 ptr += count;
109163 if (ptr >= runtime->buffer_size)
109164 ptr -= runtime->buffer_size;
109165 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
109166 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
109167
109168 isight->period_counter += count;
109169 if (isight->period_counter >= runtime->period_size) {
109170 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
109171 if (err < 0)
109172 return err;
109173
109174 - ACCESS_ONCE(isight->pcm_active) = true;
109175 + ACCESS_ONCE_RW(isight->pcm_active) = true;
109176
109177 return 0;
109178 }
109179 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
109180 {
109181 struct isight *isight = substream->private_data;
109182
109183 - ACCESS_ONCE(isight->pcm_active) = false;
109184 + ACCESS_ONCE_RW(isight->pcm_active) = false;
109185
109186 mutex_lock(&isight->mutex);
109187 isight_stop_streaming(isight);
109188 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
109189
109190 switch (cmd) {
109191 case SNDRV_PCM_TRIGGER_START:
109192 - ACCESS_ONCE(isight->pcm_running) = true;
109193 + ACCESS_ONCE_RW(isight->pcm_running) = true;
109194 break;
109195 case SNDRV_PCM_TRIGGER_STOP:
109196 - ACCESS_ONCE(isight->pcm_running) = false;
109197 + ACCESS_ONCE_RW(isight->pcm_running) = false;
109198 break;
109199 default:
109200 return -EINVAL;
109201 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
109202 index 2dba848..c682aef 100644
109203 --- a/sound/firewire/scs1x.c
109204 +++ b/sound/firewire/scs1x.c
109205 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
109206 {
109207 struct scs *scs = stream->rmidi->private_data;
109208
109209 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
109210 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
109211 if (up) {
109212 scs->output_idle = false;
109213 tasklet_schedule(&scs->tasklet);
109214 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
109215 {
109216 struct scs *scs = stream->rmidi->private_data;
109217
109218 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
109219 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
109220 }
109221
109222 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
109223 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
109224
109225 snd_card_disconnect(scs->card);
109226
109227 - ACCESS_ONCE(scs->output) = NULL;
109228 - ACCESS_ONCE(scs->input) = NULL;
109229 + ACCESS_ONCE_RW(scs->output) = NULL;
109230 + ACCESS_ONCE_RW(scs->input) = NULL;
109231
109232 wait_event(scs->idle_wait, scs->output_idle);
109233
109234 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
109235 index 4e3fcfb..ab45a9d 100644
109236 --- a/sound/isa/sb/emu8000_synth.c
109237 +++ b/sound/isa/sb/emu8000_synth.c
109238 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
109239 {
109240
109241 static struct snd_seq_dev_ops ops = {
109242 - snd_emu8000_new_device,
109243 - snd_emu8000_delete_device,
109244 + .init_device = snd_emu8000_new_device,
109245 + .free_device = snd_emu8000_delete_device,
109246 };
109247 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
109248 sizeof(struct snd_emu8000*));
109249 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
109250 index 048439a..3be9f6f 100644
109251 --- a/sound/oss/sb_audio.c
109252 +++ b/sound/oss/sb_audio.c
109253 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
109254 buf16 = (signed short *)(localbuf + localoffs);
109255 while (c)
109256 {
109257 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
109258 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
109259 if (copy_from_user(lbuf8,
109260 userbuf+useroffs + p,
109261 locallen))
109262 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
109263 index a33e8ce..2262303 100644
109264 --- a/sound/oss/swarm_cs4297a.c
109265 +++ b/sound/oss/swarm_cs4297a.c
109266 @@ -2623,7 +2623,6 @@ static int __init cs4297a_init(void)
109267 {
109268 struct cs4297a_state *s;
109269 u32 pwr, id;
109270 - mm_segment_t fs;
109271 int rval;
109272 u64 cfg;
109273 int mdio_val;
109274 @@ -2709,22 +2708,23 @@ static int __init cs4297a_init(void)
109275 if (!rval) {
109276 char *sb1250_duart_present;
109277
109278 +#if 0
109279 + mm_segment_t fs;
109280 fs = get_fs();
109281 set_fs(KERNEL_DS);
109282 -#if 0
109283 val = SOUND_MASK_LINE;
109284 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
109285 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
109286 val = initvol[i].vol;
109287 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
109288 }
109289 + set_fs(fs);
109290 // cs4297a_write_ac97(s, 0x18, 0x0808);
109291 #else
109292 // cs4297a_write_ac97(s, 0x5e, 0x180);
109293 cs4297a_write_ac97(s, 0x02, 0x0808);
109294 cs4297a_write_ac97(s, 0x18, 0x0808);
109295 #endif
109296 - set_fs(fs);
109297
109298 list_add(&s->list, &cs4297a_devs);
109299
109300 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
109301 index 4c41c90..37f3631 100644
109302 --- a/sound/pci/emu10k1/emu10k1_synth.c
109303 +++ b/sound/pci/emu10k1/emu10k1_synth.c
109304 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
109305 {
109306
109307 static struct snd_seq_dev_ops ops = {
109308 - snd_emu10k1_synth_new_device,
109309 - snd_emu10k1_synth_delete_device,
109310 + .init_device = snd_emu10k1_synth_new_device,
109311 + .free_device = snd_emu10k1_synth_delete_device,
109312 };
109313 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
109314 sizeof(struct snd_emu10k1_synth_arg));
109315 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
109316 index 15e0089..ad6bc9b 100644
109317 --- a/sound/pci/hda/hda_codec.c
109318 +++ b/sound/pci/hda/hda_codec.c
109319 @@ -966,14 +966,10 @@ find_codec_preset(struct hda_codec *codec)
109320 mutex_unlock(&preset_mutex);
109321
109322 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
109323 - char name[32];
109324 if (!mod_requested)
109325 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
109326 - codec->vendor_id);
109327 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
109328 else
109329 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
109330 - (codec->vendor_id >> 16) & 0xffff);
109331 - request_module(name);
109332 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
109333 mod_requested++;
109334 goto again;
109335 }
109336 @@ -2800,7 +2796,7 @@ static int get_kctl_0dB_offset(struct hda_codec *codec,
109337 /* FIXME: set_fs() hack for obtaining user-space TLV data */
109338 mm_segment_t fs = get_fs();
109339 set_fs(get_ds());
109340 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
109341 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
109342 tlv = _tlv;
109343 set_fs(fs);
109344 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
109345 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
109346 index 4631a23..001ae57 100644
109347 --- a/sound/pci/ymfpci/ymfpci.h
109348 +++ b/sound/pci/ymfpci/ymfpci.h
109349 @@ -358,7 +358,7 @@ struct snd_ymfpci {
109350 spinlock_t reg_lock;
109351 spinlock_t voice_lock;
109352 wait_queue_head_t interrupt_sleep;
109353 - atomic_t interrupt_sleep_count;
109354 + atomic_unchecked_t interrupt_sleep_count;
109355 struct snd_info_entry *proc_entry;
109356 const struct firmware *dsp_microcode;
109357 const struct firmware *controller_microcode;
109358 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
109359 index 81c916a..516f0bf 100644
109360 --- a/sound/pci/ymfpci/ymfpci_main.c
109361 +++ b/sound/pci/ymfpci/ymfpci_main.c
109362 @@ -204,8 +204,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
109363 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
109364 break;
109365 }
109366 - if (atomic_read(&chip->interrupt_sleep_count)) {
109367 - atomic_set(&chip->interrupt_sleep_count, 0);
109368 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
109369 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
109370 wake_up(&chip->interrupt_sleep);
109371 }
109372 __end:
109373 @@ -789,7 +789,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
109374 continue;
109375 init_waitqueue_entry(&wait, current);
109376 add_wait_queue(&chip->interrupt_sleep, &wait);
109377 - atomic_inc(&chip->interrupt_sleep_count);
109378 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
109379 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
109380 remove_wait_queue(&chip->interrupt_sleep, &wait);
109381 }
109382 @@ -827,8 +827,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
109383 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
109384 spin_unlock(&chip->reg_lock);
109385
109386 - if (atomic_read(&chip->interrupt_sleep_count)) {
109387 - atomic_set(&chip->interrupt_sleep_count, 0);
109388 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
109389 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
109390 wake_up(&chip->interrupt_sleep);
109391 }
109392 }
109393 @@ -2423,7 +2423,7 @@ int snd_ymfpci_create(struct snd_card *card,
109394 spin_lock_init(&chip->reg_lock);
109395 spin_lock_init(&chip->voice_lock);
109396 init_waitqueue_head(&chip->interrupt_sleep);
109397 - atomic_set(&chip->interrupt_sleep_count, 0);
109398 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
109399 chip->card = card;
109400 chip->pci = pci;
109401 chip->irq = -1;
109402 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
109403 index b60ff56..7307f0f 100644
109404 --- a/sound/soc/soc-core.c
109405 +++ b/sound/soc/soc-core.c
109406 @@ -2132,8 +2132,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
109407 if (ret)
109408 return ret;
109409
109410 - ops->warm_reset = snd_soc_ac97_warm_reset;
109411 - ops->reset = snd_soc_ac97_reset;
109412 + pax_open_kernel();
109413 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
109414 + *(void **)&ops->reset = snd_soc_ac97_reset;
109415 + pax_close_kernel();
109416
109417 snd_ac97_rst_cfg = cfg;
109418 return 0;
109419 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
109420 index 7778b8e..3d619fc 100644
109421 --- a/sound/synth/emux/emux_seq.c
109422 +++ b/sound/synth/emux/emux_seq.c
109423 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
109424 * MIDI emulation operators
109425 */
109426 static struct snd_midi_op emux_ops = {
109427 - snd_emux_note_on,
109428 - snd_emux_note_off,
109429 - snd_emux_key_press,
109430 - snd_emux_terminate_note,
109431 - snd_emux_control,
109432 - snd_emux_nrpn,
109433 - snd_emux_sysex,
109434 + .note_on = snd_emux_note_on,
109435 + .note_off = snd_emux_note_off,
109436 + .key_press = snd_emux_key_press,
109437 + .note_terminate = snd_emux_terminate_note,
109438 + .control = snd_emux_control,
109439 + .nrpn = snd_emux_nrpn,
109440 + .sysex = snd_emux_sysex,
109441 };
109442
109443
109444 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
109445 new file mode 100644
109446 index 0000000..de92ed9
109447 --- /dev/null
109448 +++ b/tools/gcc/.gitignore
109449 @@ -0,0 +1 @@
109450 +randomize_layout_seed.h
109451 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
109452 new file mode 100644
109453 index 0000000..7b8921f
109454 --- /dev/null
109455 +++ b/tools/gcc/Makefile
109456 @@ -0,0 +1,52 @@
109457 +#CC := gcc
109458 +#PLUGIN_SOURCE_FILES := pax_plugin.c
109459 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
109460 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
109461 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
109462 +
109463 +ifeq ($(PLUGINCC),$(HOSTCC))
109464 +HOSTLIBS := hostlibs
109465 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu99 -ggdb
109466 +export HOST_EXTRACFLAGS
109467 +else
109468 +HOSTLIBS := hostcxxlibs
109469 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter -Wno-narrowing -Wno-unused-variable
109470 +export HOST_EXTRACXXFLAGS
109471 +endif
109472 +
109473 +export GCCPLUGINS_DIR HOSTLIBS
109474 +
109475 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
109476 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
109477 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
109478 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
109479 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
109480 +$(HOSTLIBS)-y += colorize_plugin.so
109481 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
109482 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
109483 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
109484 +
109485 +subdir-$(CONFIG_PAX_SIZE_OVERFLOW) := size_overflow_plugin
109486 +subdir- += size_overflow_plugin
109487 +
109488 +always := $($(HOSTLIBS)-y)
109489 +
109490 +constify_plugin-objs := constify_plugin.o
109491 +stackleak_plugin-objs := stackleak_plugin.o
109492 +kallocstat_plugin-objs := kallocstat_plugin.o
109493 +kernexec_plugin-objs := kernexec_plugin.o
109494 +checker_plugin-objs := checker_plugin.o
109495 +colorize_plugin-objs := colorize_plugin.o
109496 +latent_entropy_plugin-objs := latent_entropy_plugin.o
109497 +structleak_plugin-objs := structleak_plugin.o
109498 +randomize_layout_plugin-objs := randomize_layout_plugin.o
109499 +
109500 +$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
109501 +
109502 +quiet_cmd_create_randomize_layout_seed = GENSEED $@
109503 + cmd_create_randomize_layout_seed = \
109504 + $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
109505 +$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
109506 + $(call if_changed,create_randomize_layout_seed)
109507 +
109508 +targets += randomize_layout_seed.h randomize_layout_hash.h
109509 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
109510 new file mode 100644
109511 index 0000000..5452feea
109512 --- /dev/null
109513 +++ b/tools/gcc/checker_plugin.c
109514 @@ -0,0 +1,150 @@
109515 +/*
109516 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
109517 + * Licensed under the GPL v2
109518 + *
109519 + * Note: the choice of the license means that the compilation process is
109520 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
109521 + * but for the kernel it doesn't matter since it doesn't link against
109522 + * any of the gcc libraries
109523 + *
109524 + * gcc plugin to implement various sparse (source code checker) features
109525 + *
109526 + * TODO:
109527 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
109528 + *
109529 + * BUGS:
109530 + * - none known
109531 + */
109532 +
109533 +#include "gcc-common.h"
109534 +
109535 +extern void c_register_addr_space (const char *str, addr_space_t as);
109536 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
109537 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
109538 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
109539 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
109540 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
109541 +
109542 +int plugin_is_GPL_compatible;
109543 +
109544 +static struct plugin_info checker_plugin_info = {
109545 + .version = "201304082245",
109546 + .help = NULL,
109547 +};
109548 +
109549 +#define ADDR_SPACE_KERNEL 0
109550 +#define ADDR_SPACE_FORCE_KERNEL 1
109551 +#define ADDR_SPACE_USER 2
109552 +#define ADDR_SPACE_FORCE_USER 3
109553 +#define ADDR_SPACE_IOMEM 0
109554 +#define ADDR_SPACE_FORCE_IOMEM 0
109555 +#define ADDR_SPACE_PERCPU 0
109556 +#define ADDR_SPACE_FORCE_PERCPU 0
109557 +#define ADDR_SPACE_RCU 0
109558 +#define ADDR_SPACE_FORCE_RCU 0
109559 +
109560 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
109561 +{
109562 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
109563 +}
109564 +
109565 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
109566 +{
109567 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
109568 +}
109569 +
109570 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
109571 +{
109572 + return default_addr_space_valid_pointer_mode(mode, as);
109573 +}
109574 +
109575 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
109576 +{
109577 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
109578 +}
109579 +
109580 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
109581 +{
109582 + return default_addr_space_legitimize_address(x, oldx, mode, as);
109583 +}
109584 +
109585 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
109586 +{
109587 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
109588 + return true;
109589 +
109590 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
109591 + return true;
109592 +
109593 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
109594 + return true;
109595 +
109596 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
109597 + return true;
109598 +
109599 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
109600 + return true;
109601 +
109602 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
109603 + return true;
109604 +
109605 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
109606 + return true;
109607 +
109608 + return subset == superset;
109609 +}
109610 +
109611 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
109612 +{
109613 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
109614 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
109615 +
109616 + return op;
109617 +}
109618 +
109619 +static void register_checker_address_spaces(void *event_data, void *data)
109620 +{
109621 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
109622 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
109623 + c_register_addr_space("__user", ADDR_SPACE_USER);
109624 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
109625 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
109626 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
109627 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
109628 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
109629 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
109630 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
109631 +
109632 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
109633 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
109634 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
109635 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
109636 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
109637 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
109638 + targetm.addr_space.convert = checker_addr_space_convert;
109639 +}
109640 +
109641 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
109642 +{
109643 + const char * const plugin_name = plugin_info->base_name;
109644 + const int argc = plugin_info->argc;
109645 + const struct plugin_argument * const argv = plugin_info->argv;
109646 + int i;
109647 +
109648 + if (!plugin_default_version_check(version, &gcc_version)) {
109649 + error(G_("incompatible gcc/plugin versions"));
109650 + return 1;
109651 + }
109652 +
109653 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
109654 +
109655 + for (i = 0; i < argc; ++i)
109656 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
109657 +
109658 + if (TARGET_64BIT == 0)
109659 + return 0;
109660 +
109661 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
109662 +
109663 + return 0;
109664 +}
109665 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
109666 new file mode 100644
109667 index 0000000..54461af
109668 --- /dev/null
109669 +++ b/tools/gcc/colorize_plugin.c
109670 @@ -0,0 +1,210 @@
109671 +/*
109672 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
109673 + * Licensed under the GPL v2
109674 + *
109675 + * Note: the choice of the license means that the compilation process is
109676 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
109677 + * but for the kernel it doesn't matter since it doesn't link against
109678 + * any of the gcc libraries
109679 + *
109680 + * gcc plugin to colorize diagnostic output
109681 + *
109682 + */
109683 +
109684 +#include "gcc-common.h"
109685 +
109686 +int plugin_is_GPL_compatible;
109687 +
109688 +static struct plugin_info colorize_plugin_info = {
109689 + .version = "201404202350",
109690 + .help = "color=[never|always|auto]\tdetermine when to colorize\n",
109691 +};
109692 +
109693 +#define GREEN "\033[32m\033[K"
109694 +#define LIGHTGREEN "\033[1;32m\033[K"
109695 +#define YELLOW "\033[33m\033[K"
109696 +#define LIGHTYELLOW "\033[1;33m\033[K"
109697 +#define RED "\033[31m\033[K"
109698 +#define LIGHTRED "\033[1;31m\033[K"
109699 +#define BLUE "\033[34m\033[K"
109700 +#define LIGHTBLUE "\033[1;34m\033[K"
109701 +#define BRIGHT "\033[1;m\033[K"
109702 +#define NORMAL "\033[m\033[K"
109703 +
109704 +static diagnostic_starter_fn old_starter;
109705 +static diagnostic_finalizer_fn old_finalizer;
109706 +
109707 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
109708 +{
109709 + const char *color;
109710 + char *newprefix;
109711 +
109712 + switch (diagnostic->kind) {
109713 + case DK_NOTE:
109714 + color = LIGHTBLUE;
109715 + break;
109716 +
109717 + case DK_PEDWARN:
109718 + case DK_WARNING:
109719 + color = LIGHTYELLOW;
109720 + break;
109721 +
109722 + case DK_ERROR:
109723 + case DK_FATAL:
109724 + case DK_ICE:
109725 + case DK_PERMERROR:
109726 + case DK_SORRY:
109727 + color = LIGHTRED;
109728 + break;
109729 +
109730 + default:
109731 + color = NORMAL;
109732 + }
109733 +
109734 + old_starter(context, diagnostic);
109735 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
109736 + return;
109737 + pp_destroy_prefix(context->printer);
109738 + pp_set_prefix(context->printer, newprefix);
109739 +}
109740 +
109741 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
109742 +{
109743 + old_finalizer(context, diagnostic);
109744 +}
109745 +
109746 +static void colorize_arm(void)
109747 +{
109748 + old_starter = diagnostic_starter(global_dc);
109749 + old_finalizer = diagnostic_finalizer(global_dc);
109750 +
109751 + diagnostic_starter(global_dc) = start_colorize;
109752 + diagnostic_finalizer(global_dc) = finalize_colorize;
109753 +}
109754 +
109755 +static unsigned int execute_colorize_rearm(void)
109756 +{
109757 + if (diagnostic_starter(global_dc) == start_colorize)
109758 + return 0;
109759 +
109760 + colorize_arm();
109761 + return 0;
109762 +}
109763 +
109764 +#if BUILDING_GCC_VERSION >= 4009
109765 +static const struct pass_data colorize_rearm_pass_data = {
109766 +#else
109767 +struct simple_ipa_opt_pass colorize_rearm_pass = {
109768 + .pass = {
109769 +#endif
109770 + .type = SIMPLE_IPA_PASS,
109771 + .name = "colorize_rearm",
109772 +#if BUILDING_GCC_VERSION >= 4008
109773 + .optinfo_flags = OPTGROUP_NONE,
109774 +#endif
109775 +#if BUILDING_GCC_VERSION >= 4009
109776 + .has_gate = false,
109777 + .has_execute = true,
109778 +#else
109779 + .gate = NULL,
109780 + .execute = execute_colorize_rearm,
109781 + .sub = NULL,
109782 + .next = NULL,
109783 + .static_pass_number = 0,
109784 +#endif
109785 + .tv_id = TV_NONE,
109786 + .properties_required = 0,
109787 + .properties_provided = 0,
109788 + .properties_destroyed = 0,
109789 + .todo_flags_start = 0,
109790 + .todo_flags_finish = 0
109791 +#if BUILDING_GCC_VERSION < 4009
109792 + }
109793 +#endif
109794 +};
109795 +
109796 +#if BUILDING_GCC_VERSION >= 4009
109797 +namespace {
109798 +class colorize_rearm_pass : public simple_ipa_opt_pass {
109799 +public:
109800 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
109801 + unsigned int execute() { return execute_colorize_rearm(); }
109802 +};
109803 +}
109804 +
109805 +static opt_pass *make_colorize_rearm_pass(void)
109806 +{
109807 + return new colorize_rearm_pass();
109808 +}
109809 +#else
109810 +static struct opt_pass *make_colorize_rearm_pass(void)
109811 +{
109812 + return &colorize_rearm_pass.pass;
109813 +}
109814 +#endif
109815 +
109816 +static void colorize_start_unit(void *gcc_data, void *user_data)
109817 +{
109818 + colorize_arm();
109819 +}
109820 +
109821 +static bool should_colorize(void)
109822 +{
109823 +#if BUILDING_GCC_VERSION >= 4009
109824 + return false;
109825 +#else
109826 + char const *t = getenv("TERM");
109827 +
109828 + return t && strcmp(t, "dumb") && isatty(STDERR_FILENO);
109829 +#endif
109830 +}
109831 +
109832 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
109833 +{
109834 + const char * const plugin_name = plugin_info->base_name;
109835 + const int argc = plugin_info->argc;
109836 + const struct plugin_argument * const argv = plugin_info->argv;
109837 + int i;
109838 + struct register_pass_info colorize_rearm_pass_info;
109839 + bool colorize;
109840 +
109841 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
109842 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
109843 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
109844 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
109845 +
109846 + if (!plugin_default_version_check(version, &gcc_version)) {
109847 + error(G_("incompatible gcc/plugin versions"));
109848 + return 1;
109849 + }
109850 +
109851 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
109852 +
109853 + colorize = getenv("GCC_COLORS") ? should_colorize() : false;
109854 +
109855 + for (i = 0; i < argc; ++i) {
109856 + if (!strcmp(argv[i].key, "color")) {
109857 + if (!argv[i].value) {
109858 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
109859 + continue;
109860 + }
109861 + if (!strcmp(argv[i].value, "always"))
109862 + colorize = true;
109863 + else if (!strcmp(argv[i].value, "never"))
109864 + colorize = false;
109865 + else if (!strcmp(argv[i].value, "auto"))
109866 + colorize = should_colorize();
109867 + else
109868 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
109869 + continue;
109870 + }
109871 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
109872 + }
109873 +
109874 + if (colorize) {
109875 + // TODO: parse GCC_COLORS as used by gcc 4.9+
109876 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
109877 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
109878 + }
109879 + return 0;
109880 +}
109881 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
109882 new file mode 100644
109883 index 0000000..82bc5a8
109884 --- /dev/null
109885 +++ b/tools/gcc/constify_plugin.c
109886 @@ -0,0 +1,557 @@
109887 +/*
109888 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
109889 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
109890 + * Licensed under the GPL v2, or (at your option) v3
109891 + *
109892 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
109893 + *
109894 + * Homepage:
109895 + * http://www.grsecurity.net/~ephox/const_plugin/
109896 + *
109897 + * Usage:
109898 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
109899 + * $ gcc -fplugin=constify_plugin.so test.c -O2
109900 + */
109901 +
109902 +#include "gcc-common.h"
109903 +
109904 +// unused C type flag in all versions 4.5-4.9
109905 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
109906 +
109907 +int plugin_is_GPL_compatible;
109908 +
109909 +static struct plugin_info const_plugin_info = {
109910 + .version = "201401270210",
109911 + .help = "no-constify\tturn off constification\n",
109912 +};
109913 +
109914 +typedef struct {
109915 + bool has_fptr_field;
109916 + bool has_writable_field;
109917 + bool has_do_const_field;
109918 + bool has_no_const_field;
109919 +} constify_info;
109920 +
109921 +static const_tree get_field_type(const_tree field)
109922 +{
109923 + return strip_array_types(TREE_TYPE(field));
109924 +}
109925 +
109926 +static bool is_fptr(const_tree field)
109927 +{
109928 + const_tree ptr = get_field_type(field);
109929 +
109930 + if (TREE_CODE(ptr) != POINTER_TYPE)
109931 + return false;
109932 +
109933 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
109934 +}
109935 +
109936 +/*
109937 + * determine whether the given structure type meets the requirements for automatic constification,
109938 + * including the constification attributes on nested structure types
109939 + */
109940 +static void constifiable(const_tree node, constify_info *cinfo)
109941 +{
109942 + const_tree field;
109943 +
109944 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
109945 +
109946 + // e.g., pointer to structure fields while still constructing the structure type
109947 + if (TYPE_FIELDS(node) == NULL_TREE)
109948 + return;
109949 +
109950 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
109951 + const_tree type = get_field_type(field);
109952 + enum tree_code code = TREE_CODE(type);
109953 +
109954 + if (node == type)
109955 + continue;
109956 +
109957 + if (is_fptr(field))
109958 + cinfo->has_fptr_field = true;
109959 + else if (!TREE_READONLY(field))
109960 + cinfo->has_writable_field = true;
109961 +
109962 + if (code == RECORD_TYPE || code == UNION_TYPE) {
109963 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
109964 + cinfo->has_do_const_field = true;
109965 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
109966 + cinfo->has_no_const_field = true;
109967 + else
109968 + constifiable(type, cinfo);
109969 + }
109970 + }
109971 +}
109972 +
109973 +static bool constified(const_tree node)
109974 +{
109975 + constify_info cinfo = {
109976 + .has_fptr_field = false,
109977 + .has_writable_field = false,
109978 + .has_do_const_field = false,
109979 + .has_no_const_field = false
109980 + };
109981 +
109982 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
109983 +
109984 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
109985 +// gcc_assert(!TYPE_READONLY(node));
109986 + return false;
109987 + }
109988 +
109989 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
109990 + gcc_assert(TYPE_READONLY(node));
109991 + return true;
109992 + }
109993 +
109994 + constifiable(node, &cinfo);
109995 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
109996 + return false;
109997 +
109998 + return TYPE_READONLY(node);
109999 +}
110000 +
110001 +static void deconstify_tree(tree node);
110002 +
110003 +static void deconstify_type(tree type)
110004 +{
110005 + tree field;
110006 +
110007 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
110008 +
110009 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
110010 + const_tree fieldtype = get_field_type(field);
110011 +
110012 + // special case handling of simple ptr-to-same-array-type members
110013 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
110014 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
110015 +
110016 + if (TREE_TYPE(TREE_TYPE(field)) == type)
110017 + continue;
110018 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
110019 + continue;
110020 + if (!constified(ptrtype))
110021 + continue;
110022 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
110023 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
110024 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
110025 + }
110026 + continue;
110027 + }
110028 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
110029 + continue;
110030 + if (!constified(fieldtype))
110031 + continue;
110032 +
110033 + deconstify_tree(field);
110034 + TREE_READONLY(field) = 0;
110035 + }
110036 + TYPE_READONLY(type) = 0;
110037 + C_TYPE_FIELDS_READONLY(type) = 0;
110038 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
110039 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
110040 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
110041 + }
110042 +}
110043 +
110044 +static void deconstify_tree(tree node)
110045 +{
110046 + tree old_type, new_type, field;
110047 +
110048 + old_type = TREE_TYPE(node);
110049 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
110050 + node = TREE_TYPE(node) = copy_node(old_type);
110051 + old_type = TREE_TYPE(old_type);
110052 + }
110053 +
110054 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
110055 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
110056 +
110057 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
110058 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
110059 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
110060 + DECL_FIELD_CONTEXT(field) = new_type;
110061 +
110062 + deconstify_type(new_type);
110063 +
110064 + TREE_TYPE(node) = new_type;
110065 +}
110066 +
110067 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
110068 +{
110069 + tree type;
110070 + constify_info cinfo = {
110071 + .has_fptr_field = false,
110072 + .has_writable_field = false,
110073 + .has_do_const_field = false,
110074 + .has_no_const_field = false
110075 + };
110076 +
110077 + *no_add_attrs = true;
110078 + if (TREE_CODE(*node) == FUNCTION_DECL) {
110079 + error("%qE attribute does not apply to functions (%qF)", name, *node);
110080 + return NULL_TREE;
110081 + }
110082 +
110083 + if (TREE_CODE(*node) == PARM_DECL) {
110084 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
110085 + return NULL_TREE;
110086 + }
110087 +
110088 + if (TREE_CODE(*node) == VAR_DECL) {
110089 + error("%qE attribute does not apply to variables (%qD)", name, *node);
110090 + return NULL_TREE;
110091 + }
110092 +
110093 + if (TYPE_P(*node)) {
110094 + type = *node;
110095 + } else {
110096 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
110097 + type = TREE_TYPE(*node);
110098 + }
110099 +
110100 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
110101 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
110102 + return NULL_TREE;
110103 + }
110104 +
110105 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
110106 + error("%qE attribute is already applied to the type %qT", name, type);
110107 + return NULL_TREE;
110108 + }
110109 +
110110 + if (TYPE_P(*node)) {
110111 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
110112 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
110113 + else
110114 + *no_add_attrs = false;
110115 + return NULL_TREE;
110116 + }
110117 +
110118 + constifiable(type, &cinfo);
110119 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
110120 + deconstify_tree(*node);
110121 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
110122 + return NULL_TREE;
110123 + }
110124 +
110125 + error("%qE attribute used on type %qT that is not constified", name, type);
110126 + return NULL_TREE;
110127 +}
110128 +
110129 +static void constify_type(tree type)
110130 +{
110131 + TYPE_READONLY(type) = 1;
110132 + C_TYPE_FIELDS_READONLY(type) = 1;
110133 + TYPE_CONSTIFY_VISITED(type) = 1;
110134 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
110135 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
110136 +}
110137 +
110138 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
110139 +{
110140 + *no_add_attrs = true;
110141 + if (!TYPE_P(*node)) {
110142 + error("%qE attribute applies to types only (%qD)", name, *node);
110143 + return NULL_TREE;
110144 + }
110145 +
110146 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
110147 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
110148 + return NULL_TREE;
110149 + }
110150 +
110151 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
110152 + error("%qE attribute used on %qT is already applied to the type", name, *node);
110153 + return NULL_TREE;
110154 + }
110155 +
110156 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
110157 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
110158 + return NULL_TREE;
110159 + }
110160 +
110161 + *no_add_attrs = false;
110162 + return NULL_TREE;
110163 +}
110164 +
110165 +static struct attribute_spec no_const_attr = {
110166 + .name = "no_const",
110167 + .min_length = 0,
110168 + .max_length = 0,
110169 + .decl_required = false,
110170 + .type_required = false,
110171 + .function_type_required = false,
110172 + .handler = handle_no_const_attribute,
110173 +#if BUILDING_GCC_VERSION >= 4007
110174 + .affects_type_identity = true
110175 +#endif
110176 +};
110177 +
110178 +static struct attribute_spec do_const_attr = {
110179 + .name = "do_const",
110180 + .min_length = 0,
110181 + .max_length = 0,
110182 + .decl_required = false,
110183 + .type_required = false,
110184 + .function_type_required = false,
110185 + .handler = handle_do_const_attribute,
110186 +#if BUILDING_GCC_VERSION >= 4007
110187 + .affects_type_identity = true
110188 +#endif
110189 +};
110190 +
110191 +static void register_attributes(void *event_data, void *data)
110192 +{
110193 + register_attribute(&no_const_attr);
110194 + register_attribute(&do_const_attr);
110195 +}
110196 +
110197 +static void finish_type(void *event_data, void *data)
110198 +{
110199 + tree type = (tree)event_data;
110200 + constify_info cinfo = {
110201 + .has_fptr_field = false,
110202 + .has_writable_field = false,
110203 + .has_do_const_field = false,
110204 + .has_no_const_field = false
110205 + };
110206 +
110207 + if (type == NULL_TREE || type == error_mark_node)
110208 + return;
110209 +
110210 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
110211 + return;
110212 +
110213 + constifiable(type, &cinfo);
110214 +
110215 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
110216 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
110217 + deconstify_type(type);
110218 + TYPE_CONSTIFY_VISITED(type) = 1;
110219 + } else
110220 + error("'no_const' attribute used on type %qT that is not constified", type);
110221 + return;
110222 + }
110223 +
110224 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
110225 + if (!cinfo.has_writable_field) {
110226 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
110227 + return;
110228 + }
110229 + constify_type(type);
110230 + return;
110231 + }
110232 +
110233 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
110234 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
110235 + error("'do_const' attribute used on type %qT that is constified", type);
110236 + return;
110237 + }
110238 + constify_type(type);
110239 + return;
110240 + }
110241 +
110242 + deconstify_type(type);
110243 + TYPE_CONSTIFY_VISITED(type) = 1;
110244 +}
110245 +
110246 +static void check_global_variables(void *event_data, void *data)
110247 +{
110248 +#if BUILDING_GCC_VERSION >= 4009
110249 + varpool_node *node;
110250 +#else
110251 + struct varpool_node *node;
110252 +#endif
110253 +
110254 + FOR_EACH_VARIABLE(node) {
110255 + tree var = NODE_DECL(node);
110256 + tree type = TREE_TYPE(var);
110257 +
110258 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
110259 + continue;
110260 +
110261 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
110262 + continue;
110263 +
110264 + if (!TYPE_CONSTIFY_VISITED(type))
110265 + continue;
110266 +
110267 + if (DECL_EXTERNAL(var))
110268 + continue;
110269 +
110270 + if (DECL_INITIAL(var))
110271 + continue;
110272 +
110273 + // this works around a gcc bug/feature where uninitialized globals
110274 + // are moved into the .bss section regardless of any constification
110275 + DECL_INITIAL(var) = build_constructor(type, NULL);
110276 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
110277 + }
110278 +}
110279 +
110280 +static unsigned int check_local_variables(void)
110281 +{
110282 + unsigned int ret = 0;
110283 + tree var;
110284 +
110285 + unsigned int i;
110286 +
110287 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
110288 + tree type = TREE_TYPE(var);
110289 +
110290 + gcc_assert(DECL_P(var));
110291 + if (is_global_var(var))
110292 + continue;
110293 +
110294 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
110295 + continue;
110296 +
110297 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
110298 + continue;
110299 +
110300 + if (!TYPE_CONSTIFY_VISITED(type))
110301 + continue;
110302 +
110303 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
110304 + ret = 1;
110305 + }
110306 + return ret;
110307 +}
110308 +
110309 +#if BUILDING_GCC_VERSION >= 4009
110310 +static const struct pass_data check_local_variables_pass_data = {
110311 +#else
110312 +static struct gimple_opt_pass check_local_variables_pass = {
110313 + .pass = {
110314 +#endif
110315 + .type = GIMPLE_PASS,
110316 + .name = "check_local_variables",
110317 +#if BUILDING_GCC_VERSION >= 4008
110318 + .optinfo_flags = OPTGROUP_NONE,
110319 +#endif
110320 +#if BUILDING_GCC_VERSION >= 4009
110321 + .has_gate = false,
110322 + .has_execute = true,
110323 +#else
110324 + .gate = NULL,
110325 + .execute = check_local_variables,
110326 + .sub = NULL,
110327 + .next = NULL,
110328 + .static_pass_number = 0,
110329 +#endif
110330 + .tv_id = TV_NONE,
110331 + .properties_required = 0,
110332 + .properties_provided = 0,
110333 + .properties_destroyed = 0,
110334 + .todo_flags_start = 0,
110335 + .todo_flags_finish = 0
110336 +#if BUILDING_GCC_VERSION < 4009
110337 + }
110338 +#endif
110339 +};
110340 +
110341 +#if BUILDING_GCC_VERSION >= 4009
110342 +namespace {
110343 +class check_local_variables_pass : public gimple_opt_pass {
110344 +public:
110345 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
110346 + unsigned int execute() { return check_local_variables(); }
110347 +};
110348 +}
110349 +
110350 +static opt_pass *make_check_local_variables_pass(void)
110351 +{
110352 + return new check_local_variables_pass();
110353 +}
110354 +#else
110355 +static struct opt_pass *make_check_local_variables_pass(void)
110356 +{
110357 + return &check_local_variables_pass.pass;
110358 +}
110359 +#endif
110360 +
110361 +static struct {
110362 + const char *name;
110363 + const char *asm_op;
110364 +} sections[] = {
110365 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
110366 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
110367 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
110368 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
110369 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
110370 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
110371 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
110372 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
110373 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
110374 +};
110375 +
110376 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
110377 +
110378 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
110379 +{
110380 + size_t i;
110381 +
110382 + for (i = 0; i < ARRAY_SIZE(sections); i++)
110383 + if (!strcmp(sections[i].name, name))
110384 + return 0;
110385 + return old_section_type_flags(decl, name, reloc);
110386 +}
110387 +
110388 +static void constify_start_unit(void *gcc_data, void *user_data)
110389 +{
110390 +// size_t i;
110391 +
110392 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
110393 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
110394 +// sections[i].section = get_section(sections[i].name, 0, NULL);
110395 +
110396 + old_section_type_flags = targetm.section_type_flags;
110397 + targetm.section_type_flags = constify_section_type_flags;
110398 +}
110399 +
110400 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
110401 +{
110402 + const char * const plugin_name = plugin_info->base_name;
110403 + const int argc = plugin_info->argc;
110404 + const struct plugin_argument * const argv = plugin_info->argv;
110405 + int i;
110406 + bool constify = true;
110407 +
110408 + struct register_pass_info check_local_variables_pass_info;
110409 +
110410 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
110411 + check_local_variables_pass_info.reference_pass_name = "ssa";
110412 + check_local_variables_pass_info.ref_pass_instance_number = 1;
110413 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
110414 +
110415 + if (!plugin_default_version_check(version, &gcc_version)) {
110416 + error(G_("incompatible gcc/plugin versions"));
110417 + return 1;
110418 + }
110419 +
110420 + for (i = 0; i < argc; ++i) {
110421 + if (!(strcmp(argv[i].key, "no-constify"))) {
110422 + constify = false;
110423 + continue;
110424 + }
110425 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
110426 + }
110427 +
110428 + if (strcmp(lang_hooks.name, "GNU C")) {
110429 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
110430 + constify = false;
110431 + }
110432 +
110433 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
110434 + if (constify) {
110435 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
110436 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
110437 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
110438 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
110439 + }
110440 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
110441 +
110442 + return 0;
110443 +}
110444 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
110445 new file mode 100644
110446 index 0000000..e90c205
110447 --- /dev/null
110448 +++ b/tools/gcc/gcc-common.h
110449 @@ -0,0 +1,295 @@
110450 +#ifndef GCC_COMMON_H_INCLUDED
110451 +#define GCC_COMMON_H_INCLUDED
110452 +
110453 +#include "plugin.h"
110454 +#include "bversion.h"
110455 +#include "plugin-version.h"
110456 +#include "config.h"
110457 +#include "system.h"
110458 +#include "coretypes.h"
110459 +#include "tm.h"
110460 +#include "line-map.h"
110461 +#include "input.h"
110462 +#include "tree.h"
110463 +
110464 +#include "tree-inline.h"
110465 +#include "version.h"
110466 +#include "rtl.h"
110467 +#include "tm_p.h"
110468 +#include "flags.h"
110469 +//#include "insn-attr.h"
110470 +//#include "insn-config.h"
110471 +//#include "insn-flags.h"
110472 +#include "hard-reg-set.h"
110473 +//#include "recog.h"
110474 +#include "output.h"
110475 +#include "except.h"
110476 +#include "function.h"
110477 +#include "toplev.h"
110478 +//#include "expr.h"
110479 +#include "basic-block.h"
110480 +#include "intl.h"
110481 +#include "ggc.h"
110482 +//#include "regs.h"
110483 +#include "timevar.h"
110484 +
110485 +#include "params.h"
110486 +#include "pointer-set.h"
110487 +#include "emit-rtl.h"
110488 +//#include "reload.h"
110489 +//#include "ira.h"
110490 +//#include "dwarf2asm.h"
110491 +#include "debug.h"
110492 +#include "target.h"
110493 +#include "langhooks.h"
110494 +#include "cfgloop.h"
110495 +//#include "hosthooks.h"
110496 +#include "cgraph.h"
110497 +#include "opts.h"
110498 +//#include "coverage.h"
110499 +//#include "value-prof.h"
110500 +
110501 +#if BUILDING_GCC_VERSION >= 4007
110502 +#include "tree-pretty-print.h"
110503 +#include "gimple-pretty-print.h"
110504 +#include "c-tree.h"
110505 +//#include "alloc-pool.h"
110506 +#endif
110507 +
110508 +#if BUILDING_GCC_VERSION <= 4008
110509 +#include "tree-flow.h"
110510 +#else
110511 +#include "tree-cfgcleanup.h"
110512 +#endif
110513 +
110514 +#include "diagnostic.h"
110515 +//#include "tree-diagnostic.h"
110516 +#include "tree-dump.h"
110517 +#include "tree-pass.h"
110518 +//#include "df.h"
110519 +#include "predict.h"
110520 +#include "ipa-utils.h"
110521 +
110522 +#if BUILDING_GCC_VERSION >= 4009
110523 +#include "varasm.h"
110524 +#include "stor-layout.h"
110525 +#include "internal-fn.h"
110526 +#include "gimple-expr.h"
110527 +//#include "diagnostic-color.h"
110528 +#include "context.h"
110529 +#include "tree-ssa-alias.h"
110530 +#include "stringpool.h"
110531 +#include "tree-ssanames.h"
110532 +#include "print-tree.h"
110533 +#include "tree-eh.h"
110534 +#include "stmt.h"
110535 +#endif
110536 +
110537 +#include "gimple.h"
110538 +
110539 +#if BUILDING_GCC_VERSION >= 4009
110540 +#include "tree-ssa-operands.h"
110541 +#include "tree-phinodes.h"
110542 +#include "tree-cfg.h"
110543 +#include "gimple-iterator.h"
110544 +#include "gimple-ssa.h"
110545 +#include "ssa-iterators.h"
110546 +#endif
110547 +
110548 +//#include "lto/lto.h"
110549 +//#include "data-streamer.h"
110550 +//#include "lto-compress.h"
110551 +
110552 +//#include "expr.h" where are you...
110553 +extern rtx emit_move_insn(rtx x, rtx y);
110554 +
110555 +// missing from basic_block.h...
110556 +extern void debug_dominance_info(enum cdi_direction dir);
110557 +extern void debug_dominance_tree(enum cdi_direction dir, basic_block root);
110558 +
110559 +#define __unused __attribute__((__unused__))
110560 +
110561 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
110562 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
110563 +#define TYPE_NAME_POINTER(node) IDENTIFIER_POINTER(TYPE_NAME(node))
110564 +#define TYPE_NAME_LENGTH(node) IDENTIFIER_LENGTH(TYPE_NAME(node))
110565 +
110566 +#if BUILDING_GCC_VERSION == 4005
110567 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
110568 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
110569 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
110570 +#define TODO_rebuild_cgraph_edges 0
110571 +
110572 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
110573 +{
110574 + tree fndecl;
110575 +
110576 + if (!is_gimple_call(stmt))
110577 + return false;
110578 + fndecl = gimple_call_fndecl(stmt);
110579 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
110580 + return false;
110581 +// print_node(stderr, "pax", fndecl, 4);
110582 + return DECL_FUNCTION_CODE(fndecl) == code;
110583 +}
110584 +
110585 +static inline bool is_simple_builtin(tree decl)
110586 +{
110587 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
110588 + return false;
110589 +
110590 + switch (DECL_FUNCTION_CODE(decl)) {
110591 + /* Builtins that expand to constants. */
110592 + case BUILT_IN_CONSTANT_P:
110593 + case BUILT_IN_EXPECT:
110594 + case BUILT_IN_OBJECT_SIZE:
110595 + case BUILT_IN_UNREACHABLE:
110596 + /* Simple register moves or loads from stack. */
110597 + case BUILT_IN_RETURN_ADDRESS:
110598 + case BUILT_IN_EXTRACT_RETURN_ADDR:
110599 + case BUILT_IN_FROB_RETURN_ADDR:
110600 + case BUILT_IN_RETURN:
110601 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
110602 + case BUILT_IN_FRAME_ADDRESS:
110603 + case BUILT_IN_VA_END:
110604 + case BUILT_IN_STACK_SAVE:
110605 + case BUILT_IN_STACK_RESTORE:
110606 + /* Exception state returns or moves registers around. */
110607 + case BUILT_IN_EH_FILTER:
110608 + case BUILT_IN_EH_POINTER:
110609 + case BUILT_IN_EH_COPY_VALUES:
110610 + return true;
110611 +
110612 + default:
110613 + return false;
110614 + }
110615 +}
110616 +#endif
110617 +
110618 +#if BUILDING_GCC_VERSION <= 4006
110619 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
110620 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
110621 +
110622 +// should come from c-tree.h if only it were installed for gcc 4.5...
110623 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
110624 +
110625 +#define get_random_seed(noinit) ({ \
110626 + unsigned HOST_WIDE_INT seed; \
110627 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
110628 + seed * seed; })
110629 +
110630 +static inline bool gimple_clobber_p(gimple s)
110631 +{
110632 + return false;
110633 +}
110634 +
110635 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
110636 +{
110637 + return implicit_built_in_decls[fncode];
110638 +}
110639 +
110640 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
110641 +{
110642 + struct cgraph_node *node = cgraph_get_node(decl);
110643 +
110644 + return node ? node : cgraph_node(decl);
110645 +}
110646 +
110647 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
110648 +{
110649 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
110650 +}
110651 +
110652 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
110653 +{
110654 + struct cgraph_node *node;
110655 +
110656 + for (node = cgraph_nodes; node; node = node->next)
110657 + if (cgraph_function_with_gimple_body_p(node))
110658 + return node;
110659 + return NULL;
110660 +}
110661 +
110662 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
110663 +{
110664 + for (node = node->next; node; node = node->next)
110665 + if (cgraph_function_with_gimple_body_p(node))
110666 + return node;
110667 + return NULL;
110668 +}
110669 +
110670 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
110671 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
110672 + (node) = cgraph_next_function_with_gimple_body(node))
110673 +#endif
110674 +
110675 +#if BUILDING_GCC_VERSION == 4006
110676 +extern void debug_gimple_stmt(gimple);
110677 +extern void debug_gimple_seq(gimple_seq);
110678 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
110679 +extern void print_gimple_stmt(FILE *, gimple, int, int);
110680 +extern void print_gimple_expr(FILE *, gimple, int, int);
110681 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
110682 +#endif
110683 +
110684 +#if BUILDING_GCC_VERSION <= 4007
110685 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
110686 +#define PROP_loops 0
110687 +
110688 +static inline int bb_loop_depth(const_basic_block bb)
110689 +{
110690 + return bb->loop_father ? loop_depth(bb->loop_father) : 0;
110691 +}
110692 +
110693 +static inline bool gimple_store_p(gimple gs)
110694 +{
110695 + tree lhs = gimple_get_lhs(gs);
110696 + return lhs && !is_gimple_reg(lhs);
110697 +}
110698 +#endif
110699 +
110700 +#if BUILDING_GCC_VERSION >= 4007
110701 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
110702 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
110703 +#define cgraph_create_edge_including_clones(caller, callee, old_call_stmt, call_stmt, count, freq, nest, reason) \
110704 + cgraph_create_edge_including_clones((caller), (callee), (old_call_stmt), (call_stmt), (count), (freq), (reason))
110705 +#endif
110706 +
110707 +#if BUILDING_GCC_VERSION <= 4008
110708 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
110709 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
110710 +#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
110711 +#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
110712 +#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
110713 +#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
110714 +#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
110715 +#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
110716 +
110717 +static inline const char *get_tree_code_name(enum tree_code code)
110718 +{
110719 + gcc_assert(code < MAX_TREE_CODES);
110720 + return tree_code_name[code];
110721 +}
110722 +
110723 +#define ipa_remove_stmt_references(cnode, stmt)
110724 +#endif
110725 +
110726 +#if BUILDING_GCC_VERSION == 4008
110727 +#define NODE_DECL(node) node->symbol.decl
110728 +#else
110729 +#define NODE_DECL(node) node->decl
110730 +#endif
110731 +
110732 +#if BUILDING_GCC_VERSION >= 4008
110733 +#define add_referenced_var(var)
110734 +#define mark_sym_for_renaming(var)
110735 +#define varpool_mark_needed_node(node)
110736 +#define TODO_dump_func 0
110737 +#define TODO_dump_cgraph 0
110738 +#endif
110739 +
110740 +#if BUILDING_GCC_VERSION >= 4009
110741 +#define TODO_ggc_collect 0
110742 +#endif
110743 +
110744 +#endif
110745 diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
110746 new file mode 100644
110747 index 0000000..7514850
110748 --- /dev/null
110749 +++ b/tools/gcc/gen-random-seed.sh
110750 @@ -0,0 +1,8 @@
110751 +#!/bin/sh
110752 +
110753 +if [ ! -f "$1" ]; then
110754 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
110755 + echo "const char *randstruct_seed = \"$SEED\";" > "$1"
110756 + HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
110757 + echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
110758 +fi
110759 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
110760 new file mode 100644
110761 index 0000000..d81c094
110762 --- /dev/null
110763 +++ b/tools/gcc/kallocstat_plugin.c
110764 @@ -0,0 +1,183 @@
110765 +/*
110766 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
110767 + * Licensed under the GPL v2
110768 + *
110769 + * Note: the choice of the license means that the compilation process is
110770 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
110771 + * but for the kernel it doesn't matter since it doesn't link against
110772 + * any of the gcc libraries
110773 + *
110774 + * gcc plugin to find the distribution of k*alloc sizes
110775 + *
110776 + * TODO:
110777 + *
110778 + * BUGS:
110779 + * - none known
110780 + */
110781 +
110782 +#include "gcc-common.h"
110783 +
110784 +int plugin_is_GPL_compatible;
110785 +
110786 +static struct plugin_info kallocstat_plugin_info = {
110787 + .version = "201401260140",
110788 + .help = NULL
110789 +};
110790 +
110791 +static const char * const kalloc_functions[] = {
110792 + "__kmalloc",
110793 + "kmalloc",
110794 + "kmalloc_large",
110795 + "kmalloc_node",
110796 + "kmalloc_order",
110797 + "kmalloc_order_trace",
110798 + "kmalloc_slab",
110799 + "kzalloc",
110800 + "kzalloc_node",
110801 +};
110802 +
110803 +static bool is_kalloc(const char *fnname)
110804 +{
110805 + size_t i;
110806 +
110807 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
110808 + if (!strcmp(fnname, kalloc_functions[i]))
110809 + return true;
110810 + return false;
110811 +}
110812 +
110813 +static unsigned int execute_kallocstat(void)
110814 +{
110815 + basic_block bb;
110816 +
110817 + // 1. loop through BBs and GIMPLE statements
110818 + FOR_EACH_BB_FN(bb, cfun) {
110819 + gimple_stmt_iterator gsi;
110820 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
110821 + // gimple match:
110822 + tree fndecl, size;
110823 + gimple stmt;
110824 + const char *fnname;
110825 +
110826 + // is it a call
110827 + stmt = gsi_stmt(gsi);
110828 + if (!is_gimple_call(stmt))
110829 + continue;
110830 + fndecl = gimple_call_fndecl(stmt);
110831 + if (fndecl == NULL_TREE)
110832 + continue;
110833 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
110834 + continue;
110835 +
110836 + // is it a call to k*alloc
110837 + fnname = DECL_NAME_POINTER(fndecl);
110838 + if (!is_kalloc(fnname))
110839 + continue;
110840 +
110841 + // is the size arg const or the result of a simple const assignment
110842 + size = gimple_call_arg(stmt, 0);
110843 + while (true) {
110844 + expanded_location xloc;
110845 + size_t size_val;
110846 +
110847 + if (TREE_CONSTANT(size)) {
110848 + xloc = expand_location(gimple_location(stmt));
110849 + if (!xloc.file)
110850 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
110851 + size_val = TREE_INT_CST_LOW(size);
110852 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
110853 + break;
110854 + }
110855 +
110856 + if (TREE_CODE(size) != SSA_NAME)
110857 + break;
110858 + stmt = SSA_NAME_DEF_STMT(size);
110859 +//debug_gimple_stmt(stmt);
110860 +//debug_tree(size);
110861 + if (!stmt || !is_gimple_assign(stmt))
110862 + break;
110863 + if (gimple_num_ops(stmt) != 2)
110864 + break;
110865 + size = gimple_assign_rhs1(stmt);
110866 + }
110867 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
110868 +//debug_tree(gimple_call_fn(call_stmt));
110869 +//print_node(stderr, "pax", fndecl, 4);
110870 + }
110871 + }
110872 +
110873 + return 0;
110874 +}
110875 +
110876 +#if BUILDING_GCC_VERSION >= 4009
110877 +static const struct pass_data kallocstat_pass_data = {
110878 +#else
110879 +static struct gimple_opt_pass kallocstat_pass = {
110880 + .pass = {
110881 +#endif
110882 + .type = GIMPLE_PASS,
110883 + .name = "kallocstat",
110884 +#if BUILDING_GCC_VERSION >= 4008
110885 + .optinfo_flags = OPTGROUP_NONE,
110886 +#endif
110887 +#if BUILDING_GCC_VERSION >= 4009
110888 + .has_gate = false,
110889 + .has_execute = true,
110890 +#else
110891 + .gate = NULL,
110892 + .execute = execute_kallocstat,
110893 + .sub = NULL,
110894 + .next = NULL,
110895 + .static_pass_number = 0,
110896 +#endif
110897 + .tv_id = TV_NONE,
110898 + .properties_required = 0,
110899 + .properties_provided = 0,
110900 + .properties_destroyed = 0,
110901 + .todo_flags_start = 0,
110902 + .todo_flags_finish = 0
110903 +#if BUILDING_GCC_VERSION < 4009
110904 + }
110905 +#endif
110906 +};
110907 +
110908 +#if BUILDING_GCC_VERSION >= 4009
110909 +namespace {
110910 +class kallocstat_pass : public gimple_opt_pass {
110911 +public:
110912 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
110913 + unsigned int execute() { return execute_kallocstat(); }
110914 +};
110915 +}
110916 +
110917 +static opt_pass *make_kallocstat_pass(void)
110918 +{
110919 + return new kallocstat_pass();
110920 +}
110921 +#else
110922 +static struct opt_pass *make_kallocstat_pass(void)
110923 +{
110924 + return &kallocstat_pass.pass;
110925 +}
110926 +#endif
110927 +
110928 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
110929 +{
110930 + const char * const plugin_name = plugin_info->base_name;
110931 + struct register_pass_info kallocstat_pass_info;
110932 +
110933 + kallocstat_pass_info.pass = make_kallocstat_pass();
110934 + kallocstat_pass_info.reference_pass_name = "ssa";
110935 + kallocstat_pass_info.ref_pass_instance_number = 1;
110936 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
110937 +
110938 + if (!plugin_default_version_check(version, &gcc_version)) {
110939 + error(G_("incompatible gcc/plugin versions"));
110940 + return 1;
110941 + }
110942 +
110943 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
110944 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
110945 +
110946 + return 0;
110947 +}
110948 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
110949 new file mode 100644
110950 index 0000000..89f256d
110951 --- /dev/null
110952 +++ b/tools/gcc/kernexec_plugin.c
110953 @@ -0,0 +1,522 @@
110954 +/*
110955 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
110956 + * Licensed under the GPL v2
110957 + *
110958 + * Note: the choice of the license means that the compilation process is
110959 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
110960 + * but for the kernel it doesn't matter since it doesn't link against
110961 + * any of the gcc libraries
110962 + *
110963 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
110964 + *
110965 + * TODO:
110966 + *
110967 + * BUGS:
110968 + * - none known
110969 + */
110970 +
110971 +#include "gcc-common.h"
110972 +
110973 +int plugin_is_GPL_compatible;
110974 +
110975 +static struct plugin_info kernexec_plugin_info = {
110976 + .version = "201401260140",
110977 + .help = "method=[bts|or]\tinstrumentation method\n"
110978 +};
110979 +
110980 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
110981 +static void (*kernexec_instrument_retaddr)(rtx);
110982 +
110983 +/*
110984 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
110985 + */
110986 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
110987 +{
110988 + gimple asm_movabs_stmt;
110989 +
110990 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
110991 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
110992 + gimple_asm_set_volatile(asm_movabs_stmt, true);
110993 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
110994 + update_stmt(asm_movabs_stmt);
110995 +}
110996 +
110997 +/*
110998 + * find all asm() stmts that clobber r12 and add a reload of r12
110999 + */
111000 +static unsigned int execute_kernexec_reload(void)
111001 +{
111002 + basic_block bb;
111003 +
111004 + // 1. loop through BBs and GIMPLE statements
111005 + FOR_EACH_BB_FN(bb, cfun) {
111006 + gimple_stmt_iterator gsi;
111007 +
111008 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
111009 + // gimple match: __asm__ ("" : : : "r12");
111010 + gimple asm_stmt;
111011 + size_t nclobbers;
111012 +
111013 + // is it an asm ...
111014 + asm_stmt = gsi_stmt(gsi);
111015 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
111016 + continue;
111017 +
111018 + // ... clobbering r12
111019 + nclobbers = gimple_asm_nclobbers(asm_stmt);
111020 + while (nclobbers--) {
111021 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
111022 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
111023 + continue;
111024 + kernexec_reload_fptr_mask(&gsi);
111025 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
111026 + break;
111027 + }
111028 + }
111029 + }
111030 +
111031 + return 0;
111032 +}
111033 +
111034 +/*
111035 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
111036 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
111037 + */
111038 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
111039 +{
111040 + gimple assign_intptr, assign_new_fptr, call_stmt;
111041 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
111042 +
111043 + call_stmt = gsi_stmt(*gsi);
111044 + old_fptr = gimple_call_fn(call_stmt);
111045 +
111046 + // create temporary unsigned long variable used for bitops and cast fptr to it
111047 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
111048 + add_referenced_var(intptr);
111049 + intptr = make_ssa_name(intptr, NULL);
111050 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
111051 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
111052 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
111053 + update_stmt(assign_intptr);
111054 +
111055 + // apply logical or to temporary unsigned long and bitmask
111056 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
111057 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
111058 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
111059 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
111060 + assign_intptr = gimple_build_assign(intptr, orptr);
111061 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
111062 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
111063 + update_stmt(assign_intptr);
111064 +
111065 + // cast temporary unsigned long back to a temporary fptr variable
111066 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
111067 + add_referenced_var(new_fptr);
111068 + new_fptr = make_ssa_name(new_fptr, NULL);
111069 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
111070 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
111071 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
111072 + update_stmt(assign_new_fptr);
111073 +
111074 + // replace call stmt fn with the new fptr
111075 + gimple_call_set_fn(call_stmt, new_fptr);
111076 + update_stmt(call_stmt);
111077 +}
111078 +
111079 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
111080 +{
111081 + gimple asm_or_stmt, call_stmt;
111082 + tree old_fptr, new_fptr, input, output;
111083 +#if BUILDING_GCC_VERSION <= 4007
111084 + VEC(tree, gc) *inputs = NULL;
111085 + VEC(tree, gc) *outputs = NULL;
111086 +#else
111087 + vec<tree, va_gc> *inputs = NULL;
111088 + vec<tree, va_gc> *outputs = NULL;
111089 +#endif
111090 +
111091 + call_stmt = gsi_stmt(*gsi);
111092 + old_fptr = gimple_call_fn(call_stmt);
111093 +
111094 + // create temporary fptr variable
111095 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
111096 + add_referenced_var(new_fptr);
111097 + new_fptr = make_ssa_name(new_fptr, NULL);
111098 +
111099 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
111100 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
111101 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
111102 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
111103 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
111104 +#if BUILDING_GCC_VERSION <= 4007
111105 + VEC_safe_push(tree, gc, inputs, input);
111106 + VEC_safe_push(tree, gc, outputs, output);
111107 +#else
111108 + vec_safe_push(inputs, input);
111109 + vec_safe_push(outputs, output);
111110 +#endif
111111 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
111112 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
111113 + gimple_asm_set_volatile(asm_or_stmt, true);
111114 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
111115 + update_stmt(asm_or_stmt);
111116 +
111117 + // replace call stmt fn with the new fptr
111118 + gimple_call_set_fn(call_stmt, new_fptr);
111119 + update_stmt(call_stmt);
111120 +}
111121 +
111122 +/*
111123 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
111124 + */
111125 +static unsigned int execute_kernexec_fptr(void)
111126 +{
111127 + basic_block bb;
111128 +
111129 + // 1. loop through BBs and GIMPLE statements
111130 + FOR_EACH_BB_FN(bb, cfun) {
111131 + gimple_stmt_iterator gsi;
111132 +
111133 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
111134 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
111135 + tree fn;
111136 + gimple call_stmt;
111137 +
111138 + // is it a call ...
111139 + call_stmt = gsi_stmt(gsi);
111140 + if (!is_gimple_call(call_stmt))
111141 + continue;
111142 + fn = gimple_call_fn(call_stmt);
111143 + if (TREE_CODE(fn) == ADDR_EXPR)
111144 + continue;
111145 + if (TREE_CODE(fn) != SSA_NAME)
111146 + gcc_unreachable();
111147 +
111148 + // ... through a function pointer
111149 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
111150 + fn = SSA_NAME_VAR(fn);
111151 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
111152 + debug_tree(fn);
111153 + gcc_unreachable();
111154 + }
111155 + }
111156 + fn = TREE_TYPE(fn);
111157 + if (TREE_CODE(fn) != POINTER_TYPE)
111158 + continue;
111159 + fn = TREE_TYPE(fn);
111160 + if (TREE_CODE(fn) != FUNCTION_TYPE)
111161 + continue;
111162 +
111163 + kernexec_instrument_fptr(&gsi);
111164 +
111165 +//debug_tree(gimple_call_fn(call_stmt));
111166 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
111167 + }
111168 + }
111169 +
111170 + return 0;
111171 +}
111172 +
111173 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
111174 +static void kernexec_instrument_retaddr_bts(rtx insn)
111175 +{
111176 + rtx btsq;
111177 + rtvec argvec, constraintvec, labelvec;
111178 + int line;
111179 +
111180 + // create asm volatile("btsq $63,(%%rsp)":::)
111181 + argvec = rtvec_alloc(0);
111182 + constraintvec = rtvec_alloc(0);
111183 + labelvec = rtvec_alloc(0);
111184 + line = expand_location(RTL_LOCATION(insn)).line;
111185 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
111186 + MEM_VOLATILE_P(btsq) = 1;
111187 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
111188 + emit_insn_before(btsq, insn);
111189 +}
111190 +
111191 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
111192 +static void kernexec_instrument_retaddr_or(rtx insn)
111193 +{
111194 + rtx orq;
111195 + rtvec argvec, constraintvec, labelvec;
111196 + int line;
111197 +
111198 + // create asm volatile("orq %%r12,(%%rsp)":::)
111199 + argvec = rtvec_alloc(0);
111200 + constraintvec = rtvec_alloc(0);
111201 + labelvec = rtvec_alloc(0);
111202 + line = expand_location(RTL_LOCATION(insn)).line;
111203 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
111204 + MEM_VOLATILE_P(orq) = 1;
111205 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
111206 + emit_insn_before(orq, insn);
111207 +}
111208 +
111209 +/*
111210 + * find all asm level function returns and forcibly set the highest bit of the return address
111211 + */
111212 +static unsigned int execute_kernexec_retaddr(void)
111213 +{
111214 + rtx insn;
111215 +
111216 +// if (stack_realign_drap)
111217 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
111218 +
111219 + // 1. find function returns
111220 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
111221 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
111222 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
111223 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
111224 + rtx body;
111225 +
111226 + // is it a retn
111227 + if (!JUMP_P(insn))
111228 + continue;
111229 + body = PATTERN(insn);
111230 + if (GET_CODE(body) == PARALLEL)
111231 + body = XVECEXP(body, 0, 0);
111232 + if (!ANY_RETURN_P(body))
111233 + continue;
111234 + kernexec_instrument_retaddr(insn);
111235 + }
111236 +
111237 +// print_simple_rtl(stderr, get_insns());
111238 +// print_rtl(stderr, get_insns());
111239 +
111240 + return 0;
111241 +}
111242 +
111243 +static bool kernexec_cmodel_check(void)
111244 +{
111245 + tree section;
111246 +
111247 + if (ix86_cmodel != CM_KERNEL)
111248 + return false;
111249 +
111250 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
111251 + if (!section || !TREE_VALUE(section))
111252 + return true;
111253 +
111254 + section = TREE_VALUE(TREE_VALUE(section));
111255 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
111256 + return true;
111257 +
111258 + return false;
111259 +}
111260 +
111261 +#if BUILDING_GCC_VERSION >= 4009
111262 +static const struct pass_data kernexec_reload_pass_data = {
111263 +#else
111264 +static struct gimple_opt_pass kernexec_reload_pass = {
111265 + .pass = {
111266 +#endif
111267 + .type = GIMPLE_PASS,
111268 + .name = "kernexec_reload",
111269 +#if BUILDING_GCC_VERSION >= 4008
111270 + .optinfo_flags = OPTGROUP_NONE,
111271 +#endif
111272 +#if BUILDING_GCC_VERSION >= 4009
111273 + .has_gate = true,
111274 + .has_execute = true,
111275 +#else
111276 + .gate = kernexec_cmodel_check,
111277 + .execute = execute_kernexec_reload,
111278 + .sub = NULL,
111279 + .next = NULL,
111280 + .static_pass_number = 0,
111281 +#endif
111282 + .tv_id = TV_NONE,
111283 + .properties_required = 0,
111284 + .properties_provided = 0,
111285 + .properties_destroyed = 0,
111286 + .todo_flags_start = 0,
111287 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
111288 +#if BUILDING_GCC_VERSION < 4009
111289 + }
111290 +#endif
111291 +};
111292 +
111293 +#if BUILDING_GCC_VERSION >= 4009
111294 +static const struct pass_data kernexec_fptr_pass_data = {
111295 +#else
111296 +static struct gimple_opt_pass kernexec_fptr_pass = {
111297 + .pass = {
111298 +#endif
111299 + .type = GIMPLE_PASS,
111300 + .name = "kernexec_fptr",
111301 +#if BUILDING_GCC_VERSION >= 4008
111302 + .optinfo_flags = OPTGROUP_NONE,
111303 +#endif
111304 +#if BUILDING_GCC_VERSION >= 4009
111305 + .has_gate = true,
111306 + .has_execute = true,
111307 +#else
111308 + .gate = kernexec_cmodel_check,
111309 + .execute = execute_kernexec_fptr,
111310 + .sub = NULL,
111311 + .next = NULL,
111312 + .static_pass_number = 0,
111313 +#endif
111314 + .tv_id = TV_NONE,
111315 + .properties_required = 0,
111316 + .properties_provided = 0,
111317 + .properties_destroyed = 0,
111318 + .todo_flags_start = 0,
111319 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
111320 +#if BUILDING_GCC_VERSION < 4009
111321 + }
111322 +#endif
111323 +};
111324 +
111325 +#if BUILDING_GCC_VERSION >= 4009
111326 +static const struct pass_data kernexec_retaddr_pass_data = {
111327 +#else
111328 +static struct rtl_opt_pass kernexec_retaddr_pass = {
111329 + .pass = {
111330 +#endif
111331 + .type = RTL_PASS,
111332 + .name = "kernexec_retaddr",
111333 +#if BUILDING_GCC_VERSION >= 4008
111334 + .optinfo_flags = OPTGROUP_NONE,
111335 +#endif
111336 +#if BUILDING_GCC_VERSION >= 4009
111337 + .has_gate = true,
111338 + .has_execute = true,
111339 +#else
111340 + .gate = kernexec_cmodel_check,
111341 + .execute = execute_kernexec_retaddr,
111342 + .sub = NULL,
111343 + .next = NULL,
111344 + .static_pass_number = 0,
111345 +#endif
111346 + .tv_id = TV_NONE,
111347 + .properties_required = 0,
111348 + .properties_provided = 0,
111349 + .properties_destroyed = 0,
111350 + .todo_flags_start = 0,
111351 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
111352 +#if BUILDING_GCC_VERSION < 4009
111353 + }
111354 +#endif
111355 +};
111356 +
111357 +#if BUILDING_GCC_VERSION >= 4009
111358 +namespace {
111359 +class kernexec_reload_pass : public gimple_opt_pass {
111360 +public:
111361 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
111362 + bool gate() { return kernexec_cmodel_check(); }
111363 + unsigned int execute() { return execute_kernexec_reload(); }
111364 +};
111365 +
111366 +class kernexec_fptr_pass : public gimple_opt_pass {
111367 +public:
111368 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
111369 + bool gate() { return kernexec_cmodel_check(); }
111370 + unsigned int execute() { return execute_kernexec_fptr(); }
111371 +};
111372 +
111373 +class kernexec_retaddr_pass : public rtl_opt_pass {
111374 +public:
111375 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
111376 + bool gate() { return kernexec_cmodel_check(); }
111377 + unsigned int execute() { return execute_kernexec_retaddr(); }
111378 +};
111379 +}
111380 +
111381 +static opt_pass *make_kernexec_reload_pass(void)
111382 +{
111383 + return new kernexec_reload_pass();
111384 +}
111385 +
111386 +static opt_pass *make_kernexec_fptr_pass(void)
111387 +{
111388 + return new kernexec_fptr_pass();
111389 +}
111390 +
111391 +static opt_pass *make_kernexec_retaddr_pass(void)
111392 +{
111393 + return new kernexec_retaddr_pass();
111394 +}
111395 +#else
111396 +static struct opt_pass *make_kernexec_reload_pass(void)
111397 +{
111398 + return &kernexec_reload_pass.pass;
111399 +}
111400 +
111401 +static struct opt_pass *make_kernexec_fptr_pass(void)
111402 +{
111403 + return &kernexec_fptr_pass.pass;
111404 +}
111405 +
111406 +static struct opt_pass *make_kernexec_retaddr_pass(void)
111407 +{
111408 + return &kernexec_retaddr_pass.pass;
111409 +}
111410 +#endif
111411 +
111412 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
111413 +{
111414 + const char * const plugin_name = plugin_info->base_name;
111415 + const int argc = plugin_info->argc;
111416 + const struct plugin_argument * const argv = plugin_info->argv;
111417 + int i;
111418 + struct register_pass_info kernexec_reload_pass_info;
111419 + struct register_pass_info kernexec_fptr_pass_info;
111420 + struct register_pass_info kernexec_retaddr_pass_info;
111421 +
111422 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
111423 + kernexec_reload_pass_info.reference_pass_name = "ssa";
111424 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
111425 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
111426 +
111427 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
111428 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
111429 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
111430 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
111431 +
111432 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
111433 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
111434 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
111435 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
111436 +
111437 + if (!plugin_default_version_check(version, &gcc_version)) {
111438 + error(G_("incompatible gcc/plugin versions"));
111439 + return 1;
111440 + }
111441 +
111442 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
111443 +
111444 + if (TARGET_64BIT == 0)
111445 + return 0;
111446 +
111447 + for (i = 0; i < argc; ++i) {
111448 + if (!strcmp(argv[i].key, "method")) {
111449 + if (!argv[i].value) {
111450 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
111451 + continue;
111452 + }
111453 + if (!strcmp(argv[i].value, "bts")) {
111454 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
111455 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
111456 + } else if (!strcmp(argv[i].value, "or")) {
111457 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
111458 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
111459 + fix_register("r12", 1, 1);
111460 + } else
111461 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
111462 + continue;
111463 + }
111464 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
111465 + }
111466 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
111467 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
111468 +
111469 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
111470 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
111471 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
111472 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
111473 +
111474 + return 0;
111475 +}
111476 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
111477 new file mode 100644
111478 index 0000000..e48b323
111479 --- /dev/null
111480 +++ b/tools/gcc/latent_entropy_plugin.c
111481 @@ -0,0 +1,466 @@
111482 +/*
111483 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
111484 + * Licensed under the GPL v2
111485 + *
111486 + * Note: the choice of the license means that the compilation process is
111487 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
111488 + * but for the kernel it doesn't matter since it doesn't link against
111489 + * any of the gcc libraries
111490 + *
111491 + * gcc plugin to help generate a little bit of entropy from program state,
111492 + * used throughout the uptime of the kernel
111493 + *
111494 + * TODO:
111495 + * - add ipa pass to identify not explicitly marked candidate functions
111496 + * - mix in more program state (function arguments/return values, loop variables, etc)
111497 + * - more instrumentation control via attribute parameters
111498 + *
111499 + * BUGS:
111500 + * - LTO needs -flto-partition=none for now
111501 + */
111502 +
111503 +#include "gcc-common.h"
111504 +
111505 +int plugin_is_GPL_compatible;
111506 +
111507 +static tree latent_entropy_decl;
111508 +
111509 +static struct plugin_info latent_entropy_plugin_info = {
111510 + .version = "201409101820",
111511 + .help = NULL
111512 +};
111513 +
111514 +static unsigned HOST_WIDE_INT seed;
111515 +static unsigned HOST_WIDE_INT get_random_const(void)
111516 +{
111517 + unsigned int i;
111518 + unsigned HOST_WIDE_INT ret = 0;
111519 +
111520 + for (i = 0; i < 8 * sizeof ret; i++) {
111521 + ret = (ret << 1) | (seed & 1);
111522 + seed >>= 1;
111523 + if (ret & 1)
111524 + seed ^= 0xD800000000000000ULL;
111525 + }
111526 +
111527 + return ret;
111528 +}
111529 +
111530 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
111531 +{
111532 + tree type;
111533 + unsigned long long mask;
111534 +#if BUILDING_GCC_VERSION <= 4007
111535 + VEC(constructor_elt, gc) *vals;
111536 +#else
111537 + vec<constructor_elt, va_gc> *vals;
111538 +#endif
111539 +
111540 + switch (TREE_CODE(*node)) {
111541 + default:
111542 + *no_add_attrs = true;
111543 + error("%qE attribute only applies to functions and variables", name);
111544 + break;
111545 +
111546 + case VAR_DECL:
111547 + if (DECL_INITIAL(*node)) {
111548 + *no_add_attrs = true;
111549 + error("variable %qD with %qE attribute must not be initialized", *node, name);
111550 + break;
111551 + }
111552 +
111553 + if (!TREE_STATIC(*node)) {
111554 + *no_add_attrs = true;
111555 + error("variable %qD with %qE attribute must not be local", *node, name);
111556 + break;
111557 + }
111558 +
111559 + type = TREE_TYPE(*node);
111560 + switch (TREE_CODE(type)) {
111561 + default:
111562 + *no_add_attrs = true;
111563 + error("variable %qD with %qE attribute must be an integer or a fixed length integer array type or a fixed sized structure with integer fields", *node, name);
111564 + break;
111565 +
111566 + case RECORD_TYPE: {
111567 + tree field;
111568 + unsigned int nelt = 0;
111569 +
111570 + for (field = TYPE_FIELDS(type); field; nelt++, field = TREE_CHAIN(field)) {
111571 + tree fieldtype;
111572 +
111573 + fieldtype = TREE_TYPE(field);
111574 + if (TREE_CODE(fieldtype) != INTEGER_TYPE) {
111575 + *no_add_attrs = true;
111576 + error("structure variable %qD with %qE attribute has a non-integer field %qE", *node, name, field);
111577 + break;
111578 + }
111579 + }
111580 +
111581 + if (field)
111582 + break;
111583 +
111584 +#if BUILDING_GCC_VERSION <= 4007
111585 + vals = VEC_alloc(constructor_elt, gc, nelt);
111586 +#else
111587 + vec_alloc(vals, nelt);
111588 +#endif
111589 +
111590 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
111591 + tree fieldtype;
111592 +
111593 + fieldtype = TREE_TYPE(field);
111594 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(fieldtype)) - 1);
111595 + mask = 2 * (mask - 1) + 1;
111596 +
111597 + if (TYPE_UNSIGNED(fieldtype))
111598 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cstu(fieldtype, mask & get_random_const()));
111599 + else
111600 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cst(fieldtype, mask & get_random_const()));
111601 + }
111602 +
111603 + DECL_INITIAL(*node) = build_constructor(type, vals);
111604 +//debug_tree(DECL_INITIAL(*node));
111605 + break;
111606 + }
111607 +
111608 + case INTEGER_TYPE:
111609 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(type)) - 1);
111610 + mask = 2 * (mask - 1) + 1;
111611 +
111612 + if (TYPE_UNSIGNED(type))
111613 + DECL_INITIAL(*node) = build_int_cstu(type, mask & get_random_const());
111614 + else
111615 + DECL_INITIAL(*node) = build_int_cst(type, mask & get_random_const());
111616 + break;
111617 +
111618 + case ARRAY_TYPE: {
111619 + tree elt_type, array_size, elt_size;
111620 + unsigned int i, nelt;
111621 +
111622 + elt_type = TREE_TYPE(type);
111623 + elt_size = TYPE_SIZE_UNIT(TREE_TYPE(type));
111624 + array_size = TYPE_SIZE_UNIT(type);
111625 +
111626 + if (TREE_CODE(elt_type) != INTEGER_TYPE || !array_size || TREE_CODE(array_size) != INTEGER_CST) {
111627 + *no_add_attrs = true;
111628 + error("array variable %qD with %qE attribute must be a fixed length integer array type", *node, name);
111629 + break;
111630 + }
111631 +
111632 + nelt = TREE_INT_CST_LOW(array_size) / TREE_INT_CST_LOW(elt_size);
111633 +#if BUILDING_GCC_VERSION <= 4007
111634 + vals = VEC_alloc(constructor_elt, gc, nelt);
111635 +#else
111636 + vec_alloc(vals, nelt);
111637 +#endif
111638 +
111639 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(elt_type)) - 1);
111640 + mask = 2 * (mask - 1) + 1;
111641 +
111642 + for (i = 0; i < nelt; i++)
111643 + if (TYPE_UNSIGNED(elt_type))
111644 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cstu(elt_type, mask & get_random_const()));
111645 + else
111646 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cst(elt_type, mask & get_random_const()));
111647 +
111648 + DECL_INITIAL(*node) = build_constructor(type, vals);
111649 +//debug_tree(DECL_INITIAL(*node));
111650 + break;
111651 + }
111652 + }
111653 + break;
111654 +
111655 + case FUNCTION_DECL:
111656 + break;
111657 + }
111658 +
111659 + return NULL_TREE;
111660 +}
111661 +
111662 +static struct attribute_spec latent_entropy_attr = {
111663 + .name = "latent_entropy",
111664 + .min_length = 0,
111665 + .max_length = 0,
111666 + .decl_required = true,
111667 + .type_required = false,
111668 + .function_type_required = false,
111669 + .handler = handle_latent_entropy_attribute,
111670 +#if BUILDING_GCC_VERSION >= 4007
111671 + .affects_type_identity = false
111672 +#endif
111673 +};
111674 +
111675 +static void register_attributes(void *event_data, void *data)
111676 +{
111677 + register_attribute(&latent_entropy_attr);
111678 +}
111679 +
111680 +static bool gate_latent_entropy(void)
111681 +{
111682 + // don't bother with noreturn functions for now
111683 + if (TREE_THIS_VOLATILE(current_function_decl))
111684 + return false;
111685 +
111686 + // gcc-4.5 doesn't discover some trivial noreturn functions
111687 + if (EDGE_COUNT(EXIT_BLOCK_PTR_FOR_FN(cfun)->preds) == 0)
111688 + return false;
111689 +
111690 + return lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl)) != NULL_TREE;
111691 +}
111692 +
111693 +static enum tree_code get_op(tree *rhs)
111694 +{
111695 + static enum tree_code op;
111696 + unsigned HOST_WIDE_INT random_const;
111697 +
111698 + random_const = get_random_const();
111699 +
111700 + switch (op) {
111701 + case BIT_XOR_EXPR:
111702 + op = PLUS_EXPR;
111703 + break;
111704 +
111705 + case PLUS_EXPR:
111706 + if (rhs) {
111707 + op = LROTATE_EXPR;
111708 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
111709 + break;
111710 + }
111711 +
111712 + case LROTATE_EXPR:
111713 + default:
111714 + op = BIT_XOR_EXPR;
111715 + break;
111716 + }
111717 + if (rhs)
111718 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
111719 + return op;
111720 +}
111721 +
111722 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
111723 +{
111724 + gimple_stmt_iterator gsi;
111725 + gimple assign;
111726 + tree addxorrol, rhs;
111727 + enum tree_code op;
111728 +
111729 + op = get_op(&rhs);
111730 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
111731 + assign = gimple_build_assign(local_entropy, addxorrol);
111732 + gsi = gsi_after_labels(bb);
111733 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
111734 + update_stmt(assign);
111735 +//debug_bb(bb);
111736 +}
111737 +
111738 +static void perturb_latent_entropy(basic_block bb, tree rhs)
111739 +{
111740 + gimple_stmt_iterator gsi;
111741 + gimple assign;
111742 + tree addxorrol, temp;
111743 +
111744 + // 1. create temporary copy of latent_entropy
111745 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
111746 + add_referenced_var(temp);
111747 +
111748 + // 2. read...
111749 + temp = make_ssa_name(temp, NULL);
111750 + assign = gimple_build_assign(temp, latent_entropy_decl);
111751 + SSA_NAME_DEF_STMT(temp) = assign;
111752 + add_referenced_var(latent_entropy_decl);
111753 + gsi = gsi_after_labels(bb);
111754 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
111755 + update_stmt(assign);
111756 +
111757 + // 3. ...modify...
111758 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
111759 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
111760 + assign = gimple_build_assign(temp, addxorrol);
111761 + SSA_NAME_DEF_STMT(temp) = assign;
111762 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
111763 + update_stmt(assign);
111764 +
111765 + // 4. ...write latent_entropy
111766 + assign = gimple_build_assign(latent_entropy_decl, temp);
111767 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
111768 + update_stmt(assign);
111769 +}
111770 +
111771 +static unsigned int execute_latent_entropy(void)
111772 +{
111773 + basic_block bb;
111774 + gimple assign;
111775 + gimple_stmt_iterator gsi;
111776 + tree local_entropy;
111777 +
111778 + if (!latent_entropy_decl) {
111779 +#if BUILDING_GCC_VERSION >= 4009
111780 + varpool_node *node;
111781 +#else
111782 + struct varpool_node *node;
111783 +#endif
111784 +
111785 + FOR_EACH_VARIABLE(node) {
111786 + tree var = NODE_DECL(node);
111787 +
111788 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
111789 + continue;
111790 + latent_entropy_decl = var;
111791 +// debug_tree(var);
111792 + break;
111793 + }
111794 + if (!latent_entropy_decl) {
111795 +// debug_tree(current_function_decl);
111796 + return 0;
111797 + }
111798 + }
111799 +
111800 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
111801 +
111802 + // 1. create local entropy variable
111803 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
111804 + add_referenced_var(local_entropy);
111805 + mark_sym_for_renaming(local_entropy);
111806 +
111807 + // 2. initialize local entropy variable
111808 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
111809 + if (dom_info_available_p(CDI_DOMINATORS))
111810 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
111811 + gsi = gsi_start_bb(bb);
111812 +
111813 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
111814 +// gimple_set_location(assign, loc);
111815 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
111816 + update_stmt(assign);
111817 +//debug_bb(bb);
111818 + gcc_assert(single_succ_p(bb));
111819 + bb = single_succ(bb);
111820 +
111821 + // 3. instrument each BB with an operation on the local entropy variable
111822 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
111823 + perturb_local_entropy(bb, local_entropy);
111824 +//debug_bb(bb);
111825 + bb = bb->next_bb;
111826 + };
111827 +
111828 + // 4. mix local entropy into the global entropy variable
111829 + gcc_assert(single_pred_p(EXIT_BLOCK_PTR_FOR_FN(cfun)));
111830 + perturb_latent_entropy(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)), local_entropy);
111831 +//debug_bb(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)));
111832 + return 0;
111833 +}
111834 +
111835 +static void latent_entropy_start_unit(void *gcc_data, void *user_data)
111836 +{
111837 + tree latent_entropy_type;
111838 +
111839 + seed = get_random_seed(false);
111840 +
111841 + if (in_lto_p)
111842 + return;
111843 +
111844 + // extern volatile u64 latent_entropy
111845 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
111846 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
111847 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
111848 +
111849 + TREE_STATIC(latent_entropy_decl) = 1;
111850 + TREE_PUBLIC(latent_entropy_decl) = 1;
111851 + TREE_USED(latent_entropy_decl) = 1;
111852 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
111853 + DECL_EXTERNAL(latent_entropy_decl) = 1;
111854 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
111855 + lang_hooks.decls.pushdecl(latent_entropy_decl);
111856 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
111857 +// varpool_finalize_decl(latent_entropy_decl);
111858 +// varpool_mark_needed_node(latent_entropy_decl);
111859 +}
111860 +
111861 +#if BUILDING_GCC_VERSION >= 4009
111862 +static const struct pass_data latent_entropy_pass_data = {
111863 +#else
111864 +static struct gimple_opt_pass latent_entropy_pass = {
111865 + .pass = {
111866 +#endif
111867 + .type = GIMPLE_PASS,
111868 + .name = "latent_entropy",
111869 +#if BUILDING_GCC_VERSION >= 4008
111870 + .optinfo_flags = OPTGROUP_NONE,
111871 +#endif
111872 +#if BUILDING_GCC_VERSION >= 4009
111873 + .has_gate = true,
111874 + .has_execute = true,
111875 +#else
111876 + .gate = gate_latent_entropy,
111877 + .execute = execute_latent_entropy,
111878 + .sub = NULL,
111879 + .next = NULL,
111880 + .static_pass_number = 0,
111881 +#endif
111882 + .tv_id = TV_NONE,
111883 + .properties_required = PROP_gimple_leh | PROP_cfg,
111884 + .properties_provided = 0,
111885 + .properties_destroyed = 0,
111886 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
111887 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
111888 +#if BUILDING_GCC_VERSION < 4009
111889 + }
111890 +#endif
111891 +};
111892 +
111893 +#if BUILDING_GCC_VERSION >= 4009
111894 +namespace {
111895 +class latent_entropy_pass : public gimple_opt_pass {
111896 +public:
111897 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
111898 + bool gate() { return gate_latent_entropy(); }
111899 + unsigned int execute() { return execute_latent_entropy(); }
111900 +};
111901 +}
111902 +
111903 +static opt_pass *make_latent_entropy_pass(void)
111904 +{
111905 + return new latent_entropy_pass();
111906 +}
111907 +#else
111908 +static struct opt_pass *make_latent_entropy_pass(void)
111909 +{
111910 + return &latent_entropy_pass.pass;
111911 +}
111912 +#endif
111913 +
111914 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
111915 +{
111916 + const char * const plugin_name = plugin_info->base_name;
111917 + struct register_pass_info latent_entropy_pass_info;
111918 +
111919 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
111920 + latent_entropy_pass_info.reference_pass_name = "optimized";
111921 + latent_entropy_pass_info.ref_pass_instance_number = 1;
111922 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
111923 + static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
111924 + {
111925 + .base = &latent_entropy_decl,
111926 + .nelt = 1,
111927 + .stride = sizeof(latent_entropy_decl),
111928 + .cb = &gt_ggc_mx_tree_node,
111929 + .pchw = &gt_pch_nx_tree_node
111930 + },
111931 + LAST_GGC_ROOT_TAB
111932 + };
111933 +
111934 + if (!plugin_default_version_check(version, &gcc_version)) {
111935 + error(G_("incompatible gcc/plugin versions"));
111936 + return 1;
111937 + }
111938 +
111939 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
111940 + register_callback(plugin_name, PLUGIN_START_UNIT, &latent_entropy_start_unit, NULL);
111941 + if (!in_lto_p)
111942 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_latent_entropy);
111943 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
111944 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
111945 +
111946 + return 0;
111947 +}
111948 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
111949 new file mode 100644
111950 index 0000000..a5cb46b
111951 --- /dev/null
111952 +++ b/tools/gcc/randomize_layout_plugin.c
111953 @@ -0,0 +1,915 @@
111954 +/*
111955 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
111956 + * and PaX Team <pageexec@freemail.hu>
111957 + * Licensed under the GPL v2
111958 + *
111959 + * Usage:
111960 + * $ # for 4.5/4.6/C based 4.7
111961 + * $ gcc -I`gcc -print-file-name=plugin`/include -I`gcc -print-file-name=plugin`/include/c-family -fPIC -shared -O2 -o randomize_layout_plugin.so randomize_layout_plugin.c
111962 + * $ # for C++ based 4.7/4.8+
111963 + * $ g++ -I`g++ -print-file-name=plugin`/include -I`g++ -print-file-name=plugin`/include/c-family -fPIC -shared -O2 -o randomize_layout_plugin.so randomize_layout_plugin.c
111964 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
111965 + */
111966 +
111967 +#include "gcc-common.h"
111968 +#include "randomize_layout_seed.h"
111969 +
111970 +#if BUILDING_GCC_MAJOR < 4 || BUILDING_GCC_MINOR < 6 || (BUILDING_GCC_MINOR == 6 && BUILDING_GCC_PATCHLEVEL < 4)
111971 +#error "The RANDSTRUCT plugin requires GCC 4.6.4 or newer."
111972 +#endif
111973 +
111974 +#define ORIG_TYPE_NAME(node) \
111975 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
111976 +
111977 +int plugin_is_GPL_compatible;
111978 +
111979 +static int performance_mode;
111980 +
111981 +static struct plugin_info randomize_layout_plugin_info = {
111982 + .version = "201402201816",
111983 + .help = "disable\t\t\tdo not activate plugin\n"
111984 + "performance-mode\tenable cacheline-aware layout randomization\n"
111985 +};
111986 +
111987 +/* from old Linux dcache.h */
111988 +static inline unsigned long
111989 +partial_name_hash(unsigned long c, unsigned long prevhash)
111990 +{
111991 + return (prevhash + (c << 4) + (c >> 4)) * 11;
111992 +}
111993 +static inline unsigned int
111994 +name_hash(const unsigned char *name)
111995 +{
111996 + unsigned long hash = 0;
111997 + unsigned int len = strlen((const char *)name);
111998 + while (len--)
111999 + hash = partial_name_hash(*name++, hash);
112000 + return (unsigned int)hash;
112001 +}
112002 +
112003 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
112004 +{
112005 + tree type;
112006 +
112007 + *no_add_attrs = true;
112008 + if (TREE_CODE(*node) == FUNCTION_DECL) {
112009 + error("%qE attribute does not apply to functions (%qF)", name, *node);
112010 + return NULL_TREE;
112011 + }
112012 +
112013 + if (TREE_CODE(*node) == PARM_DECL) {
112014 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
112015 + return NULL_TREE;
112016 + }
112017 +
112018 + if (TREE_CODE(*node) == VAR_DECL) {
112019 + error("%qE attribute does not apply to variables (%qD)", name, *node);
112020 + return NULL_TREE;
112021 + }
112022 +
112023 + if (TYPE_P(*node)) {
112024 + type = *node;
112025 + } else {
112026 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
112027 + type = TREE_TYPE(*node);
112028 + }
112029 +
112030 + if (TREE_CODE(type) != RECORD_TYPE) {
112031 + error("%qE attribute used on %qT applies to struct types only", name, type);
112032 + return NULL_TREE;
112033 + }
112034 +
112035 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
112036 + error("%qE attribute is already applied to the type %qT", name, type);
112037 + return NULL_TREE;
112038 + }
112039 +
112040 + *no_add_attrs = false;
112041 +
112042 + return NULL_TREE;
112043 +}
112044 +
112045 +/* set on complete types that we don't need to inspect further at all */
112046 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
112047 +{
112048 + *no_add_attrs = false;
112049 + return NULL_TREE;
112050 +}
112051 +
112052 +/*
112053 + * set on types that we've performed a shuffle on, to prevent re-shuffling
112054 + * this does not preclude us from inspecting its fields for potential shuffles
112055 + */
112056 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
112057 +{
112058 + *no_add_attrs = false;
112059 + return NULL_TREE;
112060 +}
112061 +
112062 +/*
112063 + * 64bit variant of Bob Jenkins' public domain PRNG
112064 + * 256 bits of internal state
112065 + */
112066 +
112067 +typedef unsigned long long u64;
112068 +
112069 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
112070 +
112071 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
112072 +static u64 ranval(ranctx *x) {
112073 + u64 e = x->a - rot(x->b, 7);
112074 + x->a = x->b ^ rot(x->c, 13);
112075 + x->b = x->c + rot(x->d, 37);
112076 + x->c = x->d + e;
112077 + x->d = e + x->a;
112078 + return x->d;
112079 +}
112080 +
112081 +static void raninit(ranctx *x, u64 *seed) {
112082 + int i;
112083 +
112084 + x->a = seed[0];
112085 + x->b = seed[1];
112086 + x->c = seed[2];
112087 + x->d = seed[3];
112088 +
112089 + for (i=0; i < 30; ++i)
112090 + (void)ranval(x);
112091 +}
112092 +
112093 +static u64 shuffle_seed[4];
112094 +
112095 +struct partition_group {
112096 + tree tree_start;
112097 + unsigned long start;
112098 + unsigned long length;
112099 +};
112100 +
112101 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
112102 +{
112103 + unsigned long i;
112104 + unsigned long accum_size = 0;
112105 + unsigned long accum_length = 0;
112106 + unsigned long group_idx = 0;
112107 +
112108 + gcc_assert(length < INT_MAX);
112109 +
112110 + memset(size_groups, 0, sizeof(struct partition_group) * length);
112111 +
112112 + for (i = 0; i < length; i++) {
112113 + if (size_groups[group_idx].tree_start == NULL_TREE) {
112114 + size_groups[group_idx].tree_start = fields[i];
112115 + size_groups[group_idx].start = i;
112116 + accum_length = 0;
112117 + accum_size = 0;
112118 + }
112119 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
112120 + accum_length++;
112121 + if (accum_size >= 64) {
112122 + size_groups[group_idx].length = accum_length;
112123 + accum_length = 0;
112124 + group_idx++;
112125 + }
112126 + }
112127 +
112128 + if (size_groups[group_idx].tree_start != NULL_TREE &&
112129 + !size_groups[group_idx].length) {
112130 + size_groups[group_idx].length = accum_length;
112131 + group_idx++;
112132 + }
112133 +
112134 + *num_groups = group_idx;
112135 +}
112136 +
112137 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
112138 +{
112139 + unsigned long i, x;
112140 + struct partition_group size_group[length];
112141 + unsigned long num_groups = 0;
112142 + unsigned long randnum;
112143 +
112144 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
112145 + for (i = num_groups - 1; i > 0; i--) {
112146 + struct partition_group tmp;
112147 + randnum = ranval(prng_state) % (i + 1);
112148 + tmp = size_group[i];
112149 + size_group[i] = size_group[randnum];
112150 + size_group[randnum] = tmp;
112151 + }
112152 +
112153 + for (x = 0; x < num_groups; x++) {
112154 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
112155 + tree tmp;
112156 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
112157 + continue;
112158 + randnum = ranval(prng_state) % (i + 1);
112159 + // we could handle this case differently if desired
112160 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
112161 + continue;
112162 + tmp = newtree[i];
112163 + newtree[i] = newtree[randnum];
112164 + newtree[randnum] = tmp;
112165 + }
112166 + }
112167 +}
112168 +
112169 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
112170 +{
112171 + unsigned long i, randnum;
112172 +
112173 + for (i = length - 1; i > 0; i--) {
112174 + tree tmp;
112175 + randnum = ranval(prng_state) % (i + 1);
112176 + tmp = newtree[i];
112177 + newtree[i] = newtree[randnum];
112178 + newtree[randnum] = tmp;
112179 + }
112180 +}
112181 +
112182 +/* modern in-place Fisher-Yates shuffle */
112183 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
112184 +{
112185 + unsigned long i;
112186 + u64 seed[4];
112187 + ranctx prng_state;
112188 + const unsigned char *structname;
112189 +
112190 + if (length == 0)
112191 + return;
112192 +
112193 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
112194 +
112195 + structname = ORIG_TYPE_NAME(type);
112196 +
112197 +#ifdef __DEBUG_PLUGIN
112198 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
112199 +#ifdef __DEBUG_VERBOSE
112200 + debug_tree((tree)type);
112201 +#endif
112202 +#endif
112203 +
112204 + for (i = 0; i < 4; i++) {
112205 + seed[i] = shuffle_seed[i];
112206 + seed[i] ^= name_hash(structname);
112207 + }
112208 +
112209 + raninit(&prng_state, (u64 *)&seed);
112210 +
112211 + if (performance_mode)
112212 + performance_shuffle(newtree, length, &prng_state);
112213 + else
112214 + full_shuffle(newtree, length, &prng_state);
112215 +}
112216 +
112217 +static bool is_flexible_array(const_tree field)
112218 +{
112219 + const_tree fieldtype;
112220 + const_tree typesize;
112221 + const_tree elemtype;
112222 + const_tree elemsize;
112223 +
112224 + fieldtype = TREE_TYPE(field);
112225 + typesize = TYPE_SIZE(fieldtype);
112226 +
112227 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
112228 + return false;
112229 +
112230 + elemtype = TREE_TYPE(fieldtype);
112231 + elemsize = TYPE_SIZE(elemtype);
112232 +
112233 + /* size of type is represented in bits */
112234 +
112235 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
112236 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
112237 + return true;
112238 +
112239 + if (typesize != NULL_TREE &&
112240 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
112241 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
112242 + return true;
112243 +
112244 + return false;
112245 +}
112246 +
112247 +static int relayout_struct(tree type)
112248 +{
112249 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
112250 + unsigned long shuffle_length = num_fields;
112251 + tree field;
112252 + tree newtree[num_fields];
112253 + unsigned long i;
112254 + tree list;
112255 + tree variant;
112256 + expanded_location xloc;
112257 +
112258 + if (TYPE_FIELDS(type) == NULL_TREE)
112259 + return 0;
112260 +
112261 + if (num_fields < 2)
112262 + return 0;
112263 +
112264 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
112265 +
112266 + gcc_assert(num_fields < INT_MAX);
112267 +
112268 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
112269 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
112270 + return 0;
112271 +
112272 + /* Workaround for 3rd-party VirtualBox source that we can't modify ourselves */
112273 + if (!strcmp((const char *)ORIG_TYPE_NAME(type), "INTNETTRUNKFACTORY") ||
112274 + !strcmp((const char *)ORIG_TYPE_NAME(type), "RAWPCIFACTORY"))
112275 + return 0;
112276 +
112277 + /* throw out any structs in uapi */
112278 + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
112279 +
112280 + if (strstr(xloc.file, "/uapi/"))
112281 + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
112282 +
112283 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
112284 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
112285 + newtree[i] = field;
112286 + }
112287 +
112288 + /*
112289 + * enforce that we don't randomize the layout of the last
112290 + * element of a struct if it's a 0 or 1-length array
112291 + * or a proper flexible array
112292 + */
112293 + if (is_flexible_array(newtree[num_fields - 1]))
112294 + shuffle_length--;
112295 +
112296 + shuffle(type, (tree *)newtree, shuffle_length);
112297 +
112298 + /*
112299 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
112300 + * as gcc provides no other way to detect such code
112301 + */
112302 + list = make_node(FIELD_DECL);
112303 + TREE_CHAIN(list) = newtree[0];
112304 + TREE_TYPE(list) = void_type_node;
112305 + DECL_SIZE(list) = bitsize_zero_node;
112306 + DECL_NONADDRESSABLE_P(list) = 1;
112307 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
112308 + DECL_SIZE_UNIT(list) = size_zero_node;
112309 + DECL_FIELD_OFFSET(list) = size_zero_node;
112310 + // to satisfy the constify plugin
112311 + TREE_READONLY(list) = 1;
112312 +
112313 + for (i = 0; i < num_fields - 1; i++)
112314 + TREE_CHAIN(newtree[i]) = newtree[i+1];
112315 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
112316 +
112317 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
112318 + TYPE_FIELDS(variant) = list;
112319 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
112320 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
112321 + // force a re-layout
112322 + TYPE_SIZE(variant) = NULL_TREE;
112323 + layout_type(variant);
112324 + }
112325 +
112326 + return 1;
112327 +}
112328 +
112329 +/* from constify plugin */
112330 +static const_tree get_field_type(const_tree field)
112331 +{
112332 + return strip_array_types(TREE_TYPE(field));
112333 +}
112334 +
112335 +/* from constify plugin */
112336 +static bool is_fptr(const_tree fieldtype)
112337 +{
112338 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
112339 + return false;
112340 +
112341 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
112342 +}
112343 +
112344 +/* derived from constify plugin */
112345 +static int is_pure_ops_struct(const_tree node)
112346 +{
112347 + const_tree field;
112348 +
112349 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
112350 +
112351 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
112352 + const_tree fieldtype = get_field_type(field);
112353 + enum tree_code code = TREE_CODE(fieldtype);
112354 +
112355 + if (node == fieldtype)
112356 + continue;
112357 +
112358 + if (!is_fptr(fieldtype))
112359 + return 0;
112360 +
112361 + if (code != RECORD_TYPE && code != UNION_TYPE)
112362 + continue;
112363 +
112364 + if (!is_pure_ops_struct(fieldtype))
112365 + return 0;
112366 + }
112367 +
112368 + return 1;
112369 +}
112370 +
112371 +static void randomize_type(tree type)
112372 +{
112373 + tree variant;
112374 +
112375 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
112376 +
112377 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
112378 + return;
112379 +
112380 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
112381 + relayout_struct(type);
112382 +
112383 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
112384 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
112385 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
112386 + }
112387 +#ifdef __DEBUG_PLUGIN
112388 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
112389 +#ifdef __DEBUG_VERBOSE
112390 + debug_tree(type);
112391 +#endif
112392 +#endif
112393 +}
112394 +
112395 +static void randomize_layout_finish_decl(void *event_data, void *data)
112396 +{
112397 + tree decl = (tree)event_data;
112398 + tree type;
112399 +
112400 + if (decl == NULL_TREE || decl == error_mark_node)
112401 + return;
112402 +
112403 + type = TREE_TYPE(decl);
112404 +
112405 + if (TREE_CODE(decl) != VAR_DECL)
112406 + return;
112407 +
112408 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
112409 + return;
112410 +
112411 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
112412 + return;
112413 +
112414 + relayout_decl(decl);
112415 +}
112416 +
112417 +static void finish_type(void *event_data, void *data)
112418 +{
112419 + tree type = (tree)event_data;
112420 +
112421 + if (type == NULL_TREE || type == error_mark_node)
112422 + return;
112423 +
112424 + if (TREE_CODE(type) != RECORD_TYPE)
112425 + return;
112426 +
112427 + if (TYPE_FIELDS(type) == NULL_TREE)
112428 + return;
112429 +
112430 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
112431 + return;
112432 +
112433 +#ifdef __DEBUG_PLUGIN
112434 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
112435 +#endif
112436 +#ifdef __DEBUG_VERBOSE
112437 + debug_tree(type);
112438 +#endif
112439 + randomize_type(type);
112440 +
112441 + return;
112442 +}
112443 +
112444 +static struct attribute_spec randomize_layout_attr = {
112445 + .name = "randomize_layout",
112446 + // related to args
112447 + .min_length = 0,
112448 + .max_length = 0,
112449 + .decl_required = false,
112450 + // need type declaration
112451 + .type_required = true,
112452 + .function_type_required = false,
112453 + .handler = handle_randomize_layout_attr,
112454 +#if BUILDING_GCC_VERSION >= 4007
112455 + .affects_type_identity = true
112456 +#endif
112457 +};
112458 +
112459 +static struct attribute_spec no_randomize_layout_attr = {
112460 + .name = "no_randomize_layout",
112461 + // related to args
112462 + .min_length = 0,
112463 + .max_length = 0,
112464 + .decl_required = false,
112465 + // need type declaration
112466 + .type_required = true,
112467 + .function_type_required = false,
112468 + .handler = handle_randomize_layout_attr,
112469 +#if BUILDING_GCC_VERSION >= 4007
112470 + .affects_type_identity = true
112471 +#endif
112472 +};
112473 +
112474 +static struct attribute_spec randomize_considered_attr = {
112475 + .name = "randomize_considered",
112476 + // related to args
112477 + .min_length = 0,
112478 + .max_length = 0,
112479 + .decl_required = false,
112480 + // need type declaration
112481 + .type_required = true,
112482 + .function_type_required = false,
112483 + .handler = handle_randomize_considered_attr,
112484 +#if BUILDING_GCC_VERSION >= 4007
112485 + .affects_type_identity = false
112486 +#endif
112487 +};
112488 +
112489 +static struct attribute_spec randomize_performed_attr = {
112490 + .name = "randomize_performed",
112491 + // related to args
112492 + .min_length = 0,
112493 + .max_length = 0,
112494 + .decl_required = false,
112495 + // need type declaration
112496 + .type_required = true,
112497 + .function_type_required = false,
112498 + .handler = handle_randomize_performed_attr,
112499 +#if BUILDING_GCC_VERSION >= 4007
112500 + .affects_type_identity = false
112501 +#endif
112502 +};
112503 +
112504 +static void register_attributes(void *event_data, void *data)
112505 +{
112506 + register_attribute(&randomize_layout_attr);
112507 + register_attribute(&no_randomize_layout_attr);
112508 + register_attribute(&randomize_considered_attr);
112509 + register_attribute(&randomize_performed_attr);
112510 +}
112511 +
112512 +static void check_bad_casts_in_constructor(tree var, tree init)
112513 +{
112514 + unsigned HOST_WIDE_INT idx;
112515 + tree field, val;
112516 + tree field_type, val_type;
112517 +
112518 + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
112519 + if (TREE_CODE(val) == CONSTRUCTOR) {
112520 + check_bad_casts_in_constructor(var, val);
112521 + continue;
112522 + }
112523 +
112524 + /* pipacs' plugin creates franken-arrays that differ from those produced by
112525 + normal code which all have valid 'field' trees. work around this */
112526 + if (field == NULL_TREE)
112527 + continue;
112528 + field_type = TREE_TYPE(field);
112529 + val_type = TREE_TYPE(val);
112530 +
112531 + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
112532 + continue;
112533 +
112534 + if (field_type == val_type)
112535 + continue;
112536 +
112537 + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
112538 + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
112539 +
112540 + if (field_type == void_type_node)
112541 + continue;
112542 + if (field_type == val_type)
112543 + continue;
112544 + if (TREE_CODE(val_type) != RECORD_TYPE)
112545 + continue;
112546 +
112547 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
112548 + continue;
112549 + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
112550 + }
112551 +}
112552 +
112553 +/* derived from the constify plugin */
112554 +static void check_global_variables(void *event_data, void *data)
112555 +{
112556 + struct varpool_node *node;
112557 + tree init;
112558 +
112559 + FOR_EACH_VARIABLE(node) {
112560 + tree var = NODE_DECL(node);
112561 + init = DECL_INITIAL(var);
112562 + if (init == NULL_TREE)
112563 + continue;
112564 +
112565 + if (TREE_CODE(init) != CONSTRUCTOR)
112566 + continue;
112567 +
112568 + check_bad_casts_in_constructor(var, init);
112569 + }
112570 +}
112571 +
112572 +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
112573 +{
112574 + basic_block dom;
112575 + gimple dom_stmt;
112576 + gimple call_stmt;
112577 + const_tree dom_lhs;
112578 + const_tree poss_is_err_cond;
112579 + const_tree poss_is_err_func;
112580 + const_tree is_err_arg;
112581 +
112582 + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
112583 + if (!dom)
112584 + return false;
112585 +
112586 + dom_stmt = last_stmt(dom);
112587 + if (!dom_stmt)
112588 + return false;
112589 +
112590 + if (gimple_code(dom_stmt) != GIMPLE_COND)
112591 + return false;
112592 +
112593 + if (gimple_cond_code(dom_stmt) != NE_EXPR)
112594 + return false;
112595 +
112596 + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
112597 + return false;
112598 +
112599 + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
112600 +
112601 + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
112602 + return false;
112603 +
112604 + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
112605 +
112606 + if (gimple_code(call_stmt) != GIMPLE_CALL)
112607 + return false;
112608 +
112609 + dom_lhs = gimple_get_lhs(call_stmt);
112610 + poss_is_err_func = gimple_call_fndecl(call_stmt);
112611 + if (!poss_is_err_func)
112612 + return false;
112613 + if (dom_lhs != poss_is_err_cond)
112614 + return false;
112615 + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
112616 + return false;
112617 +
112618 + is_err_arg = gimple_call_arg(call_stmt, 0);
112619 + if (!is_err_arg)
112620 + return false;
112621 +
112622 + if (is_err_arg != rhs)
112623 + return false;
112624 +
112625 + return true;
112626 +}
112627 +
112628 +static void handle_local_var_initializers(void)
112629 +{
112630 + tree var;
112631 + unsigned int i;
112632 +
112633 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
112634 + tree init = DECL_INITIAL(var);
112635 + if (!init)
112636 + continue;
112637 + if (TREE_CODE(init) != CONSTRUCTOR)
112638 + continue;
112639 + check_bad_casts_in_constructor(var, init);
112640 + }
112641 +}
112642 +
112643 +/*
112644 + * iterate over all statements to find "bad" casts:
112645 + * those where the address of the start of a structure is cast
112646 + * to a pointer of a structure of a different type, or a
112647 + * structure pointer type is cast to a different structure pointer type
112648 + */
112649 +static unsigned int find_bad_casts(void)
112650 +{
112651 + basic_block bb;
112652 +
112653 + handle_local_var_initializers();
112654 +
112655 + FOR_ALL_BB_FN(bb, cfun) {
112656 + gimple_stmt_iterator gsi;
112657 +
112658 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
112659 + gimple stmt;
112660 + const_tree lhs;
112661 + const_tree lhs_type;
112662 + const_tree rhs1;
112663 + const_tree rhs_type;
112664 + const_tree ptr_lhs_type;
112665 + const_tree ptr_rhs_type;
112666 + const_tree op0;
112667 + const_tree op0_type;
112668 + enum tree_code rhs_code;
112669 +
112670 + stmt = gsi_stmt(gsi);
112671 +
112672 +#ifdef __DEBUG_PLUGIN
112673 +#ifdef __DEBUG_VERBOSE
112674 + debug_gimple_stmt(stmt);
112675 + debug_tree(gimple_get_lhs(stmt));
112676 +#endif
112677 +#endif
112678 +
112679 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
112680 + continue;
112681 +
112682 +#ifdef __DEBUG_PLUGIN
112683 +#ifdef __DEBUG_VERBOSE
112684 + debug_tree(gimple_assign_rhs1(stmt));
112685 +#endif
112686 +#endif
112687 +
112688 + rhs_code = gimple_assign_rhs_code(stmt);
112689 +
112690 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
112691 + continue;
112692 +
112693 + lhs = gimple_get_lhs(stmt);
112694 + lhs_type = TREE_TYPE(lhs);
112695 + rhs1 = gimple_assign_rhs1(stmt);
112696 + rhs_type = TREE_TYPE(rhs1);
112697 +
112698 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
112699 + TREE_CODE(lhs_type) != POINTER_TYPE)
112700 + continue;
112701 +
112702 + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
112703 + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
112704 +
112705 + if (ptr_rhs_type == void_type_node)
112706 + continue;
112707 +
112708 + if (ptr_lhs_type == void_type_node)
112709 + continue;
112710 +
112711 + if (dominated_by_is_err(rhs1, bb))
112712 + continue;
112713 +
112714 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
112715 +#ifndef __DEBUG_PLUGIN
112716 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
112717 +#endif
112718 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
112719 + continue;
112720 + }
112721 +
112722 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
112723 + continue;
112724 +
112725 + if (rhs_code == ADDR_EXPR) {
112726 + op0 = TREE_OPERAND(rhs1, 0);
112727 +
112728 + if (op0 == NULL_TREE)
112729 + continue;
112730 +
112731 + if (TREE_CODE(op0) != VAR_DECL)
112732 + continue;
112733 +
112734 + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
112735 + if (op0_type == ptr_lhs_type)
112736 + continue;
112737 +
112738 +#ifndef __DEBUG_PLUGIN
112739 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
112740 +#endif
112741 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
112742 + } else {
112743 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
112744 + /* skip bogus type casts introduced by container_of */
112745 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
112746 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
112747 + continue;
112748 +#ifndef __DEBUG_PLUGIN
112749 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
112750 +#endif
112751 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
112752 + }
112753 +
112754 + }
112755 + }
112756 + return 0;
112757 +}
112758 +
112759 +#if BUILDING_GCC_VERSION >= 4009
112760 +static const struct pass_data randomize_layout_bad_cast_data = {
112761 +#else
112762 +static struct gimple_opt_pass randomize_layout_bad_cast = {
112763 + .pass = {
112764 +#endif
112765 + .type = GIMPLE_PASS,
112766 + .name = "randomize_layout_bad_cast",
112767 +#if BUILDING_GCC_VERSION >= 4008
112768 + .optinfo_flags = OPTGROUP_NONE,
112769 +#endif
112770 +#if BUILDING_GCC_VERSION >= 4009
112771 + .has_gate = false,
112772 + .has_execute = true,
112773 +#else
112774 + .gate = NULL,
112775 + .execute = find_bad_casts,
112776 + .sub = NULL,
112777 + .next = NULL,
112778 + .static_pass_number = 0,
112779 +#endif
112780 + .tv_id = TV_NONE,
112781 + .properties_required = PROP_cfg,
112782 + .properties_provided = 0,
112783 + .properties_destroyed = 0,
112784 + .todo_flags_start = 0,
112785 + .todo_flags_finish = TODO_dump_func
112786 +#if BUILDING_GCC_VERSION < 4009
112787 + }
112788 +#endif
112789 +};
112790 +
112791 +#if BUILDING_GCC_VERSION >= 4009
112792 +namespace {
112793 +class randomize_layout_bad_cast : public gimple_opt_pass {
112794 +public:
112795 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
112796 + unsigned int execute() { return find_bad_casts(); }
112797 +};
112798 +}
112799 +#endif
112800 +
112801 +static struct opt_pass *make_randomize_layout_bad_cast(void)
112802 +{
112803 +#if BUILDING_GCC_VERSION >= 4009
112804 + return new randomize_layout_bad_cast();
112805 +#else
112806 + return &randomize_layout_bad_cast.pass;
112807 +#endif
112808 +}
112809 +
112810 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
112811 +{
112812 + int i;
112813 + const char * const plugin_name = plugin_info->base_name;
112814 + const int argc = plugin_info->argc;
112815 + const struct plugin_argument * const argv = plugin_info->argv;
112816 + bool enable = true;
112817 + int obtained_seed = 0;
112818 + struct register_pass_info randomize_layout_bad_cast_info;
112819 +
112820 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
112821 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
112822 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
112823 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
112824 +
112825 + if (!plugin_default_version_check(version, &gcc_version)) {
112826 + error(G_("incompatible gcc/plugin versions"));
112827 + return 1;
112828 + }
112829 +
112830 + if (strcmp(lang_hooks.name, "GNU C")) {
112831 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
112832 + enable = false;
112833 + }
112834 +
112835 + for (i = 0; i < argc; ++i) {
112836 + if (!strcmp(argv[i].key, "disable")) {
112837 + enable = false;
112838 + continue;
112839 + }
112840 + if (!strcmp(argv[i].key, "performance-mode")) {
112841 + performance_mode = 1;
112842 + continue;
112843 + }
112844 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
112845 + }
112846 +
112847 + if (strlen(randstruct_seed) != 64) {
112848 + error(G_("invalid seed value supplied for %s plugin"), plugin_name);
112849 + return 1;
112850 + }
112851 + obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
112852 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
112853 + if (obtained_seed != 4) {
112854 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
112855 + return 1;
112856 + }
112857 +
112858 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
112859 + if (enable) {
112860 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
112861 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
112862 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
112863 + register_callback(plugin_name, PLUGIN_FINISH_DECL, randomize_layout_finish_decl, NULL);
112864 + }
112865 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
112866 +
112867 + return 0;
112868 +}
112869 diff --git a/tools/gcc/size_overflow_plugin/.gitignore b/tools/gcc/size_overflow_plugin/.gitignore
112870 new file mode 100644
112871 index 0000000..1f0214f
112872 --- /dev/null
112873 +++ b/tools/gcc/size_overflow_plugin/.gitignore
112874 @@ -0,0 +1,3 @@
112875 +randomize_layout_seed.h
112876 +size_overflow_hash.h
112877 +size_overflow_hash_aux.h
112878 diff --git a/tools/gcc/size_overflow_plugin/Makefile b/tools/gcc/size_overflow_plugin/Makefile
112879 new file mode 100644
112880 index 0000000..1ae2ed5
112881 --- /dev/null
112882 +++ b/tools/gcc/size_overflow_plugin/Makefile
112883 @@ -0,0 +1,20 @@
112884 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
112885 +always := $($(HOSTLIBS)-y)
112886 +
112887 +size_overflow_plugin-objs := $(patsubst $(srctree)/$(src)/%.c,%.o,$(wildcard $(srctree)/$(src)/*.c))
112888 +
112889 +$(patsubst $(srctree)/$(src)/%.c,$(obj)/%.o,$(wildcard $(srctree)/$(src)/*.c)): $(objtree)/$(obj)/size_overflow_hash.h $(objtree)/$(obj)/size_overflow_hash_aux.h
112890 +
112891 +quiet_cmd_build_size_overflow_hash = GENHASH $@
112892 + cmd_build_size_overflow_hash = \
112893 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash -d $< -o $@
112894 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
112895 + $(call if_changed,build_size_overflow_hash)
112896 +
112897 +quiet_cmd_build_size_overflow_hash_aux = GENHASH $@
112898 + cmd_build_size_overflow_hash_aux = \
112899 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash_aux -d $< -o $@
112900 +$(objtree)/$(obj)/size_overflow_hash_aux.h: $(src)/size_overflow_hash_aux.data FORCE
112901 + $(call if_changed,build_size_overflow_hash_aux)
112902 +
112903 +targets += size_overflow_hash.h size_overflow_hash_aux.h
112904 diff --git a/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
112905 new file mode 100644
112906 index 0000000..12b1e3b
112907 --- /dev/null
112908 +++ b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
112909 @@ -0,0 +1,102 @@
112910 +#!/bin/bash
112911 +
112912 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
112913 +
112914 +header1="size_overflow_hash.h"
112915 +database="size_overflow_hash.data"
112916 +n=65536
112917 +hashtable_name="size_overflow_hash"
112918 +
112919 +usage() {
112920 +cat <<EOF
112921 +usage: $0 options
112922 +OPTIONS:
112923 + -h|--help help
112924 + -o header file
112925 + -d database file
112926 + -n hash array size
112927 + -s name of the hash table
112928 +EOF
112929 + return 0
112930 +}
112931 +
112932 +while true
112933 +do
112934 + case "$1" in
112935 + -h|--help) usage && exit 0;;
112936 + -n) n=$2; shift 2;;
112937 + -o) header1="$2"; shift 2;;
112938 + -d) database="$2"; shift 2;;
112939 + -s) hashtable_name="$2"; shift 2;;
112940 + --) shift 1; break ;;
112941 + *) break ;;
112942 + esac
112943 +done
112944 +
112945 +create_defines() {
112946 + for i in `seq 0 31`
112947 + do
112948 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
112949 + done
112950 + echo >> "$header1"
112951 +}
112952 +
112953 +create_structs() {
112954 + rm -f "$header1"
112955 +
112956 + create_defines
112957 +
112958 + cat "$database" | while read data
112959 + do
112960 + data_array=($data)
112961 + struct_hash_name="${data_array[0]}"
112962 + funcn="${data_array[1]}"
112963 + params="${data_array[2]}"
112964 + next="${data_array[4]}"
112965 +
112966 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
112967 +
112968 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
112969 + echo -en "\t.param\t= " >> "$header1"
112970 + line=
112971 + for param_num in ${params//-/ };
112972 + do
112973 + line="${line}PARAM"$param_num"|"
112974 + done
112975 +
112976 + echo -e "${line%?},\n};\n" >> "$header1"
112977 + done
112978 +}
112979 +
112980 +create_headers() {
112981 + echo "const struct size_overflow_hash * const $hashtable_name[$n] = {" >> "$header1"
112982 +}
112983 +
112984 +create_array_elements() {
112985 + index=0
112986 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
112987 + do
112988 + data_array=($data)
112989 + i="${data_array[3]}"
112990 + hash="${data_array[0]}"
112991 + while [[ $index -lt $i ]]
112992 + do
112993 + echo -e "\t["$index"]\t= NULL," >> "$header1"
112994 + index=$(($index + 1))
112995 + done
112996 + index=$(($index + 1))
112997 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
112998 + done
112999 + echo '};' >> $header1
113000 +}
113001 +
113002 +size_overflow_plugin_dir=`dirname $header1`
113003 +if [ "$size_overflow_plugin_dir" != '.' ]; then
113004 + mkdir -p "$size_overflow_plugin_dir" 2> /dev/null
113005 +fi
113006 +
113007 +create_structs
113008 +create_headers
113009 +create_array_elements
113010 +
113011 +exit 0
113012 diff --git a/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
113013 new file mode 100644
113014 index 0000000..c43901f
113015 --- /dev/null
113016 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
113017 @@ -0,0 +1,748 @@
113018 +/*
113019 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
113020 + * Licensed under the GPL v2, or (at your option) v3
113021 + *
113022 + * Homepage:
113023 + * http://www.grsecurity.net/~ephox/overflow_plugin/
113024 + *
113025 + * Documentation:
113026 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
113027 + *
113028 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
113029 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
113030 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
113031 + *
113032 + * Usage:
113033 + * $ make
113034 + * $ make run
113035 + */
113036 +
113037 +#include "gcc-common.h"
113038 +#include "size_overflow.h"
113039 +
113040 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
113041 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
113042 +
113043 +// data for the size_overflow asm stmt
113044 +struct asm_data {
113045 + gimple def_stmt;
113046 + tree input;
113047 + tree output;
113048 +};
113049 +
113050 +#if BUILDING_GCC_VERSION <= 4007
113051 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
113052 +#else
113053 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
113054 +#endif
113055 +{
113056 + tree list;
113057 +#if BUILDING_GCC_VERSION <= 4007
113058 + VEC(tree, gc) *vec_list = NULL;
113059 +#else
113060 + vec<tree, va_gc> *vec_list = NULL;
113061 +#endif
113062 +
113063 + list = build_tree_list(NULL_TREE, string);
113064 + list = chainon(NULL_TREE, build_tree_list(list, io));
113065 +#if BUILDING_GCC_VERSION <= 4007
113066 + VEC_safe_push(tree, gc, vec_list, list);
113067 +#else
113068 + vec_safe_push(vec_list, list);
113069 +#endif
113070 + return vec_list;
113071 +}
113072 +
113073 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
113074 +{
113075 + gimple asm_stmt;
113076 + gimple_stmt_iterator gsi;
113077 +#if BUILDING_GCC_VERSION <= 4007
113078 + VEC(tree, gc) *input, *output = NULL;
113079 +#else
113080 + vec<tree, va_gc> *input, *output = NULL;
113081 +#endif
113082 +
113083 + input = create_asm_io_list(str_input, asm_data->input);
113084 +
113085 + if (asm_data->output)
113086 + output = create_asm_io_list(str_output, asm_data->output);
113087 +
113088 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
113089 + gsi = gsi_for_stmt(asm_data->def_stmt);
113090 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
113091 +
113092 + if (asm_data->output)
113093 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
113094 +}
113095 +
113096 +static void replace_call_lhs(const struct asm_data *asm_data)
113097 +{
113098 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
113099 + update_stmt(asm_data->def_stmt);
113100 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
113101 +}
113102 +
113103 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
113104 +{
113105 + enum mark cur_fndecl_attr;
113106 + gimple phi = get_def_stmt(result);
113107 + unsigned int i, n = gimple_phi_num_args(phi);
113108 +
113109 + pointer_set_insert(visited, phi);
113110 + for (i = 0; i < n; i++) {
113111 + tree arg = gimple_phi_arg_def(phi, i);
113112 +
113113 + cur_fndecl_attr = search_intentional(visited, arg);
113114 + if (cur_fndecl_attr != MARK_NO)
113115 + return cur_fndecl_attr;
113116 + }
113117 + return MARK_NO;
113118 +}
113119 +
113120 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
113121 +{
113122 + enum mark cur_fndecl_attr;
113123 + const_tree rhs1, rhs2;
113124 + gimple def_stmt = get_def_stmt(lhs);
113125 +
113126 + rhs1 = gimple_assign_rhs1(def_stmt);
113127 + rhs2 = gimple_assign_rhs2(def_stmt);
113128 +
113129 + cur_fndecl_attr = search_intentional(visited, rhs1);
113130 + if (cur_fndecl_attr != MARK_NO)
113131 + return cur_fndecl_attr;
113132 + return search_intentional(visited, rhs2);
113133 +}
113134 +
113135 +// Look up the intentional_overflow attribute on the caller and the callee functions.
113136 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
113137 +{
113138 + const_gimple def_stmt;
113139 +
113140 + if (TREE_CODE(lhs) != SSA_NAME)
113141 + return get_intentional_attr_type(lhs);
113142 +
113143 + def_stmt = get_def_stmt(lhs);
113144 + if (!def_stmt)
113145 + return MARK_NO;
113146 +
113147 + if (pointer_set_contains(visited, def_stmt))
113148 + return MARK_NO;
113149 +
113150 + switch (gimple_code(def_stmt)) {
113151 + case GIMPLE_NOP:
113152 + return search_intentional(visited, SSA_NAME_VAR(lhs));
113153 + case GIMPLE_ASM:
113154 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
113155 + return MARK_TURN_OFF;
113156 + return MARK_NO;
113157 + case GIMPLE_CALL:
113158 + return MARK_NO;
113159 + case GIMPLE_PHI:
113160 + return search_intentional_phi(visited, lhs);
113161 + case GIMPLE_ASSIGN:
113162 + switch (gimple_num_ops(def_stmt)) {
113163 + case 2:
113164 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
113165 + case 3:
113166 + return search_intentional_binary(visited, lhs);
113167 + }
113168 + case GIMPLE_RETURN:
113169 + return MARK_NO;
113170 + default:
113171 + debug_gimple_stmt((gimple)def_stmt);
113172 + error("%s: unknown gimple code", __func__);
113173 + gcc_unreachable();
113174 + }
113175 +}
113176 +
113177 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
113178 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
113179 +{
113180 + const_tree fndecl;
113181 + struct pointer_set_t *visited;
113182 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
113183 +
113184 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
113185 + if (is_end_intentional_intentional_attr(fndecl, argnum))
113186 + decl_attr = MARK_NOT_INTENTIONAL;
113187 + else if (is_yes_intentional_attr(fndecl, argnum))
113188 + decl_attr = MARK_YES;
113189 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
113190 + return MARK_TURN_OFF;
113191 + }
113192 +
113193 + visited = pointer_set_create();
113194 + cur_fndecl_attr = search_intentional(visited, arg);
113195 + pointer_set_destroy(visited);
113196 +
113197 + switch (cur_fndecl_attr) {
113198 + case MARK_NO:
113199 + case MARK_TURN_OFF:
113200 + return cur_fndecl_attr;
113201 + default:
113202 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
113203 + return MARK_YES;
113204 + }
113205 +}
113206 +
113207 +static void check_missing_size_overflow_attribute(tree var)
113208 +{
113209 + tree orig_fndecl;
113210 + unsigned int num;
113211 +
113212 + if (is_a_return_check(var))
113213 + orig_fndecl = DECL_ORIGIN(var);
113214 + else
113215 + orig_fndecl = DECL_ORIGIN(current_function_decl);
113216 +
113217 + num = get_function_num(var, orig_fndecl);
113218 + if (num == CANNOT_FIND_ARG)
113219 + return;
113220 +
113221 + is_missing_function(orig_fndecl, num);
113222 +}
113223 +
113224 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
113225 +{
113226 + gimple phi = get_def_stmt(result);
113227 + unsigned int i, n = gimple_phi_num_args(phi);
113228 +
113229 + pointer_set_insert(visited, phi);
113230 + for (i = 0; i < n; i++) {
113231 + tree arg = gimple_phi_arg_def(phi, i);
113232 +
113233 + search_size_overflow_attribute(visited, arg);
113234 + }
113235 +}
113236 +
113237 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
113238 +{
113239 + const_gimple def_stmt = get_def_stmt(lhs);
113240 + tree rhs1, rhs2;
113241 +
113242 + rhs1 = gimple_assign_rhs1(def_stmt);
113243 + rhs2 = gimple_assign_rhs2(def_stmt);
113244 +
113245 + search_size_overflow_attribute(visited, rhs1);
113246 + search_size_overflow_attribute(visited, rhs2);
113247 +}
113248 +
113249 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
113250 +{
113251 + const_gimple def_stmt;
113252 +
113253 + if (TREE_CODE(lhs) == PARM_DECL) {
113254 + check_missing_size_overflow_attribute(lhs);
113255 + return;
113256 + }
113257 +
113258 + def_stmt = get_def_stmt(lhs);
113259 + if (!def_stmt)
113260 + return;
113261 +
113262 + if (pointer_set_insert(visited, def_stmt))
113263 + return;
113264 +
113265 + switch (gimple_code(def_stmt)) {
113266 + case GIMPLE_NOP:
113267 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
113268 + case GIMPLE_ASM:
113269 + return;
113270 + case GIMPLE_CALL: {
113271 + tree fndecl = gimple_call_fndecl(def_stmt);
113272 +
113273 + if (fndecl == NULL_TREE)
113274 + return;
113275 + check_missing_size_overflow_attribute(fndecl);
113276 + return;
113277 + }
113278 + case GIMPLE_PHI:
113279 + return search_size_overflow_attribute_phi(visited, lhs);
113280 + case GIMPLE_ASSIGN:
113281 + switch (gimple_num_ops(def_stmt)) {
113282 + case 2:
113283 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
113284 + case 3:
113285 + return search_size_overflow_attribute_binary(visited, lhs);
113286 + }
113287 + default:
113288 + debug_gimple_stmt((gimple)def_stmt);
113289 + error("%s: unknown gimple code", __func__);
113290 + gcc_unreachable();
113291 + }
113292 +}
113293 +
113294 +// Search missing entries in the hash table (invoked from the gimple pass)
113295 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
113296 +{
113297 + tree fndecl = NULL_TREE;
113298 + tree lhs;
113299 + struct pointer_set_t *visited;
113300 +
113301 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
113302 + return;
113303 +
113304 + if (num == 0) {
113305 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
113306 + lhs = gimple_return_retval(stmt);
113307 + } else {
113308 + gcc_assert(is_gimple_call(stmt));
113309 + lhs = gimple_call_arg(stmt, num - 1);
113310 + fndecl = gimple_call_fndecl(stmt);
113311 + }
113312 +
113313 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
113314 + return;
113315 +
113316 + visited = pointer_set_create();
113317 + search_size_overflow_attribute(visited, lhs);
113318 + pointer_set_destroy(visited);
113319 +}
113320 +
113321 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
113322 +{
113323 + gimple_stmt_iterator gsi;
113324 + gimple assign;
113325 +
113326 + assign = gimple_build_assign(asm_data->input, asm_data->output);
113327 + gsi = gsi_for_stmt(stmt);
113328 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
113329 + asm_data->def_stmt = assign;
113330 +
113331 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
113332 + asm_data->output = make_ssa_name(asm_data->output, stmt);
113333 + if (gimple_code(stmt) == GIMPLE_RETURN)
113334 + gimple_return_set_retval(stmt, asm_data->output);
113335 + else
113336 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
113337 + update_stmt(stmt);
113338 +}
113339 +
113340 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
113341 +{
113342 + const char *fn_name;
113343 + char *asm_comment;
113344 + unsigned int len;
113345 +
113346 + if (argnum == 0)
113347 + fn_name = DECL_NAME_POINTER(current_function_decl);
113348 + else
113349 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
113350 +
113351 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
113352 + gcc_assert(len > 0);
113353 +
113354 + return asm_comment;
113355 +}
113356 +
113357 +static const char *convert_mark_to_str(enum mark mark)
113358 +{
113359 + switch (mark) {
113360 + case MARK_NO:
113361 + return OK_ASM_STR;
113362 + case MARK_YES:
113363 + case MARK_NOT_INTENTIONAL:
113364 + return YES_ASM_STR;
113365 + case MARK_TURN_OFF:
113366 + return TURN_OFF_ASM_STR;
113367 + }
113368 +
113369 + gcc_unreachable();
113370 +}
113371 +
113372 +/* Create the input of the size_overflow asm stmt.
113373 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
113374 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
113375 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
113376 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
113377 + */
113378 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
113379 +{
113380 + if (!asm_data->def_stmt) {
113381 + asm_data->input = NULL_TREE;
113382 + return;
113383 + }
113384 +
113385 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
113386 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
113387 +
113388 + switch (gimple_code(asm_data->def_stmt)) {
113389 + case GIMPLE_ASSIGN:
113390 + case GIMPLE_CALL:
113391 + replace_call_lhs(asm_data);
113392 + break;
113393 + case GIMPLE_PHI:
113394 + create_output_from_phi(stmt, argnum, asm_data);
113395 + break;
113396 + case GIMPLE_NOP: {
113397 + enum mark mark;
113398 + const char *mark_str;
113399 + char *asm_comment;
113400 +
113401 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
113402 +
113403 + asm_data->input = asm_data->output;
113404 + asm_data->output = NULL;
113405 + asm_data->def_stmt = stmt;
113406 +
113407 + mark_str = convert_mark_to_str(mark);
113408 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
113409 +
113410 + create_asm_stmt(asm_comment, build_string(3, "rm"), NULL, asm_data);
113411 + free(asm_comment);
113412 + asm_data->input = NULL_TREE;
113413 + break;
113414 + }
113415 + case GIMPLE_ASM:
113416 + if (is_size_overflow_asm(asm_data->def_stmt)) {
113417 + asm_data->input = NULL_TREE;
113418 + break;
113419 + }
113420 + default:
113421 + debug_gimple_stmt(asm_data->def_stmt);
113422 + gcc_unreachable();
113423 + }
113424 +}
113425 +
113426 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
113427 + * is of the right kind create the appropriate size_overflow asm stmts:
113428 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
113429 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
113430 + */
113431 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
113432 +{
113433 + struct asm_data asm_data;
113434 + const char *mark_str;
113435 + char *asm_comment;
113436 + enum mark mark;
113437 +
113438 + if (is_gimple_constant(output_node))
113439 + return;
113440 +
113441 + asm_data.output = output_node;
113442 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
113443 + if (mark != MARK_TURN_OFF)
113444 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
113445 +
113446 + asm_data.def_stmt = get_def_stmt(asm_data.output);
113447 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
113448 + return;
113449 +
113450 + create_asm_input(stmt, argnum, &asm_data);
113451 + if (asm_data.input == NULL_TREE)
113452 + return;
113453 +
113454 + mark_str = convert_mark_to_str(mark);
113455 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
113456 + create_asm_stmt(asm_comment, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
113457 + free(asm_comment);
113458 +}
113459 +
113460 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
113461 +static bool create_mark_asm(gimple stmt, enum mark mark)
113462 +{
113463 + struct asm_data asm_data;
113464 + const char *asm_str;
113465 +
113466 + switch (mark) {
113467 + case MARK_TURN_OFF:
113468 + asm_str = TURN_OFF_ASM_STR;
113469 + break;
113470 + case MARK_NOT_INTENTIONAL:
113471 + case MARK_YES:
113472 + asm_str = YES_ASM_STR;
113473 + break;
113474 + default:
113475 + gcc_unreachable();
113476 + }
113477 +
113478 + asm_data.def_stmt = stmt;
113479 + asm_data.output = gimple_call_lhs(stmt);
113480 +
113481 + if (asm_data.output == NULL_TREE) {
113482 + asm_data.input = gimple_call_arg(stmt, 0);
113483 + if (is_gimple_constant(asm_data.input))
113484 + return false;
113485 + asm_data.output = NULL;
113486 + create_asm_stmt(asm_str, build_string(3, "rm"), NULL, &asm_data);
113487 + return true;
113488 + }
113489 +
113490 + create_asm_input(stmt, 0, &asm_data);
113491 + gcc_assert(asm_data.input != NULL_TREE);
113492 +
113493 + create_asm_stmt(asm_str, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
113494 + return true;
113495 +}
113496 +
113497 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
113498 +{
113499 + gimple def_stmt;
113500 +
113501 + def_stmt = get_def_stmt(lhs);
113502 + if (!def_stmt)
113503 + return;
113504 +
113505 + if (pointer_set_insert(visited, def_stmt))
113506 + return;
113507 +
113508 + switch (gimple_code(def_stmt)) {
113509 + case GIMPLE_NOP:
113510 + case GIMPLE_ASM:
113511 + case GIMPLE_CALL:
113512 + break;
113513 + case GIMPLE_PHI: {
113514 + unsigned int i, n = gimple_phi_num_args(def_stmt);
113515 +
113516 + pointer_set_insert(visited, def_stmt);
113517 +
113518 + for (i = 0; i < n; i++) {
113519 + tree arg = gimple_phi_arg_def(def_stmt, i);
113520 +
113521 + walk_use_def_ptr(visited, arg);
113522 + }
113523 + }
113524 + case GIMPLE_ASSIGN:
113525 + switch (gimple_num_ops(def_stmt)) {
113526 + case 2:
113527 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
113528 + return;
113529 + case 3:
113530 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
113531 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
113532 + return;
113533 + default:
113534 + return;
113535 + }
113536 + default:
113537 + debug_gimple_stmt((gimple)def_stmt);
113538 + error("%s: unknown gimple code", __func__);
113539 + gcc_unreachable();
113540 + }
113541 +}
113542 +
113543 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
113544 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
113545 +{
113546 + struct pointer_set_t *visited;
113547 +
113548 + visited = pointer_set_create();
113549 + walk_use_def_ptr(visited, arg);
113550 + pointer_set_destroy(visited);
113551 +}
113552 +
113553 +// Determine the return value and insert the asm stmt to mark the return stmt.
113554 +static void insert_asm_ret(gimple stmt)
113555 +{
113556 + tree ret;
113557 +
113558 + ret = gimple_return_retval(stmt);
113559 + create_size_overflow_asm(stmt, ret, 0);
113560 +}
113561 +
113562 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
113563 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
113564 +{
113565 + tree arg;
113566 + unsigned int argnum;
113567 +
113568 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
113569 + gcc_assert(argnum != 0);
113570 + if (argnum == CANNOT_FIND_ARG)
113571 + return;
113572 +
113573 + arg = gimple_call_arg(stmt, argnum - 1);
113574 + gcc_assert(arg != NULL_TREE);
113575 +
113576 + // skip all ptr - ptr expressions
113577 + insert_mark_not_intentional_asm_at_ptr(arg);
113578 +
113579 + create_size_overflow_asm(stmt, arg, argnum);
113580 +}
113581 +
113582 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
113583 +static void set_argnum_attribute(const_tree attr, bool *argnums)
113584 +{
113585 + unsigned int argnum;
113586 + tree attr_value;
113587 +
113588 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
113589 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
113590 + argnums[argnum] = true;
113591 + }
113592 +}
113593 +
113594 +// If a function arg or the return value is in the hash table then set its index in the array.
113595 +static void set_argnum_hash(tree fndecl, bool *argnums)
113596 +{
113597 + unsigned int num;
113598 + const struct size_overflow_hash *hash;
113599 +
113600 + hash = get_function_hash(DECL_ORIGIN(fndecl));
113601 + if (!hash)
113602 + return;
113603 +
113604 + for (num = 0; num <= MAX_PARAM; num++) {
113605 + if (!(hash->param & (1U << num)))
113606 + continue;
113607 +
113608 + argnums[num] = true;
113609 + }
113610 +}
113611 +
113612 +static bool is_all_the_argnums_empty(bool *argnums)
113613 +{
113614 + unsigned int i;
113615 +
113616 + for (i = 0; i <= MAX_PARAM; i++)
113617 + if (argnums[i])
113618 + return false;
113619 + return true;
113620 +}
113621 +
113622 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
113623 +static void search_interesting_args(tree fndecl, bool *argnums)
113624 +{
113625 + const_tree attr;
113626 +
113627 + set_argnum_hash(fndecl, argnums);
113628 + if (!is_all_the_argnums_empty(argnums))
113629 + return;
113630 +
113631 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
113632 + if (attr && TREE_VALUE(attr))
113633 + set_argnum_attribute(attr, argnums);
113634 +}
113635 +
113636 +/*
113637 + * Look up the intentional_overflow attribute that turns off ipa based duplication
113638 + * on the callee function.
113639 + */
113640 +static bool is_mark_turn_off_attribute(gimple stmt)
113641 +{
113642 + enum mark mark;
113643 + const_tree fndecl = gimple_call_fndecl(stmt);
113644 +
113645 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
113646 + if (mark == MARK_TURN_OFF)
113647 + return true;
113648 + return false;
113649 +}
113650 +
113651 +// If the argument(s) of the callee function is/are in the hash table or are marked by an attribute then mark the call stmt with an asm stmt
113652 +static void handle_interesting_function(gimple stmt)
113653 +{
113654 + unsigned int argnum;
113655 + tree fndecl;
113656 + bool orig_argnums[MAX_PARAM + 1] = {false};
113657 +
113658 + if (gimple_call_num_args(stmt) == 0)
113659 + return;
113660 + fndecl = gimple_call_fndecl(stmt);
113661 + if (fndecl == NULL_TREE)
113662 + return;
113663 + fndecl = DECL_ORIGIN(fndecl);
113664 +
113665 + if (is_mark_turn_off_attribute(stmt)) {
113666 + create_mark_asm(stmt, MARK_TURN_OFF);
113667 + return;
113668 + }
113669 +
113670 + search_interesting_args(fndecl, orig_argnums);
113671 +
113672 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
113673 + if (orig_argnums[argnum])
113674 + insert_asm_arg(stmt, argnum);
113675 +}
113676 +
113677 +// If the return value of the caller function is in hash table (its index is 0) then mark the return stmt with an asm stmt
113678 +static void handle_interesting_ret(gimple stmt)
113679 +{
113680 + bool orig_argnums[MAX_PARAM + 1] = {false};
113681 +
113682 + search_interesting_args(current_function_decl, orig_argnums);
113683 +
113684 + if (orig_argnums[0])
113685 + insert_asm_ret(stmt);
113686 +}
113687 +
113688 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
113689 +static unsigned int search_interesting_functions(void)
113690 +{
113691 + basic_block bb;
113692 +
113693 + FOR_ALL_BB_FN(bb, cfun) {
113694 + gimple_stmt_iterator gsi;
113695 +
113696 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
113697 + gimple stmt = gsi_stmt(gsi);
113698 +
113699 + if (is_size_overflow_asm(stmt))
113700 + continue;
113701 +
113702 + if (is_gimple_call(stmt))
113703 + handle_interesting_function(stmt);
113704 + else if (gimple_code(stmt) == GIMPLE_RETURN)
113705 + handle_interesting_ret(stmt);
113706 + }
113707 + }
113708 + return 0;
113709 +}
113710 +
113711 +/*
113712 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
113713 + * this pass inserts asm stmts to mark the interesting args
113714 + * that the ipa pass will detect and insert the size overflow checks for.
113715 + */
113716 +#if BUILDING_GCC_VERSION >= 4009
113717 +static const struct pass_data insert_size_overflow_asm_pass_data = {
113718 +#else
113719 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
113720 + .pass = {
113721 +#endif
113722 + .type = GIMPLE_PASS,
113723 + .name = "insert_size_overflow_asm",
113724 +#if BUILDING_GCC_VERSION >= 4008
113725 + .optinfo_flags = OPTGROUP_NONE,
113726 +#endif
113727 +#if BUILDING_GCC_VERSION >= 4009
113728 + .has_gate = false,
113729 + .has_execute = true,
113730 +#else
113731 + .gate = NULL,
113732 + .execute = search_interesting_functions,
113733 + .sub = NULL,
113734 + .next = NULL,
113735 + .static_pass_number = 0,
113736 +#endif
113737 + .tv_id = TV_NONE,
113738 + .properties_required = PROP_cfg,
113739 + .properties_provided = 0,
113740 + .properties_destroyed = 0,
113741 + .todo_flags_start = 0,
113742 + .todo_flags_finish = TODO_dump_func | TODO_verify_ssa | TODO_verify_stmts | TODO_remove_unused_locals | TODO_update_ssa_no_phi | TODO_cleanup_cfg | TODO_ggc_collect | TODO_verify_flow
113743 +#if BUILDING_GCC_VERSION < 4009
113744 + }
113745 +#endif
113746 +};
113747 +
113748 +#if BUILDING_GCC_VERSION >= 4009
113749 +namespace {
113750 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
113751 +public:
113752 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
113753 + unsigned int execute() { return search_interesting_functions(); }
113754 +};
113755 +}
113756 +#endif
113757 +
113758 +struct opt_pass *make_insert_size_overflow_asm_pass(void)
113759 +{
113760 +#if BUILDING_GCC_VERSION >= 4009
113761 + return new insert_size_overflow_asm_pass();
113762 +#else
113763 + return &insert_size_overflow_asm_pass.pass;
113764 +#endif
113765 +}
113766 diff --git a/tools/gcc/size_overflow_plugin/insert_size_overflow_check_core.c b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_core.c
113767 new file mode 100644
113768 index 0000000..73f0a12
113769 --- /dev/null
113770 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_core.c
113771 @@ -0,0 +1,943 @@
113772 +/*
113773 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
113774 + * Licensed under the GPL v2, or (at your option) v3
113775 + *
113776 + * Homepage:
113777 + * http://www.grsecurity.net/~ephox/overflow_plugin/
113778 + *
113779 + * Documentation:
113780 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
113781 + *
113782 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
113783 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
113784 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
113785 + *
113786 + * Usage:
113787 + * $ make
113788 + * $ make run
113789 + */
113790 +
113791 +#include "gcc-common.h"
113792 +#include "size_overflow.h"
113793 +
113794 +#define MIN_CHECK true
113795 +#define MAX_CHECK false
113796 +
113797 +static tree get_size_overflow_type(struct visited *visited, const_gimple stmt, const_tree node)
113798 +{
113799 + const_tree type;
113800 + tree new_type;
113801 +
113802 + gcc_assert(node != NULL_TREE);
113803 +
113804 + type = TREE_TYPE(node);
113805 +
113806 + if (pointer_set_contains(visited->my_stmts, stmt))
113807 + return TREE_TYPE(node);
113808 +
113809 + switch (TYPE_MODE(type)) {
113810 + case QImode:
113811 + new_type = size_overflow_type_HI;
113812 + break;
113813 + case HImode:
113814 + new_type = size_overflow_type_SI;
113815 + break;
113816 + case SImode:
113817 + new_type = size_overflow_type_DI;
113818 + break;
113819 + case DImode:
113820 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
113821 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
113822 + else
113823 + new_type = size_overflow_type_TI;
113824 + break;
113825 + case TImode:
113826 + gcc_assert(!TYPE_UNSIGNED(type));
113827 + new_type = size_overflow_type_TI;
113828 + break;
113829 + default:
113830 + debug_tree((tree)node);
113831 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
113832 + gcc_unreachable();
113833 + }
113834 +
113835 + if (TYPE_QUALS(type) != 0)
113836 + return build_qualified_type(new_type, TYPE_QUALS(type));
113837 + return new_type;
113838 +}
113839 +
113840 +static tree get_lhs(const_gimple stmt)
113841 +{
113842 + switch (gimple_code(stmt)) {
113843 + case GIMPLE_ASSIGN:
113844 + case GIMPLE_CALL:
113845 + return gimple_get_lhs(stmt);
113846 + case GIMPLE_PHI:
113847 + return gimple_phi_result(stmt);
113848 + default:
113849 + return NULL_TREE;
113850 + }
113851 +}
113852 +
113853 +static tree cast_to_new_size_overflow_type(struct visited *visited, gimple stmt, tree rhs, tree size_overflow_type, bool before)
113854 +{
113855 + gimple_stmt_iterator gsi;
113856 + tree lhs;
113857 + gimple new_stmt;
113858 +
113859 + if (rhs == NULL_TREE)
113860 + return NULL_TREE;
113861 +
113862 + gsi = gsi_for_stmt(stmt);
113863 + new_stmt = build_cast_stmt(visited, size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
113864 + pointer_set_insert(visited->my_stmts, new_stmt);
113865 +
113866 + lhs = get_lhs(new_stmt);
113867 + gcc_assert(lhs != NULL_TREE);
113868 + return lhs;
113869 +}
113870 +
113871 +tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before)
113872 +{
113873 + tree lhs, dst_type;
113874 + gimple_stmt_iterator gsi;
113875 +
113876 + if (rhs1 == NULL_TREE) {
113877 + debug_gimple_stmt(oldstmt);
113878 + error("%s: rhs1 is NULL_TREE", __func__);
113879 + gcc_unreachable();
113880 + }
113881 +
113882 + switch (gimple_code(oldstmt)) {
113883 + case GIMPLE_ASM:
113884 + lhs = rhs1;
113885 + break;
113886 + case GIMPLE_CALL:
113887 + case GIMPLE_ASSIGN:
113888 + lhs = gimple_get_lhs(oldstmt);
113889 + break;
113890 + default:
113891 + debug_gimple_stmt(oldstmt);
113892 + gcc_unreachable();
113893 + }
113894 +
113895 + gsi = gsi_for_stmt(oldstmt);
113896 + pointer_set_insert(visited->stmts, oldstmt);
113897 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
113898 + basic_block next_bb, cur_bb;
113899 + const_edge e;
113900 +
113901 + gcc_assert(before == false);
113902 + gcc_assert(stmt_can_throw_internal(oldstmt));
113903 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
113904 + gcc_assert(!gsi_end_p(gsi));
113905 +
113906 + cur_bb = gimple_bb(oldstmt);
113907 + next_bb = cur_bb->next_bb;
113908 + e = find_edge(cur_bb, next_bb);
113909 + gcc_assert(e != NULL);
113910 + gcc_assert(e->flags & EDGE_FALLTHRU);
113911 +
113912 + gsi = gsi_after_labels(next_bb);
113913 + gcc_assert(!gsi_end_p(gsi));
113914 +
113915 + before = true;
113916 + oldstmt = gsi_stmt(gsi);
113917 + }
113918 +
113919 + dst_type = get_size_overflow_type(visited, oldstmt, lhs);
113920 +
113921 + if (is_gimple_constant(rhs1))
113922 + return cast_a_tree(dst_type, rhs1);
113923 + return cast_to_new_size_overflow_type(visited, oldstmt, rhs1, dst_type, before);
113924 +}
113925 +
113926 +tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
113927 +{
113928 + gimple stmt;
113929 + gimple_stmt_iterator gsi;
113930 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
113931 +
113932 + if (pointer_set_contains(visited->my_stmts, oldstmt))
113933 + return lhs;
113934 +
113935 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
113936 + rhs1 = gimple_assign_rhs1(oldstmt);
113937 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
113938 + }
113939 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
113940 + rhs2 = gimple_assign_rhs2(oldstmt);
113941 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
113942 + }
113943 +
113944 + stmt = gimple_copy(oldstmt);
113945 + gimple_set_location(stmt, gimple_location(oldstmt));
113946 + pointer_set_insert(visited->my_stmts, stmt);
113947 +
113948 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
113949 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
113950 +
113951 + size_overflow_type = get_size_overflow_type(visited, oldstmt, node);
113952 +
113953 + new_var = create_new_var(size_overflow_type);
113954 + new_var = make_ssa_name(new_var, stmt);
113955 + gimple_assign_set_lhs(stmt, new_var);
113956 +
113957 + if (rhs1 != NULL_TREE)
113958 + gimple_assign_set_rhs1(stmt, rhs1);
113959 +
113960 + if (rhs2 != NULL_TREE)
113961 + gimple_assign_set_rhs2(stmt, rhs2);
113962 +#if BUILDING_GCC_VERSION >= 4006
113963 + if (rhs3 != NULL_TREE)
113964 + gimple_assign_set_rhs3(stmt, rhs3);
113965 +#endif
113966 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
113967 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
113968 +
113969 + gsi = gsi_for_stmt(oldstmt);
113970 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
113971 + update_stmt(stmt);
113972 + pointer_set_insert(visited->stmts, oldstmt);
113973 + return gimple_assign_lhs(stmt);
113974 +}
113975 +
113976 +static tree cast_parm_decl(struct visited *visited, tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
113977 +{
113978 + gimple assign;
113979 + gimple_stmt_iterator gsi;
113980 + basic_block first_bb;
113981 +
113982 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
113983 +
113984 + if (bb->index == 0) {
113985 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
113986 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
113987 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
113988 + bb = first_bb;
113989 + }
113990 +
113991 + gsi = gsi_after_labels(bb);
113992 + assign = build_cast_stmt(visited, size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
113993 + pointer_set_insert(visited->my_stmts, assign);
113994 +
113995 + return gimple_assign_lhs(assign);
113996 +}
113997 +
113998 +static tree use_phi_ssa_name(struct visited *visited, tree ssa_name_var, tree new_arg)
113999 +{
114000 + gimple_stmt_iterator gsi;
114001 + gimple assign, def_stmt = get_def_stmt(new_arg);
114002 +
114003 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
114004 + gsi = gsi_after_labels(gimple_bb(def_stmt));
114005 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
114006 + } else {
114007 + gsi = gsi_for_stmt(def_stmt);
114008 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
114009 + }
114010 +
114011 + pointer_set_insert(visited->my_stmts, assign);
114012 + return gimple_assign_lhs(assign);
114013 +}
114014 +
114015 +static tree cast_visited_phi_arg(struct visited *visited, tree ssa_name_var, tree arg, tree size_overflow_type)
114016 +{
114017 + basic_block bb;
114018 + gimple_stmt_iterator gsi;
114019 + const_gimple def_stmt;
114020 + gimple assign;
114021 +
114022 + def_stmt = get_def_stmt(arg);
114023 + bb = gimple_bb(def_stmt);
114024 + gcc_assert(bb->index != 0);
114025 + gsi = gsi_after_labels(bb);
114026 +
114027 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
114028 + pointer_set_insert(visited->my_stmts, assign);
114029 + return gimple_assign_lhs(assign);
114030 +}
114031 +
114032 +static tree create_new_phi_arg(struct visited *visited, tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
114033 +{
114034 + tree size_overflow_type;
114035 + tree arg;
114036 + const_gimple def_stmt;
114037 +
114038 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
114039 + return new_arg;
114040 +
114041 + arg = gimple_phi_arg_def(oldstmt, i);
114042 + def_stmt = get_def_stmt(arg);
114043 + gcc_assert(def_stmt != NULL);
114044 + size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
114045 +
114046 + switch (gimple_code(def_stmt)) {
114047 + case GIMPLE_PHI:
114048 + return cast_visited_phi_arg(visited, ssa_name_var, arg, size_overflow_type);
114049 + case GIMPLE_NOP: {
114050 + basic_block bb;
114051 +
114052 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
114053 + return cast_parm_decl(visited, ssa_name_var, arg, size_overflow_type, bb);
114054 + }
114055 + case GIMPLE_ASM: {
114056 + gimple_stmt_iterator gsi;
114057 + gimple assign, stmt = get_def_stmt(arg);
114058 +
114059 + gsi = gsi_for_stmt(stmt);
114060 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
114061 + pointer_set_insert(visited->my_stmts, assign);
114062 + return gimple_assign_lhs(assign);
114063 + }
114064 + default:
114065 + gcc_assert(new_arg != NULL_TREE);
114066 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
114067 + return use_phi_ssa_name(visited, ssa_name_var, new_arg);
114068 + }
114069 +}
114070 +
114071 +static gimple overflow_create_phi_node(struct visited *visited, gimple oldstmt, tree result)
114072 +{
114073 + basic_block bb;
114074 + gimple phi;
114075 + gimple_seq seq;
114076 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
114077 +
114078 + bb = gsi_bb(gsi);
114079 +
114080 + if (result == NULL_TREE) {
114081 + tree old_result = gimple_phi_result(oldstmt);
114082 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, old_result);
114083 +
114084 + result = create_new_var(size_overflow_type);
114085 + }
114086 +
114087 + phi = create_phi_node(result, bb);
114088 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
114089 + seq = phi_nodes(bb);
114090 + gsi = gsi_last(seq);
114091 + gsi_remove(&gsi, false);
114092 +
114093 + gsi = gsi_for_stmt(oldstmt);
114094 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
114095 + gimple_set_bb(phi, bb);
114096 + return phi;
114097 +}
114098 +
114099 +#if BUILDING_GCC_VERSION <= 4007
114100 +static tree create_new_phi_node(struct visited *visited, VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
114101 +#else
114102 +static tree create_new_phi_node(struct visited *visited, vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
114103 +#endif
114104 +{
114105 + gimple new_phi;
114106 + unsigned int i;
114107 + tree arg, result;
114108 + location_t loc = gimple_location(oldstmt);
114109 +
114110 +#if BUILDING_GCC_VERSION <= 4007
114111 + gcc_assert(!VEC_empty(tree, *args));
114112 +#else
114113 + gcc_assert(!args->is_empty());
114114 +#endif
114115 +
114116 + new_phi = overflow_create_phi_node(visited, oldstmt, ssa_name_var);
114117 + result = gimple_phi_result(new_phi);
114118 + ssa_name_var = SSA_NAME_VAR(result);
114119 +
114120 +#if BUILDING_GCC_VERSION <= 4007
114121 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
114122 +#else
114123 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
114124 +#endif
114125 + arg = create_new_phi_arg(visited, ssa_name_var, arg, oldstmt, i);
114126 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
114127 + }
114128 +
114129 +#if BUILDING_GCC_VERSION <= 4007
114130 + VEC_free(tree, heap, *args);
114131 +#else
114132 + vec_free(args);
114133 +#endif
114134 + update_stmt(new_phi);
114135 + pointer_set_insert(visited->my_stmts, new_phi);
114136 + return result;
114137 +}
114138 +
114139 +static tree handle_phi(struct visited *visited, struct cgraph_node *caller_node, tree orig_result)
114140 +{
114141 + tree ssa_name_var = NULL_TREE;
114142 +#if BUILDING_GCC_VERSION <= 4007
114143 + VEC(tree, heap) *args = NULL;
114144 +#else
114145 + vec<tree, va_heap, vl_embed> *args = NULL;
114146 +#endif
114147 + gimple oldstmt = get_def_stmt(orig_result);
114148 + unsigned int i, len = gimple_phi_num_args(oldstmt);
114149 +
114150 + pointer_set_insert(visited->stmts, oldstmt);
114151 + for (i = 0; i < len; i++) {
114152 + tree arg, new_arg;
114153 +
114154 + arg = gimple_phi_arg_def(oldstmt, i);
114155 + new_arg = expand(visited, caller_node, arg);
114156 +
114157 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
114158 + ssa_name_var = SSA_NAME_VAR(new_arg);
114159 +
114160 + if (is_gimple_constant(arg)) {
114161 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
114162 +
114163 + new_arg = cast_a_tree(size_overflow_type, arg);
114164 + }
114165 +
114166 +#if BUILDING_GCC_VERSION <= 4007
114167 + VEC_safe_push(tree, heap, args, new_arg);
114168 +#else
114169 + vec_safe_push(args, new_arg);
114170 +#endif
114171 + }
114172 +
114173 +#if BUILDING_GCC_VERSION <= 4007
114174 + return create_new_phi_node(visited, &args, ssa_name_var, oldstmt);
114175 +#else
114176 + return create_new_phi_node(visited, args, ssa_name_var, oldstmt);
114177 +#endif
114178 +}
114179 +
114180 +static tree create_cast_assign(struct visited *visited, gimple stmt)
114181 +{
114182 + tree rhs1 = gimple_assign_rhs1(stmt);
114183 + tree lhs = gimple_assign_lhs(stmt);
114184 + const_tree rhs1_type = TREE_TYPE(rhs1);
114185 + const_tree lhs_type = TREE_TYPE(lhs);
114186 +
114187 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
114188 + return create_assign(visited, stmt, lhs, AFTER_STMT);
114189 +
114190 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
114191 +}
114192 +
114193 +static bool skip_lhs_cast_check(const_gimple stmt)
114194 +{
114195 + const_tree rhs = gimple_assign_rhs1(stmt);
114196 + const_gimple def_stmt = get_def_stmt(rhs);
114197 +
114198 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
114199 + if (gimple_code(def_stmt) == GIMPLE_ASM)
114200 + return true;
114201 +
114202 + if (is_const_plus_unsigned_signed_truncation(rhs))
114203 + return true;
114204 +
114205 + return false;
114206 +}
114207 +
114208 +static tree create_string_param(tree string)
114209 +{
114210 + tree i_type, a_type;
114211 + const int length = TREE_STRING_LENGTH(string);
114212 +
114213 + gcc_assert(length > 0);
114214 +
114215 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
114216 + a_type = build_array_type(char_type_node, i_type);
114217 +
114218 + TREE_TYPE(string) = a_type;
114219 + TREE_CONSTANT(string) = 1;
114220 + TREE_READONLY(string) = 1;
114221 +
114222 + return build1(ADDR_EXPR, ptr_type_node, string);
114223 +}
114224 +
114225 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
114226 +{
114227 + gimple cond_stmt;
114228 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
114229 +
114230 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
114231 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
114232 + update_stmt(cond_stmt);
114233 +}
114234 +
114235 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
114236 +{
114237 + gimple func_stmt;
114238 + const_gimple def_stmt;
114239 + const_tree loc_line;
114240 + tree loc_file, ssa_name, current_func;
114241 + expanded_location xloc;
114242 + char *ssa_name_buf;
114243 + int len;
114244 + struct cgraph_edge *edge;
114245 + struct cgraph_node *callee_node;
114246 + int frequency;
114247 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
114248 +
114249 + def_stmt = get_def_stmt(arg);
114250 + xloc = expand_location(gimple_location(def_stmt));
114251 +
114252 + if (!gimple_has_location(def_stmt)) {
114253 + xloc = expand_location(gimple_location(stmt));
114254 + if (!gimple_has_location(stmt))
114255 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
114256 + }
114257 +
114258 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
114259 +
114260 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
114261 + loc_file = create_string_param(loc_file);
114262 +
114263 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
114264 + current_func = create_string_param(current_func);
114265 +
114266 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
114267 + call_count++;
114268 + len = asprintf(&ssa_name_buf, "%s_%u %s, count: %u\n", DECL_NAME_POINTER(SSA_NAME_VAR(arg)), SSA_NAME_VERSION(arg), min ? "min" : "max", call_count);
114269 + gcc_assert(len > 0);
114270 + ssa_name = build_string(len + 1, ssa_name_buf);
114271 + free(ssa_name_buf);
114272 + ssa_name = create_string_param(ssa_name);
114273 +
114274 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
114275 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
114276 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
114277 +
114278 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
114279 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
114280 +
114281 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
114282 + gcc_assert(edge != NULL);
114283 +}
114284 +
114285 +static void insert_check_size_overflow(struct cgraph_node *caller_node, gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
114286 +{
114287 + basic_block cond_bb, join_bb, bb_true;
114288 + edge e;
114289 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
114290 +
114291 + cond_bb = gimple_bb(stmt);
114292 + if (before)
114293 + gsi_prev(&gsi);
114294 + if (gsi_end_p(gsi))
114295 + e = split_block_after_labels(cond_bb);
114296 + else
114297 + e = split_block(cond_bb, gsi_stmt(gsi));
114298 + cond_bb = e->src;
114299 + join_bb = e->dest;
114300 + e->flags = EDGE_FALSE_VALUE;
114301 + e->probability = REG_BR_PROB_BASE;
114302 +
114303 + bb_true = create_empty_bb(cond_bb);
114304 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
114305 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
114306 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
114307 +
114308 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
114309 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
114310 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
114311 +
114312 + if (current_loops != NULL) {
114313 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
114314 + add_bb_to_loop(bb_true, cond_bb->loop_father);
114315 + }
114316 +
114317 + insert_cond(cond_bb, arg, cond_code, type_value);
114318 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
114319 +
114320 +// print_the_code_insertions(stmt);
114321 +}
114322 +
114323 +void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
114324 +{
114325 + const_tree rhs_type = TREE_TYPE(rhs);
114326 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
114327 +
114328 + gcc_assert(rhs_type != NULL_TREE);
114329 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
114330 + return;
114331 +
114332 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
114333 +
114334 + if (is_const_plus_unsigned_signed_truncation(rhs))
114335 + return;
114336 +
114337 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
114338 + // typemax (-1) < typemin (0)
114339 + if (TREE_OVERFLOW(type_max))
114340 + return;
114341 +
114342 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
114343 +
114344 + cast_rhs_type = TREE_TYPE(cast_rhs);
114345 + type_max_type = TREE_TYPE(type_max);
114346 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
114347 +
114348 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
114349 +
114350 + // special case: get_size_overflow_type(), 32, u64->s
114351 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
114352 + return;
114353 +
114354 + type_min_type = TREE_TYPE(type_min);
114355 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
114356 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
114357 +}
114358 +
114359 +static tree create_cast_overflow_check(struct visited *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
114360 +{
114361 + bool cast_lhs, cast_rhs;
114362 + tree lhs = gimple_assign_lhs(stmt);
114363 + tree rhs = gimple_assign_rhs1(stmt);
114364 + const_tree lhs_type = TREE_TYPE(lhs);
114365 + const_tree rhs_type = TREE_TYPE(rhs);
114366 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
114367 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
114368 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
114369 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
114370 +
114371 + static bool check_lhs[3][4] = {
114372 + // ss su us uu
114373 + { false, true, true, false }, // lhs > rhs
114374 + { false, false, false, false }, // lhs = rhs
114375 + { true, true, true, true }, // lhs < rhs
114376 + };
114377 +
114378 + static bool check_rhs[3][4] = {
114379 + // ss su us uu
114380 + { true, false, true, true }, // lhs > rhs
114381 + { true, false, true, true }, // lhs = rhs
114382 + { true, false, true, true }, // lhs < rhs
114383 + };
114384 +
114385 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
114386 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
114387 + return create_assign(visited, stmt, lhs, AFTER_STMT);
114388 +
114389 + if (lhs_size > rhs_size) {
114390 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
114391 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
114392 + } else if (lhs_size == rhs_size) {
114393 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
114394 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
114395 + } else {
114396 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
114397 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
114398 + }
114399 +
114400 + if (!cast_lhs && !cast_rhs)
114401 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
114402 +
114403 + if (cast_lhs && !skip_lhs_cast_check(stmt))
114404 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
114405 +
114406 + if (cast_rhs)
114407 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
114408 +
114409 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
114410 +}
114411 +
114412 +static tree handle_unary_rhs(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
114413 +{
114414 + enum tree_code rhs_code;
114415 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
114416 +
114417 + if (pointer_set_contains(visited->my_stmts, stmt))
114418 + return lhs;
114419 +
114420 + rhs1 = gimple_assign_rhs1(stmt);
114421 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
114422 + return create_assign(visited, stmt, lhs, AFTER_STMT);
114423 +
114424 + new_rhs1 = expand(visited, caller_node, rhs1);
114425 +
114426 + if (new_rhs1 == NULL_TREE)
114427 + return create_cast_assign(visited, stmt);
114428 +
114429 + if (pointer_set_contains(visited->no_cast_check, stmt))
114430 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
114431 +
114432 + rhs_code = gimple_assign_rhs_code(stmt);
114433 + if (rhs_code == BIT_NOT_EXPR || rhs_code == NEGATE_EXPR) {
114434 + tree size_overflow_type = get_size_overflow_type(visited, stmt, rhs1);
114435 +
114436 + new_rhs1 = cast_to_new_size_overflow_type(visited, stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
114437 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
114438 + return create_assign(visited, stmt, lhs, AFTER_STMT);
114439 + }
114440 +
114441 + if (!gimple_assign_cast_p(stmt))
114442 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
114443 +
114444 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
114445 +}
114446 +
114447 +static tree handle_unary_ops(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
114448 +{
114449 + tree rhs1, lhs = gimple_assign_lhs(stmt);
114450 + gimple def_stmt = get_def_stmt(lhs);
114451 +
114452 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
114453 + rhs1 = gimple_assign_rhs1(def_stmt);
114454 +
114455 + if (is_gimple_constant(rhs1))
114456 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
114457 +
114458 + switch (TREE_CODE(rhs1)) {
114459 + case SSA_NAME: {
114460 + tree ret = handle_unary_rhs(visited, caller_node, def_stmt);
114461 +
114462 + if (gimple_assign_cast_p(stmt))
114463 + unsigned_signed_cast_intentional_overflow(visited, stmt);
114464 + return ret;
114465 + }
114466 + case ARRAY_REF:
114467 + case BIT_FIELD_REF:
114468 + case ADDR_EXPR:
114469 + case COMPONENT_REF:
114470 + case INDIRECT_REF:
114471 +#if BUILDING_GCC_VERSION >= 4006
114472 + case MEM_REF:
114473 +#endif
114474 + case TARGET_MEM_REF:
114475 + case VIEW_CONVERT_EXPR:
114476 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
114477 + case PARM_DECL:
114478 + case VAR_DECL:
114479 + return create_assign(visited, stmt, lhs, AFTER_STMT);
114480 +
114481 + default:
114482 + debug_gimple_stmt(def_stmt);
114483 + debug_tree(rhs1);
114484 + gcc_unreachable();
114485 + }
114486 +}
114487 +
114488 +static void __unused print_the_code_insertions(const_gimple stmt)
114489 +{
114490 + location_t loc = gimple_location(stmt);
114491 +
114492 + inform(loc, "Integer size_overflow check applied here.");
114493 +}
114494 +
114495 +static bool is_from_cast(const_tree node)
114496 +{
114497 + gimple def_stmt = get_def_stmt(node);
114498 +
114499 + if (!def_stmt)
114500 + return false;
114501 +
114502 + if (gimple_assign_cast_p(def_stmt))
114503 + return true;
114504 +
114505 + return false;
114506 +}
114507 +
114508 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
114509 +static bool is_a_ptr_minus(gimple stmt)
114510 +{
114511 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
114512 +
114513 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
114514 + return false;
114515 +
114516 + rhs1 = gimple_assign_rhs1(stmt);
114517 + if (!is_from_cast(rhs1))
114518 + return false;
114519 +
114520 + rhs2 = gimple_assign_rhs2(stmt);
114521 + if (!is_from_cast(rhs2))
114522 + return false;
114523 +
114524 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
114525 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
114526 +
114527 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
114528 + return false;
114529 +
114530 + return true;
114531 +}
114532 +
114533 +static tree handle_binary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
114534 +{
114535 + enum intentional_overflow_type res;
114536 + tree rhs1, rhs2, new_lhs;
114537 + gimple def_stmt = get_def_stmt(lhs);
114538 + tree new_rhs1 = NULL_TREE;
114539 + tree new_rhs2 = NULL_TREE;
114540 +
114541 + if (is_a_ptr_minus(def_stmt))
114542 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
114543 +
114544 + rhs1 = gimple_assign_rhs1(def_stmt);
114545 + rhs2 = gimple_assign_rhs2(def_stmt);
114546 +
114547 + /* no DImode/TImode division in the 32/64 bit kernel */
114548 + switch (gimple_assign_rhs_code(def_stmt)) {
114549 + case RDIV_EXPR:
114550 + case TRUNC_DIV_EXPR:
114551 + case CEIL_DIV_EXPR:
114552 + case FLOOR_DIV_EXPR:
114553 + case ROUND_DIV_EXPR:
114554 + case TRUNC_MOD_EXPR:
114555 + case CEIL_MOD_EXPR:
114556 + case FLOOR_MOD_EXPR:
114557 + case ROUND_MOD_EXPR:
114558 + case EXACT_DIV_EXPR:
114559 + case POINTER_PLUS_EXPR:
114560 + case BIT_AND_EXPR:
114561 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
114562 + default:
114563 + break;
114564 + }
114565 +
114566 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
114567 + if (new_lhs != NULL_TREE)
114568 + return new_lhs;
114569 +
114570 + if (TREE_CODE(rhs1) == SSA_NAME)
114571 + new_rhs1 = expand(visited, caller_node, rhs1);
114572 + if (TREE_CODE(rhs2) == SSA_NAME)
114573 + new_rhs2 = expand(visited, caller_node, rhs2);
114574 +
114575 + res = add_mul_intentional_overflow(def_stmt);
114576 + if (res != NO_INTENTIONAL_OVERFLOW) {
114577 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
114578 + insert_cast_expr(visited, get_def_stmt(new_lhs), res);
114579 + return new_lhs;
114580 + }
114581 +
114582 + if (skip_expr_on_double_type(def_stmt)) {
114583 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
114584 + insert_cast_expr(visited, get_def_stmt(new_lhs), NO_INTENTIONAL_OVERFLOW);
114585 + return new_lhs;
114586 + }
114587 +
114588 + if (is_a_neg_overflow(def_stmt, rhs2))
114589 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
114590 + if (is_a_neg_overflow(def_stmt, rhs1))
114591 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
114592 +
114593 +
114594 + if (is_a_constant_overflow(def_stmt, rhs2))
114595 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
114596 + if (is_a_constant_overflow(def_stmt, rhs1))
114597 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
114598 +
114599 + // the const is between 0 and (signed) MAX
114600 + if (is_gimple_constant(rhs1))
114601 + new_rhs1 = create_assign(visited, def_stmt, rhs1, BEFORE_STMT);
114602 + if (is_gimple_constant(rhs2))
114603 + new_rhs2 = create_assign(visited, def_stmt, rhs2, BEFORE_STMT);
114604 +
114605 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
114606 +}
114607 +
114608 +#if BUILDING_GCC_VERSION >= 4006
114609 +static tree get_new_rhs(struct visited *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
114610 +{
114611 + if (is_gimple_constant(rhs))
114612 + return cast_a_tree(size_overflow_type, rhs);
114613 + if (TREE_CODE(rhs) != SSA_NAME)
114614 + return NULL_TREE;
114615 + return expand(visited, caller_node, rhs);
114616 +}
114617 +
114618 +static tree handle_ternary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
114619 +{
114620 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
114621 + gimple def_stmt = get_def_stmt(lhs);
114622 +
114623 + size_overflow_type = get_size_overflow_type(visited, def_stmt, lhs);
114624 +
114625 + rhs1 = gimple_assign_rhs1(def_stmt);
114626 + rhs2 = gimple_assign_rhs2(def_stmt);
114627 + rhs3 = gimple_assign_rhs3(def_stmt);
114628 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
114629 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
114630 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
114631 +
114632 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
114633 +}
114634 +#endif
114635 +
114636 +static tree get_my_stmt_lhs(struct visited *visited, gimple stmt)
114637 +{
114638 + gimple_stmt_iterator gsi;
114639 + gimple next_stmt = NULL;
114640 +
114641 + gsi = gsi_for_stmt(stmt);
114642 +
114643 + do {
114644 + gsi_next(&gsi);
114645 + next_stmt = gsi_stmt(gsi);
114646 +
114647 + if (gimple_code(stmt) == GIMPLE_PHI && !pointer_set_contains(visited->my_stmts, next_stmt))
114648 + return NULL_TREE;
114649 +
114650 + if (pointer_set_contains(visited->my_stmts, next_stmt) && !pointer_set_contains(visited->skip_expr_casts, next_stmt))
114651 + break;
114652 +
114653 + gcc_assert(pointer_set_contains(visited->my_stmts, next_stmt));
114654 + } while (!gsi_end_p(gsi));
114655 +
114656 + gcc_assert(next_stmt);
114657 + return get_lhs(next_stmt);
114658 +}
114659 +
114660 +static tree expand_visited(struct visited *visited, gimple def_stmt)
114661 +{
114662 + gimple_stmt_iterator gsi;
114663 + enum gimple_code code = gimple_code(def_stmt);
114664 +
114665 + if (code == GIMPLE_ASM)
114666 + return NULL_TREE;
114667 +
114668 + gsi = gsi_for_stmt(def_stmt);
114669 + gsi_next(&gsi);
114670 +
114671 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
114672 + return NULL_TREE;
114673 + return get_my_stmt_lhs(visited, def_stmt);
114674 +}
114675 +
114676 +tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
114677 +{
114678 + gimple def_stmt;
114679 +
114680 + def_stmt = get_def_stmt(lhs);
114681 +
114682 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
114683 + return NULL_TREE;
114684 +
114685 + if (pointer_set_contains(visited->my_stmts, def_stmt))
114686 + return lhs;
114687 +
114688 + if (pointer_set_contains(visited->stmts, def_stmt))
114689 + return expand_visited(visited, def_stmt);
114690 +
114691 + switch (gimple_code(def_stmt)) {
114692 + case GIMPLE_PHI:
114693 + return handle_phi(visited, caller_node, lhs);
114694 + case GIMPLE_CALL:
114695 + case GIMPLE_ASM:
114696 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
114697 + case GIMPLE_ASSIGN:
114698 + switch (gimple_num_ops(def_stmt)) {
114699 + case 2:
114700 + return handle_unary_ops(visited, caller_node, def_stmt);
114701 + case 3:
114702 + return handle_binary_ops(visited, caller_node, lhs);
114703 +#if BUILDING_GCC_VERSION >= 4006
114704 + case 4:
114705 + return handle_ternary_ops(visited, caller_node, lhs);
114706 +#endif
114707 + }
114708 + default:
114709 + debug_gimple_stmt(def_stmt);
114710 + error("%s: unknown gimple code", __func__);
114711 + gcc_unreachable();
114712 + }
114713 +}
114714 +
114715 diff --git a/tools/gcc/size_overflow_plugin/insert_size_overflow_check_ipa.c b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_ipa.c
114716 new file mode 100644
114717 index 0000000..df50164
114718 --- /dev/null
114719 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_ipa.c
114720 @@ -0,0 +1,1141 @@
114721 +/*
114722 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114723 + * Licensed under the GPL v2, or (at your option) v3
114724 + *
114725 + * Homepage:
114726 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114727 + *
114728 + * Documentation:
114729 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114730 + *
114731 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114732 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114733 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114734 + *
114735 + * Usage:
114736 + * $ make
114737 + * $ make run
114738 + */
114739 +
114740 +#include "gcc-common.h"
114741 +#include "size_overflow.h"
114742 +
114743 +#define VEC_LEN 128
114744 +#define RET_CHECK NULL_TREE
114745 +#define WRONG_NODE 32
114746 +#define NOT_INTENTIONAL_ASM NULL
114747 +
114748 +unsigned int call_count;
114749 +
114750 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
114751 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
114752 +
114753 +struct visited_fns {
114754 + struct visited_fns *next;
114755 + const_tree fndecl;
114756 + unsigned int num;
114757 + const_gimple first_stmt;
114758 +};
114759 +
114760 +struct next_cgraph_node {
114761 + struct next_cgraph_node *next;
114762 + struct cgraph_node *current_function;
114763 + tree callee_fndecl;
114764 + unsigned int num;
114765 +};
114766 +
114767 +// Don't want to duplicate entries in next_cgraph_node
114768 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
114769 +{
114770 + const_tree new_callee_fndecl;
114771 + struct next_cgraph_node *cur_node;
114772 +
114773 + if (fndecl == RET_CHECK)
114774 + new_callee_fndecl = NODE_DECL(node);
114775 + else
114776 + new_callee_fndecl = fndecl;
114777 +
114778 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
114779 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
114780 + continue;
114781 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
114782 + continue;
114783 + if (num == cur_node->num)
114784 + return true;
114785 + }
114786 + return false;
114787 +}
114788 +
114789 +/* Add a next_cgraph_node into the list for handle_function().
114790 + * handle_function() iterates over all the next cgraph nodes and
114791 + * starts the overflow check insertion process.
114792 + */
114793 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
114794 +{
114795 + struct next_cgraph_node *new_node;
114796 +
114797 + if (is_in_next_cgraph_node(head, node, fndecl, num))
114798 + return head;
114799 +
114800 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
114801 + new_node->current_function = node;
114802 + new_node->next = NULL;
114803 + new_node->num = num;
114804 + if (fndecl == RET_CHECK)
114805 + new_node->callee_fndecl = NODE_DECL(node);
114806 + else
114807 + new_node->callee_fndecl = fndecl;
114808 +
114809 + if (!head)
114810 + return new_node;
114811 +
114812 + new_node->next = head;
114813 + return new_node;
114814 +}
114815 +
114816 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
114817 +{
114818 + struct cgraph_edge *e;
114819 +
114820 + if (num == 0)
114821 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
114822 +
114823 + for (e = node->callers; e; e = e->next_caller) {
114824 + tree fndecl = gimple_call_fndecl(e->call_stmt);
114825 +
114826 + gcc_assert(fndecl != NULL_TREE);
114827 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
114828 + }
114829 +
114830 + return head;
114831 +}
114832 +
114833 +struct missing_functions {
114834 + struct missing_functions *next;
114835 + const_tree node;
114836 + tree fndecl;
114837 +};
114838 +
114839 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
114840 +{
114841 + struct missing_functions *new_function;
114842 +
114843 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
114844 + new_function->node = node;
114845 + new_function->next = NULL;
114846 +
114847 + if (TREE_CODE(node) == FUNCTION_DECL)
114848 + new_function->fndecl = node;
114849 + else
114850 + new_function->fndecl = current_function_decl;
114851 + gcc_assert(new_function->fndecl);
114852 +
114853 + if (!missing_fn_head)
114854 + return new_function;
114855 +
114856 + new_function->next = missing_fn_head;
114857 + return new_function;
114858 +}
114859 +
114860 +/* If the function is missing from the hash table and it is a static function
114861 + * then create a next_cgraph_node from it for handle_function()
114862 + */
114863 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
114864 +{
114865 + unsigned int num;
114866 + const_tree orig_fndecl;
114867 + struct cgraph_node *next_node = NULL;
114868 +
114869 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
114870 +
114871 + num = get_function_num(missing_fn_head->node, orig_fndecl);
114872 + if (num == CANNOT_FIND_ARG)
114873 + return cnodes;
114874 +
114875 + if (!is_missing_function(orig_fndecl, num))
114876 + return cnodes;
114877 +
114878 + next_node = cgraph_get_node(missing_fn_head->fndecl);
114879 + if (next_node && next_node->local.local)
114880 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
114881 + return cnodes;
114882 +}
114883 +
114884 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
114885 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
114886 + */
114887 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
114888 +{
114889 + unsigned int i;
114890 + tree node;
114891 + struct missing_functions *cur, *missing_fn_head = NULL;
114892 +
114893 +#if BUILDING_GCC_VERSION <= 4007
114894 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
114895 +#else
114896 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
114897 +#endif
114898 + switch (TREE_CODE(node)) {
114899 + case PARM_DECL:
114900 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
114901 + break;
114902 + case FUNCTION_DECL:
114903 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
114904 + break;
114905 + default:
114906 + break;
114907 + }
114908 + }
114909 +
114910 + while (missing_fn_head) {
114911 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
114912 +
114913 + cur = missing_fn_head->next;
114914 + free(missing_fn_head);
114915 + missing_fn_head = cur;
114916 + }
114917 +
114918 + return cnodes;
114919 +}
114920 +
114921 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
114922 +{
114923 + gimple phi = get_def_stmt(result);
114924 + unsigned int i, n = gimple_phi_num_args(phi);
114925 +
114926 + pointer_set_insert(visited, phi);
114927 + for (i = 0; i < n; i++) {
114928 + const_tree arg = gimple_phi_arg_def(phi, i);
114929 +
114930 + set_conditions(visited, interesting_conditions, arg);
114931 + }
114932 +}
114933 +
114934 +enum conditions {
114935 + FROM_CONST, NOT_UNARY, CAST, RET, PHI
114936 +};
114937 +
114938 +// Search for constants, cast assignments and binary/ternary assignments
114939 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
114940 +{
114941 + gimple def_stmt = get_def_stmt(lhs);
114942 +
114943 + if (is_gimple_constant(lhs)) {
114944 + interesting_conditions[FROM_CONST] = true;
114945 + return;
114946 + }
114947 +
114948 + if (!def_stmt)
114949 + return;
114950 +
114951 + if (pointer_set_contains(visited, def_stmt))
114952 + return;
114953 +
114954 + switch (gimple_code(def_stmt)) {
114955 + case GIMPLE_CALL:
114956 + if (lhs == gimple_call_lhs(def_stmt))
114957 + interesting_conditions[RET] = true;
114958 + return;
114959 + case GIMPLE_NOP:
114960 + case GIMPLE_ASM:
114961 + return;
114962 + case GIMPLE_PHI:
114963 + interesting_conditions[PHI] = true;
114964 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
114965 + case GIMPLE_ASSIGN:
114966 + if (gimple_num_ops(def_stmt) == 2) {
114967 + const_tree rhs = gimple_assign_rhs1(def_stmt);
114968 +
114969 + if (gimple_assign_cast_p(def_stmt))
114970 + interesting_conditions[CAST] = true;
114971 +
114972 + return set_conditions(visited, interesting_conditions, rhs);
114973 + } else {
114974 + interesting_conditions[NOT_UNARY] = true;
114975 + return;
114976 + }
114977 + default:
114978 + debug_gimple_stmt(def_stmt);
114979 + gcc_unreachable();
114980 + }
114981 +}
114982 +
114983 +// determine whether duplication will be necessary or not.
114984 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
114985 +{
114986 + struct pointer_set_t *visited;
114987 +
114988 + if (gimple_assign_cast_p(cur_node->first_stmt))
114989 + interesting_conditions[CAST] = true;
114990 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
114991 + interesting_conditions[NOT_UNARY] = true;
114992 +
114993 + visited = pointer_set_create();
114994 + set_conditions(visited, interesting_conditions, cur_node->node);
114995 + pointer_set_destroy(visited);
114996 +}
114997 +
114998 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
114999 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
115000 +{
115001 + gimple assign;
115002 + gimple_stmt_iterator gsi;
115003 +
115004 + // already removed
115005 + if (gimple_bb(asm_stmt) == NULL)
115006 + return;
115007 + gsi = gsi_for_stmt(asm_stmt);
115008 +
115009 + assign = gimple_build_assign(lhs, rhs);
115010 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
115011 + SSA_NAME_DEF_STMT(lhs) = assign;
115012 +
115013 + gsi_remove(&gsi, true);
115014 +}
115015 +
115016 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
115017 + * stmt is a return otherwise it is the callee function.
115018 + */
115019 +const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
115020 +{
115021 + const_tree fndecl;
115022 +
115023 + if (argnum == 0)
115024 + fndecl = current_function_decl;
115025 + else
115026 + fndecl = gimple_call_fndecl(stmt);
115027 +
115028 + if (fndecl == NULL_TREE)
115029 + return NULL_TREE;
115030 +
115031 + return DECL_ORIGIN(fndecl);
115032 +}
115033 +
115034 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
115035 +static bool skip_asm(const_tree arg)
115036 +{
115037 + gimple def_stmt = get_def_stmt(arg);
115038 +
115039 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
115040 + return false;
115041 +
115042 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
115043 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
115044 +}
115045 +
115046 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
115047 +{
115048 + gimple phi = get_def_stmt(result);
115049 + unsigned int i, n = gimple_phi_num_args(phi);
115050 +
115051 + pointer_set_insert(visited, phi);
115052 + for (i = 0; i < n; i++) {
115053 + tree arg = gimple_phi_arg_def(phi, i);
115054 +
115055 + walk_use_def(visited, cur_node, arg);
115056 + }
115057 +}
115058 +
115059 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
115060 +{
115061 + gimple def_stmt = get_def_stmt(lhs);
115062 + tree rhs1, rhs2;
115063 +
115064 + rhs1 = gimple_assign_rhs1(def_stmt);
115065 + rhs2 = gimple_assign_rhs2(def_stmt);
115066 +
115067 + walk_use_def(visited, cur_node, rhs1);
115068 + walk_use_def(visited, cur_node, rhs2);
115069 +}
115070 +
115071 +static void insert_last_node(struct interesting_node *cur_node, tree node)
115072 +{
115073 + unsigned int i;
115074 + tree element;
115075 + enum tree_code code;
115076 +
115077 + gcc_assert(node != NULL_TREE);
115078 +
115079 + if (is_gimple_constant(node))
115080 + return;
115081 +
115082 + code = TREE_CODE(node);
115083 + if (code == VAR_DECL) {
115084 + node = DECL_ORIGIN(node);
115085 + code = TREE_CODE(node);
115086 + }
115087 +
115088 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
115089 + return;
115090 +
115091 +#if BUILDING_GCC_VERSION <= 4007
115092 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
115093 +#else
115094 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
115095 +#endif
115096 + if (operand_equal_p(node, element, 0))
115097 + return;
115098 + }
115099 +
115100 +#if BUILDING_GCC_VERSION <= 4007
115101 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
115102 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
115103 +#else
115104 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
115105 + vec_safe_push(cur_node->last_nodes, node);
115106 +#endif
115107 +}
115108 +
115109 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
115110 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
115111 +{
115112 + if (!is_size_overflow_asm(stmt))
115113 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
115114 +}
115115 +
115116 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
115117 + * and component refs (for checking the intentional_overflow attribute).
115118 + */
115119 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
115120 +{
115121 + const_gimple def_stmt;
115122 +
115123 + if (TREE_CODE(lhs) != SSA_NAME) {
115124 + insert_last_node(cur_node, lhs);
115125 + return;
115126 + }
115127 +
115128 + def_stmt = get_def_stmt(lhs);
115129 + if (!def_stmt)
115130 + return;
115131 +
115132 + if (pointer_set_insert(visited, def_stmt))
115133 + return;
115134 +
115135 + switch (gimple_code(def_stmt)) {
115136 + case GIMPLE_NOP:
115137 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
115138 + case GIMPLE_ASM:
115139 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
115140 + case GIMPLE_CALL: {
115141 + tree fndecl = gimple_call_fndecl(def_stmt);
115142 +
115143 + if (fndecl == NULL_TREE)
115144 + return;
115145 + insert_last_node(cur_node, fndecl);
115146 + return;
115147 + }
115148 + case GIMPLE_PHI:
115149 + return walk_use_def_phi(visited, cur_node, lhs);
115150 + case GIMPLE_ASSIGN:
115151 + switch (gimple_num_ops(def_stmt)) {
115152 + case 2:
115153 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
115154 + case 3:
115155 + return walk_use_def_binary(visited, cur_node, lhs);
115156 + }
115157 + default:
115158 + debug_gimple_stmt((gimple)def_stmt);
115159 + error("%s: unknown gimple code", __func__);
115160 + gcc_unreachable();
115161 + }
115162 +}
115163 +
115164 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
115165 +static void set_last_nodes(struct interesting_node *cur_node)
115166 +{
115167 + struct pointer_set_t *visited;
115168 +
115169 + visited = pointer_set_create();
115170 + walk_use_def(visited, cur_node, cur_node->node);
115171 + pointer_set_destroy(visited);
115172 +}
115173 +
115174 +enum precond {
115175 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
115176 +};
115177 +
115178 +/* If there is a mark_turn_off intentional attribute on the caller or the callee then there is no duplication and missing size_overflow attribute check anywhere.
115179 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
115180 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
115181 + * It skips the possible error codes too.
115182 + */
115183 +static enum precond check_preconditions(struct interesting_node *cur_node)
115184 +{
115185 + bool interesting_conditions[5] = {false, false, false, false, false};
115186 +
115187 + set_last_nodes(cur_node);
115188 +
115189 + check_intentional_attribute_ipa(cur_node);
115190 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
115191 + return NO_ATTRIBUTE_SEARCH;
115192 +
115193 + search_interesting_conditions(cur_node, interesting_conditions);
115194 +
115195 + // error code: a phi, unary assign (not cast) and returns only
115196 + if (!interesting_conditions[NOT_UNARY] && interesting_conditions[PHI] && interesting_conditions[RET] && !interesting_conditions[CAST])
115197 + return NO_ATTRIBUTE_SEARCH;
115198 +
115199 + // error code: def_stmts trace back to a constant and there are no binary/ternary assigments
115200 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
115201 + return NO_ATTRIBUTE_SEARCH;
115202 +
115203 + // unnecessary overflow check
115204 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
115205 + return NO_CHECK_INSERT;
115206 +
115207 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
115208 + return NO_CHECK_INSERT;
115209 +
115210 + return NONE;
115211 +}
115212 +
115213 +static tree cast_to_orig_type(struct visited *visited, gimple stmt, const_tree orig_node, tree new_node)
115214 +{
115215 + const_gimple assign;
115216 + tree orig_type = TREE_TYPE(orig_node);
115217 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
115218 +
115219 + assign = build_cast_stmt(visited, orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
115220 + return gimple_assign_lhs(assign);
115221 +}
115222 +
115223 +static void change_orig_node(struct visited *visited, struct interesting_node *cur_node, tree new_node)
115224 +{
115225 + void (*set_rhs)(gimple, tree);
115226 + gimple stmt = cur_node->first_stmt;
115227 + const_tree orig_node = cur_node->node;
115228 +
115229 + switch (gimple_code(stmt)) {
115230 + case GIMPLE_RETURN:
115231 + gimple_return_set_retval(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
115232 + break;
115233 + case GIMPLE_CALL:
115234 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(visited, stmt, orig_node, new_node));
115235 + break;
115236 + case GIMPLE_ASSIGN:
115237 + switch (cur_node->num) {
115238 + case 1:
115239 + set_rhs = &gimple_assign_set_rhs1;
115240 + break;
115241 + case 2:
115242 + set_rhs = &gimple_assign_set_rhs2;
115243 + break;
115244 +#if BUILDING_GCC_VERSION >= 4006
115245 + case 3:
115246 + set_rhs = &gimple_assign_set_rhs3;
115247 + break;
115248 +#endif
115249 + default:
115250 + gcc_unreachable();
115251 + }
115252 +
115253 + set_rhs(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
115254 + break;
115255 + default:
115256 + debug_gimple_stmt(stmt);
115257 + gcc_unreachable();
115258 + }
115259 +
115260 + update_stmt(stmt);
115261 +}
115262 +
115263 +static struct visited *create_visited(void)
115264 +{
115265 + struct visited *new_node;
115266 +
115267 + new_node = (struct visited *)xmalloc(sizeof(*new_node));
115268 + new_node->stmts = pointer_set_create();
115269 + new_node->my_stmts = pointer_set_create();
115270 + new_node->skip_expr_casts = pointer_set_create();
115271 + new_node->no_cast_check = pointer_set_create();
115272 + return new_node;
115273 +}
115274 +
115275 +static void free_visited(struct visited *visited)
115276 +{
115277 + pointer_set_destroy(visited->stmts);
115278 + pointer_set_destroy(visited->my_stmts);
115279 + pointer_set_destroy(visited->skip_expr_casts);
115280 + pointer_set_destroy(visited->no_cast_check);
115281 +
115282 + free(visited);
115283 +}
115284 +
115285 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
115286 + * it decides whether the duplication is necessary or not and it searches for missing size_overflow attributes. After expand() it changes the orig node to the duplicated node
115287 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
115288 + */
115289 +static struct next_cgraph_node *handle_interesting_stmt(struct visited *visited, struct next_cgraph_node *cnodes, struct interesting_node *cur_node, struct cgraph_node *caller_node)
115290 +{
115291 + enum precond ret;
115292 + tree new_node, orig_node = cur_node->node;
115293 +
115294 + ret = check_preconditions(cur_node);
115295 + if (ret == NO_ATTRIBUTE_SEARCH)
115296 + return cnodes;
115297 +
115298 + cnodes = search_overflow_attribute(cnodes, cur_node);
115299 +
115300 + if (ret == NO_CHECK_INSERT)
115301 + return cnodes;
115302 +
115303 + new_node = expand(visited, caller_node, orig_node);
115304 + if (new_node == NULL_TREE)
115305 + return cnodes;
115306 +
115307 + change_orig_node(visited, cur_node, new_node);
115308 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
115309 +
115310 + return cnodes;
115311 +}
115312 +
115313 +// Check visited_fns interesting nodes.
115314 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
115315 +{
115316 + struct interesting_node *cur;
115317 +
115318 + for (cur = head; cur; cur = cur->next) {
115319 + if (!operand_equal_p(node, cur->node, 0))
115320 + continue;
115321 + if (num != cur->num)
115322 + continue;
115323 + if (first_stmt == cur->first_stmt)
115324 + return true;
115325 + }
115326 + return false;
115327 +}
115328 +
115329 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
115330 + first_stmt: it is the call or assignment or ret stmt, change_orig_node() will change the original node (retval, or function arg) in this
115331 + last_nodes: they are the last stmts in the recursion (they haven't a def_stmt). They are useful in the missing size_overflow attribute check and
115332 + the intentional_overflow attribute check. They are collected by set_last_nodes().
115333 + num: arg count of a call stmt or 0 when it is a ret
115334 + node: the recursion starts from here, it is a call arg or a return value
115335 + fndecl: the fndecl of the interesting node when the node is an arg. it is the fndecl of the callee function otherwise it is the fndecl of the caller (current_function_fndecl) function.
115336 + intentional_attr_decl: intentional_overflow attribute of the callee function
115337 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
115338 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
115339 + */
115340 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
115341 +{
115342 + struct interesting_node *new_node;
115343 + tree fndecl;
115344 + enum gimple_code code;
115345 +
115346 + gcc_assert(node != NULL_TREE);
115347 + code = gimple_code(first_stmt);
115348 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
115349 +
115350 + if (num == CANNOT_FIND_ARG)
115351 + return head;
115352 +
115353 + if (skip_types(node))
115354 + return head;
115355 +
115356 + if (skip_asm(node))
115357 + return head;
115358 +
115359 + if (is_gimple_call(first_stmt))
115360 + fndecl = gimple_call_fndecl(first_stmt);
115361 + else
115362 + fndecl = current_function_decl;
115363 +
115364 + if (fndecl == NULL_TREE)
115365 + return head;
115366 +
115367 + if (is_in_interesting_node(head, first_stmt, node, num))
115368 + return head;
115369 +
115370 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
115371 +
115372 + new_node->next = NULL;
115373 + new_node->first_stmt = first_stmt;
115374 +#if BUILDING_GCC_VERSION <= 4007
115375 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
115376 +#else
115377 + vec_alloc(new_node->last_nodes, VEC_LEN);
115378 +#endif
115379 + new_node->num = num;
115380 + new_node->node = node;
115381 + new_node->fndecl = fndecl;
115382 + new_node->intentional_attr_decl = MARK_NO;
115383 + new_node->intentional_attr_cur_fndecl = MARK_NO;
115384 + new_node->intentional_mark_from_gimple = asm_stmt;
115385 +
115386 + if (!head)
115387 + return new_node;
115388 +
115389 + new_node->next = head;
115390 + return new_node;
115391 +}
115392 +
115393 +/* Check the ret stmts in the functions on the next cgraph node list (these functions will be in the hash table and they are reachable from ipa).
115394 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
115395 + */
115396 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
115397 +{
115398 + struct next_cgraph_node *cur_node;
115399 + tree ret = gimple_return_retval(stmt);
115400 +
115401 + if (ret == NULL_TREE)
115402 + return head;
115403 +
115404 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
115405 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
115406 + continue;
115407 + if (cur_node->num == 0)
115408 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
115409 + }
115410 +
115411 + return head;
115412 +}
115413 +
115414 +/* Check the call stmts in the functions on the next cgraph node list (these functions will be in the hash table and they are reachable from ipa).
115415 + * If the call stmt is in the next cgraph node list then it's an interesting call.
115416 + */
115417 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
115418 +{
115419 + unsigned int argnum;
115420 + tree arg;
115421 + const_tree fndecl;
115422 + struct next_cgraph_node *cur_node;
115423 +
115424 + fndecl = gimple_call_fndecl(stmt);
115425 + if (fndecl == NULL_TREE)
115426 + return head;
115427 +
115428 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
115429 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
115430 + continue;
115431 + argnum = get_correct_arg_count(cur_node->num, fndecl);
115432 + gcc_assert(argnum != CANNOT_FIND_ARG);
115433 + if (argnum == 0)
115434 + continue;
115435 +
115436 + arg = gimple_call_arg(stmt, argnum - 1);
115437 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
115438 + }
115439 +
115440 + return head;
115441 +}
115442 +
115443 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
115444 +{
115445 + if (!operand_equal_p(orig_node, node, 0))
115446 + return WRONG_NODE;
115447 + if (skip_types(node))
115448 + return WRONG_NODE;
115449 + return ret_count;
115450 +}
115451 +
115452 +// Get the index of the rhs node in an assignment
115453 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
115454 +{
115455 + const_tree rhs1, rhs2;
115456 + unsigned int ret;
115457 +
115458 + gcc_assert(stmt);
115459 + gcc_assert(is_gimple_assign(stmt));
115460 +
115461 + rhs1 = gimple_assign_rhs1(stmt);
115462 + gcc_assert(rhs1 != NULL_TREE);
115463 +
115464 + switch (gimple_num_ops(stmt)) {
115465 + case 2:
115466 + return check_ops(node, rhs1, 1);
115467 + case 3:
115468 + ret = check_ops(node, rhs1, 1);
115469 + if (ret != WRONG_NODE)
115470 + return ret;
115471 +
115472 + rhs2 = gimple_assign_rhs2(stmt);
115473 + gcc_assert(rhs2 != NULL_TREE);
115474 + return check_ops(node, rhs2, 2);
115475 + default:
115476 + gcc_unreachable();
115477 + }
115478 +}
115479 +
115480 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
115481 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
115482 +{
115483 + unsigned int i;
115484 +
115485 + if (gimple_call_fndecl(stmt) == NULL_TREE)
115486 + return CANNOT_FIND_ARG;
115487 +
115488 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
115489 + tree node;
115490 +
115491 + node = gimple_call_arg(stmt, i);
115492 + if (!operand_equal_p(arg, node, 0))
115493 + continue;
115494 + if (!skip_types(node))
115495 + return i + 1;
115496 + }
115497 +
115498 + return CANNOT_FIND_ARG;
115499 +}
115500 +
115501 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
115502 + * any of return, call or assignment stmts (because of inlining).
115503 + */
115504 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
115505 +{
115506 + use_operand_p use_p;
115507 + imm_use_iterator imm_iter;
115508 + unsigned int argnum;
115509 +
115510 + gcc_assert(TREE_CODE(node) == SSA_NAME);
115511 +
115512 + if (pointer_set_insert(visited, node))
115513 + return head;
115514 +
115515 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
115516 + gimple stmt = USE_STMT(use_p);
115517 +
115518 + if (stmt == NULL)
115519 + return head;
115520 + if (is_gimple_debug(stmt))
115521 + continue;
115522 +
115523 + switch (gimple_code(stmt)) {
115524 + case GIMPLE_CALL:
115525 + argnum = find_arg_number_gimple(node, stmt);
115526 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
115527 + break;
115528 + case GIMPLE_RETURN:
115529 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
115530 + break;
115531 + case GIMPLE_ASSIGN:
115532 + argnum = get_assign_ops_count(stmt, node);
115533 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
115534 + break;
115535 + case GIMPLE_PHI: {
115536 + tree result = gimple_phi_result(stmt);
115537 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
115538 + break;
115539 + }
115540 + case GIMPLE_ASM:
115541 + if (gimple_asm_noutputs(stmt) != 0)
115542 + break;
115543 + if (!is_size_overflow_asm(stmt))
115544 + break;
115545 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
115546 + break;
115547 + case GIMPLE_COND:
115548 + case GIMPLE_SWITCH:
115549 + break;
115550 + default:
115551 + debug_gimple_stmt(stmt);
115552 + gcc_unreachable();
115553 + break;
115554 + }
115555 + }
115556 + return head;
115557 +}
115558 +
115559 +static void remove_size_overflow_asm(gimple stmt)
115560 +{
115561 + gimple_stmt_iterator gsi;
115562 + tree input, output;
115563 +
115564 + if (!is_size_overflow_asm(stmt))
115565 + return;
115566 +
115567 + if (gimple_asm_noutputs(stmt) == 0) {
115568 + gsi = gsi_for_stmt(stmt);
115569 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
115570 + gsi_remove(&gsi, true);
115571 + return;
115572 + }
115573 +
115574 + input = gimple_asm_input_op(stmt, 0);
115575 + output = gimple_asm_output_op(stmt, 0);
115576 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
115577 +}
115578 +
115579 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
115580 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
115581 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
115582 + */
115583 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
115584 +{
115585 + const_tree output;
115586 + struct pointer_set_t *visited;
115587 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
115588 +
115589 + if (!is_size_overflow_asm(stmt))
115590 + return head;
115591 +
115592 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
115593 + intentional_asm = stmt;
115594 +
115595 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
115596 +
115597 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
115598 + return head;
115599 +
115600 + if (gimple_asm_noutputs(stmt) == 0) {
115601 + const_tree input;
115602 +
115603 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
115604 + return head;
115605 +
115606 + input = gimple_asm_input_op(stmt, 0);
115607 + remove_size_overflow_asm(stmt);
115608 + if (is_gimple_constant(TREE_VALUE(input)))
115609 + return head;
115610 + visited = pointer_set_create();
115611 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
115612 + pointer_set_destroy(visited);
115613 + return head;
115614 + }
115615 +
115616 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
115617 + remove_size_overflow_asm(stmt);
115618 +
115619 + visited = pointer_set_create();
115620 + output = gimple_asm_output_op(stmt, 0);
115621 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
115622 + pointer_set_destroy(visited);
115623 + return head;
115624 +}
115625 +
115626 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
115627 + * or a call stmt or a return stmt and store them in the interesting_node list
115628 + */
115629 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
115630 +{
115631 + basic_block bb;
115632 + struct interesting_node *head = NULL;
115633 +
115634 + FOR_ALL_BB_FN(bb, cfun) {
115635 + gimple_stmt_iterator gsi;
115636 +
115637 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
115638 + enum gimple_code code;
115639 + gimple stmt = gsi_stmt(gsi);
115640 +
115641 + code = gimple_code(stmt);
115642 +
115643 + if (code == GIMPLE_ASM)
115644 + head = handle_stmt_by_size_overflow_asm(stmt, head);
115645 +
115646 + if (!next_node)
115647 + continue;
115648 + if (code == GIMPLE_CALL)
115649 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
115650 + if (code == GIMPLE_RETURN)
115651 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
115652 + }
115653 + }
115654 + return head;
115655 +}
115656 +
115657 +static void free_interesting_node(struct interesting_node *head)
115658 +{
115659 + struct interesting_node *cur;
115660 +
115661 + while (head) {
115662 + cur = head->next;
115663 +#if BUILDING_GCC_VERSION <= 4007
115664 + VEC_free(tree, gc, head->last_nodes);
115665 +#else
115666 + vec_free(head->last_nodes);
115667 +#endif
115668 + free(head);
115669 + head = cur;
115670 + }
115671 +}
115672 +
115673 +static struct visited_fns *insert_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
115674 +{
115675 + struct visited_fns *new_visited_fns;
115676 +
115677 + new_visited_fns = (struct visited_fns *)xmalloc(sizeof(*new_visited_fns));
115678 + new_visited_fns->fndecl = cur_node->fndecl;
115679 + new_visited_fns->num = cur_node->num;
115680 + new_visited_fns->first_stmt = cur_node->first_stmt;
115681 + new_visited_fns->next = NULL;
115682 +
115683 + if (!head)
115684 + return new_visited_fns;
115685 +
115686 + new_visited_fns->next = head;
115687 + return new_visited_fns;
115688 +}
115689 +
115690 +/* Check whether the function was already visited_fns. If the fndecl, the arg count of the fndecl and the first_stmt (call or return) are same then
115691 + * it is a visited_fns function.
115692 + */
115693 +static bool is_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
115694 +{
115695 + struct visited_fns *cur;
115696 +
115697 + if (!head)
115698 + return false;
115699 +
115700 + for (cur = head; cur; cur = cur->next) {
115701 + if (cur_node->first_stmt != cur->first_stmt)
115702 + continue;
115703 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
115704 + continue;
115705 + if (cur_node->num == cur->num)
115706 + return true;
115707 + }
115708 + return false;
115709 +}
115710 +
115711 +static void free_next_cgraph_node(struct next_cgraph_node *head)
115712 +{
115713 + struct next_cgraph_node *cur;
115714 +
115715 + while (head) {
115716 + cur = head->next;
115717 + free(head);
115718 + head = cur;
115719 + }
115720 +}
115721 +
115722 +static void remove_all_size_overflow_asm(void)
115723 +{
115724 + basic_block bb;
115725 +
115726 + FOR_ALL_BB_FN(bb, cfun) {
115727 + gimple_stmt_iterator si;
115728 +
115729 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
115730 + remove_size_overflow_asm(gsi_stmt(si));
115731 + }
115732 +}
115733 +
115734 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
115735 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
115736 + * the newly collected interesting functions (they are interesting if there is control flow between
115737 + * the interesting stmts and them).
115738 + */
115739 +static struct visited_fns *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited_fns *visited_fns)
115740 +{
115741 + struct visited *visited;
115742 + struct interesting_node *head, *cur_node;
115743 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
115744 +
115745 + set_current_function_decl(NODE_DECL(node));
115746 + call_count = 0;
115747 +
115748 + head = collect_interesting_stmts(next_node);
115749 +
115750 + visited = create_visited();
115751 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
115752 + if (is_visited_fns_function(visited_fns, cur_node))
115753 + continue;
115754 + cnodes_head = handle_interesting_stmt(visited, cnodes_head, cur_node, node);
115755 + visited_fns = insert_visited_fns_function(visited_fns, cur_node);
115756 + }
115757 +
115758 + free_visited(visited);
115759 + free_interesting_node(head);
115760 + remove_all_size_overflow_asm();
115761 + unset_current_function_decl();
115762 +
115763 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
115764 + visited_fns = handle_function(cur_cnodes->current_function, cur_cnodes, visited_fns);
115765 +
115766 + free_next_cgraph_node(cnodes_head);
115767 + return visited_fns;
115768 +}
115769 +
115770 +static void free_visited_fns(struct visited_fns *head)
115771 +{
115772 + struct visited_fns *cur;
115773 +
115774 + while (head) {
115775 + cur = head->next;
115776 + free(head);
115777 + head = cur;
115778 + }
115779 +}
115780 +
115781 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
115782 +unsigned int search_function(void)
115783 +{
115784 + struct cgraph_node *node;
115785 + struct visited_fns *visited_fns = NULL;
115786 +
115787 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
115788 + gcc_assert(cgraph_function_flags_ready);
115789 +#if BUILDING_GCC_VERSION <= 4007
115790 + gcc_assert(node->reachable);
115791 +#endif
115792 +
115793 + visited_fns = handle_function(node, NULL, visited_fns);
115794 + }
115795 +
115796 + free_visited_fns(visited_fns);
115797 + return 0;
115798 +}
115799 +
115800 +#if BUILDING_GCC_VERSION >= 4009
115801 +static const struct pass_data insert_size_overflow_check_data = {
115802 +#else
115803 +static struct ipa_opt_pass_d insert_size_overflow_check = {
115804 + .pass = {
115805 +#endif
115806 + .type = SIMPLE_IPA_PASS,
115807 + .name = "size_overflow",
115808 +#if BUILDING_GCC_VERSION >= 4008
115809 + .optinfo_flags = OPTGROUP_NONE,
115810 +#endif
115811 +#if BUILDING_GCC_VERSION >= 4009
115812 + .has_gate = false,
115813 + .has_execute = true,
115814 +#else
115815 + .gate = NULL,
115816 + .execute = search_function,
115817 + .sub = NULL,
115818 + .next = NULL,
115819 + .static_pass_number = 0,
115820 +#endif
115821 + .tv_id = TV_NONE,
115822 + .properties_required = 0,
115823 + .properties_provided = 0,
115824 + .properties_destroyed = 0,
115825 + .todo_flags_start = 0,
115826 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_remove_unused_locals | TODO_ggc_collect | TODO_verify_flow | TODO_dump_cgraph | TODO_dump_func | TODO_update_ssa_no_phi,
115827 +#if BUILDING_GCC_VERSION < 4009
115828 + },
115829 + .generate_summary = NULL,
115830 + .write_summary = NULL,
115831 + .read_summary = NULL,
115832 +#if BUILDING_GCC_VERSION >= 4006
115833 + .write_optimization_summary = NULL,
115834 + .read_optimization_summary = NULL,
115835 +#endif
115836 + .stmt_fixup = NULL,
115837 + .function_transform_todo_flags_start = 0,
115838 + .function_transform = NULL,
115839 + .variable_transform = NULL,
115840 +#endif
115841 +};
115842 +
115843 +#if BUILDING_GCC_VERSION >= 4009
115844 +namespace {
115845 +class insert_size_overflow_check : public ipa_opt_pass_d {
115846 +public:
115847 + insert_size_overflow_check() : ipa_opt_pass_d(insert_size_overflow_check_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
115848 + unsigned int execute() { return search_function(); }
115849 +};
115850 +}
115851 +#endif
115852 +
115853 +struct opt_pass *make_insert_size_overflow_check(void)
115854 +{
115855 +#if BUILDING_GCC_VERSION >= 4009
115856 + return new insert_size_overflow_check();
115857 +#else
115858 + return &insert_size_overflow_check.pass;
115859 +#endif
115860 +}
115861 +
115862 diff --git a/tools/gcc/size_overflow_plugin/intentional_overflow.c b/tools/gcc/size_overflow_plugin/intentional_overflow.c
115863 new file mode 100644
115864 index 0000000..d71d72a
115865 --- /dev/null
115866 +++ b/tools/gcc/size_overflow_plugin/intentional_overflow.c
115867 @@ -0,0 +1,736 @@
115868 +/*
115869 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
115870 + * Licensed under the GPL v2, or (at your option) v3
115871 + *
115872 + * Homepage:
115873 + * http://www.grsecurity.net/~ephox/overflow_plugin/
115874 + *
115875 + * Documentation:
115876 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
115877 + *
115878 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
115879 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
115880 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
115881 + *
115882 + * Usage:
115883 + * $ make
115884 + * $ make run
115885 + */
115886 +
115887 +#include "gcc-common.h"
115888 +#include "size_overflow.h"
115889 +
115890 +/* Get the param of the intentional_overflow attribute.
115891 + * * 0: MARK_NOT_INTENTIONAL
115892 + * * 1..MAX_PARAM: MARK_YES
115893 + * * -1: MARK_TURN_OFF
115894 + */
115895 +static tree get_attribute_param(const_tree decl)
115896 +{
115897 + const_tree attr;
115898 +
115899 + if (decl == NULL_TREE)
115900 + return NULL_TREE;
115901 +
115902 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
115903 + if (!attr || !TREE_VALUE(attr))
115904 + return NULL_TREE;
115905 +
115906 + return TREE_VALUE(attr);
115907 +}
115908 +
115909 +// MARK_TURN_OFF
115910 +bool is_turn_off_intentional_attr(const_tree decl)
115911 +{
115912 + const_tree param_head;
115913 +
115914 + param_head = get_attribute_param(decl);
115915 + if (param_head == NULL_TREE)
115916 + return false;
115917 +
115918 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
115919 + return true;
115920 + return false;
115921 +}
115922 +
115923 +// MARK_NOT_INTENTIONAL
115924 +bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
115925 +{
115926 + const_tree param_head;
115927 +
115928 + if (argnum == 0)
115929 + return false;
115930 +
115931 + param_head = get_attribute_param(decl);
115932 + if (param_head == NULL_TREE)
115933 + return false;
115934 +
115935 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
115936 + return true;
115937 + return false;
115938 +}
115939 +
115940 +// MARK_YES
115941 +bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
115942 +{
115943 + tree param, param_head;
115944 +
115945 + if (argnum == 0)
115946 + return false;
115947 +
115948 + param_head = get_attribute_param(decl);
115949 + for (param = param_head; param; param = TREE_CHAIN(param))
115950 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
115951 + return true;
115952 + return false;
115953 +}
115954 +
115955 +void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
115956 +{
115957 + location_t loc;
115958 +
115959 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
115960 + return;
115961 +
115962 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
115963 + return;
115964 +
115965 + loc = DECL_SOURCE_LOCATION(decl);
115966 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
115967 +}
115968 +
115969 +// Get the field decl of a component ref for intentional_overflow checking
115970 +static const_tree search_field_decl(const_tree comp_ref)
115971 +{
115972 + const_tree field = NULL_TREE;
115973 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
115974 +
115975 + for (i = 0; i < len; i++) {
115976 + field = TREE_OPERAND(comp_ref, i);
115977 + if (TREE_CODE(field) == FIELD_DECL)
115978 + break;
115979 + }
115980 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
115981 + return field;
115982 +}
115983 +
115984 +/* Get the type of the intentional_overflow attribute of a node
115985 + * * MARK_TURN_OFF
115986 + * * MARK_YES
115987 + * * MARK_NO
115988 + * * MARK_NOT_INTENTIONAL
115989 + */
115990 +enum mark get_intentional_attr_type(const_tree node)
115991 +{
115992 + const_tree cur_decl;
115993 +
115994 + if (node == NULL_TREE)
115995 + return MARK_NO;
115996 +
115997 + switch (TREE_CODE(node)) {
115998 + case COMPONENT_REF:
115999 + cur_decl = search_field_decl(node);
116000 + if (is_turn_off_intentional_attr(cur_decl))
116001 + return MARK_TURN_OFF;
116002 + if (is_end_intentional_intentional_attr(cur_decl, 1))
116003 + return MARK_YES;
116004 + break;
116005 + case PARM_DECL: {
116006 + unsigned int argnum;
116007 +
116008 + cur_decl = DECL_ORIGIN(current_function_decl);
116009 + argnum = find_arg_number_tree(node, cur_decl);
116010 + if (argnum == CANNOT_FIND_ARG)
116011 + return MARK_NO;
116012 + if (is_yes_intentional_attr(cur_decl, argnum))
116013 + return MARK_YES;
116014 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
116015 + return MARK_NOT_INTENTIONAL;
116016 + break;
116017 + }
116018 + case FUNCTION_DECL:
116019 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
116020 + return MARK_TURN_OFF;
116021 + break;
116022 + default:
116023 + break;
116024 + }
116025 + return MARK_NO;
116026 +}
116027 +
116028 +// Search for the intentional_overflow attribute on the last nodes
116029 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
116030 +{
116031 + unsigned int i;
116032 + tree last_node;
116033 + enum mark mark = MARK_NO;
116034 +
116035 +#if BUILDING_GCC_VERSION <= 4007
116036 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
116037 +#else
116038 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
116039 +#endif
116040 + mark = get_intentional_attr_type(last_node);
116041 + if (mark != MARK_NO)
116042 + break;
116043 + }
116044 + return mark;
116045 +}
116046 +
116047 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
116048 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
116049 + */
116050 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
116051 +{
116052 + if (!cur_node->intentional_mark_from_gimple)
116053 + return false;
116054 +
116055 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
116056 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
116057 + else
116058 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
116059 +
116060 + // skip param decls
116061 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
116062 + return true;
116063 + return true;
116064 +}
116065 +
116066 +/* Search intentional_overflow attribute on caller and on callee too.
116067 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
116068 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
116069 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
116070 +*/
116071 +void check_intentional_attribute_ipa(struct interesting_node *cur_node)
116072 +{
116073 + const_tree fndecl;
116074 +
116075 + if (is_intentional_attribute_from_gimple(cur_node))
116076 + return;
116077 +
116078 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
116079 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
116080 + return;
116081 + }
116082 +
116083 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
116084 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
116085 + return;
116086 + }
116087 +
116088 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
116089 + return;
116090 +
116091 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
116092 + if (is_turn_off_intentional_attr(fndecl)) {
116093 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
116094 + return;
116095 + }
116096 +
116097 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
116098 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
116099 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
116100 + cur_node->intentional_attr_decl = MARK_YES;
116101 +
116102 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
116103 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
116104 +}
116105 +
116106 +bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
116107 +{
116108 + const_tree rhs1, lhs, rhs1_type, lhs_type;
116109 + enum machine_mode lhs_mode, rhs_mode;
116110 + gimple def_stmt = get_def_stmt(no_const_rhs);
116111 +
116112 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
116113 + return false;
116114 +
116115 + rhs1 = gimple_assign_rhs1(def_stmt);
116116 + lhs = gimple_assign_lhs(def_stmt);
116117 + rhs1_type = TREE_TYPE(rhs1);
116118 + lhs_type = TREE_TYPE(lhs);
116119 + rhs_mode = TYPE_MODE(rhs1_type);
116120 + lhs_mode = TYPE_MODE(lhs_type);
116121 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
116122 + return false;
116123 +
116124 + return true;
116125 +}
116126 +
116127 +static unsigned int uses_num(tree node)
116128 +{
116129 + imm_use_iterator imm_iter;
116130 + use_operand_p use_p;
116131 + unsigned int num = 0;
116132 +
116133 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
116134 + gimple use_stmt = USE_STMT(use_p);
116135 +
116136 + if (use_stmt == NULL)
116137 + return num;
116138 + if (is_gimple_debug(use_stmt))
116139 + continue;
116140 + if (gimple_assign_cast_p(use_stmt) && is_size_overflow_type(gimple_assign_lhs(use_stmt)))
116141 + continue;
116142 + num++;
116143 + }
116144 + return num;
116145 +}
116146 +
116147 +static bool no_uses(tree node)
116148 +{
116149 + return !uses_num(node);
116150 +}
116151 +
116152 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
116153 +bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
116154 +{
116155 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
116156 + gimple def_stmt = get_def_stmt(lhs);
116157 +
116158 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
116159 + return false;
116160 +
116161 + rhs1 = gimple_assign_rhs1(def_stmt);
116162 + rhs_type = TREE_TYPE(rhs1);
116163 + lhs_type = TREE_TYPE(lhs);
116164 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
116165 + return false;
116166 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
116167 + return false;
116168 +
116169 + def_stmt = get_def_stmt(rhs1);
116170 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
116171 + return false;
116172 +
116173 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
116174 + return false;
116175 +
116176 + rhs1 = gimple_assign_rhs1(def_stmt);
116177 + rhs2 = gimple_assign_rhs2(def_stmt);
116178 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
116179 + return false;
116180 +
116181 + if (is_gimple_constant(rhs2))
116182 + not_const_rhs = rhs1;
116183 + else
116184 + not_const_rhs = rhs2;
116185 +
116186 + return no_uses(not_const_rhs);
116187 +}
116188 +
116189 +static bool is_lt_signed_type_max(const_tree rhs)
116190 +{
116191 + const_tree new_type, type_max, type = TREE_TYPE(rhs);
116192 +
116193 + if (!TYPE_UNSIGNED(type))
116194 + return true;
116195 +
116196 + switch (TYPE_MODE(type)) {
116197 + case QImode:
116198 + new_type = intQI_type_node;
116199 + break;
116200 + case HImode:
116201 + new_type = intHI_type_node;
116202 + break;
116203 + case SImode:
116204 + new_type = intSI_type_node;
116205 + break;
116206 + case DImode:
116207 + new_type = intDI_type_node;
116208 + break;
116209 + default:
116210 + debug_tree((tree)type);
116211 + gcc_unreachable();
116212 + }
116213 +
116214 + type_max = TYPE_MAX_VALUE(new_type);
116215 + if (!tree_int_cst_lt(type_max, rhs))
116216 + return true;
116217 +
116218 + return false;
116219 +}
116220 +
116221 +static bool is_gt_zero(const_tree rhs)
116222 +{
116223 + const_tree type = TREE_TYPE(rhs);
116224 +
116225 + if (TYPE_UNSIGNED(type))
116226 + return true;
116227 +
116228 + if (!tree_int_cst_lt(rhs, integer_zero_node))
116229 + return true;
116230 +
116231 + return false;
116232 +}
116233 +
116234 +bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
116235 +{
116236 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
116237 + return false;
116238 + if (!is_gimple_constant(rhs))
116239 + return false;
116240 +
116241 + // If the const is between 0 and the max value of the signed type of the same bitsize then there is no intentional overflow
116242 + if (is_lt_signed_type_max(rhs) && is_gt_zero(rhs))
116243 + return false;
116244 +
116245 + return true;
116246 +}
116247 +
116248 +static tree change_assign_rhs(struct visited *visited, gimple stmt, const_tree orig_rhs, tree new_rhs)
116249 +{
116250 + gimple assign;
116251 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
116252 + tree origtype = TREE_TYPE(orig_rhs);
116253 +
116254 + gcc_assert(is_gimple_assign(stmt));
116255 +
116256 + assign = build_cast_stmt(visited, origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
116257 + pointer_set_insert(visited->my_stmts, assign);
116258 + return gimple_assign_lhs(assign);
116259 +}
116260 +
116261 +tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2)
116262 +{
116263 + tree new_rhs, orig_rhs;
116264 + void (*gimple_assign_set_rhs)(gimple, tree);
116265 + tree rhs1 = gimple_assign_rhs1(stmt);
116266 + tree rhs2 = gimple_assign_rhs2(stmt);
116267 + tree lhs = gimple_assign_lhs(stmt);
116268 +
116269 + if (!check_overflow)
116270 + return create_assign(visited, stmt, lhs, AFTER_STMT);
116271 +
116272 + if (change_rhs == NULL_TREE)
116273 + return create_assign(visited, stmt, lhs, AFTER_STMT);
116274 +
116275 + if (new_rhs2 == NULL_TREE) {
116276 + orig_rhs = rhs1;
116277 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
116278 + } else {
116279 + orig_rhs = rhs2;
116280 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
116281 + }
116282 +
116283 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
116284 +
116285 + new_rhs = change_assign_rhs(visited, stmt, orig_rhs, change_rhs);
116286 + gimple_assign_set_rhs(stmt, new_rhs);
116287 + update_stmt(stmt);
116288 +
116289 + return create_assign(visited, stmt, lhs, AFTER_STMT);
116290 +}
116291 +
116292 +static bool is_subtraction_special(struct visited *visited, const_gimple stmt)
116293 +{
116294 + gimple rhs1_def_stmt, rhs2_def_stmt;
116295 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
116296 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
116297 + const_tree rhs1 = gimple_assign_rhs1(stmt);
116298 + const_tree rhs2 = gimple_assign_rhs2(stmt);
116299 +
116300 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
116301 + return false;
116302 +
116303 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
116304 +
116305 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
116306 + return false;
116307 +
116308 + rhs1_def_stmt = get_def_stmt(rhs1);
116309 + rhs2_def_stmt = get_def_stmt(rhs2);
116310 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
116311 + return false;
116312 +
116313 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
116314 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
116315 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
116316 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
116317 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
116318 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
116319 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
116320 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
116321 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
116322 + return false;
116323 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
116324 + return false;
116325 +
116326 + pointer_set_insert(visited->no_cast_check, rhs1_def_stmt);
116327 + pointer_set_insert(visited->no_cast_check, rhs2_def_stmt);
116328 + return true;
116329 +}
116330 +
116331 +static gimple create_binary_assign(struct visited *visited, enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
116332 +{
116333 + gimple assign;
116334 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
116335 + tree type = TREE_TYPE(rhs1);
116336 + tree lhs = create_new_var(type);
116337 +
116338 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
116339 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
116340 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
116341 +
116342 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
116343 + update_stmt(assign);
116344 + pointer_set_insert(visited->my_stmts, assign);
116345 + return assign;
116346 +}
116347 +
116348 +static tree cast_to_TI_type(struct visited *visited, gimple stmt, tree node)
116349 +{
116350 + gimple_stmt_iterator gsi;
116351 + gimple cast_stmt;
116352 + tree type = TREE_TYPE(node);
116353 +
116354 + if (types_compatible_p(type, intTI_type_node))
116355 + return node;
116356 +
116357 + gsi = gsi_for_stmt(stmt);
116358 + cast_stmt = build_cast_stmt(visited, intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
116359 + pointer_set_insert(visited->my_stmts, cast_stmt);
116360 + return gimple_assign_lhs(cast_stmt);
116361 +}
116362 +
116363 +static tree get_def_stmt_rhs(struct visited *visited, const_tree var)
116364 +{
116365 + tree rhs1, def_stmt_rhs1;
116366 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
116367 +
116368 + def_stmt = get_def_stmt(var);
116369 + if (!gimple_assign_cast_p(def_stmt))
116370 + return NULL_TREE;
116371 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && pointer_set_contains(visited->my_stmts, def_stmt) && gimple_assign_cast_p(def_stmt));
116372 +
116373 + rhs1 = gimple_assign_rhs1(def_stmt);
116374 + rhs1_def_stmt = get_def_stmt(rhs1);
116375 + if (!gimple_assign_cast_p(rhs1_def_stmt))
116376 + return rhs1;
116377 +
116378 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
116379 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
116380 +
116381 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
116382 + case GIMPLE_CALL:
116383 + case GIMPLE_NOP:
116384 + case GIMPLE_ASM:
116385 + case GIMPLE_PHI:
116386 + return def_stmt_rhs1;
116387 + case GIMPLE_ASSIGN:
116388 + return rhs1;
116389 + default:
116390 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
116391 + gcc_unreachable();
116392 + }
116393 +}
116394 +
116395 +tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs)
116396 +{
116397 + tree new_rhs1, new_rhs2;
116398 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
116399 + gimple assign, stmt = get_def_stmt(lhs);
116400 + tree rhs1 = gimple_assign_rhs1(stmt);
116401 + tree rhs2 = gimple_assign_rhs2(stmt);
116402 +
116403 + if (!is_subtraction_special(visited, stmt))
116404 + return NULL_TREE;
116405 +
116406 + new_rhs1 = expand(visited, caller_node, rhs1);
116407 + new_rhs2 = expand(visited, caller_node, rhs2);
116408 +
116409 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs1);
116410 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs2);
116411 +
116412 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
116413 + return NULL_TREE;
116414 +
116415 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
116416 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs1_def_stmt_rhs1);
116417 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs2_def_stmt_rhs1);
116418 + }
116419 +
116420 + assign = create_binary_assign(visited, MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
116421 + new_lhs = gimple_assign_lhs(assign);
116422 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
116423 +
116424 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
116425 +}
116426 +
116427 +bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
116428 +{
116429 + const_gimple def_stmt;
116430 +
116431 + if (TREE_CODE(rhs) != SSA_NAME)
116432 + return false;
116433 +
116434 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
116435 + return false;
116436 +
116437 + def_stmt = get_def_stmt(rhs);
116438 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
116439 + return false;
116440 +
116441 + return true;
116442 +}
116443 +
116444 +/* e.g., drivers/acpi/acpica/utids.c acpi_ut_execute_CID()
116445 + * ((count - 1) * sizeof(struct acpi_pnp_dee_id_list) -> (count + fffffff) * 16
116446 + * fffffff * 16 > signed max -> truncate
116447 + */
116448 +static bool look_for_mult_and_add(const_gimple stmt)
116449 +{
116450 + const_tree res;
116451 + tree rhs1, rhs2, def_rhs1, def_rhs2, const_rhs, def_const_rhs;
116452 + const_gimple def_stmt;
116453 +
116454 + if (!stmt || gimple_code(stmt) == GIMPLE_NOP)
116455 + return false;
116456 + if (!is_gimple_assign(stmt))
116457 + return false;
116458 + if (gimple_assign_rhs_code(stmt) != MULT_EXPR)
116459 + return false;
116460 +
116461 + rhs1 = gimple_assign_rhs1(stmt);
116462 + rhs2 = gimple_assign_rhs2(stmt);
116463 + if (is_gimple_constant(rhs1)) {
116464 + const_rhs = rhs1;
116465 + def_stmt = get_def_stmt(rhs2);
116466 + } else if (is_gimple_constant(rhs2)) {
116467 + const_rhs = rhs2;
116468 + def_stmt = get_def_stmt(rhs1);
116469 + } else
116470 + return false;
116471 +
116472 + if (!is_gimple_assign(def_stmt))
116473 + return false;
116474 +
116475 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR && gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
116476 + return false;
116477 +
116478 + def_rhs1 = gimple_assign_rhs1(def_stmt);
116479 + def_rhs2 = gimple_assign_rhs2(def_stmt);
116480 + if (is_gimple_constant(def_rhs1))
116481 + def_const_rhs = def_rhs1;
116482 + else if (is_gimple_constant(def_rhs2))
116483 + def_const_rhs = def_rhs2;
116484 + else
116485 + return false;
116486 +
116487 + res = fold_binary_loc(gimple_location(def_stmt), MULT_EXPR, TREE_TYPE(const_rhs), const_rhs, def_const_rhs);
116488 + if (is_lt_signed_type_max(res) && is_gt_zero(res))
116489 + return false;
116490 + return true;
116491 +}
116492 +
116493 +enum intentional_overflow_type add_mul_intentional_overflow(const_gimple stmt)
116494 +{
116495 + const_gimple def_stmt_1, def_stmt_2;
116496 + const_tree rhs1, rhs2;
116497 + bool add_mul_rhs1, add_mul_rhs2;
116498 +
116499 + rhs1 = gimple_assign_rhs1(stmt);
116500 + def_stmt_1 = get_def_stmt(rhs1);
116501 + add_mul_rhs1 = look_for_mult_and_add(def_stmt_1);
116502 +
116503 + rhs2 = gimple_assign_rhs2(stmt);
116504 + def_stmt_2 = get_def_stmt(rhs2);
116505 + add_mul_rhs2 = look_for_mult_and_add(def_stmt_2);
116506 +
116507 + if (add_mul_rhs1)
116508 + return RHS1_INTENTIONAL_OVERFLOW;
116509 + if (add_mul_rhs2)
116510 + return RHS2_INTENTIONAL_OVERFLOW;
116511 + return NO_INTENTIONAL_OVERFLOW;
116512 +}
116513 +
116514 +static gimple get_dup_stmt(struct visited *visited, gimple stmt)
116515 +{
116516 + gimple my_stmt;
116517 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
116518 +
116519 + gsi_next(&gsi);
116520 + my_stmt = gsi_stmt(gsi);
116521 +
116522 + gcc_assert(pointer_set_contains(visited->my_stmts, my_stmt));
116523 + gcc_assert(gimple_assign_rhs_code(stmt) == gimple_assign_rhs_code(my_stmt));
116524 +
116525 + return my_stmt;
116526 +}
116527 +
116528 +/* unsigned type -> unary or binary assign (rhs1 or rhs2 is constant)
116529 + * unsigned type cast to signed type, unsigned type: no more uses
116530 + * e.g., lib/vsprintf.c:simple_strtol()
116531 + * _10 = (unsigned long int) _9
116532 + * _11 = -_10;
116533 + * _12 = (long int) _11; (_11_ no more uses)
116534 + */
116535 +static bool is_call_or_cast(gimple stmt)
116536 +{
116537 + return gimple_assign_cast_p(stmt) || is_gimple_call(stmt);
116538 +}
116539 +
116540 +static bool is_unsigned_cast_or_call_def_stmt(const_tree node)
116541 +{
116542 + const_tree rhs;
116543 + gimple def_stmt;
116544 +
116545 + if (node == NULL_TREE)
116546 + return true;
116547 + if (is_gimple_constant(node))
116548 + return true;
116549 +
116550 + def_stmt = get_def_stmt(node);
116551 + if (!def_stmt)
116552 + return false;
116553 +
116554 + if (is_call_or_cast(def_stmt))
116555 + return true;
116556 +
116557 + if (!is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 2)
116558 + return false;
116559 + rhs = gimple_assign_rhs1(def_stmt);
116560 + def_stmt = get_def_stmt(rhs);
116561 + if (!def_stmt)
116562 + return false;
116563 + return is_call_or_cast(def_stmt);
116564 +}
116565 +
116566 +void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt)
116567 +{
116568 + unsigned int use_num;
116569 + gimple so_stmt;
116570 + const_gimple def_stmt;
116571 + const_tree rhs1, rhs2;
116572 + tree rhs = gimple_assign_rhs1(stmt);
116573 + tree lhs_type = TREE_TYPE(gimple_assign_lhs(stmt));
116574 + const_tree rhs_type = TREE_TYPE(rhs);
116575 +
116576 + if (!(TYPE_UNSIGNED(rhs_type) && !TYPE_UNSIGNED(lhs_type)))
116577 + return;
116578 + if (GET_MODE_BITSIZE(TYPE_MODE(rhs_type)) != GET_MODE_BITSIZE(TYPE_MODE(lhs_type)))
116579 + return;
116580 + use_num = uses_num(rhs);
116581 + if (use_num != 1)
116582 + return;
116583 +
116584 + def_stmt = get_def_stmt(rhs);
116585 + if (!def_stmt)
116586 + return;
116587 + if (!is_gimple_assign(def_stmt))
116588 + return;
116589 +
116590 + rhs1 = gimple_assign_rhs1(def_stmt);
116591 + if (!is_unsigned_cast_or_call_def_stmt(rhs1))
116592 + return;
116593 +
116594 + rhs2 = gimple_assign_rhs2(def_stmt);
116595 + if (!is_unsigned_cast_or_call_def_stmt(rhs2))
116596 + return;
116597 + if (gimple_num_ops(def_stmt) == 3 && !is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
116598 + return;
116599 +
116600 + so_stmt = get_dup_stmt(visited, stmt);
116601 + create_up_and_down_cast(visited, so_stmt, lhs_type, gimple_assign_rhs1(so_stmt));
116602 +}
116603 +
116604 diff --git a/tools/gcc/size_overflow_plugin/misc.c b/tools/gcc/size_overflow_plugin/misc.c
116605 new file mode 100644
116606 index 0000000..4bddad2
116607 --- /dev/null
116608 +++ b/tools/gcc/size_overflow_plugin/misc.c
116609 @@ -0,0 +1,203 @@
116610 +/*
116611 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
116612 + * Licensed under the GPL v2, or (at your option) v3
116613 + *
116614 + * Homepage:
116615 + * http://www.grsecurity.net/~ephox/overflow_plugin/
116616 + *
116617 + * Documentation:
116618 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
116619 + *
116620 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
116621 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
116622 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
116623 + *
116624 + * Usage:
116625 + * $ make
116626 + * $ make run
116627 + */
116628 +
116629 +#include "gcc-common.h"
116630 +#include "size_overflow.h"
116631 +
116632 +void set_current_function_decl(tree fndecl)
116633 +{
116634 + gcc_assert(fndecl != NULL_TREE);
116635 +
116636 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
116637 + calculate_dominance_info(CDI_DOMINATORS);
116638 + current_function_decl = fndecl;
116639 +}
116640 +
116641 +void unset_current_function_decl(void)
116642 +{
116643 + free_dominance_info(CDI_DOMINATORS);
116644 + pop_cfun();
116645 + current_function_decl = NULL_TREE;
116646 +}
116647 +
116648 +static bool is_bool(const_tree node)
116649 +{
116650 + const_tree type;
116651 +
116652 + if (node == NULL_TREE)
116653 + return false;
116654 +
116655 + type = TREE_TYPE(node);
116656 + if (!INTEGRAL_TYPE_P(type))
116657 + return false;
116658 + if (TREE_CODE(type) == BOOLEAN_TYPE)
116659 + return true;
116660 + if (TYPE_PRECISION(type) == 1)
116661 + return true;
116662 + return false;
116663 +}
116664 +
116665 +bool skip_types(const_tree var)
116666 +{
116667 + tree type;
116668 + enum tree_code code;
116669 +
116670 + if (is_gimple_constant(var))
116671 + return true;
116672 +
116673 + switch (TREE_CODE(var)) {
116674 + case ADDR_EXPR:
116675 +#if BUILDING_GCC_VERSION >= 4006
116676 + case MEM_REF:
116677 +#endif
116678 + case ARRAY_REF:
116679 + case BIT_FIELD_REF:
116680 + case INDIRECT_REF:
116681 + case TARGET_MEM_REF:
116682 + case COMPONENT_REF:
116683 + case VAR_DECL:
116684 + case VIEW_CONVERT_EXPR:
116685 + return true;
116686 + default:
116687 + break;
116688 + }
116689 +
116690 + code = TREE_CODE(var);
116691 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
116692 +
116693 + type = TREE_TYPE(var);
116694 + switch (TREE_CODE(type)) {
116695 + case INTEGER_TYPE:
116696 + case ENUMERAL_TYPE:
116697 + return false;
116698 + case BOOLEAN_TYPE:
116699 + return is_bool(var);
116700 + default:
116701 + return true;
116702 + }
116703 +}
116704 +
116705 +gimple get_def_stmt(const_tree node)
116706 +{
116707 + gcc_assert(node != NULL_TREE);
116708 +
116709 + if (skip_types(node))
116710 + return NULL;
116711 +
116712 + if (TREE_CODE(node) != SSA_NAME)
116713 + return NULL;
116714 + return SSA_NAME_DEF_STMT(node);
116715 +}
116716 +
116717 +tree create_new_var(tree type)
116718 +{
116719 + tree new_var = create_tmp_var(type, "cicus");
116720 +
116721 + add_referenced_var(new_var);
116722 + return new_var;
116723 +}
116724 +
116725 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
116726 +{
116727 + const_gimple def_stmt = get_def_stmt(rhs);
116728 +
116729 + if (force)
116730 + return false;
116731 +
116732 + if (is_gimple_constant(rhs))
116733 + return false;
116734 +
116735 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
116736 + return false;
116737 +
116738 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
116739 + return false;
116740 +
116741 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
116742 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
116743 + return false;
116744 +
116745 + return true;
116746 +}
116747 +
116748 +tree cast_a_tree(tree type, tree var)
116749 +{
116750 + gcc_assert(type != NULL_TREE);
116751 + gcc_assert(var != NULL_TREE);
116752 + gcc_assert(fold_convertible_p(type, var));
116753 +
116754 + return fold_convert(type, var);
116755 +}
116756 +
116757 +gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
116758 +{
116759 + gimple assign, def_stmt;
116760 +
116761 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
116762 + gcc_assert(!is_gimple_constant(rhs));
116763 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
116764 + gcc_unreachable();
116765 +
116766 + def_stmt = get_def_stmt(rhs);
116767 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && pointer_set_contains(visited->my_stmts, def_stmt))
116768 + return def_stmt;
116769 +
116770 + if (lhs == CREATE_NEW_VAR)
116771 + lhs = create_new_var(dst_type);
116772 +
116773 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
116774 +
116775 + if (!gsi_end_p(*gsi)) {
116776 + location_t loc = gimple_location(gsi_stmt(*gsi));
116777 + gimple_set_location(assign, loc);
116778 + }
116779 +
116780 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
116781 +
116782 + if (before)
116783 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
116784 + else
116785 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
116786 + update_stmt(assign);
116787 + return assign;
116788 +}
116789 +
116790 +bool is_size_overflow_type(const_tree var)
116791 +{
116792 + const char *name;
116793 + const_tree type_name, type;
116794 +
116795 + if (var == NULL_TREE)
116796 + return false;
116797 +
116798 + type = TREE_TYPE(var);
116799 + type_name = TYPE_NAME(type);
116800 + if (type_name == NULL_TREE)
116801 + return false;
116802 +
116803 + if (DECL_P(type_name))
116804 + name = DECL_NAME_POINTER(type_name);
116805 + else
116806 + name = IDENTIFIER_POINTER(type_name);
116807 +
116808 + if (!strncmp(name, "size_overflow_type", 18))
116809 + return true;
116810 + return false;
116811 +}
116812 +
116813 diff --git a/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
116814 new file mode 100644
116815 index 0000000..7c9e6d1
116816 --- /dev/null
116817 +++ b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
116818 @@ -0,0 +1,138 @@
116819 +/*
116820 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
116821 + * Licensed under the GPL v2, or (at your option) v3
116822 + *
116823 + * Homepage:
116824 + * http://www.grsecurity.net/~ephox/overflow_plugin/
116825 + *
116826 + * Documentation:
116827 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
116828 + *
116829 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
116830 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
116831 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
116832 + *
116833 + * Usage:
116834 + * $ make
116835 + * $ make run
116836 + */
116837 +
116838 +#include "gcc-common.h"
116839 +#include "size_overflow.h"
116840 +
116841 +bool skip_expr_on_double_type(const_gimple stmt)
116842 +{
116843 + enum tree_code code = gimple_assign_rhs_code(stmt);
116844 +
116845 + switch (code) {
116846 + case RSHIFT_EXPR:
116847 + case TRUNC_DIV_EXPR:
116848 + case CEIL_DIV_EXPR:
116849 + case FLOOR_DIV_EXPR:
116850 + case ROUND_DIV_EXPR:
116851 + case EXACT_DIV_EXPR:
116852 + case RDIV_EXPR:
116853 + case TRUNC_MOD_EXPR:
116854 + case CEIL_MOD_EXPR:
116855 + case FLOOR_MOD_EXPR:
116856 + case ROUND_MOD_EXPR:
116857 + return true;
116858 + default:
116859 + return false;
116860 + }
116861 +}
116862 +
116863 +void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs)
116864 +{
116865 + const_tree orig_rhs1;
116866 + tree down_lhs, new_lhs, dup_type = TREE_TYPE(rhs);
116867 + gimple down_cast, up_cast;
116868 + gimple_stmt_iterator gsi = gsi_for_stmt(use_stmt);
116869 +
116870 + down_cast = build_cast_stmt(visited, orig_type, rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
116871 + down_lhs = gimple_assign_lhs(down_cast);
116872 +
116873 + gsi = gsi_for_stmt(use_stmt);
116874 + up_cast = build_cast_stmt(visited, dup_type, down_lhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
116875 + new_lhs = gimple_assign_lhs(up_cast);
116876 +
116877 + orig_rhs1 = gimple_assign_rhs1(use_stmt);
116878 + if (operand_equal_p(orig_rhs1, rhs, 0))
116879 + gimple_assign_set_rhs1(use_stmt, new_lhs);
116880 + else
116881 + gimple_assign_set_rhs2(use_stmt, new_lhs);
116882 + update_stmt(use_stmt);
116883 +
116884 + pointer_set_insert(visited->my_stmts, up_cast);
116885 + pointer_set_insert(visited->my_stmts, down_cast);
116886 + pointer_set_insert(visited->skip_expr_casts, up_cast);
116887 + pointer_set_insert(visited->skip_expr_casts, down_cast);
116888 +}
116889 +
116890 +static tree get_proper_unsigned_half_type(const_tree node)
116891 +{
116892 + tree new_type, type;
116893 +
116894 + gcc_assert(is_size_overflow_type(node));
116895 +
116896 + type = TREE_TYPE(node);
116897 + switch (TYPE_MODE(type)) {
116898 + case HImode:
116899 + new_type = unsigned_intQI_type_node;
116900 + break;
116901 + case SImode:
116902 + new_type = unsigned_intHI_type_node;
116903 + break;
116904 + case DImode:
116905 + new_type = unsigned_intSI_type_node;
116906 + break;
116907 + case TImode:
116908 + new_type = unsigned_intDI_type_node;
116909 + break;
116910 + default:
116911 + gcc_unreachable();
116912 + }
116913 +
116914 + if (TYPE_QUALS(type) != 0)
116915 + return build_qualified_type(new_type, TYPE_QUALS(type));
116916 + return new_type;
116917 +}
116918 +
116919 +static void insert_cast_rhs(struct visited *visited, gimple stmt, tree rhs)
116920 +{
116921 + tree type;
116922 +
116923 + if (rhs == NULL_TREE)
116924 + return;
116925 + if (!is_size_overflow_type(rhs))
116926 + return;
116927 +
116928 + type = get_proper_unsigned_half_type(rhs);
116929 + if (is_gimple_constant(rhs))
116930 + return;
116931 + create_up_and_down_cast(visited, stmt, type, rhs);
116932 +}
116933 +
116934 +static void insert_cast(struct visited *visited, gimple stmt, tree rhs)
116935 +{
116936 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && !is_size_overflow_type(rhs))
116937 + return;
116938 + gcc_assert(is_size_overflow_type(rhs));
116939 + insert_cast_rhs(visited, stmt, rhs);
116940 +}
116941 +
116942 +void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type)
116943 +{
116944 + tree rhs1, rhs2;
116945 +
116946 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS1_INTENTIONAL_OVERFLOW) {
116947 + rhs1 = gimple_assign_rhs1(stmt);
116948 + insert_cast(visited, stmt, rhs1);
116949 + }
116950 +
116951 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS2_INTENTIONAL_OVERFLOW) {
116952 + rhs2 = gimple_assign_rhs2(stmt);
116953 + insert_cast(visited, stmt, rhs2);
116954 + }
116955 +}
116956 +
116957 diff --git a/tools/gcc/size_overflow_plugin/size_overflow.h b/tools/gcc/size_overflow_plugin/size_overflow.h
116958 new file mode 100644
116959 index 0000000..e5b4e50
116960 --- /dev/null
116961 +++ b/tools/gcc/size_overflow_plugin/size_overflow.h
116962 @@ -0,0 +1,127 @@
116963 +#ifndef SIZE_OVERFLOW_H
116964 +#define SIZE_OVERFLOW_H
116965 +
116966 +#define CREATE_NEW_VAR NULL_TREE
116967 +#define CANNOT_FIND_ARG 32
116968 +#define MAX_PARAM 31
116969 +#define BEFORE_STMT true
116970 +#define AFTER_STMT false
116971 +
116972 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
116973 +#define YES_ASM_STR "# size_overflow MARK_YES "
116974 +#define OK_ASM_STR "# size_overflow "
116975 +
116976 +enum mark {
116977 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
116978 +};
116979 +
116980 +enum intentional_overflow_type {
116981 + NO_INTENTIONAL_OVERFLOW, RHS1_INTENTIONAL_OVERFLOW, RHS2_INTENTIONAL_OVERFLOW
116982 +};
116983 +
116984 +struct visited {
116985 + struct pointer_set_t *stmts;
116986 + struct pointer_set_t *my_stmts;
116987 + struct pointer_set_t *skip_expr_casts;
116988 + struct pointer_set_t *no_cast_check;
116989 +};
116990 +
116991 +// size_overflow_plugin.c
116992 +extern tree report_size_overflow_decl;
116993 +extern tree size_overflow_type_HI;
116994 +extern tree size_overflow_type_SI;
116995 +extern tree size_overflow_type_DI;
116996 +extern tree size_overflow_type_TI;
116997 +
116998 +
116999 +// size_overflow_plugin_hash.c
117000 +struct size_overflow_hash {
117001 + const struct size_overflow_hash * const next;
117002 + const char * const name;
117003 + const unsigned int param;
117004 +};
117005 +
117006 +struct interesting_node {
117007 + struct interesting_node *next;
117008 + gimple first_stmt;
117009 + const_tree fndecl;
117010 + tree node;
117011 +#if BUILDING_GCC_VERSION <= 4007
117012 + VEC(tree, gc) *last_nodes;
117013 +#else
117014 + vec<tree, va_gc> *last_nodes;
117015 +#endif
117016 + unsigned int num;
117017 + enum mark intentional_attr_decl;
117018 + enum mark intentional_attr_cur_fndecl;
117019 + gimple intentional_mark_from_gimple;
117020 +};
117021 +
117022 +extern bool is_size_overflow_asm(const_gimple stmt);
117023 +extern unsigned int get_function_num(const_tree node, const_tree orig_fndecl);
117024 +extern unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl);
117025 +extern bool is_missing_function(const_tree orig_fndecl, unsigned int num);
117026 +extern bool is_a_return_check(const_tree node);
117027 +extern const struct size_overflow_hash *get_function_hash(const_tree fndecl);
117028 +extern unsigned int find_arg_number_tree(const_tree arg, const_tree func);
117029 +
117030 +
117031 +// size_overflow_debug.c
117032 +extern struct opt_pass *make_dump_pass(void);
117033 +
117034 +
117035 +// intentional_overflow.c
117036 +extern enum mark get_intentional_attr_type(const_tree node);
117037 +extern bool is_size_overflow_intentional_asm_yes(const_gimple stmt);
117038 +extern bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt);
117039 +extern bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum);
117040 +extern bool is_yes_intentional_attr(const_tree decl, unsigned int argnum);
117041 +extern bool is_turn_off_intentional_attr(const_tree decl);
117042 +extern void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum);
117043 +extern void check_intentional_attribute_ipa(struct interesting_node *cur_node);
117044 +extern bool is_a_cast_and_const_overflow(const_tree no_const_rhs);
117045 +extern bool is_const_plus_unsigned_signed_truncation(const_tree lhs);
117046 +extern bool is_a_constant_overflow(const_gimple stmt, const_tree rhs);
117047 +extern tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2);
117048 +extern tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs);
117049 +extern bool is_a_neg_overflow(const_gimple stmt, const_tree rhs);
117050 +extern enum intentional_overflow_type add_mul_intentional_overflow(const_gimple def_stmt);
117051 +extern void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt);
117052 +
117053 +
117054 +// insert_size_overflow_check_ipa.c
117055 +extern unsigned int search_function(void);
117056 +extern unsigned int call_count;
117057 +extern struct opt_pass *make_insert_size_overflow_check(void);
117058 +extern const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum);
117059 +
117060 +
117061 +// insert_size_overflow_asm.c
117062 +extern struct opt_pass *make_insert_size_overflow_asm_pass(void);
117063 +
117064 +
117065 +// misc.c
117066 +extern void set_current_function_decl(tree fndecl);
117067 +extern void unset_current_function_decl(void);
117068 +extern gimple get_def_stmt(const_tree node);
117069 +extern tree create_new_var(tree type);
117070 +extern gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force);
117071 +extern bool skip_types(const_tree var);
117072 +extern tree cast_a_tree(tree type, tree var);
117073 +extern bool is_size_overflow_type(const_tree var);
117074 +
117075 +
117076 +// insert_size_overflow_check_core.c
117077 +extern tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs);
117078 +extern void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
117079 +extern tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
117080 +extern tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before);
117081 +
117082 +
117083 +// remove_unnecessary_dup.c
117084 +extern struct opt_pass *make_remove_unnecessary_dup_pass(void);
117085 +extern void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type);
117086 +extern bool skip_expr_on_double_type(const_gimple stmt);
117087 +extern void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs);
117088 +
117089 +#endif
117090 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_debug.c b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
117091 new file mode 100644
117092 index 0000000..4378111
117093 --- /dev/null
117094 +++ b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
117095 @@ -0,0 +1,116 @@
117096 +/*
117097 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
117098 + * Licensed under the GPL v2, or (at your option) v3
117099 + *
117100 + * Homepage:
117101 + * http://www.grsecurity.net/~ephox/overflow_plugin/
117102 + *
117103 + * Documentation:
117104 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
117105 + *
117106 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
117107 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
117108 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
117109 + *
117110 + * Usage:
117111 + * $ make
117112 + * $ make run
117113 + */
117114 +
117115 +#include "gcc-common.h"
117116 +
117117 +static unsigned int dump_functions(void)
117118 +{
117119 + struct cgraph_node *node;
117120 +
117121 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
117122 + basic_block bb;
117123 +
117124 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
117125 + current_function_decl = NODE_DECL(node);
117126 +
117127 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
117128 +
117129 + FOR_ALL_BB_FN(bb, cfun) {
117130 + gimple_stmt_iterator si;
117131 +
117132 + fprintf(stderr, "<bb %u>:\n", bb->index);
117133 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
117134 + debug_gimple_stmt(gsi_stmt(si));
117135 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
117136 + debug_gimple_stmt(gsi_stmt(si));
117137 + fprintf(stderr, "\n");
117138 + }
117139 +
117140 + fprintf(stderr, "-------------------------------------------------------------------------\n");
117141 +
117142 + pop_cfun();
117143 + current_function_decl = NULL_TREE;
117144 + }
117145 +
117146 + fprintf(stderr, "###############################################################################\n");
117147 +
117148 + return 0;
117149 +}
117150 +
117151 +#if BUILDING_GCC_VERSION >= 4009
117152 +static const struct pass_data dump_pass_data = {
117153 +#else
117154 +static struct ipa_opt_pass_d dump_pass = {
117155 + .pass = {
117156 +#endif
117157 + .type = SIMPLE_IPA_PASS,
117158 + .name = "dump",
117159 +#if BUILDING_GCC_VERSION >= 4008
117160 + .optinfo_flags = OPTGROUP_NONE,
117161 +#endif
117162 +#if BUILDING_GCC_VERSION >= 4009
117163 + .has_gate = false,
117164 + .has_execute = true,
117165 +#else
117166 + .gate = NULL,
117167 + .execute = dump_functions,
117168 + .sub = NULL,
117169 + .next = NULL,
117170 + .static_pass_number = 0,
117171 +#endif
117172 + .tv_id = TV_NONE,
117173 + .properties_required = 0,
117174 + .properties_provided = 0,
117175 + .properties_destroyed = 0,
117176 + .todo_flags_start = 0,
117177 + .todo_flags_finish = 0,
117178 +#if BUILDING_GCC_VERSION < 4009
117179 + },
117180 + .generate_summary = NULL,
117181 + .write_summary = NULL,
117182 + .read_summary = NULL,
117183 +#if BUILDING_GCC_VERSION >= 4006
117184 + .write_optimization_summary = NULL,
117185 + .read_optimization_summary = NULL,
117186 +#endif
117187 + .stmt_fixup = NULL,
117188 + .function_transform_todo_flags_start = 0,
117189 + .function_transform = NULL,
117190 + .variable_transform = NULL,
117191 +#endif
117192 +};
117193 +
117194 +#if BUILDING_GCC_VERSION >= 4009
117195 +namespace {
117196 +class dump_pass : public ipa_opt_pass_d {
117197 +public:
117198 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
117199 + unsigned int execute() { return dump_functions(); }
117200 +};
117201 +}
117202 +#endif
117203 +
117204 +struct opt_pass *make_dump_pass(void)
117205 +{
117206 +#if BUILDING_GCC_VERSION >= 4009
117207 + return new dump_pass();
117208 +#else
117209 + return &dump_pass.pass;
117210 +#endif
117211 +}
117212 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash.data b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
117213 new file mode 100644
117214 index 0000000..367aa34
117215 --- /dev/null
117216 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
117217 @@ -0,0 +1,6028 @@
117218 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
117219 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
117220 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
117221 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
117222 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
117223 +padzero_55 padzero 1 55 &sel_read_policyvers_55
117224 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
117225 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
117226 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
117227 +load_msg_95 load_msg 2 95 NULL
117228 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
117229 +init_q_132 init_q 4 132 NULL
117230 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
117231 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
117232 +ping_v6_sendmsg_152 ping_v6_sendmsg 4 152 NULL
117233 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 NULL nohasharray
117234 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 &ext4_ext_get_actual_len_153
117235 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
117236 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
117237 +obd_proc_jobid_var_seq_write_199 obd_proc_jobid_var_seq_write 3 199 NULL
117238 +ll_xattr_cache_seq_write_250 ll_xattr_cache_seq_write 3 250 NULL
117239 +vpdma_create_desc_list_255 vpdma_create_desc_list 2 255 NULL
117240 +br_port_info_size_268 br_port_info_size 0 268 NULL
117241 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
117242 +SYSC_connect_304 SYSC_connect 3 304 NULL
117243 +syslog_print_307 syslog_print 2 307 NULL
117244 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
117245 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
117246 +aio_read_events_ring_410 aio_read_events_ring 3-0 410 NULL
117247 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
117248 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
117249 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
117250 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
117251 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
117252 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
117253 +smp_send_cmd_512 smp_send_cmd 3 512 NULL
117254 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
117255 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
117256 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
117257 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
117258 +lpfc_nlp_state_name_556 lpfc_nlp_state_name 2 556 NULL
117259 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
117260 +start_isoc_chain_565 start_isoc_chain 2 565 NULL nohasharray
117261 +dev_hard_header_565 dev_hard_header 0 565 &start_isoc_chain_565
117262 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
117263 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
117264 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
117265 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
117266 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
117267 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
117268 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
117269 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
117270 +unlink_queued_645 unlink_queued 4 645 NULL
117271 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
117272 +nvif_notify_new_671 nvif_notify_new 6 671 NULL
117273 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
117274 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
117275 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
117276 +dvb_video_write_754 dvb_video_write 3 754 NULL
117277 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
117278 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
117279 +if_writecmd_815 if_writecmd 2 815 NULL
117280 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
117281 +error_state_read_859 error_state_read 6 859 NULL
117282 +lustre_init_msg_v2_864 lustre_init_msg_v2 2 864 NULL
117283 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
117284 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
117285 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
117286 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
117287 +__nodes_weight_956 __nodes_weight 2-0 956 NULL
117288 +bnx2x_fill_fw_str_968 bnx2x_fill_fw_str 3 968 NULL
117289 +usnic_ib_qp_grp_dump_hdr_989 usnic_ib_qp_grp_dump_hdr 2 989 NULL
117290 +readreg_1017 readreg 0-1 1017 NULL
117291 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
117292 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
117293 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
117294 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
117295 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
117296 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
117297 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
117298 +__arch_hweight8_1105 __arch_hweight8 0 1105 NULL
117299 +utf8s_to_utf16s_1115 utf8s_to_utf16s 0 1115 NULL
117300 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
117301 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
117302 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
117303 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
117304 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
117305 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
117306 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
117307 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
117308 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
117309 +kernfs_file_direct_read_1238 kernfs_file_direct_read 3 1238 NULL
117310 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
117311 +drm_primary_helper_create_plane_1262 drm_primary_helper_create_plane 3 1262 NULL
117312 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
117313 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
117314 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
117315 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
117316 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
117317 +posix_acl_xattr_set_1301 posix_acl_xattr_set 4 1301 NULL
117318 +ffs_1322 ffs 0 1322 NULL
117319 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
117320 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
117321 +bond_verify_device_path_1352 bond_verify_device_path 3 1352 NULL
117322 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
117323 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
117324 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
117325 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
117326 +xpcs_reg_addr_read_1381 xpcs_reg_addr_read 3 1381 NULL
117327 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
117328 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
117329 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
117330 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
117331 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
117332 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
117333 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
117334 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
117335 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
117336 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
117337 +fpregs_set_1497 fpregs_set 4 1497 NULL
117338 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
117339 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
117340 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
117341 +ffs_mutex_lock_1564 ffs_mutex_lock 0 1564 NULL
117342 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
117343 +ipath_ht_handle_hwerrors_1592 ipath_ht_handle_hwerrors 3 1592 NULL
117344 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
117345 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
117346 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
117347 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
117348 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
117349 +rmap_add_1677 rmap_add 3 1677 NULL
117350 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
117351 +iwl_dbgfs_d0i3_refs_read_1705 iwl_dbgfs_d0i3_refs_read 3 1705 NULL
117352 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
117353 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
117354 +btrfs_dir_data_len_1714 btrfs_dir_data_len 0 1714 NULL
117355 +internal_create_group_1733 internal_create_group 0 1733 NULL
117356 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
117357 +usb_ep_align_maybe_1743 usb_ep_align_maybe 0-3 1743 NULL
117358 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
117359 +cosa_write_1774 cosa_write 3 1774 NULL
117360 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
117361 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2-0 1815 NULL
117362 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
117363 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
117364 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
117365 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
117366 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
117367 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
117368 +azx_get_position_1927 azx_get_position 0 1927 NULL
117369 +bdev_erase_1933 bdev_erase 3 1933 NULL
117370 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
117371 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL nohasharray
117372 +nvif_object_sclass_1940 nvif_object_sclass 3 1940 &cyttsp_probe_1940
117373 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
117374 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
117375 +qla2xxx_get_vpd_field_1965 qla2xxx_get_vpd_field 4 1965 NULL
117376 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
117377 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
117378 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
117379 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
117380 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
117381 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
117382 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
117383 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
117384 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
117385 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
117386 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
117387 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
117388 +xgmac_reg_value_read_2095 xgmac_reg_value_read 3 2095 NULL
117389 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
117390 +audit_expand_2098 audit_expand 0 2098 NULL
117391 +__set_print_fmt_2106 __set_print_fmt 0 2106 NULL
117392 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
117393 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
117394 +btrfs_file_extent_inline_len_2116 btrfs_file_extent_inline_len 0 2116 NULL
117395 +enable_read_2117 enable_read 3 2117 NULL
117396 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
117397 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
117398 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
117399 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
117400 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
117401 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
117402 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
117403 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
117404 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
117405 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
117406 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
117407 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
117408 +do_update_counters_2259 do_update_counters 4 2259 NULL
117409 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
117410 +vpdma_alloc_desc_buf_2278 vpdma_alloc_desc_buf 2 2278 NULL
117411 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
117412 +sr_read_cmd_2299 sr_read_cmd 5 2299 NULL
117413 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
117414 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
117415 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 NULL nohasharray
117416 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 &hfsplus_find_init_2318
117417 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
117418 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
117419 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
117420 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
117421 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
117422 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
117423 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
117424 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
117425 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
117426 +raid1_size_2419 raid1_size 0-2 2419 NULL
117427 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
117428 +wiphy_new_2482 wiphy_new 2 2482 NULL
117429 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
117430 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
117431 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
117432 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
117433 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
117434 +smk_write_syslog_2529 smk_write_syslog 3 2529 NULL
117435 +__ceph_setxattr_2532 __ceph_setxattr 4 2532 NULL
117436 +sfw_create_rpc_2562 sfw_create_rpc 4 2562 NULL
117437 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
117438 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
117439 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
117440 +slot_bytes_2609 slot_bytes 0 2609 NULL
117441 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
117442 +switch_status_2629 switch_status 5 2629 NULL
117443 +_proc_do_string_2632 _proc_do_string 2 2632 NULL
117444 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
117445 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
117446 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
117447 +oti6858_write_2692 oti6858_write 4 2692 NULL
117448 +copy_to_iter_iovec_2697 copy_to_iter_iovec 2 2697 NULL
117449 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
117450 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
117451 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
117452 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
117453 +fsl_edma_alloc_desc_2769 fsl_edma_alloc_desc 2 2769 NULL
117454 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
117455 +set_msr_hyperv_pw_2785 set_msr_hyperv_pw 3 2785 NULL
117456 +device_add_attrs_2789 device_add_attrs 0 2789 NULL
117457 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
117458 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
117459 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL
117460 +sock_create_2838 sock_create 0 2838 NULL
117461 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
117462 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
117463 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
117464 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
117465 +nla_padlen_2883 nla_padlen 1 2883 NULL
117466 +cmm_write_2896 cmm_write 3 2896 NULL
117467 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
117468 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
117469 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
117470 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
117471 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
117472 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
117473 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
117474 +bio_setup_sector_2970 bio_setup_sector 3 2970 NULL
117475 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
117476 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
117477 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
117478 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
117479 +depth_write_3021 depth_write 3 3021 NULL
117480 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
117481 +nvme_split_and_submit_3027 nvme_split_and_submit 3 3027 NULL
117482 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
117483 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
117484 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
117485 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
117486 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
117487 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
117488 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
117489 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
117490 +hfsplus_asc2uni_3071 hfsplus_asc2uni 0 3071 NULL nohasharray
117491 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 &hfsplus_asc2uni_3071
117492 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
117493 +bio_integrity_intervals_3094 bio_integrity_intervals 0-2 3094 NULL
117494 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
117495 +rb_alloc_3102 rb_alloc 1 3102 NULL
117496 +ufshcd_get_rsp_upiu_result_3114 ufshcd_get_rsp_upiu_result 0 3114 NULL
117497 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
117498 +print_time_3132 print_time 0 3132 NULL
117499 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
117500 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
117501 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
117502 +pkcs7_sig_note_signature_3178 pkcs7_sig_note_signature 5 3178 NULL
117503 +uinput_ioctl_handler_3181 uinput_ioctl_handler 2 3181 NULL nohasharray
117504 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 &uinput_ioctl_handler_3181
117505 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
117506 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
117507 +alloc_context_3194 alloc_context 1 3194 NULL
117508 +dma_init_coherent_memory_3197 dma_init_coherent_memory 3 3197 NULL
117509 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
117510 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
117511 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
117512 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
117513 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
117514 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
117515 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
117516 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
117517 +key_key_read_3241 key_key_read 3 3241 NULL
117518 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
117519 +ieee80211_if_write_beacon_loss_3296 ieee80211_if_write_beacon_loss 3 3296 NULL
117520 +cgroup_name_3300 cgroup_name 3 3300 NULL
117521 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 0-4-3 3314 NULL
117522 +_iwl_dbgfs_d3_sram_write_3315 _iwl_dbgfs_d3_sram_write 3 3315 NULL
117523 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
117524 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
117525 +sysfs_create_group_3339 sysfs_create_group 0 3339 NULL
117526 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
117527 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
117528 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
117529 +scnprintf_3360 scnprintf 0-2 3360 NULL
117530 +sr_read_3366 sr_read 3 3366 NULL
117531 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
117532 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
117533 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
117534 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
117535 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
117536 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
117537 +softsynth_write_3455 softsynth_write 3 3455 NULL
117538 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL
117539 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
117540 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
117541 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
117542 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
117543 +SyS_readv_3539 SyS_readv 3 3539 NULL
117544 +nouveau_fuse_create__3546 nouveau_fuse_create_ 4 3546 NULL
117545 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
117546 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
117547 +evtchn_read_3569 evtchn_read 3 3569 NULL
117548 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
117549 +vc_resize_3585 vc_resize 3-2 3585 NULL
117550 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
117551 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
117552 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
117553 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
117554 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
117555 +fm10k_alloc_q_vector_3638 fm10k_alloc_q_vector 4-6 3638 NULL
117556 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
117557 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
117558 +_iwl_dbgfs_tx_flush_write_3675 _iwl_dbgfs_tx_flush_write 3 3675 NULL
117559 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
117560 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
117561 +msm_otg_mode_write_3788 msm_otg_mode_write 3 3788 NULL
117562 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
117563 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
117564 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
117565 +ceph_do_getattr_3838 ceph_do_getattr 0 3838 NULL
117566 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
117567 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
117568 +get_fd_set_3866 get_fd_set 1 3866 NULL
117569 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
117570 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
117571 +nvram_write_3894 nvram_write 3 3894 NULL
117572 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
117573 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
117574 +vcs_write_3910 vcs_write 3 3910 NULL
117575 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
117576 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
117577 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
117578 +mite_bytes_written_to_memory_lb_3987 mite_bytes_written_to_memory_lb 0 3987 NULL
117579 +copy_from_user_atomic_iovec_3990 copy_from_user_atomic_iovec 0-4 3990 NULL
117580 +do_add_counters_3992 do_add_counters 3 3992 NULL
117581 +userspace_status_4004 userspace_status 4 4004 NULL
117582 +xfs_check_block_4005 xfs_check_block 4 4005 NULL nohasharray
117583 +mei_write_4005 mei_write 3 4005 &xfs_check_block_4005
117584 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
117585 +blk_end_request_4024 blk_end_request 3 4024 NULL
117586 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
117587 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
117588 +read_file_queues_4078 read_file_queues 3 4078 NULL
117589 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
117590 +C_SYSC_rt_sigpending_4114 C_SYSC_rt_sigpending 2 4114 NULL
117591 +tm6000_read_4151 tm6000_read 3 4151 NULL
117592 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
117593 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
117594 +get_alua_req_4166 get_alua_req 3 4166 NULL
117595 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
117596 +read_file_bool_4180 read_file_bool 3 4180 NULL
117597 +lstcon_test_add_4190 lstcon_test_add 10 4190 NULL
117598 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
117599 +f1x_determine_channel_4202 f1x_determine_channel 2 4202 NULL
117600 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
117601 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
117602 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
117603 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
117604 +get_connectors_for_crtc_4291 get_connectors_for_crtc 0 4291 NULL
117605 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
117606 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
117607 +count_strings_4315 count_strings 0 4315 NULL nohasharray
117608 +cfg80211_inform_bss_4315 cfg80211_inform_bss 9 4315 &count_strings_4315
117609 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
117610 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
117611 +ima_eventdigest_init_common_4338 ima_eventdigest_init_common 2 4338 NULL
117612 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 0-3 4365 NULL nohasharray
117613 +lookup_string_4365 lookup_string 0 4365 &__copy_from_user_inatomic_4365
117614 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
117615 +access_process_vm_4412 access_process_vm 0 4412 NULL nohasharray
117616 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 &access_process_vm_4412
117617 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
117618 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
117619 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
117620 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
117621 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 5-0 4481 NULL
117622 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
117623 +set_link_security_4502 set_link_security 4 4502 NULL
117624 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
117625 +tty_register_device_4544 tty_register_device 2 4544 NULL
117626 +fsl_edma_prep_slave_sg_4555 fsl_edma_prep_slave_sg 3 4555 NULL
117627 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
117628 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
117629 +bch_alloc_4593 bch_alloc 1 4593 NULL
117630 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
117631 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
117632 +nve0_gpio_intr_mask_4665 nve0_gpio_intr_mask 4-3 4665 NULL
117633 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
117634 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
117635 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
117636 +kone_receive_4690 kone_receive 4 4690 NULL
117637 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
117638 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
117639 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
117640 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
117641 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 NULL nohasharray
117642 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 &ll_rw_offset_stats_seq_write_4736
117643 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
117644 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
117645 +create_subvol_4791 create_subvol 4 4791 NULL
117646 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
117647 +C_SYSC_setsockopt_4806 C_SYSC_setsockopt 5 4806 NULL
117648 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
117649 +scsi_end_request_4839 scsi_end_request 3-4 4839 NULL
117650 +comedi_buf_write_free_4847 comedi_buf_write_free 2 4847 NULL
117651 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
117652 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
117653 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
117654 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
117655 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
117656 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
117657 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
117658 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
117659 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
117660 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
117661 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
117662 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
117663 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
117664 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 3-2 5066 NULL
117665 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
117666 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
117667 +get_random_bytes_5091 get_random_bytes 2 5091 NULL nohasharray
117668 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3-4-0 5091 &get_random_bytes_5091 nohasharray
117669 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &kfifo_copy_from_user_5091
117670 +sound_write_5102 sound_write 3 5102 NULL
117671 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
117672 +qib_7220_handle_hwerrors_5142 qib_7220_handle_hwerrors 3 5142 NULL
117673 +bucket_table_alloc_5149 bucket_table_alloc 1 5149 NULL
117674 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
117675 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
117676 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
117677 +trf7970a_read_cont_5179 trf7970a_read_cont 4 5179 NULL
117678 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
117679 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
117680 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
117681 +ipv4_tun_to_nlattr_5261 ipv4_tun_to_nlattr 4 5261 NULL
117682 +dvb_ringbuffer_write_user_5270 dvb_ringbuffer_write_user 3 5270 NULL
117683 +xgmac_reg_addr_read_5278 xgmac_reg_addr_read 3 5278 NULL
117684 +usb_descriptor_fillbuf_5302 usb_descriptor_fillbuf 0 5302 NULL
117685 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
117686 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
117687 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
117688 +uinput_ioctl_5342 uinput_ioctl 2 5342 NULL
117689 +cq_free_res_5355 cq_free_res 5 5355 NULL
117690 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
117691 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
117692 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
117693 +ll_xattr_cache_refill_5468 ll_xattr_cache_refill 0 5468 NULL
117694 +kernfs_fop_write_5471 kernfs_fop_write 3 5471 NULL
117695 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
117696 +pci_enable_msix_exact_5482 pci_enable_msix_exact 3 5482 NULL
117697 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
117698 +tty_write_5494 tty_write 3 5494 NULL
117699 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL nohasharray
117700 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 &tomoyo_update_domain_5498
117701 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
117702 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
117703 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
117704 +le_readq_5557 le_readq 0 5557 NULL
117705 +inw_5558 inw 0 5558 NULL
117706 +bioset_create_5580 bioset_create 1 5580 NULL
117707 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
117708 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
117709 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
117710 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
117711 +get_arg_5694 get_arg 3 5694 NULL
117712 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
117713 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
117714 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
117715 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
117716 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
117717 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL nohasharray
117718 +ath10k_core_create_5806 ath10k_core_create 1 5806 &skb_copy_datagram_iovec_5806
117719 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
117720 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
117721 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
117722 +setup_req_5848 setup_req 3 5848 NULL
117723 +ria_page_count_5849 ria_page_count 0 5849 NULL
117724 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
117725 +uinput_compat_ioctl_5861 uinput_compat_ioctl 2 5861 NULL
117726 +config_buf_5862 config_buf 0 5862 NULL nohasharray
117727 +ufshcd_check_query_response_5862 ufshcd_check_query_response 0 5862 &config_buf_5862
117728 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
117729 +port_show_regs_5904 port_show_regs 3 5904 NULL
117730 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
117731 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
117732 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
117733 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
117734 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
117735 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
117736 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
117737 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
117738 +SyS_semop_5980 SyS_semop 3 5980 NULL
117739 +btrfs_item_offset_6019 btrfs_item_offset 0 6019 NULL
117740 +alloc_msg_6072 alloc_msg 1 6072 NULL
117741 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
117742 +_random_read_6098 _random_read 3 6098 NULL
117743 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 NULL nohasharray
117744 +force_static_address_read_6110 force_static_address_read 3 6110 &ipmi_addr_length_6110
117745 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
117746 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
117747 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
117748 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
117749 +maybe_insert_hole_6167 maybe_insert_hole 3 6167 NULL
117750 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
117751 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
117752 +snd_efw_command_get_phys_meters_6190 snd_efw_command_get_phys_meters 3 6190 NULL
117753 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
117754 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
117755 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
117756 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
117757 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
117758 +of_gpio_count_6270 of_gpio_count 0 6270 NULL
117759 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
117760 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
117761 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
117762 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
117763 +serial_port_in_6291 serial_port_in 0 6291 NULL
117764 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
117765 +hfsplus_direct_IO_6313 hfsplus_direct_IO 4 6313 NULL
117766 +SyS_mincore_6329 SyS_mincore 2-1 6329 NULL nohasharray
117767 +hfa384x_inw_6329 hfa384x_inw 0 6329 &SyS_mincore_6329
117768 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
117769 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
117770 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
117771 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
117772 +arch_gnttab_valloc_6372 arch_gnttab_valloc 2 6372 NULL
117773 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL nohasharray
117774 +sync_fence_alloc_6378 sync_fence_alloc 1 6378 &osd_req_read_sg_kern_6378
117775 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
117776 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
117777 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
117778 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
117779 +C_SYSC_vmsplice_6470 C_SYSC_vmsplice 3 6470 NULL
117780 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
117781 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
117782 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
117783 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
117784 +mei_read_6507 mei_read 3 6507 NULL
117785 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
117786 +wdm_read_6549 wdm_read 3 6549 NULL
117787 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
117788 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
117789 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
117790 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
117791 +xfs_do_div_6649 xfs_do_div 0-2 6649 NULL
117792 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
117793 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
117794 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
117795 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
117796 +mpeg_read_6708 mpeg_read 3 6708 NULL
117797 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
117798 +check_clk_sync_6717 check_clk_sync 2 6717 NULL
117799 +video_proc_write_6724 video_proc_write 3 6724 NULL
117800 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
117801 +inet_recv_error_6744 inet_recv_error 3 6744 NULL
117802 +kobject_add_varg_6781 kobject_add_varg 0 6781 NULL
117803 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
117804 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
117805 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
117806 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
117807 +ll_xattr_cache_find_6798 ll_xattr_cache_find 0 6798 NULL
117808 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
117809 +rounded_hashtable_size_6802 rounded_hashtable_size 0 6802 NULL
117810 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
117811 +calc_pages_for_6838 calc_pages_for 0-1-2 6838 NULL
117812 +blk_alloc_flush_queue_6839 blk_alloc_flush_queue 3 6839 NULL
117813 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
117814 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
117815 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
117816 +dio_complete_6879 dio_complete 0-3-2 6879 NULL
117817 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
117818 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
117819 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
117820 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
117821 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
117822 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
117823 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
117824 +do_msgrcv_6921 do_msgrcv 3 6921 NULL
117825 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
117826 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
117827 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
117828 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
117829 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
117830 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 NULL nohasharray
117831 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 &i40e_dbg_dump_write_6973
117832 +lustre_pack_reply_6982 lustre_pack_reply 2 6982 NULL
117833 +request_key_async_6990 request_key_async 4 6990 NULL
117834 +tpl_write_6998 tpl_write 3 6998 NULL
117835 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
117836 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
117837 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
117838 +wimax_msg_7030 wimax_msg 4 7030 NULL
117839 +ceph_kvmalloc_7033 ceph_kvmalloc 1 7033 NULL
117840 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
117841 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
117842 +nouveau_device_create__7063 nouveau_device_create_ 7 7063 NULL
117843 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
117844 +event_enable_read_7074 event_enable_read 3 7074 NULL
117845 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL nohasharray
117846 +tipc_send_packet_7091 tipc_send_packet 4 7091 &beacon_interval_read_7091
117847 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
117848 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
117849 +qib_format_hwerrors_7133 qib_format_hwerrors 5 7133 NULL
117850 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
117851 +qlcnic_enable_msix_7144 qlcnic_enable_msix 2 7144 NULL
117852 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
117853 +hdlc_loop_7255 hdlc_loop 0 7255 NULL
117854 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL nohasharray
117855 +kimage_alloc_init_7282 kimage_alloc_init 3 7282 &rx_rate_rx_frames_per_rates_read_7282
117856 +get_string_7302 get_string 0 7302 NULL
117857 +pci_vpd_info_field_size_7324 pci_vpd_info_field_size 0 7324 NULL
117858 +mgmt_control_7349 mgmt_control 3 7349 NULL
117859 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
117860 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
117861 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
117862 +hweight_long_7388 hweight_long 0-1 7388 NULL
117863 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
117864 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
117865 +audmux_read_file_7400 audmux_read_file 3 7400 NULL
117866 +readb_7401 readb 0 7401 NULL
117867 +tipc_recvmsg_7402 tipc_recvmsg 4 7402 NULL
117868 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
117869 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
117870 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
117871 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
117872 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
117873 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
117874 +garp_request_join_7471 garp_request_join 4 7471 NULL nohasharray
117875 +ReadHSCX_7471 ReadHSCX 0 7471 &garp_request_join_7471
117876 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
117877 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
117878 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
117879 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
117880 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
117881 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
117882 +netvsc_get_slots_7565 netvsc_get_slots 0 7565 NULL
117883 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
117884 +groups_alloc_7614 groups_alloc 1 7614 NULL nohasharray
117885 +create_dir_7614 create_dir 0 7614 &groups_alloc_7614
117886 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
117887 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
117888 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
117889 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
117890 +dev_write_7708 dev_write 3 7708 NULL
117891 +pci_raw_set_power_state_7729 pci_raw_set_power_state 0 7729 NULL
117892 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
117893 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
117894 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
117895 +__videobuf_read_start_7782 __videobuf_read_start 0 7782 NULL
117896 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
117897 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
117898 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL nohasharray
117899 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 &diva_os_copy_from_user_7792
117900 +seq_buf_alloc_7828 seq_buf_alloc 1 7828 NULL
117901 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
117902 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
117903 +config_desc_7878 config_desc 0 7878 NULL
117904 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
117905 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
117906 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
117907 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
117908 +integrity_digsig_verify_7956 integrity_digsig_verify 3 7956 NULL
117909 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
117910 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
117911 +vcs_read_8017 vcs_read 3 8017 NULL
117912 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
117913 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
117914 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
117915 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
117916 +venus_lookup_8121 venus_lookup 4 8121 NULL
117917 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
117918 +xfs_file_fallocate_8150 xfs_file_fallocate 3-4 8150 NULL
117919 +ufshcd_wait_for_dev_cmd_8168 ufshcd_wait_for_dev_cmd 0 8168 NULL
117920 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
117921 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
117922 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
117923 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
117924 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
117925 +play_iframe_8219 play_iframe 3 8219 NULL
117926 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
117927 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
117928 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
117929 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
117930 +init_cdev_8274 init_cdev 1 8274 NULL
117931 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
117932 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
117933 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
117934 +rtw_cfg80211_rx_action_8329 rtw_cfg80211_rx_action 3 8329 NULL
117935 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
117936 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
117937 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
117938 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
117939 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
117940 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
117941 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
117942 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
117943 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
117944 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
117945 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
117946 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
117947 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
117948 +dev_config_8506 dev_config 3 8506 NULL
117949 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
117950 +nouveau_platform_device_create__8514 nouveau_platform_device_create_ 2 8514 NULL
117951 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
117952 +user_on_off_8552 user_on_off 2 8552 NULL
117953 +profile_remove_8556 profile_remove 3 8556 NULL
117954 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
117955 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
117956 +tower_write_8580 tower_write 3 8580 NULL
117957 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
117958 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
117959 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
117960 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
117961 +fuse_send_write_pages_8636 fuse_send_write_pages 5-0 8636 NULL
117962 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
117963 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
117964 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
117965 +bpf_prog_size_8685 bpf_prog_size 0 8685 NULL
117966 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
117967 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
117968 +arcfb_write_8702 arcfb_write 3 8702 NULL
117969 +i_size_read_8703 i_size_read 0 8703 NULL nohasharray
117970 +init_header_8703 init_header 0 8703 &i_size_read_8703
117971 +ufshcd_get_tr_ocs_8706 ufshcd_get_tr_ocs 0 8706 NULL
117972 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
117973 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
117974 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
117975 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
117976 +iov_iter_zero_8748 iov_iter_zero 1 8748 NULL
117977 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
117978 +compound_order_8750 compound_order 0 8750 NULL
117979 +cfg80211_inform_bss_width_8754 cfg80211_inform_bss_width 10 8754 NULL
117980 +yurex_write_8761 yurex_write 3 8761 NULL
117981 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
117982 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
117983 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
117984 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 4-3 8785 NULL
117985 +__bitmap_weight_8796 __bitmap_weight 0-2 8796 NULL
117986 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
117987 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
117988 +ll_xattr_cache_get_8829 ll_xattr_cache_get 0 8829 NULL
117989 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
117990 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
117991 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
117992 +iwl_rx_packet_len_8854 iwl_rx_packet_len 0 8854 NULL
117993 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
117994 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
117995 +xgmac_reg_value_write_8860 xgmac_reg_value_write 3 8860 NULL
117996 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
117997 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
117998 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 NULL nohasharray
117999 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 &ab3100_get_set_reg_8890
118000 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
118001 +sysfs_merge_group_8917 sysfs_merge_group 0 8917 NULL
118002 +write_file_ani_8918 write_file_ani 3 8918 NULL
118003 +layout_commit_8926 layout_commit 3 8926 NULL
118004 +cp2112_hid_get_8933 cp2112_hid_get 4 8933 NULL
118005 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
118006 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
118007 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
118008 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
118009 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
118010 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
118011 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
118012 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
118013 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
118014 +sony_register_touchpad_8981 sony_register_touchpad 2 8981 NULL
118015 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
118016 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
118017 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
118018 +fd_ioctl_9028 fd_ioctl 3 9028 NULL
118019 +nla_put_9042 nla_put 3 9042 NULL
118020 +sta_tx_latency_stat_header_9050 sta_tx_latency_stat_header 0-3-4 9050 NULL
118021 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
118022 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
118023 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
118024 +create_queues_9088 create_queues 2-3 9088 NULL
118025 +nvkm_output_create__9091 nvkm_output_create_ 6 9091 NULL
118026 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
118027 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
118028 +gfn_to_rmap_9110 gfn_to_rmap 3-2 9110 NULL nohasharray
118029 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 &gfn_to_rmap_9110
118030 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
118031 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
118032 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
118033 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
118034 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
118035 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
118036 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
118037 +iwl_dbgfs_frame_stats_read_9211 iwl_dbgfs_frame_stats_read 3 9211 NULL
118038 +card_send_command_9215 card_send_command 3 9215 NULL
118039 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
118040 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
118041 +l2cap_create_connless_pdu_9222 l2cap_create_connless_pdu 3 9222 NULL
118042 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
118043 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
118044 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
118045 +flakey_status_9274 flakey_status 5 9274 NULL
118046 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
118047 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
118048 +__blockdev_direct_IO_9321 __blockdev_direct_IO 0-6 9321 NULL
118049 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
118050 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
118051 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
118052 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
118053 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
118054 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
118055 +read_9397 read 3 9397 NULL
118056 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
118057 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
118058 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
118059 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
118060 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
118061 +get_registers_9470 get_registers 4 9470 NULL nohasharray
118062 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 &get_registers_9470
118063 +crypt_status_9492 crypt_status 5 9492 NULL
118064 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
118065 +lp_write_9511 lp_write 3 9511 NULL
118066 +mext_calc_swap_extents_9517 mext_calc_swap_extents 4 9517 NULL
118067 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
118068 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
118069 +read_file_dma_9530 read_file_dma 3 9530 NULL
118070 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
118071 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
118072 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
118073 +fw_node_create_9559 fw_node_create 2 9559 NULL
118074 +kobj_map_9566 kobj_map 2-3 9566 NULL
118075 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
118076 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
118077 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
118078 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
118079 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
118080 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
118081 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
118082 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
118083 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
118084 +tipc_port_mcast_xmit_9663 tipc_port_mcast_xmit 4 9663 NULL
118085 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
118086 +dns_query_9676 dns_query 3 9676 NULL
118087 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
118088 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
118089 +lowpan_control_write_9699 lowpan_control_write 3 9699 NULL
118090 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
118091 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
118092 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
118093 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
118094 +parse_uac2_sample_rate_range_9718 parse_uac2_sample_rate_range 0 9718 NULL
118095 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
118096 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
118097 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
118098 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
118099 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
118100 +regmap_multi_reg_write_bypassed_9751 regmap_multi_reg_write_bypassed 3 9751 NULL nohasharray
118101 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 &regmap_multi_reg_write_bypassed_9751
118102 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
118103 +copy_page_from_iter_bvec_9767 copy_page_from_iter_bvec 0-3 9767 NULL
118104 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
118105 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
118106 +bio_alloc_map_data_9798 bio_alloc_map_data 1 9798 NULL
118107 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 NULL nohasharray
118108 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 &ieee80211_if_read_state_9813
118109 +compat_SyS_vmsplice_9828 compat_SyS_vmsplice 3 9828 NULL
118110 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
118111 +f1x_translate_sysaddr_to_cs_9868 f1x_translate_sysaddr_to_cs 2 9868 NULL
118112 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
118113 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
118114 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
118115 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 3-5 9895 NULL
118116 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
118117 +iwl_dbgfs_prph_reg_read_9928 iwl_dbgfs_prph_reg_read 3 9928 NULL
118118 +root_nfs_parse_options_9937 root_nfs_parse_options 3 9937 NULL
118119 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
118120 +read_file_misc_9948 read_file_misc 3 9948 NULL
118121 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
118122 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
118123 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
118124 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
118125 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
118126 +ceph_oloc_oid_to_pg_10003 ceph_oloc_oid_to_pg 0 10003 NULL
118127 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
118128 +asymmetric_key_generate_id_10064 asymmetric_key_generate_id 2-4 10064 NULL
118129 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
118130 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
118131 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
118132 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
118133 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
118134 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
118135 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL nohasharray
118136 +tracing_nsecs_write_10157 tracing_nsecs_write 3 10157 &rx_out_of_mem_read_10157
118137 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
118138 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
118139 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
118140 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
118141 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
118142 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
118143 +lmv_hsm_req_count_10245 lmv_hsm_req_count 0 10245 NULL
118144 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
118145 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
118146 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
118147 +nvif_object_new_10300 nvif_object_new 5 10300 NULL
118148 +read_emulate_10310 read_emulate 2-4 10310 NULL
118149 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
118150 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
118151 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
118152 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
118153 +whci_add_cap_10350 whci_add_cap 0 10350 NULL
118154 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
118155 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
118156 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
118157 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
118158 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
118159 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
118160 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
118161 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
118162 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
118163 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
118164 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
118165 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
118166 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
118167 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
118168 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
118169 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
118170 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
118171 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
118172 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
118173 +otp_read_10594 otp_read 2-4-5 10594 NULL
118174 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
118175 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
118176 +fq_alloc_node_10633 fq_alloc_node 1 10633 NULL
118177 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
118178 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
118179 +parport_write_10669 parport_write 0 10669 NULL
118180 +edge_write_10692 edge_write 4 10692 NULL
118181 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
118182 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
118183 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 NULL nohasharray
118184 +shash_async_setkey_10720 shash_async_setkey 3 10720 &pvr2_ioread_read_10720
118185 +spi_sync_10731 spi_sync 0 10731 NULL
118186 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL nohasharray
118187 +apu_get_register_10737 apu_get_register 0 10737 &sctp_getsockopt_maxseg_10737
118188 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
118189 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
118190 +rd_build_prot_space_10761 rd_build_prot_space 2-3 10761 NULL
118191 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
118192 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
118193 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
118194 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
118195 +ext4_direct_IO_10843 ext4_direct_IO 4 10843 NULL
118196 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
118197 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
118198 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
118199 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
118200 +get_scq_10897 get_scq 2 10897 NULL
118201 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
118202 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
118203 +__copy_from_user_10918 __copy_from_user 0-3 10918 NULL
118204 +kobject_add_10919 kobject_add 0 10919 NULL
118205 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
118206 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
118207 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
118208 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
118209 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
118210 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
118211 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
118212 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
118213 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
118214 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 NULL nohasharray
118215 +qlcnic_83xx_calculate_msix_vector_11063 qlcnic_83xx_calculate_msix_vector 0 11063 &insert_inline_extent_backref_11063
118216 +xfs_collapse_file_space_11075 xfs_collapse_file_space 2-3 11075 NULL
118217 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
118218 +count_argc_11083 count_argc 0 11083 NULL
118219 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
118220 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
118221 +tc90522_master_xfer_11119 tc90522_master_xfer 3 11119 NULL
118222 +page_offset_11120 page_offset 0 11120 NULL
118223 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
118224 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
118225 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 3-4 11172 NULL
118226 +copy_from_iter_iovec_11196 copy_from_iter_iovec 2 11196 NULL
118227 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
118228 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
118229 +of_irq_count_11253 of_irq_count 0 11253 NULL
118230 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
118231 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
118232 +SYSC_getrandom_11294 SYSC_getrandom 2 11294 NULL
118233 +tipc_msg_build_11304 tipc_msg_build 3-4-5 11304 NULL
118234 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
118235 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
118236 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
118237 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
118238 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
118239 +construct_key_11329 construct_key 3 11329 NULL nohasharray
118240 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
118241 +next_segment_11330 next_segment 0-2-1 11330 NULL
118242 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
118243 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
118244 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
118245 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
118246 +of_get_available_child_count_11361 of_get_available_child_count 0 11361 NULL
118247 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
118248 +tcf_register_action_11381 tcf_register_action 2 11381 NULL nohasharray
118249 +nft_value_dump_11381 nft_value_dump 3 11381 &tcf_register_action_11381
118250 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
118251 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
118252 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
118253 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
118254 +str_to_user_11411 str_to_user 2 11411 NULL
118255 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
118256 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
118257 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 NULL
118258 +trace_options_read_11419 trace_options_read 3 11419 NULL
118259 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
118260 +bttv_read_11432 bttv_read 3 11432 NULL
118261 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
118262 +ufshcd_change_queue_depth_11477 ufshcd_change_queue_depth 2 11477 NULL
118263 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL nohasharray
118264 +pci_set_power_state_11479 pci_set_power_state 0 11479 &sca3000_read_first_n_hw_rb_11479
118265 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
118266 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
118267 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
118268 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
118269 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
118270 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
118271 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
118272 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
118273 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
118274 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
118275 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
118276 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
118277 +C_SYSC_migrate_pages_11618 C_SYSC_migrate_pages 2 11618 NULL
118278 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
118279 +nla_total_size_11658 nla_total_size 0-1 11658 NULL
118280 +srpc_create_client_rpc_11664 srpc_create_client_rpc 3 11664 NULL nohasharray
118281 +slab_ksize_11664 slab_ksize 0 11664 &srpc_create_client_rpc_11664
118282 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
118283 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
118284 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
118285 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
118286 +split_11691 split 2 11691 NULL
118287 +compat_SyS_keyctl_11695 compat_SyS_keyctl 4 11695 NULL nohasharray
118288 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 &compat_SyS_keyctl_11695
118289 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
118290 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
118291 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
118292 +ieee80211_get_num_supported_channels_11768 ieee80211_get_num_supported_channels 0 11768 NULL
118293 +tipc_sendmsg_11769 tipc_sendmsg 4 11769 NULL
118294 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
118295 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
118296 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
118297 +umc_device_register_11824 umc_device_register 0 11824 NULL
118298 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
118299 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
118300 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
118301 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
118302 +pci_enable_msix_range_11852 pci_enable_msix_range 0-4 11852 NULL
118303 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
118304 +l2cap_chan_send_11878 l2cap_chan_send 3 11878 NULL
118305 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
118306 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
118307 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
118308 +ti_write_11916 ti_write 4 11916 NULL
118309 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
118310 +bitmap_remap_11929 bitmap_remap 5 11929 NULL
118311 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
118312 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
118313 +f1x_swap_interleaved_region_11970 f1x_swap_interleaved_region 0-2 11970 NULL
118314 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
118315 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
118316 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
118317 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
118318 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
118319 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
118320 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
118321 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
118322 +set_powered_12129 set_powered 4 12129 NULL
118323 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
118324 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
118325 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
118326 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
118327 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
118328 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
118329 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
118330 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
118331 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
118332 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
118333 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
118334 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
118335 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
118336 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
118337 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
118338 +usnic_ib_qp_grp_dump_rows_12239 usnic_ib_qp_grp_dump_rows 3 12239 NULL
118339 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
118340 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
118341 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
118342 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
118343 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
118344 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
118345 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
118346 +usnic_transport_sock_to_str_12322 usnic_transport_sock_to_str 2-0 12322 NULL
118347 +ufshcd_copy_query_response_12324 ufshcd_copy_query_response 0 12324 NULL
118348 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
118349 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
118350 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
118351 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
118352 +write_file_dump_12391 write_file_dump 3 12391 NULL nohasharray
118353 +btrfs_file_extent_ram_bytes_12391 btrfs_file_extent_ram_bytes 0 12391 &write_file_dump_12391 nohasharray
118354 +populate_dir_12391 populate_dir 0 12391 &btrfs_file_extent_ram_bytes_12391
118355 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
118356 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
118357 +cfs_array_alloc_12441 cfs_array_alloc 1-2 12441 NULL
118358 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
118359 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
118360 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
118361 +__ceph_osdc_start_request_12502 __ceph_osdc_start_request 0 12502 NULL
118362 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
118363 +nvkm_event_init_12565 nvkm_event_init 3-2 12565 NULL
118364 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
118365 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
118366 +_iwl_dbgfs_prph_reg_write_12597 _iwl_dbgfs_prph_reg_write 3 12597 NULL
118367 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
118368 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
118369 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
118370 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
118371 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
118372 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
118373 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
118374 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
118375 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
118376 +lustre_pack_request_v2_12665 lustre_pack_request_v2 2 12665 NULL
118377 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
118378 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
118379 +ext4_writepage_trans_blocks_12674 ext4_writepage_trans_blocks 0 12674 NULL
118380 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
118381 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
118382 +ivtv_write_12721 ivtv_write 3 12721 NULL
118383 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
118384 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
118385 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
118386 +listxattr_12769 listxattr 3 12769 NULL
118387 +sctp_ssnmap_init_12772 sctp_ssnmap_init 2-3 12772 NULL
118388 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
118389 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
118390 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
118391 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
118392 +spidev_sync_12842 spidev_sync 0 12842 NULL
118393 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
118394 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
118395 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
118396 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
118397 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
118398 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
118399 +bm_status_write_12964 bm_status_write 3 12964 NULL
118400 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
118401 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
118402 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
118403 +bset_prev_bytes_13020 bset_prev_bytes 0 13020 NULL
118404 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
118405 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
118406 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
118407 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
118408 +ufshcd_compose_upiu_13076 ufshcd_compose_upiu 0 13076 NULL
118409 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
118410 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
118411 +SyS_msgrcv_13109 SyS_msgrcv 3 13109 NULL
118412 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
118413 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
118414 +blk_update_request_13146 blk_update_request 3 13146 NULL
118415 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
118416 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
118417 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
118418 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
118419 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
118420 +comedi_read_13199 comedi_read 3 13199 NULL
118421 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
118422 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
118423 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
118424 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
118425 +_iwl_dbgfs_disable_power_off_write_13243 _iwl_dbgfs_disable_power_off_write 3 13243 NULL
118426 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
118427 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
118428 +bio_integrity_trim_13259 bio_integrity_trim 3-2 13259 NULL
118429 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
118430 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
118431 +nvkm_ltc_create__13275 nvkm_ltc_create_ 4 13275 NULL
118432 +il4965_stats_flag_13281 il4965_stats_flag 0-3 13281 NULL
118433 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
118434 +nvkm_i2c_pad_create__13292 nvkm_i2c_pad_create_ 5 13292 NULL
118435 +sd_major_13294 sd_major 0-1 13294 NULL
118436 +read_file_phy_err_13318 read_file_phy_err 3 13318 NULL
118437 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
118438 +round_event_name_len_13348 round_event_name_len 0 13348 NULL
118439 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
118440 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
118441 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
118442 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
118443 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
118444 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
118445 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
118446 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
118447 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
118448 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
118449 +data_read_13494 data_read 3 13494 NULL nohasharray
118450 +ext_prop_data_store_13494 ext_prop_data_store 3 13494 &data_read_13494
118451 +ocfs2_align_bytes_to_blocks_13512 ocfs2_align_bytes_to_blocks 0-2 13512 NULL
118452 +core_status_13515 core_status 4 13515 NULL
118453 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
118454 +bm_init_13529 bm_init 2 13529 NULL
118455 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
118456 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
118457 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
118458 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
118459 +cache_write_13589 cache_write 3 13589 NULL
118460 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
118461 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
118462 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
118463 +packet_snd_13634 packet_snd 3 13634 NULL
118464 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
118465 +cache_downcall_13666 cache_downcall 3 13666 NULL
118466 +usb_get_string_13693 usb_get_string 0 13693 NULL
118467 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
118468 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
118469 +udf_direct_IO_13765 udf_direct_IO 4 13765 NULL
118470 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
118471 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
118472 +alloc_indirect_13783 alloc_indirect 1 13783 NULL
118473 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
118474 +random_read_13815 random_read 3 13815 NULL
118475 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
118476 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
118477 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
118478 +qce_ahash_hmac_setkey_13837 qce_ahash_hmac_setkey 3 13837 NULL
118479 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
118480 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
118481 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
118482 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
118483 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
118484 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
118485 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
118486 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
118487 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
118488 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
118489 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
118490 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
118491 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
118492 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
118493 +qcam_read_13977 qcam_read 3 13977 NULL
118494 +dsp_read_13980 dsp_read 2 13980 NULL
118495 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
118496 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
118497 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
118498 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
118499 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
118500 +pci_add_ext_cap_save_buffer_14032 pci_add_ext_cap_save_buffer 3 14032 NULL
118501 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
118502 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
118503 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
118504 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
118505 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
118506 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
118507 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
118508 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
118509 +em_canid_change_14150 em_canid_change 3 14150 NULL
118510 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
118511 +midi_alloc_ep_req_14159 midi_alloc_ep_req 2 14159 NULL
118512 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
118513 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
118514 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
118515 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
118516 +alloc_async_14208 alloc_async 1 14208 NULL
118517 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
118518 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
118519 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
118520 +btrfs_token_file_extent_ram_bytes_14247 btrfs_token_file_extent_ram_bytes 0 14247 NULL
118521 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
118522 +rr_status_14293 rr_status 5 14293 NULL
118523 +read_default_ldt_14302 read_default_ldt 2 14302 NULL nohasharray
118524 +lustre_pack_reply_flags_14302 lustre_pack_reply_flags 2 14302 &read_default_ldt_14302
118525 +oo_objects_14319 oo_objects 0 14319 NULL
118526 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
118527 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
118528 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
118529 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
118530 +lowpan_read_14369 lowpan_read 3 14369 NULL
118531 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
118532 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
118533 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
118534 +get_kcore_size_14425 get_kcore_size 0 14425 NULL
118535 +_iwl_dbgfs_sram_write_14439 _iwl_dbgfs_sram_write 3 14439 NULL
118536 +block_size_14443 block_size 0 14443 NULL
118537 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
118538 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
118539 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
118540 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0-1 14470 NULL
118541 +dma_transfer_size_14473 dma_transfer_size 0 14473 NULL
118542 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
118543 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
118544 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
118545 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 NULL nohasharray
118546 +ep0_write_14536 ep0_write 3 14536 &dataflash_read_user_otp_14536
118547 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
118548 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
118549 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
118550 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
118551 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
118552 +ufshcd_compose_dev_cmd_14626 ufshcd_compose_dev_cmd 0 14626 NULL
118553 +dbJoin_14644 dbJoin 0 14644 NULL
118554 +profile_replace_14652 profile_replace 3 14652 NULL
118555 +usnic_vnic_dump_14662 usnic_vnic_dump 3 14662 NULL
118556 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
118557 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
118558 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
118559 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
118560 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
118561 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
118562 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
118563 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
118564 +vfd_write_14717 vfd_write 3 14717 NULL
118565 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
118566 +raid1_resize_14740 raid1_resize 2 14740 NULL
118567 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
118568 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
118569 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
118570 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
118571 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
118572 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
118573 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
118574 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL nohasharray
118575 +ttm_page_pool_free_14797 ttm_page_pool_free 2-0 14797 &__kfifo_in_14797
118576 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
118577 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
118578 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
118579 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
118580 +lcd_write_14857 lcd_write 3 14857 NULL
118581 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
118582 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
118583 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
118584 +netlbl_catmap_walk_14902 netlbl_catmap_walk 0-2 14902 NULL
118585 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
118586 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923 nohasharray
118587 +ptlrpc_prep_req_pool_14923 ptlrpc_prep_req_pool 4 14923 &qp_memcpy_to_queue_iov_14923
118588 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
118589 +queue_cnt_14951 queue_cnt 0 14951 NULL
118590 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
118591 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
118592 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
118593 +setkey_14987 setkey 3 14987 NULL nohasharray
118594 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
118595 +sctp_setsockopt_default_sndinfo_15011 sctp_setsockopt_default_sndinfo 3 15011 NULL
118596 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
118597 +read_file_node_aggr_15040 read_file_node_aggr 3 15040 NULL
118598 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
118599 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
118600 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
118601 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5-0 15072 NULL
118602 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
118603 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
118604 +compat_SyS_pwritev_15118 compat_SyS_pwritev 3 15118 NULL
118605 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
118606 +start_port_15124 start_port 0 15124 NULL
118607 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
118608 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
118609 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
118610 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
118611 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
118612 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
118613 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
118614 +wacom_led_putimage_15264 wacom_led_putimage 4 15264 NULL
118615 +simple_strtol_15273 simple_strtol 0 15273 NULL
118616 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
118617 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
118618 +ioread16_15342 ioread16 0 15342 NULL
118619 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
118620 +blkdev_readpages_15357 blkdev_readpages 4 15357 NULL
118621 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
118622 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
118623 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
118624 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
118625 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
118626 +get_modalias_15406 get_modalias 2 15406 NULL
118627 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
118628 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 2-0 15438 NULL
118629 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
118630 +memweight_15450 memweight 2 15450 NULL
118631 +__clone_and_map_data_bio_15498 __clone_and_map_data_bio 3 15498 NULL
118632 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
118633 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
118634 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
118635 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
118636 +persistent_status_15574 persistent_status 4 15574 NULL
118637 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
118638 +vme_user_write_15587 vme_user_write 3 15587 NULL
118639 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
118640 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
118641 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
118642 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642 nohasharray
118643 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &pipeline_hs_tx_stat_fifo_int_read_15642
118644 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
118645 +fs_path_add_15648 fs_path_add 3 15648 NULL
118646 +xsd_read_15653 xsd_read 3 15653 NULL
118647 +unix_bind_15668 unix_bind 3 15668 NULL
118648 +dm_read_15674 dm_read 3 15674 NULL nohasharray
118649 +SyS_connect_15674 SyS_connect 3 15674 &dm_read_15674
118650 +uinput_str_to_user_15695 uinput_str_to_user 3 15695 NULL
118651 +__sk_migrate_realloc_15709 __sk_migrate_realloc 3 15709 NULL
118652 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
118653 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
118654 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
118655 +gnttab_expand_15817 gnttab_expand 1 15817 NULL nohasharray
118656 +nameseq_list_15817 nameseq_list 3-0 15817 &gnttab_expand_15817
118657 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
118658 +table_size_15851 table_size 0-1-2 15851 NULL
118659 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
118660 +media_entity_init_15870 media_entity_init 2-4 15870 NULL
118661 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
118662 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
118663 +power_read_15939 power_read 3 15939 NULL
118664 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
118665 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
118666 +memblock_virt_alloc_try_nid_15954 memblock_virt_alloc_try_nid 1 15954 NULL
118667 +smk_read_ptrace_15974 smk_read_ptrace 3 15974 NULL
118668 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
118669 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
118670 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
118671 +SYSC_kexec_file_load_16058 SYSC_kexec_file_load 3 16058 NULL
118672 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
118673 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
118674 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
118675 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
118676 +udelay_test_write_16111 udelay_test_write 3 16111 NULL
118677 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
118678 +fsm_init_16134 fsm_init 2 16134 NULL
118679 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
118680 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
118681 +mapping_level_16188 mapping_level 2-0 16188 NULL
118682 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
118683 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
118684 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
118685 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
118686 +create_table_16213 create_table 2 16213 NULL
118687 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
118688 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
118689 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
118690 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
118691 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 NULL
118692 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
118693 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
118694 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
118695 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
118696 +nand_bch_init_16280 nand_bch_init 3-2 16280 NULL nohasharray
118697 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 &nand_bch_init_16280
118698 +account_16283 account 0-4-2 16283 NULL nohasharray
118699 +mirror_status_16283 mirror_status 5 16283 &account_16283
118700 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
118701 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
118702 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
118703 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
118704 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
118705 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
118706 +sysfs_create_groups_16360 sysfs_create_groups 0 16360 NULL
118707 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
118708 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
118709 +nv50_pioc_create_16389 nv50_pioc_create 5 16389 NULL
118710 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
118711 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
118712 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
118713 +cmdline_store_16442 cmdline_store 4 16442 NULL
118714 +copy_from_user_bvec_16447 copy_from_user_bvec 0-4 16447 NULL
118715 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
118716 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
118717 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
118718 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
118719 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
118720 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
118721 +raid10_resize_16537 raid10_resize 2 16537 NULL
118722 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
118723 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
118724 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0-1 16589 NULL
118725 +compat_SyS_migrate_pages_16618 compat_SyS_migrate_pages 2 16618 NULL
118726 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
118727 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
118728 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
118729 +_iwl_dbgfs_bt_force_ant_write_16701 _iwl_dbgfs_bt_force_ant_write 3 16701 NULL
118730 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
118731 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
118732 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
118733 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
118734 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
118735 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
118736 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
118737 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
118738 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
118739 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL
118740 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
118741 +st_write_16874 st_write 3 16874 NULL
118742 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
118743 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
118744 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
118745 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
118746 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
118747 +svcxdr_dupstr_16963 svcxdr_dupstr 3 16963 NULL
118748 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
118749 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
118750 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
118751 +C_SYSC_keyctl_17041 C_SYSC_keyctl 4 17041 NULL
118752 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
118753 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
118754 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
118755 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
118756 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
118757 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
118758 +entry_length_17093 entry_length 0 17093 NULL
118759 +write_mem_17114 write_mem 3 17114 NULL
118760 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
118761 +do_blockdev_direct_IO_17143 do_blockdev_direct_IO 0-6 17143 NULL
118762 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
118763 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
118764 +mxt_upload_cfg_mem_17157 mxt_upload_cfg_mem 4 17157 NULL
118765 +sep_read_17161 sep_read 3 17161 NULL
118766 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
118767 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
118768 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
118769 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
118770 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189
118771 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
118772 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
118773 +sync_request_17208 sync_request 2 17208 NULL
118774 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
118775 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
118776 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
118777 +alloc_ep_17269 alloc_ep 1 17269 NULL
118778 +pg_read_17276 pg_read 3 17276 NULL
118779 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
118780 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
118781 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
118782 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
118783 +__ptlrpc_request_bufs_pack_17298 __ptlrpc_request_bufs_pack 4 17298 NULL
118784 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
118785 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
118786 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
118787 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
118788 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
118789 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
118790 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
118791 +copy_from_iter_17433 copy_from_iter 2 17433 NULL
118792 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
118793 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
118794 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
118795 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
118796 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
118797 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
118798 +copy_page_from_iter_17512 copy_page_from_iter 3-0 17512 NULL
118799 +reiserfs_direct_IO_17513 reiserfs_direct_IO 4 17513 NULL
118800 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
118801 +qp_free_res_17541 qp_free_res 5 17541 NULL
118802 +__copy_to_user_17551 __copy_to_user 0-3 17551 NULL
118803 +copy_from_user_17559 copy_from_user 3-0 17559 NULL
118804 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
118805 +wil_write_file_rxon_17581 wil_write_file_rxon 3 17581 NULL
118806 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
118807 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
118808 +osst_execute_17607 osst_execute 7-6 17607 NULL
118809 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
118810 +dma_map_page_17628 dma_map_page 0 17628 NULL
118811 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
118812 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
118813 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
118814 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
118815 +venus_rename_17707 venus_rename 4-5 17707 NULL
118816 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
118817 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
118818 +nv92_gpio_intr_mask_17773 nv92_gpio_intr_mask 4-3 17773 NULL
118819 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
118820 +lpuart_copy_rx_to_tty_17801 lpuart_copy_rx_to_tty 3 17801 NULL
118821 +_iwl_dbgfs_set_nic_temperature_write_17804 _iwl_dbgfs_set_nic_temperature_write 3 17804 NULL
118822 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
118823 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
118824 +em28xx_audio_ep_packet_size_17844 em28xx_audio_ep_packet_size 0 17844 NULL
118825 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
118826 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
118827 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
118828 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
118829 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
118830 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
118831 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
118832 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
118833 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
118834 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
118835 +dev_pm_opp_get_opp_count_17911 dev_pm_opp_get_opp_count 0 17911 NULL
118836 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
118837 +tipc_port_iovec_rcv_17921 tipc_port_iovec_rcv 3 17921 NULL
118838 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
118839 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
118840 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
118841 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
118842 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
118843 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
118844 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
118845 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
118846 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
118847 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
118848 +__btrfs_drop_extents_18049 __btrfs_drop_extents 5 18049 NULL
118849 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
118850 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
118851 +fpregs_get_18066 fpregs_get 4 18066 NULL
118852 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
118853 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
118854 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
118855 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
118856 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
118857 +svc_getnl_18120 svc_getnl 0 18120 NULL
118858 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
118859 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
118860 +enable_ints_write_18170 enable_ints_write 3 18170 NULL
118861 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
118862 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
118863 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
118864 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
118865 +fill_ext_prop_18233 fill_ext_prop 0 18233 NULL
118866 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
118867 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
118868 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
118869 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
118870 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
118871 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
118872 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
118873 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
118874 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
118875 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
118876 +um_idi_write_18293 um_idi_write 3 18293 NULL
118877 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
118878 +lustre_msg_hdr_size_18308 lustre_msg_hdr_size 2 18308 NULL
118879 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
118880 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
118881 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
118882 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
118883 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
118884 +copy_page_to_iter_18345 copy_page_to_iter 0-3 18345 NULL
118885 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
118886 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
118887 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
118888 +ep_io_18367 ep_io 0 18367 NULL
118889 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
118890 +__ceph_getxattr_18386 __ceph_getxattr 0 18386 NULL
118891 +ci_role_write_18388 ci_role_write 3 18388 NULL
118892 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
118893 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
118894 +nvif_device_init_18418 nvif_device_init 6 18418 NULL
118895 +memblock_virt_alloc_node_nopanic_18431 memblock_virt_alloc_node_nopanic 1 18431 NULL
118896 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
118897 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
118898 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
118899 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
118900 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL nohasharray
118901 +mite_bytes_in_transit_18479 mite_bytes_in_transit 0 18479 &pci_vpd_lrdt_size_18479
118902 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
118903 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
118904 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
118905 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
118906 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
118907 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
118908 +tipc_send2port_18531 tipc_send2port 4 18531 NULL
118909 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
118910 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
118911 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
118912 +debug_output_18575 debug_output 3 18575 NULL
118913 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL nohasharray
118914 +slabinfo_write_18600 slabinfo_write 3 18600 &filemap_fdatawait_range_18600
118915 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
118916 +from_buffer_18625 from_buffer 3 18625 NULL
118917 +kmalloc_kernel_18641 kmalloc_kernel 1 18641 NULL
118918 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
118919 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
118920 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
118921 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
118922 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
118923 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
118924 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
118925 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
118926 +nfs4_init_callback_netid_18717 nfs4_init_callback_netid 3 18717 NULL
118927 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
118928 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
118929 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
118930 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
118931 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
118932 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
118933 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
118934 +fence_context_alloc_18792 fence_context_alloc 1 18792 NULL
118935 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
118936 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
118937 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
118938 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
118939 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
118940 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
118941 +devm_mdiobus_alloc_size_18902 devm_mdiobus_alloc_size 2 18902 NULL
118942 +tracing_thresh_write_18909 tracing_thresh_write 3 18909 NULL
118943 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
118944 +xfs_buf_read_uncached_18922 xfs_buf_read_uncached 3 18922 NULL
118945 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
118946 +snapshot_write_next_18937 snapshot_write_next 0 18937 NULL
118947 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
118948 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
118949 +huge_page_size_19008 huge_page_size 0 19008 NULL
118950 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
118951 +sysfs_create_dir_ns_19033 sysfs_create_dir_ns 0 19033 NULL
118952 +revalidate_19043 revalidate 2 19043 NULL
118953 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
118954 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL
118955 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
118956 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
118957 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
118958 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
118959 +skb_gro_offset_19123 skb_gro_offset 0 19123 NULL
118960 +cma_bitmap_maxno_19135 cma_bitmap_maxno 0 19135 NULL
118961 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
118962 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
118963 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
118964 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
118965 +read_extent_buffer_to_user_19189 read_extent_buffer_to_user 4-3 19189 NULL
118966 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
118967 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 0-3 19214 NULL
118968 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
118969 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
118970 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
118971 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
118972 +ucma_query_19260 ucma_query 4 19260 NULL
118973 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
118974 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
118975 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
118976 +qc_capture_19298 qc_capture 3 19298 NULL
118977 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 4-3 19303 NULL
118978 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
118979 +debug_read_19322 debug_read 3 19322 NULL
118980 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 NULL nohasharray
118981 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 &lbs_host_sleep_write_19332
118982 +closure_sub_19359 closure_sub 2 19359 NULL
118983 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
118984 +read_zero_19366 read_zero 3 19366 NULL
118985 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
118986 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
118987 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
118988 +hid_hw_raw_request_19408 hid_hw_raw_request 0 19408 NULL
118989 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
118990 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
118991 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
118992 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
118993 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
118994 +sky2_read16_19475 sky2_read16 0 19475 NULL
118995 +__read_status_pciv2_19492 __read_status_pciv2 0 19492 NULL
118996 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
118997 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
118998 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
118999 +ttm_dma_page_pool_free_19527 ttm_dma_page_pool_free 2-0 19527 NULL
119000 +cfc_write_array_to_buffer_19529 cfc_write_array_to_buffer 3 19529 NULL
119001 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
119002 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
119003 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
119004 +nfsd_read_19568 nfsd_read 5 19568 NULL
119005 +ieee80211_key_alloc_19575 ieee80211_key_alloc 3 19575 NULL
119006 +bm_status_read_19583 bm_status_read 3 19583 NULL
119007 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
119008 +drbg_sec_strength_19604 drbg_sec_strength 0 19604 NULL
119009 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
119010 +parser_init_19651 parser_init 2 19651 NULL
119011 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
119012 +memblock_virt_alloc_low_nopanic_19714 memblock_virt_alloc_low_nopanic 1 19714 NULL
119013 +read_reg_19723 read_reg 0 19723 NULL
119014 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
119015 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
119016 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
119017 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
119018 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
119019 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
119020 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
119021 +readhscx_19769 readhscx 0 19769 NULL
119022 +ath10k_write_htt_max_amsdu_ampdu_19820 ath10k_write_htt_max_amsdu_ampdu 3 19820 NULL
119023 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
119024 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
119025 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
119026 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
119027 +__nla_put_19857 __nla_put 3 19857 NULL
119028 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
119029 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
119030 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
119031 +mangle_name_19923 mangle_name 0 19923 NULL
119032 +tipc_sk_show_19928 tipc_sk_show 3-0 19928 NULL
119033 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
119034 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
119035 +azx_get_pos_lpib_19933 azx_get_pos_lpib 0 19933 NULL
119036 +v4l2_ctrl_new_19942 v4l2_ctrl_new 8-12 19942 NULL
119037 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
119038 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
119039 +ll_xattr_cache_list_19954 ll_xattr_cache_list 0 19954 NULL
119040 +get_jack_mode_name_19976 get_jack_mode_name 4 19976 NULL
119041 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
119042 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL nohasharray
119043 +i40e_reserve_msix_vectors_19989 i40e_reserve_msix_vectors 2 19989 &rtw_set_wps_probe_resp_19989
119044 +lustre_pack_request_19992 lustre_pack_request 3 19992 NULL
119045 +find_overflow_devnum_19995 find_overflow_devnum 0 19995 NULL
119046 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
119047 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 NULL nohasharray
119048 +event_trigger_write_20009 event_trigger_write 3 20009 &lov_stripe_md_size_20009
119049 +tree_mod_log_eb_move_20011 tree_mod_log_eb_move 5 20011 NULL
119050 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
119051 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
119052 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 0-4 20067 NULL
119053 +target_message_20072 target_message 2 20072 NULL
119054 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
119055 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
119056 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
119057 +team_options_register_20091 team_options_register 3 20091 NULL
119058 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
119059 +root_nfs_copy_20111 root_nfs_copy 3 20111 NULL
119060 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
119061 +ext4_ext_direct_IO_20165 ext4_ext_direct_IO 4 20165 NULL
119062 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
119063 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
119064 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
119065 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
119066 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
119067 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
119068 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
119069 +btrfs_header_nritems_20296 btrfs_header_nritems 0 20296 NULL
119070 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
119071 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
119072 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
119073 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
119074 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
119075 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
119076 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
119077 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
119078 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL
119079 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 NULL nohasharray
119080 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 &SyS_get_mempolicy_20399
119081 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
119082 +read_buf_20469 read_buf 2 20469 NULL
119083 +bio_trim_20472 bio_trim 2 20472 NULL
119084 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
119085 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
119086 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
119087 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
119088 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
119089 +venus_create_20555 venus_create 4 20555 NULL
119090 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
119091 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
119092 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
119093 +set_secure_conn_20596 set_secure_conn 4 20596 NULL
119094 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
119095 +lirc_write_20604 lirc_write 3 20604 NULL
119096 +qib_qsfp_write_20614 qib_qsfp_write 0-4-2 20614 NULL
119097 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
119098 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
119099 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3-4 20646 NULL
119100 +cpulist_scnprintf_20648 cpulist_scnprintf 2-0 20648 NULL
119101 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
119102 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
119103 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
119104 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
119105 +cpumask_size_20683 cpumask_size 0 20683 NULL
119106 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
119107 +xpcs_reg_addr_write_20694 xpcs_reg_addr_write 3 20694 NULL
119108 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
119109 +__maestro_read_20700 __maestro_read 0 20700 NULL
119110 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
119111 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
119112 +hfs_direct_IO_20714 hfs_direct_IO 4 20714 NULL
119113 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
119114 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
119115 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
119116 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
119117 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
119118 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL
119119 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
119120 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
119121 +edid_write_20797 edid_write 3 20797 NULL
119122 +lowpan_write_20800 lowpan_write 3 20800 NULL
119123 +strndup_user_20819 strndup_user 2 20819 NULL
119124 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
119125 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
119126 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
119127 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
119128 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
119129 +get_name_20855 get_name 4 20855 NULL
119130 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
119131 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
119132 +srq_free_res_20868 srq_free_res 5 20868 NULL
119133 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
119134 +req_capsule_filled_sizes_20888 req_capsule_filled_sizes 0 20888 NULL
119135 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
119136 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
119137 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
119138 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
119139 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
119140 +htable_bits_20933 htable_bits 0 20933 NULL
119141 +cfg80211_rx_assoc_resp_20934 cfg80211_rx_assoc_resp 4 20934 NULL
119142 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
119143 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
119144 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
119145 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
119146 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
119147 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
119148 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
119149 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
119150 +arch_gnttab_init_21030 arch_gnttab_init 1 21030 NULL
119151 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
119152 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
119153 +fsl_edma_prep_dma_cyclic_21042 fsl_edma_prep_dma_cyclic 4-3 21042 NULL
119154 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
119155 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
119156 +qdisc_get_default_21072 qdisc_get_default 2 21072 NULL
119157 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
119158 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
119159 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
119160 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
119161 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
119162 +_efx_mcdi_rpc_async_21119 _efx_mcdi_rpc_async 4-5 21119 NULL
119163 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
119164 +mei_dbgfs_read_active_21172 mei_dbgfs_read_active 3 21172 NULL
119165 +bioset_create_nobvec_21180 bioset_create_nobvec 1 21180 NULL
119166 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
119167 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
119168 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
119169 +get_numpages_21227 get_numpages 0-1-2 21227 NULL
119170 +input_ff_create_21240 input_ff_create 2 21240 NULL
119171 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
119172 +fru_length_21257 fru_length 0 21257 NULL
119173 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
119174 +ocfs2_blocks_for_bytes_21268 ocfs2_blocks_for_bytes 0-2 21268 NULL
119175 +drm_universal_plane_init_21296 drm_universal_plane_init 6 21296 NULL
119176 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
119177 +add_res_range_21310 add_res_range 4 21310 NULL
119178 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
119179 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
119180 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
119181 +azx_get_delay_from_lpib_21348 azx_get_delay_from_lpib 3 21348 NULL
119182 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
119183 +allocate_cmdlines_buffer_21355 allocate_cmdlines_buffer 1 21355 NULL
119184 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
119185 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
119186 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
119187 +insert_ptr_21386 insert_ptr 6 21386 NULL
119188 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
119189 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
119190 +usnic_ib_dump_vf_hdr_21423 usnic_ib_dump_vf_hdr 3 21423 NULL
119191 +snapshot_read_next_21426 snapshot_read_next 0 21426 NULL
119192 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
119193 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
119194 +nouveau_clock_create__21449 nouveau_clock_create_ 8 21449 NULL
119195 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
119196 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
119197 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
119198 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
119199 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
119200 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
119201 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
119202 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
119203 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
119204 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
119205 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
119206 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
119207 +ocfs2_refcount_cow_hunk_21630 ocfs2_refcount_cow_hunk 3-4 21630 NULL
119208 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
119209 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
119210 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
119211 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
119212 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL nohasharray
119213 +proc_maps_open_21687 proc_maps_open 4 21687 &rtllib_alloc_txb_21687
119214 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
119215 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
119216 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
119217 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
119218 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
119219 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
119220 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
119221 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
119222 +_iwl_dbgfs_sta_drain_write_21837 _iwl_dbgfs_sta_drain_write 3 21837 NULL
119223 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
119224 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
119225 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
119226 +msix_capability_init_21870 msix_capability_init 0 21870 NULL
119227 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
119228 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
119229 +__btrfs_direct_write_21894 __btrfs_direct_write 3 21894 NULL
119230 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL nohasharray
119231 +nvme_submit_sync_cmd_21911 nvme_submit_sync_cmd 0 21911 &dbAllocCtl_21911
119232 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
119233 +twl_i2c_write_u16_21953 twl_i2c_write_u16 3 21953 NULL
119234 +__build_xattrs_21979 __build_xattrs 0 21979 NULL
119235 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
119236 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 0-3 22001 NULL nohasharray
119237 +rxpipe_descr_host_int_trig_rx_data_read_22001 rxpipe_descr_host_int_trig_rx_data_read 3 22001 &compat_rw_copy_check_uvector_22001
119238 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
119239 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
119240 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
119241 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
119242 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
119243 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
119244 +mem_rw_22085 mem_rw 3 22085 NULL
119245 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
119246 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
119247 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
119248 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
119249 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
119250 +nve0_aux_mask_22158 nve0_aux_mask 2 22158 NULL
119251 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
119252 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
119253 +mem_write_22232 mem_write 3 22232 NULL
119254 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
119255 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
119256 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
119257 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
119258 +add_res_tree_22263 add_res_tree 7 22263 NULL
119259 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
119260 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL nohasharray
119261 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 &__tun_chr_ioctl_22300
119262 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
119263 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
119264 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
119265 +C_SYSC_msgrcv_22320 C_SYSC_msgrcv 3 22320 NULL
119266 +atomic_read_22342 atomic_read 0 22342 NULL
119267 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
119268 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
119269 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
119270 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
119271 +zoran_write_22404 zoran_write 3 22404 NULL
119272 +queue_reply_22416 queue_reply 3 22416 NULL
119273 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
119274 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
119275 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
119276 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
119277 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL nohasharray
119278 +video_write_22490 video_write 3 22490 &qib_user_sdma_alloc_header_22490
119279 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
119280 +mutex_lock_interruptible_22505 mutex_lock_interruptible 0 22505 NULL
119281 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
119282 +ntb_setup_bwd_msix_22549 ntb_setup_bwd_msix 2 22549 NULL
119283 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
119284 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
119285 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
119286 +cfs_expr_list_values_22600 cfs_expr_list_values 0 22600 NULL
119287 +snapshot_read_22601 snapshot_read 3 22601 NULL
119288 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
119289 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
119290 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
119291 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
119292 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
119293 +compat_SyS_msgrcv_22661 compat_SyS_msgrcv 3 22661 NULL
119294 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
119295 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
119296 +reg_umr_22686 reg_umr 5 22686 NULL
119297 +SYSC_vmsplice_22697 SYSC_vmsplice 3 22697 NULL
119298 +nr_cpusets_22705 nr_cpusets 0 22705 NULL
119299 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
119300 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
119301 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
119302 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
119303 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
119304 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
119305 +print_frame_22769 print_frame 0 22769 NULL
119306 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
119307 +vnic_dev_get_res_count_22791 vnic_dev_get_res_count 0 22791 NULL
119308 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
119309 +create_attr_set_22861 create_attr_set 1 22861 NULL
119310 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
119311 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
119312 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
119313 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
119314 +ion_handle_test_kernel_22900 ion_handle_test_kernel 4-3 22900 NULL nohasharray
119315 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 &ion_handle_test_kernel_22900
119316 +nfs4_acl_bytes_22915 nfs4_acl_bytes 0-1 22915 NULL
119317 +__set_xattr_22923 __set_xattr 0 22923 NULL
119318 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
119319 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
119320 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
119321 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
119322 +vme_get_size_22964 vme_get_size 0 22964 NULL
119323 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
119324 +cached_dev_cache_miss_22979 cached_dev_cache_miss 4 22979 NULL
119325 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
119326 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
119327 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
119328 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
119329 +ocfs2_refcount_cow_xattr_23029 ocfs2_refcount_cow_xattr 6-7 23029 NULL
119330 +st_status_23032 st_status 5 23032 NULL
119331 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
119332 +comedi_buf_write_n_available_23057 comedi_buf_write_n_available 0 23057 NULL
119333 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
119334 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
119335 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
119336 +kvm_mmu_gva_to_gpa_write_23075 kvm_mmu_gva_to_gpa_write 0 23075 NULL
119337 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
119338 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
119339 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
119340 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
119341 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
119342 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
119343 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
119344 +bset_tree_bytes_23111 bset_tree_bytes 0 23111 NULL nohasharray
119345 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 &bset_tree_bytes_23111
119346 +__clear_user_23118 __clear_user 0-2 23118 NULL
119347 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
119348 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
119349 +read_file_ani_23161 read_file_ani 3 23161 NULL
119350 +usblp_write_23178 usblp_write 3 23178 NULL
119351 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
119352 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
119353 +tipc_sendmcast_23214 tipc_sendmcast 4 23214 NULL
119354 +mcryptd_alloc_instance_23221 mcryptd_alloc_instance 2-3 23221 NULL
119355 +nft_hash_tbl_alloc_23224 nft_hash_tbl_alloc 1 23224 NULL
119356 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
119357 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL nohasharray
119358 +__read_status_pci_23229 __read_status_pci 0 23229 &xlog_get_bp_23229
119359 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
119360 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
119361 +__gfn_to_rmap_23240 __gfn_to_rmap 1-2 23240 NULL
119362 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
119363 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
119364 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
119365 +ec_i2c_count_message_23285 ec_i2c_count_message 0-2 23285 NULL
119366 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
119367 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
119368 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
119369 +page_readlink_23346 page_readlink 3 23346 NULL
119370 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
119371 +get_dst_timing_23358 get_dst_timing 0 23358 NULL
119372 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
119373 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
119374 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
119375 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
119376 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
119377 +linear_conf_23485 linear_conf 2 23485 NULL
119378 +event_filter_read_23494 event_filter_read 3 23494 NULL
119379 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
119380 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
119381 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
119382 +hash_ipmark6_expire_23518 hash_ipmark6_expire 4 23518 NULL
119383 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
119384 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
119385 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
119386 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
119387 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
119388 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
119389 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
119390 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
119391 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
119392 +sInW_23663 sInW 0 23663 NULL
119393 +SyS_connect_23669 SyS_connect 3 23669 NULL
119394 +cx18_read_23699 cx18_read 3 23699 NULL
119395 +at_get_23708 at_get 0 23708 NULL
119396 +get_conn_info_23723 get_conn_info 4 23723 NULL
119397 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
119398 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
119399 +__build_packet_message_23778 __build_packet_message 4-10 23778 NULL
119400 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
119401 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
119402 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
119403 +map_write_23795 map_write 3 23795 NULL
119404 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
119405 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
119406 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
119407 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
119408 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
119409 +p54_init_common_23850 p54_init_common 1 23850 NULL
119410 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
119411 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
119412 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
119413 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
119414 +iov_iter_get_pages_alloc_23903 iov_iter_get_pages_alloc 3-0 23903 NULL
119415 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
119416 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
119417 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
119418 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
119419 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
119420 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
119421 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
119422 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
119423 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
119424 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
119425 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
119426 +xfs_zero_file_space_24000 xfs_zero_file_space 2-3 24000 NULL
119427 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
119428 +give_pages_24021 give_pages 3 24021 NULL
119429 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
119430 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
119431 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
119432 +iwl_dbgfs_low_latency_read_24062 iwl_dbgfs_low_latency_read 3 24062 NULL
119433 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
119434 +C_SYSC_process_vm_writev_24102 C_SYSC_process_vm_writev 3-5 24102 NULL
119435 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
119436 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
119437 +lov_brw_24122 lov_brw 4 24122 NULL
119438 +mpu401_read_24126 mpu401_read 3 24126 NULL
119439 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
119440 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
119441 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
119442 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
119443 +adu_read_24177 adu_read 3 24177 NULL
119444 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
119445 +nv94_aux_24197 nv94_aux 3-6 24197 NULL
119446 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
119447 +efx_vf_size_24213 efx_vf_size 0 24213 NULL
119448 +tcpprobe_sprint_24222 tcpprobe_sprint 0-2 24222 NULL
119449 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 NULL nohasharray
119450 +mei_amthif_read_24224 mei_amthif_read 4 24224 &pcpu_embed_first_chunk_24224
119451 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
119452 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
119453 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
119454 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
119455 +thin_status_24278 thin_status 5 24278 NULL
119456 +msg_size_24288 msg_size 0 24288 NULL
119457 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
119458 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
119459 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
119460 +C_SYSC_pwritev_24345 C_SYSC_pwritev 3 24345 NULL
119461 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
119462 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
119463 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
119464 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
119465 +igetword_24373 igetword 0 24373 NULL
119466 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
119467 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
119468 +getxattr_24398 getxattr 4 24398 NULL nohasharray
119469 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
119470 +populate_msi_sysfs_24399 populate_msi_sysfs 0 24399 NULL
119471 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
119472 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
119473 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
119474 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
119475 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
119476 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
119477 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
119478 +smk_user_access_24440 smk_user_access 3 24440 NULL nohasharray
119479 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 &smk_user_access_24440
119480 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
119481 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
119482 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
119483 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
119484 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
119485 +pd_video_read_24510 pd_video_read 3 24510 NULL
119486 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
119487 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
119488 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
119489 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
119490 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
119491 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
119492 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
119493 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605 nohasharray
119494 +i915_error_state_buf_init_24605 i915_error_state_buf_init 3 24605 &lov_alloc_memmd_24605
119495 +SyS_poll_24620 SyS_poll 2 24620 NULL
119496 +context_alloc_24645 context_alloc 3 24645 NULL
119497 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
119498 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
119499 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
119500 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
119501 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
119502 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
119503 +ocfs2_cow_file_pos_24751 ocfs2_cow_file_pos 3 24751 NULL
119504 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
119505 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
119506 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
119507 +cache_read_24790 cache_read 3 24790 NULL
119508 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
119509 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
119510 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
119511 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
119512 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
119513 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
119514 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
119515 +queues_read_24877 queues_read 3 24877 NULL
119516 +iov_iter_npages_bvec_24905 iov_iter_npages_bvec 0-2 24905 NULL
119517 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
119518 +xpcs_reg_value_write_24922 xpcs_reg_value_write 3 24922 NULL
119519 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
119520 +ocfs2_fiemap_24949 ocfs2_fiemap 4-3 24949 NULL
119521 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
119522 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
119523 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL nohasharray
119524 +ath10k_fw_crash_dump_read_24987 ath10k_fw_crash_dump_read 3 24987 &llc_ui_sendmsg_24987
119525 +info_debugfs_read_helper_24988 info_debugfs_read_helper 0 24988 NULL
119526 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
119527 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
119528 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
119529 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
119530 +load_unaligned_zeropad_25050 load_unaligned_zeropad 0 25050 NULL
119531 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
119532 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
119533 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
119534 +do_add_page_to_bio_25071 do_add_page_to_bio 2 25071 NULL
119535 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
119536 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
119537 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
119538 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
119539 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 NULL
119540 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
119541 +security_socket_post_create_25221 security_socket_post_create 0 25221 NULL
119542 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
119543 +stripe_status_25259 stripe_status 5 25259 NULL
119544 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
119545 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
119546 +vfs_writev_25278 vfs_writev 3 25278 NULL
119547 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
119548 +cx25821_write_frame_25315 cx25821_write_frame 3 25315 NULL
119549 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
119550 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
119551 +SYSC_kexec_load_25361 SYSC_kexec_load 2 25361 NULL
119552 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
119553 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
119554 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
119555 +mcp795_rtcc_read_25415 mcp795_rtcc_read 4 25415 NULL
119556 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
119557 +ipath_decode_err_25468 ipath_decode_err 3 25468 NULL
119558 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
119559 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
119560 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
119561 +mxt_obj_size_25510 mxt_obj_size 0 25510 NULL
119562 +sb_permission_25523 sb_permission 0 25523 NULL
119563 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
119564 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
119565 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
119566 +ht_print_chan_25556 ht_print_chan 0-3-4 25556 NULL
119567 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
119568 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
119569 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
119570 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
119571 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
119572 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
119573 +__direct_map_25647 __direct_map 6-5 25647 NULL
119574 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
119575 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
119576 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
119577 +prom_early_alloc_25692 prom_early_alloc 1 25692 NULL
119578 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
119579 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
119580 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
119581 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
119582 +xgbe_common_read_25743 xgbe_common_read 2 25743 NULL
119583 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
119584 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
119585 +sg_read_25799 sg_read 3 25799 NULL
119586 +system_enable_read_25815 system_enable_read 3 25815 NULL
119587 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
119588 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
119589 +parport_read_25855 parport_read 0 25855 NULL
119590 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
119591 +key_attr_size_25865 key_attr_size 0 25865 NULL
119592 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
119593 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
119594 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
119595 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
119596 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
119597 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
119598 +rcname_read_25919 rcname_read 3 25919 NULL
119599 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
119600 +key_flags_read_25931 key_flags_read 3 25931 NULL
119601 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
119602 +flush_25957 flush 2 25957 NULL
119603 +_regmap_multi_reg_write_25967 _regmap_multi_reg_write 3 25967 NULL
119604 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
119605 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
119606 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
119607 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
119608 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
119609 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
119610 +pri_wm_latency_write_26063 pri_wm_latency_write 3 26063 NULL
119611 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
119612 +i8042_pnp_id_to_string_26108 i8042_pnp_id_to_string 3 26108 NULL
119613 +read_sb_page_26119 read_sb_page 5 26119 NULL
119614 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
119615 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
119616 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
119617 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
119618 +disk_devt_26180 disk_devt 0 26180 NULL
119619 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
119620 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
119621 +mce_write_26201 mce_write 3 26201 NULL
119622 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
119623 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
119624 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
119625 +nlm_end_grace_read_26234 nlm_end_grace_read 3 26234 NULL
119626 +genwqe_ffdc_buff_size_26263 genwqe_ffdc_buff_size 0 26263 NULL
119627 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
119628 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
119629 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL
119630 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
119631 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
119632 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
119633 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
119634 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
119635 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
119636 +ntty_write_26404 ntty_write 3 26404 NULL
119637 +firmware_store_26408 firmware_store 4 26408 NULL
119638 +pagemap_read_26441 pagemap_read 3 26441 NULL
119639 +tower_read_26461 tower_read 3 26461 NULL nohasharray
119640 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 &tower_read_26461
119641 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
119642 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
119643 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL nohasharray
119644 +msi_verify_entries_26490 msi_verify_entries 0 26490 &dvb_ca_en50221_io_ioctl_26490
119645 +read_vmcore_26501 read_vmcore 3 26501 NULL
119646 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
119647 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
119648 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
119649 +alloc_ep_req_26521 alloc_ep_req 3-2 26521 NULL
119650 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
119651 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
119652 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
119653 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
119654 +kernfs_name_locked_26617 kernfs_name_locked 3 26617 NULL
119655 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
119656 +amdtp_stream_get_max_payload_26645 amdtp_stream_get_max_payload 0 26645 NULL
119657 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
119658 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
119659 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
119660 +flowinfo_read_26683 flowinfo_read 3 26683 NULL
119661 +sysfs_add_file_26716 sysfs_add_file 0 26716 NULL
119662 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
119663 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
119664 +bos_desc_26752 bos_desc 0 26752 NULL
119665 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
119666 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
119667 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
119668 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
119669 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
119670 +smk_write_load_26829 smk_write_load 3 26829 NULL
119671 +snd_pcm_action_mutex_26832 snd_pcm_action_mutex 0 26832 NULL
119672 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
119673 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
119674 +ss_alloc_ep_req_26848 ss_alloc_ep_req 2 26848 NULL
119675 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
119676 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
119677 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
119678 +skb_zerocopy_headlen_26910 skb_zerocopy_headlen 0 26910 NULL
119679 +hhf_zalloc_26912 hhf_zalloc 1 26912 NULL
119680 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
119681 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
119682 +brcmf_usb_dl_cmd_26931 brcmf_usb_dl_cmd 4 26931 NULL
119683 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
119684 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
119685 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
119686 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
119687 +do_trimming_26952 do_trimming 3 26952 NULL nohasharray
119688 +extract_entropy_user_26952 extract_entropy_user 3 26952 &do_trimming_26952
119689 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
119690 +lustre_msg_size_26995 lustre_msg_size 2 26995 NULL
119691 +sc16is7xx_port_read_27051 sc16is7xx_port_read 0 27051 NULL
119692 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
119693 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3 27064 NULL
119694 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
119695 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
119696 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
119697 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
119698 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
119699 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
119700 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
119701 +pms_capture_27142 pms_capture 4 27142 NULL
119702 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
119703 +wil_write_file_wmi_27150 wil_write_file_wmi 3 27150 NULL
119704 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
119705 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
119706 +write_kmem_27225 write_kmem 3 27225 NULL nohasharray
119707 +svcxdr_tmpalloc_27225 svcxdr_tmpalloc 2 27225 &write_kmem_27225
119708 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
119709 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
119710 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
119711 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
119712 +get_rx_fifo_content_27283 get_rx_fifo_content 0 27283 NULL
119713 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
119714 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
119715 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
119716 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
119717 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
119718 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
119719 +seq_read_27411 seq_read 3 27411 NULL
119720 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
119721 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
119722 +ocfs2_refcount_cal_cow_clusters_27422 ocfs2_refcount_cal_cow_clusters 3-4 27422 NULL
119723 +cypress_write_27423 cypress_write 4 27423 NULL
119724 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
119725 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
119726 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
119727 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
119728 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
119729 +garmin_read_process_27509 garmin_read_process 3 27509 NULL nohasharray
119730 +mcryptd_hash_setkey_27509 mcryptd_hash_setkey 3 27509 &garmin_read_process_27509
119731 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
119732 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
119733 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
119734 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
119735 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
119736 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
119737 +C_SYSC_mbind_27636 C_SYSC_mbind 5 27636 NULL
119738 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 NULL nohasharray
119739 +read_flush_procfs_27642 read_flush_procfs 3 27642 &ocfs2_xattr_ibody_get_27642 nohasharray
119740 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &read_flush_procfs_27642
119741 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
119742 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
119743 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
119744 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
119745 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
119746 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
119747 +evm_write_key_27715 evm_write_key 3 27715 NULL
119748 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
119749 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
119750 +load_scode_27738 load_scode 2 27738 NULL
119751 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
119752 +transport_init_session_tags_27776 transport_init_session_tags 1-2 27776 NULL
119753 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
119754 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
119755 +SyS_readv_27804 SyS_readv 3 27804 NULL
119756 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
119757 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
119758 +init_header_complete_27833 init_header_complete 0 27833 NULL
119759 +read_profile_27859 read_profile 3 27859 NULL
119760 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
119761 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
119762 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
119763 +i915_error_object_create_sized_27919 i915_error_object_create_sized 4 27919 NULL
119764 +check_mapped_name_27943 check_mapped_name 3 27943 NULL
119765 +bio_next_split_27961 bio_next_split 2 27961 NULL nohasharray
119766 +tracing_clock_write_27961 tracing_clock_write 3 27961 &bio_next_split_27961
119767 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
119768 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL nohasharray
119769 +device_register_27972 device_register 0 27972 &mic_rx_pkts_read_27972
119770 +compat_SyS_set_mempolicy_27975 compat_SyS_set_mempolicy 3 27975 NULL
119771 +pci_enable_device_flags_27977 pci_enable_device_flags 0 27977 NULL
119772 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
119773 +seq_get_buf_28006 seq_get_buf 0 28006 NULL
119774 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
119775 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
119776 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
119777 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
119778 +pool_status_28055 pool_status 5 28055 NULL
119779 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
119780 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
119781 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
119782 +acpi_gsb_i2c_write_bytes_28082 acpi_gsb_i2c_write_bytes 4 28082 NULL
119783 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
119784 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
119785 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
119786 +m25p80_read_reg_28132 m25p80_read_reg 4 28132 NULL
119787 +video_read_28148 video_read 3 28148 NULL
119788 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
119789 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
119790 +vread_28173 vread 0-3 28173 NULL
119791 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
119792 +counter_free_res_28187 counter_free_res 5 28187 NULL
119793 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
119794 +nvkm_output_dp_create__28192 nvkm_output_dp_create_ 6 28192 NULL
119795 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
119796 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
119797 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
119798 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
119799 +usemap_size_28281 usemap_size 0 28281 NULL
119800 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
119801 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
119802 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
119803 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
119804 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
119805 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
119806 +xpcs_mmd_read_28331 xpcs_mmd_read 3 28331 NULL
119807 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
119808 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
119809 +snapshot_write_28351 snapshot_write 3 28351 NULL
119810 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
119811 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
119812 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
119813 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
119814 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
119815 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
119816 +__videobuf_mmap_setup_28421 __videobuf_mmap_setup 0 28421 NULL
119817 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
119818 +hid_hw_output_report_28429 hid_hw_output_report 0 28429 NULL
119819 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
119820 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
119821 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
119822 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
119823 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
119824 +sh_irda_init_iobuf_28527 sh_irda_init_iobuf 2 28527 NULL nohasharray
119825 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 &sh_irda_init_iobuf_28527
119826 +early_init_dt_alloc_memory_arch_28528 early_init_dt_alloc_memory_arch 1 28528 NULL
119827 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
119828 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 NULL nohasharray
119829 +aio_read_events_28545 aio_read_events 3 28545 &run_delalloc_range_28545 nohasharray
119830 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 &aio_read_events_28545
119831 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
119832 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
119833 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
119834 +task_cgroup_path_28599 task_cgroup_path 3 28599 NULL
119835 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
119836 +xgbe_common_write_28609 xgbe_common_write 2 28609 NULL
119837 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
119838 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 5-3 28622 NULL
119839 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
119840 +qib_handle_6120_hwerrors_28642 qib_handle_6120_hwerrors 3 28642 NULL
119841 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
119842 +iwl_dbgfs_nic_temp_read_28662 iwl_dbgfs_nic_temp_read 3 28662 NULL
119843 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
119844 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
119845 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
119846 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
119847 +spi_execute_28736 spi_execute 5 28736 NULL
119848 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
119849 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
119850 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
119851 +nv50_dmac_create_28762 nv50_dmac_create 5 28762 NULL
119852 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
119853 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
119854 +sel_write_member_28800 sel_write_member 3 28800 NULL
119855 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
119856 +kernel_tree_alloc_28833 kernel_tree_alloc 1 28833 NULL
119857 +parser_init_byteStream_28841 parser_init_byteStream 2 28841 NULL
119858 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
119859 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
119860 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
119861 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
119862 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
119863 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
119864 +push_rx_28939 push_rx 3 28939 NULL
119865 +mxuport_prepare_write_buffer_28943 mxuport_prepare_write_buffer 3 28943 NULL
119866 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
119867 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
119868 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
119869 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
119870 +bin_uuid_28999 bin_uuid 3 28999 NULL
119871 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
119872 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
119873 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
119874 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
119875 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
119876 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
119877 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
119878 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
119879 +ccp_init_dm_workarea_29097 ccp_init_dm_workarea 3 29097 NULL
119880 +__compat_sys_preadv64_29103 __compat_sys_preadv64 3 29103 NULL
119881 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
119882 +snprintf_29125 snprintf 0 29125 NULL
119883 +iov_shorten_29130 iov_shorten 0 29130 NULL
119884 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
119885 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
119886 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
119887 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
119888 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
119889 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
119890 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
119891 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
119892 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
119893 +rbd_osd_req_create_29260 rbd_osd_req_create 3 29260 NULL
119894 +mwifiex_hscfg_write_29262 mwifiex_hscfg_write 3 29262 NULL
119895 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
119896 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
119897 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
119898 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
119899 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
119900 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
119901 +obd_proc_jobid_name_seq_write_29332 obd_proc_jobid_name_seq_write 3 29332 NULL
119902 +tun_put_user_29337 tun_put_user 5 29337 NULL
119903 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
119904 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
119905 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
119906 +mempool_create_29437 mempool_create 1 29437 NULL
119907 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
119908 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
119909 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
119910 +memcg_update_cache_params_29465 memcg_update_cache_params 2 29465 NULL
119911 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
119912 +do_register_entry_29478 do_register_entry 4 29478 NULL
119913 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
119914 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
119915 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
119916 +usnic_vnic_spec_dump_29508 usnic_vnic_spec_dump 2 29508 NULL
119917 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
119918 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
119919 +pci_enable_msix_29524 pci_enable_msix 0 29524 NULL
119920 +mic_vringh_copy_29531 mic_vringh_copy 4 29531 NULL
119921 +ftrace_write_29551 ftrace_write 3 29551 NULL
119922 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
119923 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
119924 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
119925 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
119926 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
119927 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
119928 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
119929 +slots_per_page_29601 slots_per_page 0 29601 NULL
119930 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
119931 +lstcon_rpc_init_29623 lstcon_rpc_init 4 29623 NULL
119932 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
119933 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
119934 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL nohasharray
119935 +spmi_controller_alloc_29654 spmi_controller_alloc 2 29654 &sctp_make_abort_user_29654
119936 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
119937 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
119938 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
119939 +probes_write_29711 probes_write 3 29711 NULL
119940 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
119941 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
119942 +std_nic_write_29752 std_nic_write 3 29752 NULL
119943 +static_key_count_29771 static_key_count 0 29771 NULL
119944 +tg3_irq_count_29786 tg3_irq_count 0 29786 NULL
119945 +dbAlloc_29794 dbAlloc 0 29794 NULL
119946 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
119947 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
119948 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
119949 +count_partial_29850 count_partial 0 29850 NULL
119950 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
119951 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
119952 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
119953 +rtw_cfg80211_indicate_sta_assoc_29897 rtw_cfg80211_indicate_sta_assoc 3 29897 NULL
119954 +nv94_gpio_intr_mask_29907 nv94_gpio_intr_mask 4-3 29907 NULL
119955 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
119956 +write_file_queue_29922 write_file_queue 3 29922 NULL
119957 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
119958 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
119959 +zero_iovec_29955 zero_iovec 1 29955 NULL
119960 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
119961 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
119962 +sysfs_add_file_mode_ns_30038 sysfs_add_file_mode_ns 0 30038 NULL
119963 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 0-4 30040 NULL
119964 +drp_wmove_30043 drp_wmove 4 30043 NULL
119965 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
119966 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
119967 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
119968 +defragment_dma_buffer_30113 defragment_dma_buffer 0 30113 NULL
119969 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
119970 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
119971 +dbg_port_buf_30145 dbg_port_buf 2 30145 NULL
119972 +elfcorehdr_read_30159 elfcorehdr_read 2 30159 NULL
119973 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
119974 +expand_inode_data_30169 expand_inode_data 3-2 30169 NULL
119975 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
119976 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
119977 +__genwqe_readq_30197 __genwqe_readq 0 30197 NULL
119978 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
119979 +SyS_semop_30227 SyS_semop 3 30227 NULL
119980 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
119981 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
119982 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
119983 +compat_readv_30273 compat_readv 3 30273 NULL
119984 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
119985 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
119986 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
119987 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
119988 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
119989 +i8254_read_30330 i8254_read 0 30330 NULL
119990 +resource_from_user_30341 resource_from_user 3 30341 NULL
119991 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
119992 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
119993 +pvscsi_change_queue_depth_30365 pvscsi_change_queue_depth 2 30365 NULL
119994 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
119995 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
119996 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
119997 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
119998 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
119999 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
120000 +enable_write_30456 enable_write 3 30456 NULL
120001 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
120002 +urandom_read_30462 urandom_read 3 30462 NULL
120003 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
120004 +adu_write_30487 adu_write 3 30487 NULL
120005 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
120006 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
120007 +memblock_virt_alloc_node_30515 memblock_virt_alloc_node 1 30515 NULL
120008 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
120009 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL nohasharray
120010 +set_config_30526 set_config 0 30526 &debug_debug2_read_30526
120011 +xfs_sb_version_hasftype_30559 xfs_sb_version_hasftype 0 30559 NULL nohasharray
120012 +ixgbevf_acquire_msix_vectors_30559 ixgbevf_acquire_msix_vectors 2 30559 &xfs_sb_version_hasftype_30559
120013 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
120014 +set_le_30581 set_le 4 30581 NULL
120015 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
120016 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
120017 +SyS_msgrcv_30611 SyS_msgrcv 3 30611 NULL
120018 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
120019 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
120020 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
120021 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
120022 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
120023 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
120024 +ni_ai_fifo_read_30681 ni_ai_fifo_read 3 30681 NULL
120025 +sst_hsw_get_dsp_position_30691 sst_hsw_get_dsp_position 0 30691 NULL
120026 +get_pages_alloc_iovec_30699 get_pages_alloc_iovec 3-0 30699 NULL
120027 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
120028 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
120029 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
120030 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 4-3 30727 NULL
120031 +snapshot_status_30744 snapshot_status 5 30744 NULL
120032 +fuse_direct_IO_30753 fuse_direct_IO 4 30753 NULL
120033 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
120034 +__bio_alloc_30787 __bio_alloc 3 30787 NULL
120035 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
120036 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
120037 +ath10k_write_fw_dbglog_30835 ath10k_write_fw_dbglog 3 30835 NULL
120038 +of_gpio_named_count_30841 of_gpio_named_count 0 30841 NULL
120039 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
120040 +cfg80211_rx_mgmt_30844 cfg80211_rx_mgmt 5 30844 NULL
120041 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
120042 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
120043 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
120044 +copy_to_iter_30901 copy_to_iter 2 30901 NULL
120045 +usnic_debugfs_buildinfo_read_30928 usnic_debugfs_buildinfo_read 3 30928 NULL
120046 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
120047 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
120048 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
120049 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
120050 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
120051 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
120052 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
120053 +stride_pg_count_31053 stride_pg_count 0-3-2-1-4-5 31053 NULL
120054 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
120055 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
120056 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
120057 +depth_read_31112 depth_read 3 31112 NULL
120058 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
120059 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
120060 +size_inside_page_31141 size_inside_page 0 31141 NULL
120061 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
120062 +nvme_set_features_31169 nvme_set_features 0 31169 NULL
120063 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
120064 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
120065 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
120066 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
120067 +__read_reg_31216 __read_reg 0 31216 NULL
120068 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
120069 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
120070 +cyy_readb_31240 cyy_readb 0 31240 NULL
120071 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
120072 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
120073 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
120074 +iwl_dbgfs_set_nic_temperature_read_31300 iwl_dbgfs_set_nic_temperature_read 3 31300 NULL
120075 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
120076 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
120077 +command_file_write_31318 command_file_write 3 31318 NULL
120078 +hwerr_crcbits_31334 hwerr_crcbits 4 31334 NULL
120079 +_regmap_raw_multi_reg_write_31336 _regmap_raw_multi_reg_write 3 31336 NULL
120080 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
120081 +outlen_write_31358 outlen_write 3 31358 NULL
120082 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
120083 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
120084 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
120085 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
120086 +inb_31388 inb 0 31388 NULL
120087 +mp_ioapic_pin_count_31393 mp_ioapic_pin_count 0 31393 NULL
120088 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
120089 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
120090 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
120091 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
120092 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
120093 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
120094 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
120095 +alg_setkey_31485 alg_setkey 3 31485 NULL
120096 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
120097 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
120098 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
120099 +hidraw_write_31536 hidraw_write 3 31536 NULL
120100 +usbvision_read_31555 usbvision_read 3 31555 NULL
120101 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
120102 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
120103 +osst_write_31581 osst_write 3 31581 NULL
120104 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
120105 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
120106 +memblock_virt_alloc_nopanic_31617 memblock_virt_alloc_nopanic 1 31617 NULL nohasharray
120107 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 &memblock_virt_alloc_nopanic_31617
120108 +usnic_ib_dump_vf_31623 usnic_ib_dump_vf 3 31623 NULL
120109 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
120110 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
120111 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
120112 +__lgread_31668 __lgread 4 31668 NULL
120113 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
120114 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
120115 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
120116 +rs_pretty_print_rate_31727 rs_pretty_print_rate 0 31727 NULL
120117 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 NULL nohasharray
120118 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 &lu_buf_check_and_grow_31735
120119 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
120120 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
120121 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
120122 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
120123 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
120124 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
120125 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
120126 +get_count_order_31800 get_count_order 0 31800 NULL
120127 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
120128 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
120129 +data_write_31805 data_write 3 31805 NULL
120130 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
120131 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
120132 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
120133 +clone_bio_31854 clone_bio 4-3 31854 NULL
120134 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
120135 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
120136 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
120137 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
120138 +xattr_permission_31907 xattr_permission 0 31907 NULL
120139 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
120140 +new_dir_31919 new_dir 3 31919 NULL
120141 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
120142 +era_status_31934 era_status 5 31934 NULL
120143 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
120144 +read_mem_31942 read_mem 3 31942 NULL
120145 +ext4_zero_range_31944 ext4_zero_range 3-2 31944 NULL
120146 +vb2_write_31948 vb2_write 3 31948 NULL
120147 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
120148 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
120149 +iwl_rx_packet_payload_len_31965 iwl_rx_packet_payload_len 0 31965 NULL
120150 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
120151 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
120152 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
120153 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
120154 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
120155 +sysfs_create_file_31996 sysfs_create_file 0 31996 NULL
120156 +calc_hmac_32010 calc_hmac 3 32010 NULL
120157 +aead_len_32021 aead_len 0 32021 NULL
120158 +sci_dma_rx_push_32029 sci_dma_rx_push 2 32029 NULL
120159 +stk_read_32038 stk_read 3 32038 NULL
120160 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
120161 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
120162 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
120163 +kiblnd_alloc_pages_32092 kiblnd_alloc_pages 3 32092 NULL
120164 +bio_alloc_32095 bio_alloc 2 32095 NULL
120165 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
120166 +wil_read_file_recovery_32104 wil_read_file_recovery 3 32104 NULL
120167 +disk_status_32120 disk_status 4 32120 NULL
120168 +kobject_add_internal_32133 kobject_add_internal 0 32133 NULL
120169 +venus_link_32165 venus_link 5 32165 NULL
120170 +ocfs2_direct_IO_32168 ocfs2_direct_IO 4 32168 NULL
120171 +do_writepages_32173 do_writepages 0 32173 NULL
120172 +del_ptr_32197 del_ptr 4 32197 NULL
120173 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
120174 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
120175 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
120176 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
120177 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
120178 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
120179 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
120180 +SyS_select_32319 SyS_select 1 32319 NULL
120181 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
120182 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
120183 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
120184 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
120185 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
120186 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL nohasharray
120187 +ReadHDLCPCI_32362 ReadHDLCPCI 0 32362 &sel_read_initcon_32362
120188 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
120189 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
120190 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
120191 +cache_status_32462 cache_status 5 32462 NULL
120192 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
120193 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
120194 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
120195 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
120196 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
120197 +disconnect_32521 disconnect 4 32521 NULL
120198 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
120199 +ilo_read_32531 ilo_read 3 32531 NULL
120200 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
120201 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
120202 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
120203 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
120204 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
120205 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
120206 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
120207 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
120208 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
120209 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
120210 +xpcs_reg_value_read_32644 xpcs_reg_value_read 3 32644 NULL
120211 +kvmalloc_32646 kvmalloc 1 32646 NULL
120212 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
120213 +generic_readlink_32654 generic_readlink 3 32654 NULL
120214 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
120215 +compat_SyS_preadv_32679 compat_SyS_preadv 3 32679 NULL
120216 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
120217 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
120218 +_xfs_buf_get_pages_32715 _xfs_buf_get_pages 2 32715 NULL
120219 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
120220 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
120221 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
120222 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
120223 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
120224 +sta_tx_latency_stat_read_32862 sta_tx_latency_stat_read 3 32862 NULL
120225 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
120226 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 NULL nohasharray
120227 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 &cifs_writedata_alloc_32880
120228 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 4-6 32884 NULL
120229 +visorchannel_dump_section_32893 visorchannel_dump_section 4 32893 NULL
120230 +tipc_link_iovec_xmit_fast_32913 tipc_link_iovec_xmit_fast 3 32913 NULL nohasharray
120231 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 &tipc_link_iovec_xmit_fast_32913
120232 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
120233 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
120234 +ptlrpc_prep_bulk_imp_32997 ptlrpc_prep_bulk_imp 2 32997 NULL
120235 +compat_filldir_32999 compat_filldir 3 32999 NULL
120236 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
120237 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
120238 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
120239 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
120240 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
120241 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
120242 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
120243 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
120244 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
120245 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
120246 +alloc_tio_33077 alloc_tio 3 33077 NULL
120247 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
120248 +f2fs_llseek_33098 f2fs_llseek 2 33098 NULL
120249 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
120250 +SyS_poll_33152 SyS_poll 2 33152 NULL
120251 +_pci_add_cap_save_buffer_33153 _pci_add_cap_save_buffer 4 33153 NULL
120252 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
120253 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
120254 +pp_read_33210 pp_read 3 33210 NULL
120255 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
120256 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
120257 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
120258 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
120259 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
120260 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
120261 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
120262 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
120263 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
120264 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
120265 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
120266 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
120267 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
120268 +nvc0_ram_create__33391 nvc0_ram_create_ 5 33391 NULL
120269 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 3-2 33394 NULL
120270 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
120271 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
120272 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
120273 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
120274 +message_stats_list_33440 message_stats_list 5 33440 NULL
120275 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
120276 +create_entry_33479 create_entry 2 33479 NULL
120277 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
120278 +res_counter_read_33499 res_counter_read 4 33499 NULL
120279 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
120280 +fb_read_33506 fb_read 3 33506 NULL
120281 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
120282 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
120283 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
120284 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
120285 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
120286 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
120287 +count_subheaders_33591 count_subheaders 0 33591 NULL
120288 +scsi_execute_33596 scsi_execute 5 33596 NULL
120289 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
120290 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
120291 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL nohasharray
120292 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 &il_dbgfs_qos_read_33615
120293 +stride_page_count_33641 stride_page_count 2 33641 NULL
120294 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
120295 +inw_p_33668 inw_p 0 33668 NULL
120296 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
120297 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
120298 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
120299 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
120300 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
120301 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
120302 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
120303 +read_file_node_recv_33729 read_file_node_recv 3 33729 NULL
120304 +__mutex_lock_interruptible_slowpath_33735 __mutex_lock_interruptible_slowpath 0 33735 NULL
120305 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
120306 +hashtab_create_33769 hashtab_create 3 33769 NULL
120307 +__btrfs_free_reserved_extent_33782 __btrfs_free_reserved_extent 2 33782 NULL
120308 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
120309 +filter_write_33819 filter_write 3 33819 NULL
120310 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
120311 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
120312 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
120313 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
120314 +azx_get_pos_posbuf_33867 azx_get_pos_posbuf 0 33867 NULL
120315 +get_user_pages_33908 get_user_pages 0 33908 NULL
120316 +sg_nents_33909 sg_nents 0 33909 NULL
120317 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
120318 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
120319 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
120320 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
120321 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
120322 +rs_sta_dbgfs_drv_tx_stats_read_33946 rs_sta_dbgfs_drv_tx_stats_read 3 33946 NULL
120323 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
120324 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
120325 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
120326 +ppp_write_34034 ppp_write 3 34034 NULL
120327 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
120328 +bm_page_io_async_34050 bm_page_io_async 2 34050 NULL
120329 +calc_linear_pos_34067 calc_linear_pos 0-4 34067 NULL
120330 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
120331 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
120332 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
120333 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
120334 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
120335 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
120336 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
120337 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
120338 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
120339 +rsi_debug_zone_write_34206 rsi_debug_zone_write 3 34206 NULL nohasharray
120340 +rbd_osd_req_create_34206 rbd_osd_req_create 3 34206 &rsi_debug_zone_write_34206
120341 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
120342 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
120343 +device_private_init_34279 device_private_init 0 34279 NULL
120344 +xgmac_reg_addr_write_34284 xgmac_reg_addr_write 3 34284 NULL
120345 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
120346 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
120347 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
120348 +proc_thread_self_readlink_34357 proc_thread_self_readlink 3 34357 NULL
120349 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
120350 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
120351 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
120352 +ea_read_34378 ea_read 0 34378 NULL nohasharray
120353 +_iwl_dbgfs_low_latency_write_34378 _iwl_dbgfs_low_latency_write 3 34378 &ea_read_34378
120354 +fuse_send_read_34379 fuse_send_read 0-4 34379 NULL
120355 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
120356 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
120357 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
120358 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 NULL nohasharray
120359 +iwl_calib_set_34400 iwl_calib_set 3 34400 &ivtv_read_pos_34400
120360 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
120361 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
120362 +security_socket_create_34439 security_socket_create 0 34439 NULL
120363 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
120364 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
120365 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
120366 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
120367 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
120368 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
120369 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
120370 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
120371 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 NULL nohasharray
120372 +tracing_stats_read_34537 tracing_stats_read 3 34537 &ext4_fallocate_34537
120373 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
120374 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
120375 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
120376 +ext4_ind_direct_IO_34574 ext4_ind_direct_IO 4 34574 NULL
120377 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
120378 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
120379 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
120380 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
120381 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
120382 +bio_integrity_bytes_34602 bio_integrity_bytes 2 34602 NULL
120383 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL
120384 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
120385 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
120386 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
120387 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
120388 +f2fs_direct_IO_34685 f2fs_direct_IO 4 34685 NULL
120389 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
120390 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
120391 +port_print_34704 port_print 3 34704 NULL
120392 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
120393 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
120394 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
120395 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
120396 +bootmode_store_34762 bootmode_store 4 34762 NULL
120397 +device_add_34766 device_add 0 34766 NULL
120398 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
120399 +ext3_direct_IO_34798 ext3_direct_IO 4 34798 NULL
120400 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
120401 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
120402 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
120403 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
120404 +file_page_index_34820 file_page_index 0-2 34820 NULL
120405 +bio_segments_34832 bio_segments 0 34832 NULL
120406 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
120407 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
120408 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
120409 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
120410 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
120411 +msg_print_text_34889 msg_print_text 0 34889 NULL
120412 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
120413 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
120414 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 NULL nohasharray
120415 +__inode_permission_34925 __inode_permission 0 34925 &btrfs_super_chunk_root_34925
120416 +sec_flags2str_34933 sec_flags2str 3 34933 NULL
120417 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
120418 +compat_SyS_kexec_load_34947 compat_SyS_kexec_load 2 34947 NULL
120419 +do_add_page_to_bio_34974 do_add_page_to_bio 2-10 34974 NULL
120420 +sdebug_change_qdepth_34994 sdebug_change_qdepth 2 34994 NULL
120421 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
120422 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
120423 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
120424 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
120425 +hwdep_read_locked_35037 hwdep_read_locked 3 35037 NULL
120426 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
120427 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
120428 +capi_write_35104 capi_write 3 35104 NULL nohasharray
120429 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
120430 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
120431 +ceph_osdc_start_request_35122 ceph_osdc_start_request 0 35122 NULL
120432 +addrs_per_inode_35151 addrs_per_inode 0 35151 NULL
120433 +message_stats_print_35158 message_stats_print 6 35158 NULL
120434 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
120435 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
120436 +compat_SyS_pselect6_35203 compat_SyS_pselect6 1 35203 NULL
120437 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
120438 +striped_read_35218 striped_read 0-2 35218 NULL nohasharray
120439 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 &striped_read_35218
120440 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
120441 +kimage_file_prepare_segments_35232 kimage_file_prepare_segments 5 35232 NULL
120442 +set_fd_set_35249 set_fd_set 1 35249 NULL
120443 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
120444 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
120445 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
120446 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
120447 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
120448 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL nohasharray
120449 +nvkm_notify_init_35283 nvkm_notify_init 7 35283 &isr_rx_rdys_read_35283
120450 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 NULL nohasharray
120451 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
120452 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
120453 +sta_tx_latency_stat_write_35323 sta_tx_latency_stat_write 3 35323 NULL
120454 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
120455 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
120456 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
120457 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
120458 +read_kmem_35372 read_kmem 3 35372 NULL
120459 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
120460 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
120461 +iwl_dbgfs_drv_rx_stats_read_35430 iwl_dbgfs_drv_rx_stats_read 3 35430 NULL
120462 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
120463 +efx_mcdi_rpc_async_quiet_35460 efx_mcdi_rpc_async_quiet 4-5 35460 NULL
120464 +macvtap_do_read_35475 macvtap_do_read 3 35475 NULL
120465 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
120466 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
120467 +async_setkey_35521 async_setkey 3 35521 NULL
120468 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
120469 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
120470 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
120471 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
120472 +ocfs2_write_zero_page_35539 ocfs2_write_zero_page 3 35539 NULL
120473 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
120474 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
120475 +C_SYSC_kexec_load_35565 C_SYSC_kexec_load 2 35565 NULL
120476 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
120477 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
120478 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
120479 +kernel_readv_35617 kernel_readv 3 35617 NULL
120480 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
120481 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
120482 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
120483 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
120484 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
120485 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
120486 +md_super_write_35703 md_super_write 4 35703 NULL
120487 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
120488 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
120489 +alloc_netdev_mqs_35806 alloc_netdev_mqs 1 35806 NULL
120490 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
120491 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
120492 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
120493 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
120494 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
120495 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
120496 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
120497 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
120498 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
120499 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
120500 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
120501 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
120502 +generic_ocp_read_35974 generic_ocp_read 3 35974 NULL nohasharray
120503 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 &generic_ocp_read_35974
120504 +acl_alloc_35979 acl_alloc 1 35979 NULL
120505 +device_add_class_symlinks_35985 device_add_class_symlinks 0 35985 NULL
120506 +write_file_antenna_35998 write_file_antenna 3 35998 NULL nohasharray
120507 +kuc_alloc_35998 kuc_alloc 1 35998 &write_file_antenna_35998
120508 +lov_mds_md_max_stripe_count_36008 lov_mds_md_max_stripe_count 0-1 36008 NULL
120509 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
120510 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
120511 +account_shadowed_36048 account_shadowed 2 36048 NULL
120512 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
120513 +write_emulate_36065 write_emulate 2-4 36065 NULL
120514 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
120515 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
120516 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
120517 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
120518 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
120519 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
120520 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
120521 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
120522 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
120523 +twl_set_36154 twl_set 2 36154 NULL
120524 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
120525 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
120526 +SyS_kexec_load_36176 SyS_kexec_load 2 36176 NULL
120527 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
120528 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
120529 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
120530 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
120531 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
120532 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
120533 +vmsplice_to_user_36245 vmsplice_to_user 3 36245 NULL nohasharray
120534 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 &vmsplice_to_user_36245
120535 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 NULL
120536 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
120537 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
120538 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
120539 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
120540 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
120541 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL nohasharray
120542 +__compat_sys_pwritev64_36328 __compat_sys_pwritev64 3 36328 &fat_compat_ioctl_filldir_36328
120543 +lc_create_36332 lc_create 4 36332 NULL
120544 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
120545 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
120546 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
120547 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
120548 +to_sector_36361 to_sector 0-1 36361 NULL
120549 +tunables_read_36385 tunables_read 3 36385 NULL
120550 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
120551 +sierra_write_36402 sierra_write 4 36402 NULL
120552 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
120553 +soc_pcm_codec_params_fixup_36434 soc_pcm_codec_params_fixup 2 36434 NULL
120554 +ReadW6692B_36445 ReadW6692B 0 36445 NULL
120555 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
120556 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
120557 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
120558 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
120559 +ds1343_nvram_write_36489 ds1343_nvram_write 5-6 36489 NULL
120560 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 NULL nohasharray
120561 +ip6_append_data_36490 ip6_append_data 4 36490 &tx_tx_checksum_result_read_36490
120562 +cmd_loop_36491 cmd_loop 0 36491 NULL
120563 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
120564 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
120565 +_iwl_dbgfs_fw_nmi_write_36515 _iwl_dbgfs_fw_nmi_write 3 36515 NULL
120566 +get_param_l_36518 get_param_l 0 36518 NULL
120567 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
120568 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
120569 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
120570 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL
120571 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
120572 +__erst_read_36579 __erst_read 0 36579 NULL
120573 +put_cmsg_36589 put_cmsg 4 36589 NULL
120574 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
120575 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
120576 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
120577 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
120578 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
120579 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
120580 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
120581 +xillybus_read_36678 xillybus_read 3 36678 NULL
120582 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
120583 +path_getxattr_36717 path_getxattr 4 36717 NULL
120584 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
120585 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
120586 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
120587 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
120588 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 5-4-3-2 36796 NULL
120589 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
120590 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
120591 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
120592 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
120593 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
120594 +cm_write_36858 cm_write 3 36858 NULL
120595 +tipc_link_iovec_long_xmit_36871 tipc_link_iovec_long_xmit 3 36871 NULL nohasharray
120596 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 &tipc_link_iovec_long_xmit_36871
120597 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
120598 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
120599 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
120600 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
120601 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
120602 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
120603 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
120604 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
120605 +setxattr_37006 setxattr 4 37006 NULL
120606 +ec_i2c_xfer_37029 ec_i2c_xfer 3 37029 NULL
120607 +ieee80211_chsw_switch_vifs_37030 ieee80211_chsw_switch_vifs 2 37030 NULL
120608 +command_file_read_37038 command_file_read 3 37038 NULL
120609 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
120610 +qp_broker_create_37053 qp_broker_create 6-5 37053 NULL nohasharray
120611 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 &qp_broker_create_37053
120612 +_iwl_dbgfs_bcast_filters_macs_write_37069 _iwl_dbgfs_bcast_filters_macs_write 3 37069 NULL
120613 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
120614 +parse_command_37079 parse_command 2 37079 NULL
120615 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
120616 +tun_get_user_37094 tun_get_user 5 37094 NULL
120617 +has_wrprotected_page_37123 has_wrprotected_page 3-2 37123 NULL
120618 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
120619 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
120620 +msg_word_37164 msg_word 0 37164 NULL
120621 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
120622 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
120623 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL
120624 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2-0 37213 NULL
120625 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
120626 +__do_replace_37227 __do_replace 5 37227 NULL
120627 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
120628 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL nohasharray
120629 +__btrfs_inc_extent_ref_37238 __btrfs_inc_extent_ref 7 37238 &rx_filter_dup_filter_read_37238
120630 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
120631 +_iwl_dbgfs_fw_restart_write_37270 _iwl_dbgfs_fw_restart_write 3 37270 NULL
120632 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
120633 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
120634 +tipc_send_37315 tipc_send 3 37315 NULL
120635 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL nohasharray
120636 +bnx2x_vf_fill_fw_str_37327 bnx2x_vf_fill_fw_str 3 37327 &l2cap_create_connless_pdu_37327
120637 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
120638 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
120639 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
120640 +seek_firmware_37372 seek_firmware 2 37372 NULL
120641 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
120642 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
120643 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
120644 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 0-7-9 37433 NULL
120645 +fru_alloc_37442 fru_alloc 1 37442 NULL
120646 +tcp_established_options_37450 tcp_established_options 0 37450 NULL
120647 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
120648 +get_est_timing_37484 get_est_timing 0 37484 NULL
120649 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
120650 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
120651 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
120652 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
120653 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
120654 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
120655 +hdr_size_37536 hdr_size 0 37536 NULL
120656 +extent_map_end_37550 extent_map_end 0 37550 NULL
120657 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
120658 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
120659 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
120660 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
120661 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
120662 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
120663 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
120664 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 NULL nohasharray
120665 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 &vmw_framebuffer_dmabuf_dirty_37661
120666 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
120667 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
120668 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
120669 +tracing_saved_cmdlines_size_write_37684 tracing_saved_cmdlines_size_write 3 37684 NULL
120670 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
120671 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
120672 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
120673 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
120674 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
120675 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
120676 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
120677 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
120678 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
120679 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
120680 +nvkm_notify_init_37806 nvkm_notify_init 6 37806 NULL
120681 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
120682 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
120683 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
120684 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
120685 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
120686 +btrfs_leaf_data_37869 btrfs_leaf_data 0 37869 NULL
120687 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
120688 +_rtw_malloc_37928 _rtw_malloc 1 37928 NULL nohasharray
120689 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 &_rtw_malloc_37928
120690 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
120691 +write_file_bool_37957 write_file_bool 3 37957 NULL
120692 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
120693 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
120694 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
120695 +vfs_readv_38011 vfs_readv 3 38011 NULL
120696 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
120697 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
120698 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
120699 +parser_init_guts_38046 parser_init_guts 2 38046 NULL
120700 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
120701 +sysfs_do_create_link_38051 sysfs_do_create_link 0 38051 NULL
120702 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
120703 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
120704 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
120705 +cifs_send_async_read_38077 cifs_send_async_read 2 38077 NULL
120706 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 NULL
120707 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
120708 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
120709 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
120710 +ep0_read_38095 ep0_read 3 38095 NULL
120711 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 NULL nohasharray
120712 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 &osc_checksum_seq_write_38096
120713 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
120714 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
120715 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
120716 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4-0 38153 NULL
120717 +btrfs_extent_same_38163 btrfs_extent_same 3-2-5 38163 NULL
120718 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
120719 +cdev_add_38176 cdev_add 2-3 38176 NULL
120720 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
120721 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
120722 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
120723 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
120724 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
120725 +nvkm_dmaobj_create__38250 nvkm_dmaobj_create_ 6 38250 NULL
120726 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
120727 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268 nohasharray
120728 +SYSC_msgrcv_38268 SYSC_msgrcv 3 38268 &ieee80211_if_read_auto_open_plinks_38268
120729 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 NULL nohasharray
120730 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 &xfs_bmbt_to_bmdr_38275
120731 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
120732 +C_SYSC_pselect6_38296 C_SYSC_pselect6 1 38296 NULL
120733 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
120734 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
120735 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
120736 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
120737 +usb_ext_prop_put_name_38352 usb_ext_prop_put_name 0-3 38352 NULL
120738 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
120739 +xfs_free_file_space_38383 xfs_free_file_space 2-3 38383 NULL
120740 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
120741 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
120742 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
120743 +iov_iter_npages_iovec_38448 iov_iter_npages_iovec 0-2 38448 NULL
120744 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
120745 +videobuf_waiton_38459 videobuf_waiton 0 38459 NULL
120746 +_iwl_dbgfs_scan_ant_rxchain_write_38479 _iwl_dbgfs_scan_ant_rxchain_write 3 38479 NULL
120747 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
120748 +dev_names_read_38509 dev_names_read 3 38509 NULL
120749 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
120750 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
120751 +set_queue_count_38519 set_queue_count 0 38519 NULL
120752 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
120753 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
120754 +kuc_len_38557 kuc_len 0-1 38557 NULL
120755 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
120756 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
120757 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
120758 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 5-3 38567 NULL
120759 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
120760 +rd_allocate_sgl_table_38607 rd_allocate_sgl_table 3 38607 NULL
120761 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
120762 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
120763 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
120764 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
120765 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
120766 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
120767 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
120768 +ufshcd_read_sdev_qdepth_38676 ufshcd_read_sdev_qdepth 0 38676 NULL
120769 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
120770 +tracing_nsecs_read_38689 tracing_nsecs_read 3 38689 NULL
120771 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
120772 +w83977af_sir_interrupt_38738 w83977af_sir_interrupt 0 38738 NULL
120773 +udf_readpages_38761 udf_readpages 4 38761 NULL
120774 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
120775 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
120776 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
120777 +do_pci_enable_device_38802 do_pci_enable_device 0 38802 NULL
120778 +err_decode_38804 err_decode 2 38804 NULL
120779 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
120780 +direct_entry_38836 direct_entry 3 38836 NULL
120781 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
120782 +interfaces_38859 interfaces 2 38859 NULL
120783 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
120784 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
120785 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
120786 +usb_maxpacket_38977 usb_maxpacket 0 38977 NULL nohasharray
120787 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 &usb_maxpacket_38977
120788 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
120789 +bio_clone_range_38997 bio_clone_range 2 38997 NULL
120790 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
120791 +get_nodes_39012 get_nodes 3 39012 NULL
120792 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
120793 +force_sc_support_read_39014 force_sc_support_read 3 39014 NULL
120794 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
120795 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
120796 +do_write_kmem_39051 do_write_kmem 0-1-3 39051 NULL
120797 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
120798 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
120799 +ea_foreach_39133 ea_foreach 0 39133 NULL
120800 +generic_permission_39150 generic_permission 0 39150 NULL
120801 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
120802 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
120803 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
120804 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
120805 +mlx4_en_create_tx_ring_39179 mlx4_en_create_tx_ring 4 39179 NULL
120806 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
120807 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
120808 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
120809 +SyS_getrandom_39235 SyS_getrandom 2 39235 NULL
120810 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
120811 +snd_pcm_capture_forward_39248 snd_pcm_capture_forward 2 39248 NULL
120812 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
120813 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
120814 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
120815 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
120816 +_iwl_dbgfs_pm_params_write_39325 _iwl_dbgfs_pm_params_write 3 39325 NULL
120817 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
120818 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
120819 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
120820 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
120821 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
120822 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
120823 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
120824 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
120825 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
120826 +__send_to_port_39386 __send_to_port 3 39386 NULL
120827 +user_power_read_39414 user_power_read 3 39414 NULL
120828 +hash_ipmark4_expire_39419 hash_ipmark4_expire 4 39419 NULL
120829 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
120830 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
120831 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
120832 +usif_ioctl_39481 usif_ioctl 3 39481 NULL
120833 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
120834 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
120835 +int_proc_write_39542 int_proc_write 3 39542 NULL
120836 +pp_write_39554 pp_write 3 39554 NULL
120837 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
120838 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
120839 +memblock_virt_alloc_internal_39600 memblock_virt_alloc_internal 1 39600 NULL
120840 +ext_depth_39607 ext_depth 0 39607 NULL
120841 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
120842 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
120843 +sdio_readb_39618 sdio_readb 0 39618 NULL
120844 +set_dev_class_39645 set_dev_class 4 39645 NULL
120845 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
120846 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
120847 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
120848 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
120849 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
120850 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
120851 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
120852 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
120853 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
120854 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
120855 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
120856 +netlbl_catmap_walkrng_39885 netlbl_catmap_walkrng 0-2 39885 NULL
120857 +pkt_add_39897 pkt_add 3 39897 NULL
120858 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
120859 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
120860 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
120861 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
120862 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 NULL nohasharray
120863 +exofs_read_kern_39921 exofs_read_kern 6 39921 &oom_score_adj_read_39921
120864 +__spi_async_39932 __spi_async 0 39932 NULL
120865 +__get_order_39935 __get_order 0 39935 NULL
120866 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
120867 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
120868 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
120869 +bio_chain_clone_range_39967 bio_chain_clone_range 3 39967 NULL
120870 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
120871 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
120872 +lustre_pack_reply_v2_39978 lustre_pack_reply_v2 2 39978 NULL
120873 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
120874 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
120875 +server_name2svname_39998 server_name2svname 4 39998 NULL
120876 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
120877 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
120878 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
120879 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
120880 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
120881 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
120882 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
120883 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
120884 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
120885 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
120886 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
120887 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL nohasharray
120888 +kvm_mmu_notifier_clear_flush_young_40143 kvm_mmu_notifier_clear_flush_young 3-4 40143 &ath10k_write_simulate_fw_crash_40143
120889 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
120890 +pt_write_40159 pt_write 3 40159 NULL
120891 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
120892 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
120893 +allocate_probes_40204 allocate_probes 1 40204 NULL
120894 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
120895 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
120896 +ocrdma_dbgfs_ops_read_40232 ocrdma_dbgfs_ops_read 3 40232 NULL
120897 +osst_read_40237 osst_read 3 40237 NULL
120898 +lpage_info_slot_40243 lpage_info_slot 1-3 40243 NULL
120899 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4-3 40248 NULL
120900 +of_get_child_count_40254 of_get_child_count 0 40254 NULL nohasharray
120901 +fsl_edma_prep_dma_cyclic_40254 fsl_edma_prep_dma_cyclic 3-4 40254 &of_get_child_count_40254
120902 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
120903 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
120904 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
120905 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
120906 +tracing_thresh_read_40295 tracing_thresh_read 3 40295 NULL
120907 +SyS_bind_40303 SyS_bind 3 40303 NULL
120908 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
120909 +mmio_read_40348 mmio_read 4 40348 NULL
120910 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
120911 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 3-2 40365 NULL
120912 +get_chars_40373 get_chars 3 40373 NULL
120913 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
120914 +proc_write_driver_40432 proc_write_driver 3 40432 NULL
120915 +repair_io_failure_40452 repair_io_failure 4-3 40452 NULL
120916 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
120917 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
120918 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
120919 +SyS_writev_40467 SyS_writev 3 40467 NULL
120920 +SyS_select_40473 SyS_select 1 40473 NULL
120921 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
120922 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
120923 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
120924 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
120925 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
120926 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
120927 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
120928 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
120929 +bl_alloc_init_bio_40569 bl_alloc_init_bio 1 40569 NULL
120930 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
120931 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
120932 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
120933 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
120934 +fops_read_40672 fops_read 3 40672 NULL
120935 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
120936 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
120937 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
120938 +pci_enable_resources_40680 pci_enable_resources 0 40680 NULL
120939 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
120940 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
120941 +lnet_new_text_buf_40717 lnet_new_text_buf 1 40717 NULL
120942 +ip_skb_dst_mtu_40718 ip_skb_dst_mtu 0 40718 NULL
120943 +of_pdt_build_one_prop_40735 of_pdt_build_one_prop 5 40735 NULL
120944 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
120945 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
120946 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
120947 +card_send_command_40757 card_send_command 3 40757 NULL
120948 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
120949 +pg_write_40766 pg_write 3 40766 NULL
120950 +kernfs_fop_read_40770 kernfs_fop_read 3 40770 NULL
120951 +show_list_40775 show_list 3-0 40775 NULL
120952 +kfifo_out_copy_r_40784 kfifo_out_copy_r 0-3 40784 NULL
120953 +bitmap_weight_40791 bitmap_weight 0-2 40791 NULL
120954 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
120955 +rtw_add_beacon_40801 rtw_add_beacon 3-5 40801 NULL
120956 +add_action_40811 add_action 4 40811 NULL
120957 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
120958 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
120959 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
120960 +read_file_queue_40895 read_file_queue 3 40895 NULL
120961 +waiters_read_40902 waiters_read 3 40902 NULL
120962 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
120963 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
120964 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
120965 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
120966 +path_listxattr_40949 path_listxattr 3 40949 NULL
120967 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
120968 +ima_appraise_measurement_40978 ima_appraise_measurement 6 40978 NULL
120969 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
120970 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
120971 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
120972 +get_pages_alloc_bvec_41012 get_pages_alloc_bvec 0-3 41012 NULL
120973 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
120974 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
120975 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
120976 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
120977 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
120978 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
120979 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
120980 +sc_only_mode_read_41076 sc_only_mode_read 3 41076 NULL
120981 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
120982 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
120983 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
120984 +dma_attach_41094 dma_attach 5-6 41094 NULL
120985 +nl80211_send_mlme_event_41099 nl80211_send_mlme_event 4 41099 NULL
120986 +provide_user_output_41105 provide_user_output 3 41105 NULL
120987 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
120988 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
120989 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
120990 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
120991 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
120992 +netif_get_num_default_rss_queues_41187 netif_get_num_default_rss_queues 0 41187 NULL
120993 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
120994 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
120995 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
120996 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
120997 +erst_read_41260 erst_read 0 41260 NULL
120998 +alloc_context_41283 alloc_context 1 41283 NULL
120999 +of_count_phandle_with_args_41291 of_count_phandle_with_args 0 41291 NULL
121000 +virtscsi_change_queue_depth_41327 virtscsi_change_queue_depth 2 41327 NULL
121001 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
121002 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
121003 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
121004 +ceph_do_getattr_41349 ceph_do_getattr 0 41349 NULL
121005 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
121006 +kmp_init_41373 kmp_init 2 41373 NULL
121007 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
121008 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
121009 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
121010 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
121011 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
121012 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
121013 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4 41442 NULL
121014 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
121015 +se_io_cb_41461 se_io_cb 3 41461 NULL
121016 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
121017 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
121018 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
121019 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
121020 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
121021 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
121022 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
121023 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
121024 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
121025 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
121026 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
121027 +nr_status_frames_41559 nr_status_frames 0-1 41559 NULL nohasharray
121028 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 &nr_status_frames_41559
121029 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
121030 +nfsd_readv_41585 nfsd_readv 4 41585 NULL
121031 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
121032 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
121033 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 NULL nohasharray
121034 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 &lbs_bcnmiss_write_41613
121035 +a2mp_send_41615 a2mp_send 4 41615 NULL
121036 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
121037 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
121038 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
121039 +get_std_timing_41654 get_std_timing 0 41654 NULL
121040 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
121041 +fill_pcm_stream_name_41685 fill_pcm_stream_name 2 41685 NULL
121042 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
121043 +connector_write_41709 connector_write 3 41709 NULL
121044 +fillonedir_41746 fillonedir 3 41746 NULL
121045 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
121046 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
121047 +ptlrpc_new_bulk_41804 ptlrpc_new_bulk 1 41804 NULL
121048 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
121049 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
121050 +kimage_file_alloc_init_41827 kimage_file_alloc_init 5 41827 NULL
121051 +copy_page_to_iter_bvec_41830 copy_page_to_iter_bvec 0-3 41830 NULL
121052 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
121053 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
121054 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
121055 +pci_map_single_41869 pci_map_single 0 41869 NULL
121056 +usb_gadget_get_string_41871 usb_gadget_get_string 0 41871 NULL
121057 +v_APCI3120_InterruptDmaMoveBlock16bit_41914 v_APCI3120_InterruptDmaMoveBlock16bit 4 41914 NULL
121058 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
121059 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 4-3 41935 NULL
121060 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
121061 +read_gssp_41947 read_gssp 3 41947 NULL
121062 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
121063 +portnames_read_41958 portnames_read 3 41958 NULL
121064 +dst_mtu_41969 dst_mtu 0 41969 NULL
121065 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
121066 +pool_allocate_42012 pool_allocate 3 42012 NULL
121067 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
121068 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
121069 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
121070 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
121071 +alloc_trace_kprobe_42041 alloc_trace_kprobe 6 42041 NULL
121072 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
121073 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
121074 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
121075 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
121076 +ufshcd_dev_cmd_completion_42080 ufshcd_dev_cmd_completion 0 42080 NULL
121077 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
121078 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
121079 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
121080 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
121081 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
121082 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
121083 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
121084 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
121085 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
121086 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
121087 +blockdev_direct_IO_42235 blockdev_direct_IO 5 42235 NULL nohasharray
121088 +pla_ocp_read_42235 pla_ocp_read 3 42235 &blockdev_direct_IO_42235
121089 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
121090 +find_last_bit_42260 find_last_bit 0 42260 NULL
121091 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
121092 +__tty_buffer_request_room_42276 __tty_buffer_request_room 2-0 42276 NULL
121093 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
121094 +__cpus_weight_42299 __cpus_weight 2-0 42299 NULL
121095 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
121096 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
121097 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
121098 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
121099 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
121100 +tcp_sync_mss_42330 tcp_sync_mss 2-0 42330 NULL
121101 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
121102 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
121103 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
121104 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
121105 +krng_get_random_42420 krng_get_random 3 42420 NULL
121106 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
121107 +spr_wm_latency_write_42441 spr_wm_latency_write 3 42441 NULL
121108 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
121109 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
121110 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
121111 +kuc_free_42455 kuc_free 2 42455 NULL
121112 +cp2112_gpio_get_42467 cp2112_gpio_get 2 42467 NULL
121113 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
121114 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
121115 +bypass_write_42498 bypass_write 3 42498 NULL
121116 +SyS_mincore_42511 SyS_mincore 1-2 42511 NULL
121117 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
121118 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
121119 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
121120 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
121121 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
121122 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
121123 +iwl_print_event_log_42566 iwl_print_event_log 0-7-5 42566 NULL
121124 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
121125 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
121126 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
121127 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
121128 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
121129 +parport_pc_compat_write_block_pio_42644 parport_pc_compat_write_block_pio 3 42644 NULL nohasharray
121130 +num_controllers_42644 num_controllers 0 42644 &parport_pc_compat_write_block_pio_42644
121131 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
121132 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
121133 +vb2_read_42703 vb2_read 3 42703 NULL
121134 +read_status_42722 read_status 0 42722 NULL
121135 +iwl_mvm_coex_dump_mbox_old_42727 iwl_mvm_coex_dump_mbox_old 4-3-0 42727 NULL
121136 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
121137 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
121138 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
121139 +dpm_sysfs_add_42756 dpm_sysfs_add 0 42756 NULL
121140 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
121141 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
121142 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
121143 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
121144 +elfcorehdr_read_notes_42786 elfcorehdr_read_notes 2 42786 NULL
121145 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
121146 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
121147 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
121148 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
121149 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
121150 +set_arg_42824 set_arg 3 42824 NULL
121151 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
121152 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
121153 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
121154 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
121155 +hd_end_request_42904 hd_end_request 2 42904 NULL
121156 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
121157 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
121158 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
121159 +ntb_setup_snb_msix_42971 ntb_setup_snb_msix 2 42971 NULL
121160 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
121161 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
121162 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
121163 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
121164 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
121165 +__bioset_create_43059 __bioset_create 1 43059 NULL
121166 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
121167 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
121168 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
121169 +sysfs_create_file_ns_43103 sysfs_create_file_ns 0 43103 NULL
121170 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
121171 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
121172 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
121173 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
121174 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
121175 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
121176 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
121177 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
121178 +uio_write_43202 uio_write 3 43202 NULL
121179 +iso_callback_43208 iso_callback 3 43208 NULL
121180 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
121181 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
121182 +atomic_long_add_return_43217 atomic_long_add_return 1 43217 NULL
121183 +gfs2_direct_IO_43220 gfs2_direct_IO 4 43220 NULL
121184 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
121185 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
121186 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
121187 +evtchn_write_43278 evtchn_write 3 43278 NULL nohasharray
121188 +parport_pc_ecp_write_block_pio_43278 parport_pc_ecp_write_block_pio 3 43278 &evtchn_write_43278
121189 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
121190 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
121191 +mmu_set_spte_43327 mmu_set_spte 7-6 43327 NULL
121192 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
121193 +xenfb_write_43412 xenfb_write 3 43412 NULL
121194 +ext4_xattr_check_names_43422 ext4_xattr_check_names 0 43422 NULL
121195 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL
121196 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
121197 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
121198 +usemap_size_43443 usemap_size 0-2-1 43443 NULL nohasharray
121199 +usb_string_43443 usb_string 0 43443 &usemap_size_43443
121200 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
121201 +fs_path_prepare_for_add_43453 fs_path_prepare_for_add 2 43453 NULL
121202 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
121203 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
121204 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
121205 +ll_direct_IO_26_43530 ll_direct_IO_26 4 43530 NULL
121206 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
121207 +read_events_43534 read_events 3 43534 NULL
121208 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
121209 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
121210 +request_resource_43548 request_resource 0 43548 NULL
121211 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
121212 +handle_frequent_errors_43599 handle_frequent_errors 4 43599 NULL
121213 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
121214 +proc_read_43614 proc_read 3 43614 NULL
121215 +disable_dma_on_even_43618 disable_dma_on_even 0 43618 NULL
121216 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
121217 +random_write_43656 random_write 3 43656 NULL
121218 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
121219 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
121220 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
121221 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
121222 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
121223 +nvkm_connector_create__43711 nvkm_connector_create_ 6 43711 NULL
121224 +fuse_send_read_43725 fuse_send_read 4-0 43725 NULL
121225 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
121226 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
121227 +__alloc_alien_cache_43734 __alloc_alien_cache 2 43734 NULL
121228 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
121229 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
121230 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
121231 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
121232 +byte_pos_43787 byte_pos 0 43787 &ocfs2_xattr_get_value_outside_43787
121233 +btrfs_copy_from_user_43806 btrfs_copy_from_user 0-3-1 43806 NULL
121234 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
121235 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
121236 +read_flush_43851 read_flush 3 43851 NULL
121237 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
121238 +ec_dbgfs_cmd_write_43895 ec_dbgfs_cmd_write 3 43895 NULL
121239 +SendString_43928 SendString 3 43928 NULL
121240 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
121241 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
121242 +nla_reserve_43984 nla_reserve 3 43984 NULL
121243 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
121244 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 NULL nohasharray
121245 +scsi_command_size_43992 scsi_command_size 0 43992 &kvm_read_guest_virt_43992 nohasharray
121246 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &scsi_command_size_43992
121247 +emit_flags_44006 emit_flags 4-3 44006 NULL
121248 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
121249 +fru_strlen_44046 fru_strlen 0 44046 NULL
121250 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
121251 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
121252 +pci_msix_vec_count_44093 pci_msix_vec_count 0 44093 NULL
121253 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
121254 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
121255 +nouveau_clock_create__44116 nouveau_clock_create_ 6 44116 NULL
121256 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
121257 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
121258 +tracing_resize_saved_cmdlines_44140 tracing_resize_saved_cmdlines 1 44140 NULL
121259 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
121260 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
121261 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
121262 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
121263 +readreg_ipac_44186 readreg_ipac 0 44186 NULL
121264 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
121265 +btrfs_item_offset_nr_44220 btrfs_item_offset_nr 0 44220 NULL
121266 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
121267 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
121268 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
121269 +device_create_file_44285 device_create_file 0 44285 NULL
121270 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
121271 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
121272 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
121273 +ccp_init_data_44324 ccp_init_data 5 44324 NULL
121274 +rs_init_44327 rs_init 1 44327 NULL
121275 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 NULL nohasharray
121276 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 &nfs_fscache_get_super_cookie_44355
121277 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
121278 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
121279 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
121280 +strlcpy_44400 strlcpy 3 44400 NULL
121281 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
121282 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
121283 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
121284 +mic_virtio_copy_to_user_44472 mic_virtio_copy_to_user 3-4 44472 NULL
121285 +write_file_debug_44476 write_file_debug 3 44476 NULL
121286 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
121287 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
121288 +bio_advance_44496 bio_advance 2 44496 NULL
121289 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
121290 +ac_register_board_44504 ac_register_board 3 44504 NULL
121291 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
121292 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
121293 +spidev_write_44510 spidev_write 3 44510 NULL
121294 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
121295 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
121296 +comm_write_44537 comm_write 3 44537 NULL
121297 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
121298 +l2cap_sock_memcpy_fromiovec_cb_44573 l2cap_sock_memcpy_fromiovec_cb 4 44573 NULL
121299 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
121300 +xpcs_mmd_write_44633 xpcs_mmd_write 3 44633 NULL
121301 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
121302 +mpi_resize_44674 mpi_resize 2 44674 NULL
121303 +sysfs_create_link_44685 sysfs_create_link 0 44685 NULL
121304 +ts_read_44687 ts_read 3 44687 NULL
121305 +write_file_spectral_bins_44696 write_file_spectral_bins 3 44696 NULL
121306 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
121307 +C_SYSC_select_44701 C_SYSC_select 1 44701 NULL
121308 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 NULL nohasharray
121309 +xfer_to_user_44713 xfer_to_user 3 44713 &__generic_block_fiemap_44713
121310 +nft_hash_tbl_size_44724 nft_hash_tbl_size 0 44724 NULL
121311 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
121312 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
121313 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
121314 +efx_wanted_parallelism_44732 efx_wanted_parallelism 0 44732 NULL
121315 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
121316 +bch_bio_max_sectors_44755 bch_bio_max_sectors 0 44755 NULL
121317 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
121318 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
121319 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
121320 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
121321 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
121322 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
121323 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
121324 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
121325 +force_static_address_write_44819 force_static_address_write 3 44819 NULL
121326 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
121327 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
121328 +sisusb_write_44834 sisusb_write 3 44834 NULL
121329 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
121330 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
121331 +copydesc_user_44855 copydesc_user 3 44855 NULL
121332 +set_advertising_44870 set_advertising 4 44870 NULL
121333 +init_rs_44873 init_rs 1 44873 NULL
121334 +skb_availroom_44883 skb_availroom 0 44883 NULL
121335 +do_tty_write_44896 do_tty_write 5 44896 NULL
121336 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
121337 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
121338 +bytepos_delta_45017 bytepos_delta 0 45017 NULL
121339 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
121340 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
121341 +sysfs_do_create_link_sd_45057 sysfs_do_create_link_sd 0 45057 NULL
121342 +sel_write_user_45060 sel_write_user 3 45060 NULL
121343 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
121344 +lnet_expand1tb_45102 lnet_expand1tb 6 45102 NULL
121345 +snd_card_new_45104 snd_card_new 5 45104 NULL
121346 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
121347 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
121348 +usbdev_read_45114 usbdev_read 3 45114 NULL
121349 +send_to_tty_45141 send_to_tty 3 45141 NULL
121350 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
121351 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
121352 +device_write_45156 device_write 3 45156 NULL nohasharray
121353 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3-4 45156 &device_write_45156
121354 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
121355 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
121356 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL nohasharray
121357 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 &snd_sb_csp_load_user_45190
121358 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
121359 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
121360 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
121361 +event_enable_write_45238 event_enable_write 3 45238 NULL
121362 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
121363 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
121364 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
121365 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
121366 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
121367 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
121368 +brcmf_sdio_died_dump_45359 brcmf_sdio_died_dump 3 45359 NULL
121369 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
121370 +count_skb_frag_slots_45395 count_skb_frag_slots 0 45395 NULL
121371 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
121372 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
121373 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
121374 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
121375 +blkdev_direct_IO_45440 blkdev_direct_IO 4 45440 NULL
121376 +__node_remap_45458 __node_remap 4 45458 NULL
121377 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
121378 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
121379 +__calc_request_pg_45470 __calc_request_pg 0 45470 NULL
121380 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
121381 +copy_macs_45534 copy_macs 4 45534 NULL
121382 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
121383 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
121384 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
121385 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
121386 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
121387 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
121388 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
121389 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
121390 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
121391 +ip_dst_mtu_maybe_forward_45627 ip_dst_mtu_maybe_forward 0 45627 NULL
121392 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
121393 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
121394 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
121395 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 NULL nohasharray
121396 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 &bscnl_emit_45699
121397 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
121398 +wlcore_smart_config_decode_event_45714 wlcore_smart_config_decode_event 2-4 45714 NULL
121399 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
121400 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
121401 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
121402 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
121403 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
121404 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
121405 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
121406 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
121407 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
121408 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
121409 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
121410 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
121411 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
121412 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
121413 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
121414 +isdn_write_45863 isdn_write 3 45863 NULL
121415 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
121416 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
121417 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
121418 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
121419 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
121420 +btree_keys_cachelines_45928 btree_keys_cachelines 0 45928 NULL
121421 +alloc_mr_45935 alloc_mr 1 45935 NULL
121422 +copy_to_45969 copy_to 3 45969 NULL
121423 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
121424 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
121425 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
121426 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 NULL nohasharray
121427 +get_free_entries_46030 get_free_entries 1 46030 &fnic_reset_stats_read_46030
121428 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
121429 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
121430 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL nohasharray
121431 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 &dma_tx_errors_read_46060
121432 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
121433 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 NULL nohasharray
121434 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 &memcg_update_array_size_46111
121435 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
121436 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
121437 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
121438 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
121439 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
121440 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
121441 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
121442 +fq_resize_46195 fq_resize 2 46195 NULL
121443 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
121444 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
121445 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
121446 +dsp_write_46218 dsp_write 2 46218 NULL
121447 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
121448 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
121449 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
121450 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
121451 +C_SYSC_ppoll_46319 C_SYSC_ppoll 2 46319 NULL
121452 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL nohasharray
121453 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 &__hwahc_dev_set_key_46328
121454 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
121455 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
121456 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
121457 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
121458 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
121459 +wdata_alloc_and_fillpages_46437 wdata_alloc_and_fillpages 1 46437 NULL
121460 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
121461 +parport_pc_fifo_write_block_46455 parport_pc_fifo_write_block 3 46455 NULL
121462 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
121463 +filldir64_46469 filldir64 3 46469 NULL
121464 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
121465 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
121466 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
121467 +kmsg_read_46514 kmsg_read 3 46514 NULL nohasharray
121468 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 &kmsg_read_46514
121469 +nlm_end_grace_write_46517 nlm_end_grace_write 3 46517 NULL
121470 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
121471 +__btrfs_free_extent_46573 __btrfs_free_extent 7 46573 NULL
121472 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
121473 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
121474 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
121475 +il3945_stats_flag_46606 il3945_stats_flag 0-3 46606 NULL
121476 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
121477 +__kfifo_out_r_46623 __kfifo_out_r 0-3 46623 NULL
121478 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
121479 +pci_enable_device_46642 pci_enable_device 0 46642 NULL
121480 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
121481 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
121482 +l2cap_create_le_flowctl_pdu_46682 l2cap_create_le_flowctl_pdu 3 46682 NULL
121483 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
121484 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
121485 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
121486 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
121487 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
121488 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
121489 +ext4_count_free_46754 ext4_count_free 2 46754 NULL
121490 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
121491 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
121492 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
121493 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
121494 +readreg_46845 readreg 0 46845 NULL
121495 +spi_async_46857 spi_async 0 46857 NULL
121496 +vsnprintf_46863 vsnprintf 0 46863 NULL
121497 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
121498 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
121499 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
121500 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
121501 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
121502 +alloc_cmdid_46904 alloc_cmdid 0 46904 NULL
121503 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
121504 +wlcore_alloc_hw_46917 wlcore_alloc_hw 1-3 46917 NULL
121505 +fb_write_46924 fb_write 3 46924 NULL
121506 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
121507 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
121508 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
121509 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
121510 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
121511 +strlcat_46985 strlcat 3 46985 NULL
121512 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
121513 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
121514 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
121515 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
121516 +fs_path_len_47060 fs_path_len 0 47060 NULL
121517 +event_trigger_regex_write_47067 event_trigger_regex_write 3 47067 NULL
121518 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
121519 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
121520 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
121521 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
121522 +mousedev_read_47123 mousedev_read 3 47123 NULL
121523 +upcall_msg_size_47141 upcall_msg_size 2 47141 NULL
121524 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
121525 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
121526 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
121527 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
121528 +options_write_47243 options_write 3 47243 NULL
121529 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
121530 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
121531 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
121532 +vsnprintf_47291 vsnprintf 0 47291 NULL
121533 +SYSC_semop_47292 SYSC_semop 3 47292 NULL
121534 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
121535 +virtqueue_add_47306 virtqueue_add 3 47306 NULL
121536 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
121537 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
121538 +nvme_submit_admin_cmd_47357 nvme_submit_admin_cmd 0 47357 NULL
121539 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
121540 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
121541 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
121542 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
121543 +nv_rd32_47390 nv_rd32 0 47390 NULL nohasharray
121544 +trace_options_core_read_47390 trace_options_core_read 3 47390 &nv_rd32_47390
121545 +nametbl_list_47391 nametbl_list 2 47391 NULL
121546 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
121547 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
121548 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
121549 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
121550 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
121551 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
121552 +C_SYSC_set_mempolicy_47466 C_SYSC_set_mempolicy 3 47466 NULL
121553 +lprocfs_fid_write_common_47471 lprocfs_fid_write_common 2 47471 NULL
121554 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
121555 +newpart_47485 newpart 6-4 47485 NULL
121556 +mcp23s17_read_regs_47491 mcp23s17_read_regs 4 47491 NULL
121557 +core_sys_select_47494 core_sys_select 1 47494 NULL
121558 +as3722_block_write_47503 as3722_block_write 2-3 47503 NULL
121559 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
121560 +unlink_simple_47506 unlink_simple 3 47506 NULL
121561 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
121562 +ec_i2c_count_response_47518 ec_i2c_count_response 0 47518 NULL
121563 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
121564 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
121565 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
121566 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
121567 +drbg_statelen_47551 drbg_statelen 0 47551 NULL
121568 +read_ldt_47570 read_ldt 2 47570 NULL
121569 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
121570 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
121571 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
121572 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
121573 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
121574 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
121575 +ccp_sha_setkey_47633 ccp_sha_setkey 3 47633 NULL
121576 +get_size_47644 get_size 1-2 47644 NULL
121577 +osc_brw_prep_request_47680 osc_brw_prep_request 5 47680 NULL
121578 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL nohasharray
121579 +ipath_format_hwmsg_47700 ipath_format_hwmsg 2 47700 &packet_recvmsg_47700
121580 +save_microcode_47717 save_microcode 3 47717 NULL
121581 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
121582 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
121583 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
121584 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
121585 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
121586 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
121587 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
121588 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
121589 +ptlrpc_prep_req_47792 ptlrpc_prep_req 4 47792 NULL
121590 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
121591 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
121592 +lov_packmd_47810 lov_packmd 0 47810 NULL
121593 +tree_mod_log_insert_move_47823 tree_mod_log_insert_move 5 47823 NULL
121594 +read_file_spectral_bins_47829 read_file_spectral_bins 3 47829 NULL
121595 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
121596 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
121597 +vhci_read_47878 vhci_read 3 47878 NULL
121598 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
121599 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
121600 +comedi_write_47926 comedi_write 3 47926 NULL
121601 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
121602 +arch_setup_msi_irq_47959 arch_setup_msi_irq 0 47959 NULL
121603 +gether_get_ifname_47972 gether_get_ifname 3 47972 NULL
121604 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
121605 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
121606 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
121607 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
121608 +lustre_cfg_len_48002 lustre_cfg_len 0-1 48002 NULL
121609 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
121610 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
121611 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
121612 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
121613 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
121614 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
121615 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
121616 +disc_write_48070 disc_write 3 48070 NULL
121617 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
121618 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
121619 +wm_latency_write_48125 wm_latency_write 3 48125 NULL
121620 +load_firmware_48128 load_firmware 2 48128 NULL
121621 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
121622 +set_discoverable_48141 set_discoverable 4 48141 NULL
121623 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
121624 +SyS_vmsplice_48150 SyS_vmsplice 3 48150 NULL
121625 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
121626 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
121627 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
121628 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
121629 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
121630 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
121631 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
121632 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
121633 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
121634 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
121635 +read_file_recv_48232 read_file_recv 3 48232 NULL
121636 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
121637 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
121638 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
121639 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
121640 +__videobuf_free_48260 __videobuf_free 0 48260 NULL
121641 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
121642 +trace_options_write_48275 trace_options_write 3 48275 NULL
121643 +send_set_info_48288 send_set_info 7 48288 NULL
121644 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
121645 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
121646 +hash_setkey_48310 hash_setkey 3 48310 NULL
121647 +kvm_mmu_pte_write_48340 kvm_mmu_pte_write 2 48340 NULL
121648 +skb_add_data_48363 skb_add_data 3 48363 NULL
121649 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
121650 +ath10k_read_htt_max_amsdu_ampdu_48401 ath10k_read_htt_max_amsdu_ampdu 3 48401 NULL
121651 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
121652 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
121653 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
121654 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
121655 +print_filtered_48442 print_filtered 2-0 48442 NULL
121656 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
121657 +copy_page_from_iter_iovec_48466 copy_page_from_iter_iovec 3-0 48466 NULL
121658 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
121659 +_iwl_dbgfs_bt_tx_prio_write_48473 _iwl_dbgfs_bt_tx_prio_write 3 48473 NULL
121660 +ipath_format_hwerrors_48487 ipath_format_hwerrors 5 48487 NULL
121661 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
121662 +ocfs2_refcount_cow_48495 ocfs2_refcount_cow 3 48495 NULL
121663 +send_control_msg_48498 send_control_msg 6 48498 NULL
121664 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
121665 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
121666 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
121667 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
121668 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
121669 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
121670 +nvif_notify_init_48578 nvif_notify_init 7 48578 NULL
121671 +llog_data_len_48607 llog_data_len 1 48607 NULL
121672 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
121673 +kernel_sock_ioctl_48644 kernel_sock_ioctl 0 48644 NULL
121674 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
121675 +mtd_read_48655 mtd_read 0 48655 NULL
121676 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
121677 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
121678 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
121679 +altera_drscan_48698 altera_drscan 2 48698 NULL
121680 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
121681 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
121682 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
121683 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
121684 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
121685 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
121686 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
121687 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
121688 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
121689 +azx_get_position_48841 azx_get_position 0 48841 NULL
121690 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
121691 +comedi_buf_write_alloc_48846 comedi_buf_write_alloc 0-2 48846 NULL
121692 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
121693 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 NULL nohasharray
121694 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 &viafb_dvp1_proc_write_48864
121695 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
121696 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
121697 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
121698 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
121699 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
121700 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
121701 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
121702 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
121703 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
121704 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
121705 +nilfs_direct_IO_48981 nilfs_direct_IO 4 48981 NULL
121706 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
121707 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
121708 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
121709 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
121710 +transient_status_49027 transient_status 4 49027 NULL
121711 +ll_xattr_cache_add_49032 ll_xattr_cache_add 4-0 49032 NULL
121712 +scsi_register_49094 scsi_register 2 49094 NULL
121713 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
121714 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
121715 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
121716 +pt_read_49136 pt_read 3 49136 NULL nohasharray
121717 +netxen_setup_msi_interrupts_49136 netxen_setup_msi_interrupts 2 49136 &pt_read_49136
121718 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
121719 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
121720 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
121721 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
121722 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
121723 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
121724 +print_queue_49191 print_queue 0-4 49191 NULL
121725 +root_nfs_cat_49192 root_nfs_cat 3 49192 NULL
121726 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
121727 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
121728 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
121729 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
121730 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
121731 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
121732 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
121733 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
121734 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
121735 +uio_read_49300 uio_read 3 49300 NULL
121736 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
121737 +SYSC_mincore_49319 SYSC_mincore 2-1 49319 NULL
121738 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
121739 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
121740 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
121741 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
121742 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
121743 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
121744 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
121745 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
121746 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
121747 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
121748 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
121749 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
121750 +tipc_bclink_get_mtu_49483 tipc_bclink_get_mtu 0 49483 NULL
121751 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
121752 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
121753 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
121754 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
121755 +smk_write_access_49561 smk_write_access 3 49561 NULL
121756 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
121757 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
121758 +readfifo_49583 readfifo 1 49583 NULL
121759 +tap_write_49595 tap_write 3 49595 NULL
121760 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
121761 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
121762 +heap_init_49617 heap_init 2 49617 NULL
121763 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
121764 +port_fops_read_49626 port_fops_read 3 49626 NULL
121765 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
121766 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
121767 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
121768 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
121769 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
121770 +write_pool_49718 write_pool 3 49718 NULL
121771 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL nohasharray
121772 +sfw_create_test_rpc_49723 sfw_create_test_rpc 4 49723 &kvm_mmu_notifier_invalidate_page_49723
121773 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
121774 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
121775 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
121776 +fuse_wr_pages_49753 fuse_wr_pages 0-1-2 49753 NULL
121777 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
121778 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
121779 +w83977af_fir_interrupt_49775 w83977af_fir_interrupt 0 49775 NULL
121780 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
121781 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
121782 +__of_parse_phandle_with_args_49807 __of_parse_phandle_with_args 0 49807 NULL
121783 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6-0 49829 NULL
121784 +add_uuid_49831 add_uuid 4 49831 NULL
121785 +iraw_loop_49842 iraw_loop 0-1 49842 NULL
121786 +twl4030_write_49846 twl4030_write 2 49846 NULL
121787 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
121788 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
121789 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
121790 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
121791 +osc_brw_49896 osc_brw 4 49896 NULL
121792 +fuse_send_write_49915 fuse_send_write 4-0 49915 NULL
121793 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
121794 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
121795 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
121796 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
121797 +security_context_to_sid_50019 security_context_to_sid 2 50019 NULL
121798 +isdn_read_50021 isdn_read 3 50021 NULL
121799 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
121800 +xlog_recovery_process_trans_50028 xlog_recovery_process_trans 4 50028 NULL
121801 +brcmf_debugfs_chipinfo_read_50033 brcmf_debugfs_chipinfo_read 3 50033 NULL
121802 +ioread8_50049 ioread8 0 50049 NULL
121803 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
121804 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
121805 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
121806 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
121807 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
121808 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
121809 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
121810 +read_file_slot_50111 read_file_slot 3 50111 NULL
121811 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
121812 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
121813 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
121814 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
121815 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
121816 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
121817 +odev_update_50169 odev_update 2 50169 NULL
121818 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL nohasharray
121819 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 &ubi_resize_volume_50172
121820 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
121821 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
121822 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
121823 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
121824 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
121825 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
121826 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
121827 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
121828 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
121829 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
121830 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
121831 +do_launder_page_50329 do_launder_page 0 50329 NULL
121832 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
121833 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
121834 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
121835 +tpm_read_50344 tpm_read 3 50344 NULL
121836 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
121837 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
121838 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
121839 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
121840 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
121841 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
121842 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
121843 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
121844 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
121845 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
121846 +device_create_sys_dev_entry_50458 device_create_sys_dev_entry 0 50458 NULL
121847 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
121848 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
121849 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
121850 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
121851 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
121852 +trigger_request_store_50548 trigger_request_store 4 50548 NULL
121853 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
121854 +fat_readpages_50582 fat_readpages 4 50582 NULL
121855 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
121856 +xillybus_write_50605 xillybus_write 3 50605 NULL
121857 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
121858 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
121859 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
121860 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
121861 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
121862 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
121863 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
121864 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
121865 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
121866 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
121867 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
121868 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
121869 +tpm_write_50798 tpm_write 3 50798 NULL
121870 +tun_do_read_50800 tun_do_read 4 50800 NULL
121871 +write_flush_50803 write_flush 3 50803 NULL
121872 +dvb_play_50814 dvb_play 3 50814 NULL
121873 +btrfs_stack_file_extent_disk_num_bytes_50825 btrfs_stack_file_extent_disk_num_bytes 0 50825 NULL
121874 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
121875 +SetArea_50835 SetArea 4 50835 NULL
121876 +nft_trans_alloc_50836 nft_trans_alloc 3 50836 NULL
121877 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
121878 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
121879 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
121880 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
121881 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
121882 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
121883 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
121884 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
121885 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
121886 +show_device_status_50947 show_device_status 0 50947 NULL
121887 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
121888 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
121889 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
121890 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
121891 +of_modalias_node_50975 of_modalias_node 3 50975 NULL
121892 +iwl_statistics_flag_50981 iwl_statistics_flag 0-3 50981 NULL
121893 +timeout_write_50991 timeout_write 3 50991 NULL
121894 +proc_write_51003 proc_write 3 51003 NULL
121895 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
121896 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
121897 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
121898 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
121899 +dump_midi_51040 dump_midi 3 51040 NULL
121900 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
121901 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
121902 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
121903 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
121904 +rsc_mgr_init_51067 rsc_mgr_init 3 51067 NULL
121905 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
121906 +__ipv4_tun_to_nlattr_51095 __ipv4_tun_to_nlattr 4 51095 NULL
121907 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
121908 +ti_recv_51110 ti_recv 3 51110 NULL
121909 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
121910 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
121911 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
121912 +i40evf_acquire_msix_vectors_51190 i40evf_acquire_msix_vectors 2 51190 NULL
121913 +iwl_dbgfs_bcast_filters_macs_read_51231 iwl_dbgfs_bcast_filters_macs_read 3 51231 NULL
121914 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
121915 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
121916 +drm_property_create_51239 drm_property_create 4 51239 NULL
121917 +st_read_51251 st_read 3 51251 NULL
121918 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
121919 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
121920 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
121921 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
121922 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
121923 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
121924 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
121925 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
121926 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
121927 +smk_write_ptrace_51333 smk_write_ptrace 3 51333 NULL
121928 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
121929 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
121930 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
121931 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
121932 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
121933 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
121934 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
121935 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
121936 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
121937 +vmxnet3_acquire_msix_vectors_51462 vmxnet3_acquire_msix_vectors 2 51462 NULL
121938 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
121939 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
121940 +osc_brw_internal_51489 osc_brw_internal 5 51489 NULL
121941 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
121942 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
121943 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
121944 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
121945 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
121946 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
121947 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
121948 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
121949 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
121950 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
121951 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
121952 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
121953 +rtw_os_xmit_resource_alloc23a_51693 rtw_os_xmit_resource_alloc23a 3 51693 NULL
121954 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
121955 +sel_write_access_51704 sel_write_access 3 51704 NULL
121956 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
121957 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
121958 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
121959 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
121960 +str_read_51731 str_read 4 51731 NULL
121961 +cm4040_read_51732 cm4040_read 3 51732 NULL
121962 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
121963 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
121964 +if_write_51756 if_write 3 51756 NULL
121965 +ssd1307fb_alloc_array_51788 ssd1307fb_alloc_array 1 51788 NULL
121966 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
121967 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
121968 +ioread32_51847 ioread32 0 51847 NULL nohasharray
121969 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
121970 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
121971 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
121972 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
121973 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
121974 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
121975 +user_read_51881 user_read 3 51881 NULL
121976 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
121977 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
121978 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
121979 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
121980 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
121981 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
121982 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
121983 +get_clock_info_51952 get_clock_info 4 51952 NULL
121984 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
121985 +get_zone_51981 get_zone 0-1 51981 NULL
121986 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
121987 +_c4iw_write_mem_dma_51991 _c4iw_write_mem_dma 3 51991 NULL
121988 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
121989 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
121990 +rdmalt_52022 rdmalt 0 52022 NULL
121991 +override_release_52032 override_release 2 52032 NULL
121992 +end_port_52042 end_port 0 52042 NULL
121993 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
121994 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
121995 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
121996 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
121997 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
121998 +mxuport_process_read_urb_data_52072 mxuport_process_read_urb_data 3 52072 NULL
121999 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
122000 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
122001 +smsdvb_stats_read_52114 smsdvb_stats_read 3 52114 NULL
122002 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
122003 +retry_count_read_52129 retry_count_read 3 52129 NULL
122004 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
122005 +sub_alloc_52140 sub_alloc 0 52140 NULL
122006 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
122007 +htable_size_52148 htable_size 0-1 52148 NULL
122008 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
122009 +tipc_node_get_mtu_52157 tipc_node_get_mtu 0 52157 NULL
122010 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
122011 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
122012 +print_prefix_52176 print_prefix 0 52176 NULL
122013 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
122014 +reiserfs_posix_acl_from_disk_52191 reiserfs_posix_acl_from_disk 2 52191 NULL
122015 +f2fs_seek_block_52194 f2fs_seek_block 2 52194 NULL
122016 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
122017 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL
122018 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
122019 +shrink_slab_52261 shrink_slab 2 52261 NULL
122020 +ext2_direct_IO_52270 ext2_direct_IO 4 52270 NULL
122021 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
122022 +handle_supp_msgs_52284 handle_supp_msgs 4 52284 NULL
122023 +kobject_set_name_vargs_52309 kobject_set_name_vargs 0 52309 NULL
122024 +read_file_reset_52310 read_file_reset 3 52310 NULL
122025 +ssd1307fb_write_52315 ssd1307fb_write 3 52315 NULL
122026 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
122027 +hwflags_read_52318 hwflags_read 3 52318 NULL
122028 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
122029 +hur_len_52339 hur_len 0 52339 NULL
122030 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL
122031 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
122032 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
122033 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
122034 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
122035 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
122036 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
122037 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
122038 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
122039 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
122040 +delay_status_52431 delay_status 5 52431 NULL
122041 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
122042 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
122043 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
122044 +bt_alloc_52457 bt_alloc 2 52457 NULL
122045 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
122046 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
122047 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
122048 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
122049 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
122050 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
122051 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
122052 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
122053 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
122054 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
122055 +SyS_vmsplice_52540 SyS_vmsplice 3 52540 NULL
122056 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
122057 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
122058 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
122059 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
122060 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
122061 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
122062 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
122063 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
122064 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
122065 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
122066 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
122067 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
122068 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
122069 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
122070 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
122071 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
122072 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
122073 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
122074 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
122075 +xenvif_write_io_ring_52802 xenvif_write_io_ring 3 52802 NULL
122076 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
122077 +lb_alloc_ep_req_52837 lb_alloc_ep_req 2 52837 NULL
122078 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
122079 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
122080 +qib_decode_6120_err_52876 qib_decode_6120_err 3 52876 NULL
122081 +twlreg_write_52880 twlreg_write 3 52880 NULL
122082 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
122083 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
122084 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
122085 +copy_from_iter_bvec_52912 copy_from_iter_bvec 0-2 52912 NULL
122086 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
122087 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
122088 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
122089 +__nodes_remap_52951 __nodes_remap 5 52951 NULL
122090 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
122091 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
122092 +num_node_state_52989 num_node_state 0 52989 NULL
122093 +efivarfs_file_write_53000 efivarfs_file_write 3 53000 NULL
122094 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
122095 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
122096 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
122097 +nv50_chan_create_53039 nv50_chan_create 5 53039 NULL
122098 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
122099 +fimc_get_alpha_mask_53057 fimc_get_alpha_mask 0 53057 NULL
122100 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
122101 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
122102 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
122103 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
122104 +ath10k_mac_create_53118 ath10k_mac_create 1 53118 NULL
122105 +verity_status_53120 verity_status 5 53120 NULL
122106 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
122107 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
122108 +copy_user_segment_list_53150 copy_user_segment_list 2 53150 NULL
122109 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
122110 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
122111 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
122112 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
122113 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
122114 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5 53258 NULL
122115 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
122116 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
122117 +f2fs_fiemap_53310 f2fs_fiemap 4 53310 NULL
122118 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
122119 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
122120 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
122121 +btree_keys_bytes_53348 btree_keys_bytes 0 53348 NULL
122122 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
122123 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
122124 +test_fw_misc_read_53384 test_fw_misc_read 3 53384 NULL
122125 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
122126 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
122127 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
122128 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
122129 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL nohasharray
122130 +create_trace_kprobe_53475 create_trace_kprobe 1 53475 &ima_write_template_field_data_53475
122131 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
122132 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
122133 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
122134 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
122135 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
122136 +check_acl_53512 check_acl 0 53512 NULL nohasharray
122137 +force_sc_support_write_53512 force_sc_support_write 3 53512 &check_acl_53512
122138 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
122139 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
122140 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
122141 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
122142 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
122143 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL nohasharray
122144 +wil_write_file_txmgmt_53626 wil_write_file_txmgmt 3 53626 &___alloc_bootmem_nopanic_53626
122145 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
122146 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
122147 +fuse_fill_write_pages_53682 fuse_fill_write_pages 0-4 53682 NULL
122148 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
122149 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
122150 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
122151 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
122152 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
122153 +wdm_write_53735 wdm_write 3 53735 NULL
122154 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 NULL
122155 +wa_populate_buf_in_urb_53758 wa_populate_buf_in_urb 3-4 53758 NULL
122156 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
122157 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
122158 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
122159 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
122160 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
122161 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
122162 +setup_data_read_53822 setup_data_read 3 53822 NULL
122163 +btrfs_free_reserved_extent_53873 btrfs_free_reserved_extent 2 53873 NULL nohasharray
122164 +pms_read_53873 pms_read 3 53873 &btrfs_free_reserved_extent_53873
122165 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
122166 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
122167 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
122168 +azx_via_get_position_53916 azx_via_get_position 0 53916 NULL
122169 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
122170 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
122171 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
122172 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
122173 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
122174 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
122175 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
122176 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
122177 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
122178 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
122179 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
122180 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
122181 +bitmap_bitremap_54096 bitmap_bitremap 4 54096 NULL
122182 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL nohasharray
122183 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2 54103 &altera_set_ir_pre_54103
122184 +__comedi_buf_write_alloc_54112 __comedi_buf_write_alloc 0-2 54112 NULL
122185 +strn_len_54122 strn_len 0 54122 NULL
122186 +isku_receive_54130 isku_receive 4 54130 NULL
122187 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
122188 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
122189 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
122190 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
122191 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
122192 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
122193 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
122194 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
122195 +mcp23s08_read_regs_54246 mcp23s08_read_regs 4 54246 NULL
122196 +reada_add_block_54247 reada_add_block 2 54247 NULL
122197 +write_file_spec_scan_ctl_54248 write_file_spec_scan_ctl 3 54248 NULL
122198 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
122199 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
122200 +audio_write_54261 audio_write 4 54261 NULL nohasharray
122201 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
122202 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
122203 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
122204 +sizeof_long_54276 sizeof_long 0 54276 NULL
122205 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
122206 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
122207 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
122208 +sprintf_54306 sprintf 0 54306 NULL
122209 +path_setxattr_54308 path_setxattr 4 54308 NULL
122210 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
122211 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
122212 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
122213 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
122214 +readlink_copy_54366 readlink_copy 2 54366 NULL
122215 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
122216 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 NULL nohasharray
122217 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 &intel_sdvo_write_cmd_54377
122218 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
122219 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 0-3 54387 NULL
122220 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL nohasharray
122221 +hash_mac4_expire_54392 hash_mac4_expire 4 54392 &iwl_dbgfs_power_save_status_read_54392
122222 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
122223 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
122224 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
122225 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
122226 +l2cap_create_basic_pdu_54508 l2cap_create_basic_pdu 3 54508 NULL
122227 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
122228 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
122229 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
122230 +viacam_read_54526 viacam_read 3 54526 NULL
122231 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
122232 +setsockopt_54539 setsockopt 5 54539 NULL
122233 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
122234 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
122235 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
122236 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
122237 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
122238 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
122239 +port_fops_write_54627 port_fops_write 3 54627 NULL
122240 +tipc_send_stream_54648 tipc_send_stream 4 54648 NULL
122241 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
122242 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
122243 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
122244 +simple_alloc_urb_54661 simple_alloc_urb 3 54661 NULL
122245 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
122246 +bus_add_device_54665 bus_add_device 0 54665 NULL
122247 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
122248 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
122249 +evm_read_key_54674 evm_read_key 3 54674 NULL
122250 +jfs_direct_IO_54687 jfs_direct_IO 4 54687 NULL
122251 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
122252 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
122253 +kzalloc_54740 kzalloc 1 54740 NULL
122254 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
122255 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
122256 +crystalhd_user_data_54754 crystalhd_user_data 3 54754 NULL
122257 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
122258 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
122259 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
122260 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
122261 +nfsd_write_54809 nfsd_write 6 54809 NULL
122262 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
122263 +kvzalloc_54815 kvzalloc 1 54815 NULL nohasharray
122264 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 &kvzalloc_54815 nohasharray
122265 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &crypto_tfm_ctx_alignment_54815
122266 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
122267 +write_rio_54837 write_rio 3 54837 NULL
122268 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
122269 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
122270 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
122271 +printer_read_54851 printer_read 3 54851 NULL
122272 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
122273 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
122274 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL nohasharray
122275 +kobject_set_name_vargs_54913 kobject_set_name_vargs 0 54913 &iscsi_pool_init_54913
122276 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
122277 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
122278 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
122279 +add_port_54941 add_port 2 54941 NULL
122280 +tipc_send2name_54946 tipc_send2name 5 54946 NULL
122281 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 0-3 54949 NULL
122282 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
122283 +c4_add_card_54968 c4_add_card 3 54968 NULL
122284 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
122285 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
122286 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
122287 +efw_transaction_55052 efw_transaction 5-7 55052 NULL
122288 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
122289 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
122290 +read_dma_55086 read_dma 3 55086 NULL
122291 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
122292 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
122293 +filldir_55137 filldir 3 55137 NULL
122294 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
122295 +npages_to_npools_55149 npages_to_npools 0-1 55149 NULL
122296 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
122297 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
122298 +compat_SyS_ppoll_55196 compat_SyS_ppoll 2 55196 NULL
122299 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
122300 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
122301 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
122302 +mlx4_load_one_55213 mlx4_load_one 3 55213 NULL
122303 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
122304 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
122305 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
122306 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
122307 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
122308 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
122309 +persistent_ram_new_55286 persistent_ram_new 1-2 55286 NULL
122310 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
122311 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
122312 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
122313 +wimax_msg_len_55304 wimax_msg_len 0 55304 NULL
122314 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 NULL nohasharray
122315 +compat_SyS_process_vm_readv_55305 compat_SyS_process_vm_readv 3-5 55305 &qp_alloc_guest_work_55305
122316 +compat_SyS_mbind_55329 compat_SyS_mbind 5 55329 NULL
122317 +vme_user_read_55338 vme_user_read 3 55338 NULL
122318 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 NULL nohasharray
122319 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 &__wa_xfer_setup_sizes_55342
122320 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
122321 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
122322 +nouveau_cli_create_55425 nouveau_cli_create 3 55425 NULL
122323 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
122324 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
122325 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
122326 +ufshcd_exec_dev_cmd_55479 ufshcd_exec_dev_cmd 0 55479 NULL
122327 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
122328 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
122329 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
122330 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
122331 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
122332 +ea_get_55522 ea_get 3-0 55522 NULL
122333 +buffer_size_55534 buffer_size 0 55534 NULL
122334 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
122335 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
122336 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
122337 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
122338 +compat_SyS_setsockopt_55581 compat_SyS_setsockopt 5 55581 NULL
122339 +add_partition_55588 add_partition 2 55588 NULL
122340 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
122341 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL
122342 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
122343 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
122344 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
122345 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 NULL nohasharray
122346 +pktgen_if_write_55628 pktgen_if_write 3 55628 &reiserfs_xattr_get_55628
122347 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
122348 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
122349 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
122350 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
122351 +get_info_55681 get_info 3 55681 NULL
122352 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
122353 +ext4_alloc_file_blocks_55689 ext4_alloc_file_blocks 3 55689 NULL
122354 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
122355 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
122356 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
122357 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
122358 +set_local_name_55757 set_local_name 4 55757 NULL
122359 +ethtool_copy_validate_indir_55769 ethtool_copy_validate_indir 4 55769 NULL
122360 +strlen_55778 strlen 0 55778 NULL
122361 +set_spte_55783 set_spte 4-5 55783 NULL
122362 +conf_read_55786 conf_read 3 55786 NULL nohasharray
122363 +req_bio_endio_55786 req_bio_endio 3 55786 &conf_read_55786
122364 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
122365 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
122366 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
122367 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
122368 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
122369 +hsc_write_55875 hsc_write 3 55875 NULL
122370 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
122371 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
122372 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
122373 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
122374 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
122375 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
122376 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
122377 +simple_read_from_buffer_55957 simple_read_from_buffer 5-2-0 55957 NULL
122378 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
122379 +btrfs_clone_55977 btrfs_clone 5-3-6 55977 NULL
122380 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
122381 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
122382 +iwl_trans_read_prph_56052 iwl_trans_read_prph 0 56052 NULL
122383 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
122384 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
122385 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
122386 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
122387 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
122388 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
122389 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 0-3 56194 NULL
122390 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
122391 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
122392 +ufshcd_query_descriptor_56236 ufshcd_query_descriptor 0 56236 NULL
122393 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
122394 +fd_copyin_56247 fd_copyin 3 56247 NULL
122395 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
122396 +acpi_ex_get_serial_access_length_56275 acpi_ex_get_serial_access_length 0-2 56275 NULL
122397 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
122398 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
122399 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
122400 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
122401 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
122402 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
122403 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
122404 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
122405 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
122406 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
122407 +mite_device_bytes_transferred_56355 mite_device_bytes_transferred 0 56355 NULL
122408 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 0-4 56368 NULL
122409 +dev_read_56369 dev_read 3 56369 NULL
122410 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
122411 +lnet_ping_56378 lnet_ping 4 56378 NULL
122412 +write_gssp_56404 write_gssp 3 56404 NULL
122413 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
122414 +store_msg_56417 store_msg 3 56417 NULL
122415 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
122416 +l2cap_segment_le_sdu_56426 l2cap_segment_le_sdu 4 56426 NULL nohasharray
122417 +nvme_submit_cmd_56426 nvme_submit_cmd 0 56426 &l2cap_segment_le_sdu_56426
122418 +lprocfs_fid_space_seq_write_56431 lprocfs_fid_space_seq_write 3 56431 NULL nohasharray
122419 +ec_dbgfs_cmd_read_56431 ec_dbgfs_cmd_read 3 56431 &lprocfs_fid_space_seq_write_56431
122420 +fl_create_56435 fl_create 5 56435 NULL
122421 +gnttab_map_56439 gnttab_map 2 56439 NULL
122422 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
122423 +set_connectable_56458 set_connectable 4 56458 NULL
122424 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
122425 +putused_user_56467 putused_user 3 56467 NULL
122426 +ocfs2_zero_extend_range_56468 ocfs2_zero_extend_range 3-2 56468 NULL
122427 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
122428 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
122429 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
122430 +memblock_virt_alloc_56501 memblock_virt_alloc 1 56501 NULL
122431 +init_map_ip_56508 init_map_ip 5 56508 NULL
122432 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3 56512 NULL
122433 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
122434 +ip_options_get_56538 ip_options_get 4 56538 NULL
122435 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
122436 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
122437 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
122438 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
122439 +gro_pull_from_frag0_56593 gro_pull_from_frag0 2 56593 NULL
122440 +event_filter_write_56609 event_filter_write 3 56609 NULL
122441 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
122442 +gather_array_56641 gather_array 3 56641 NULL
122443 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
122444 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
122445 +nv50_gpio_intr_mask_56665 nv50_gpio_intr_mask 4-3 56665 NULL
122446 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
122447 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
122448 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
122449 +sfw_alloc_pages_56709 sfw_alloc_pages 3 56709 NULL
122450 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
122451 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
122452 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
122453 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
122454 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
122455 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
122456 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
122457 +ion_ioctl_56806 ion_ioctl 2 56806 NULL
122458 +do_syslog_56807 do_syslog 3 56807 NULL
122459 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
122460 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
122461 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
122462 +gk20a_ram_get_56863 gk20a_ram_get 2 56863 NULL
122463 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
122464 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
122465 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
122466 +le_auto_conn_write_56895 le_auto_conn_write 3 56895 NULL nohasharray
122467 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 &le_auto_conn_write_56895
122468 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
122469 +strcspn_56913 strcspn 0 56913 NULL
122470 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
122471 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
122472 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
122473 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
122474 +sptlrpc_secflags2str_56995 sptlrpc_secflags2str 3 56995 NULL
122475 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
122476 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
122477 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
122478 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL nohasharray
122479 +skb_network_offset_57043 skb_network_offset 0 57043 &ieee80211_if_fmt_state_57043
122480 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
122481 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
122482 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
122483 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
122484 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
122485 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
122486 +altera_get_note_57099 altera_get_note 6 57099 NULL
122487 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
122488 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
122489 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
122490 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL nohasharray
122491 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 &ima_show_htable_value_57136 nohasharray
122492 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136
122493 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
122494 +_iwl_dbgfs_bf_params_write_57141 _iwl_dbgfs_bf_params_write 3 57141 NULL
122495 +acpi_gsb_i2c_read_bytes_57145 acpi_gsb_i2c_read_bytes 4 57145 NULL
122496 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
122497 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
122498 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
122499 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
122500 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
122501 +dma_fifo_alloc_57236 dma_fifo_alloc 2-3-5 57236 NULL
122502 +drbg_blocklen_57239 drbg_blocklen 0 57239 NULL
122503 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
122504 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
122505 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
122506 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
122507 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
122508 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
122509 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
122510 +string_length_no_trail_57290 string_length_no_trail 0-2 57290 NULL
122511 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
122512 +write_file_regval_57313 write_file_regval 3 57313 NULL
122513 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
122514 +usblp_read_57342 usblp_read 3 57342 NULL
122515 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
122516 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
122517 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
122518 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
122519 +bzImage64_load_57388 bzImage64_load 7 57388 NULL
122520 +read_file_blob_57406 read_file_blob 3 57406 NULL
122521 +enclosure_register_57412 enclosure_register 3 57412 NULL
122522 +read_file_eeprom_57428 read_file_eeprom 3 57428 NULL
122523 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
122524 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
122525 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
122526 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
122527 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
122528 +read_file_skb_rx_57490 read_file_skb_rx 3 57490 NULL
122529 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
122530 +skb_headlen_57501 skb_headlen 0 57501 NULL
122531 +copy_in_user_57502 copy_in_user 3 57502 NULL
122532 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL
122533 +init_tag_map_57515 init_tag_map 3 57515 NULL
122534 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 NULL nohasharray
122535 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 &wil_read_file_ssid_57517
122536 +cmm_read_57520 cmm_read 3 57520 NULL
122537 +inode_permission_57531 inode_permission 0 57531 NULL
122538 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
122539 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
122540 +compat_SyS_process_vm_writev_57542 compat_SyS_process_vm_writev 3-5 57542 NULL
122541 +ReadHDLCPnP_57559 ReadHDLCPnP 0 57559 NULL
122542 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
122543 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
122544 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
122545 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
122546 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
122547 +copy_to_iter_bvec_57604 copy_to_iter_bvec 0-2 57604 NULL
122548 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
122549 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
122550 +mem_read_57631 mem_read 3 57631 NULL
122551 +r3964_write_57662 r3964_write 4 57662 NULL
122552 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
122553 +__lgwrite_57669 __lgwrite 4 57669 NULL
122554 +f1x_match_to_this_node_57695 f1x_match_to_this_node 3 57695 NULL
122555 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
122556 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
122557 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL
122558 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
122559 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
122560 +ld2_57794 ld2 0 57794 NULL
122561 +ivtv_read_57796 ivtv_read 3 57796 NULL
122562 +ion_test_ioctl_57799 ion_test_ioctl 2 57799 NULL
122563 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
122564 +copy_to_user_57835 copy_to_user 3-0 57835 NULL
122565 +flash_read_57843 flash_read 3 57843 NULL
122566 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
122567 +radeon_ttm_gtt_read_57879 radeon_ttm_gtt_read 3 57879 NULL
122568 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
122569 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
122570 +ll_xattr_find_get_lock_57912 ll_xattr_find_get_lock 0 57912 NULL
122571 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
122572 +mwifiex_hscfg_read_57920 mwifiex_hscfg_read 3 57920 NULL
122573 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
122574 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
122575 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
122576 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
122577 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
122578 +arch_gnttab_init_57948 arch_gnttab_init 2-1 57948 NULL
122579 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
122580 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
122581 +iov_iter_npages_57979 iov_iter_npages 0-2 57979 NULL
122582 +do_rx_dma_57996 do_rx_dma 5 57996 NULL
122583 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
122584 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
122585 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
122586 +mce_async_out_58056 mce_async_out 3 58056 NULL
122587 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
122588 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
122589 +cm4040_write_58079 cm4040_write 3 58079 NULL
122590 +savemem_58129 savemem 3 58129 NULL
122591 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
122592 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
122593 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
122594 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
122595 +i40evf_allocate_virt_mem_d_58210 i40evf_allocate_virt_mem_d 3 58210 NULL
122596 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
122597 +read_file_debug_58256 read_file_debug 3 58256 NULL
122598 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
122599 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
122600 +profile_load_58267 profile_load 3 58267 NULL
122601 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
122602 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
122603 +r100_mm_rreg_58276 r100_mm_rreg 0 58276 NULL
122604 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
122605 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
122606 +mic_virtio_copy_from_user_58323 mic_virtio_copy_from_user 3 58323 NULL
122607 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
122608 +lstcon_rpc_prep_58325 lstcon_rpc_prep 4 58325 NULL
122609 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
122610 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
122611 +ec_i2c_parse_response_58347 ec_i2c_parse_response 0 58347 NULL
122612 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
122613 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
122614 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
122615 +kvm_mmu_write_protect_pt_masked_58406 kvm_mmu_write_protect_pt_masked 3 58406 NULL nohasharray
122616 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 &kvm_mmu_write_protect_pt_masked_58406
122617 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
122618 +capabilities_read_58457 capabilities_read 3 58457 NULL
122619 +usnic_vnic_get_resources_58462 usnic_vnic_get_resources 3 58462 NULL
122620 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 NULL nohasharray
122621 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 &compat_do_ipt_set_ctl_58466
122622 +nv_rd08_58472 nv_rd08 0 58472 NULL
122623 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
122624 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
122625 +dw_spi_show_regs_58486 dw_spi_show_regs 3 58486 NULL
122626 +btrfs_cont_expand_58498 btrfs_cont_expand 2-3 58498 NULL
122627 +tcf_hash_create_58507 tcf_hash_create 4 58507 NULL
122628 +cifs_write_from_iter_58526 cifs_write_from_iter 2 58526 NULL
122629 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
122630 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
122631 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
122632 +cur_wm_latency_write_58581 cur_wm_latency_write 3 58581 NULL
122633 +get_rhf_errstring_58582 get_rhf_errstring 3 58582 NULL
122634 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
122635 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
122636 +xip_file_read_58592 xip_file_read 3 58592 NULL
122637 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
122638 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
122639 +btrfs_direct_IO_58608 btrfs_direct_IO 4 58608 NULL
122640 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
122641 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
122642 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
122643 +find_zero_58685 find_zero 0-1 58685 NULL
122644 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
122645 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
122646 +visor_charqueue_create_58703 visor_charqueue_create 1 58703 NULL
122647 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
122648 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
122649 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
122650 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
122651 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
122652 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
122653 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
122654 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
122655 +ep_read_58813 ep_read 3 58813 NULL
122656 +command_write_58841 command_write 3 58841 NULL
122657 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
122658 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
122659 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
122660 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
122661 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
122662 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
122663 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
122664 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
122665 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
122666 +init_list_set_59005 init_list_set 3 59005 NULL
122667 +ep_write_59008 ep_write 3 59008 NULL
122668 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
122669 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
122670 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
122671 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
122672 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
122673 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL
122674 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
122675 +sta_tx_latency_stat_table_59122 sta_tx_latency_stat_table 0-4-5 59122 NULL nohasharray
122676 +scsi_io_completion_59122 scsi_io_completion 2 59122 &sta_tx_latency_stat_table_59122
122677 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
122678 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL nohasharray
122679 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 &framebuffer_alloc_59145
122680 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
122681 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
122682 +ksize_59176 ksize 0 59176 NULL
122683 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
122684 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
122685 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
122686 +check_mapped_selector_name_59216 check_mapped_selector_name 5 59216 NULL
122687 +dt3155_read_59226 dt3155_read 3 59226 NULL
122688 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-1-2 59229 NULL
122689 +nla_len_59258 nla_len 0 59258 NULL
122690 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
122691 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
122692 +fd_copyout_59323 fd_copyout 3 59323 NULL
122693 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
122694 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
122695 +__map_request_59350 __map_request 0 59350 NULL
122696 +SyS_getrandom_59366 SyS_getrandom 2 59366 NULL
122697 +f2fs_fallocate_59377 f2fs_fallocate 4-3 59377 NULL
122698 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
122699 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
122700 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
122701 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
122702 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
122703 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
122704 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
122705 +tipc_recv_stream_59456 tipc_recv_stream 4 59456 NULL
122706 +_iwl_dbgfs_bcast_filters_write_59491 _iwl_dbgfs_bcast_filters_write 3 59491 NULL
122707 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
122708 +C_SYSC_get_mempolicy_59516 C_SYSC_get_mempolicy 3 59516 NULL
122709 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
122710 +msix_setup_entries_59545 msix_setup_entries 0 59545 NULL
122711 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
122712 +tunables_write_59563 tunables_write 3 59563 NULL
122713 +bio_split_59564 bio_split 2 59564 NULL
122714 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
122715 +write_pbl_59583 write_pbl 4 59583 NULL
122716 +memdup_user_59590 memdup_user 2 59590 NULL
122717 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL nohasharray
122718 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 &mem_fwlog_free_mem_blks_read_59616
122719 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
122720 +mtrr_write_59622 mtrr_write 3 59622 NULL
122721 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
122722 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
122723 +hidraw_read_59650 hidraw_read 3 59650 NULL
122724 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
122725 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
122726 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
122727 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
122728 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
122729 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
122730 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
122731 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL nohasharray
122732 +nv94_aux_mask_59740 nv94_aux_mask 2 59740 &ieee80211_if_read_fwded_unicast_59740
122733 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
122734 +strnlen_59746 strnlen 0 59746 NULL
122735 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
122736 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
122737 +venus_remove_59781 venus_remove 4 59781 NULL
122738 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
122739 +C_SYSC_preadv_59801 C_SYSC_preadv 3 59801 NULL
122740 +ipw_write_59807 ipw_write 3 59807 NULL
122741 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
122742 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
122743 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
122744 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
122745 +biovec_create_pool_59878 biovec_create_pool 1 59878 NULL
122746 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
122747 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
122748 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
122749 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
122750 +ath10k_read_dfs_stats_59949 ath10k_read_dfs_stats 3 59949 NULL
122751 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
122752 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
122753 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
122754 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
122755 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
122756 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
122757 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
122758 +copy_items_60009 copy_items 7 60009 NULL
122759 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
122760 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
122761 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
122762 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
122763 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
122764 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
122765 +vcs_size_60050 vcs_size 0 60050 NULL
122766 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
122767 +compat_writev_60063 compat_writev 3 60063 NULL
122768 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
122769 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
122770 +usb_os_desc_prepare_interf_dir_60075 usb_os_desc_prepare_interf_dir 2 60075 NULL
122771 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
122772 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
122773 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
122774 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
122775 +pcpu_need_to_extend_60133 pcpu_need_to_extend 0 60133 NULL
122776 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
122777 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
122778 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
122779 +init_state_60165 init_state 2 60165 NULL
122780 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 NULL nohasharray
122781 +sg_build_sgat_60179 sg_build_sgat 3 60179 &jffs2_alloc_full_dirent_60179
122782 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
122783 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL nohasharray
122784 +arch_setup_msi_irqs_60193 arch_setup_msi_irqs 0 60193 &rx_rx_tkip_replays_read_60193
122785 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
122786 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
122787 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
122788 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
122789 +printer_write_60276 printer_write 3 60276 NULL
122790 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
122791 +getDataLength_60301 getDataLength 0 60301 NULL
122792 +bch_subtract_dirty_60306 bch_subtract_dirty 3-4 60306 NULL
122793 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
122794 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
122795 +max_unfragmented_pages_60362 max_unfragmented_pages 0 60362 NULL
122796 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
122797 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
122798 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
122799 +driver_names_read_60399 driver_names_read 3 60399 NULL
122800 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
122801 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
122802 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
122803 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
122804 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
122805 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
122806 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
122807 +compat_SyS_get_mempolicy_60527 compat_SyS_get_mempolicy 3 60527 NULL
122808 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
122809 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
122810 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
122811 +xfs_vm_direct_IO_60557 xfs_vm_direct_IO 4 60557 NULL
122812 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
122813 +memblock_virt_alloc_try_nid_nopanic_60604 memblock_virt_alloc_try_nid_nopanic 1 60604 NULL
122814 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
122815 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
122816 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
122817 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
122818 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
122819 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
122820 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
122821 +raid_status_60755 raid_status 5 60755 NULL
122822 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
122823 +opticon_write_60775 opticon_write 4 60775 NULL
122824 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
122825 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
122826 +nvif_object_init_60848 nvif_object_init 6 60848 NULL
122827 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
122828 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
122829 +generic_writepages_60871 generic_writepages 0 60871 NULL
122830 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
122831 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
122832 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
122833 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
122834 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
122835 +pti_char_write_60960 pti_char_write 3 60960 NULL
122836 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
122837 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
122838 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
122839 +generic_file_direct_write_60995 generic_file_direct_write 0 60995 NULL
122840 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
122841 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
122842 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
122843 +read_file_ackto_61037 read_file_ackto 3 61037 NULL
122844 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
122845 +symtab_init_61050 symtab_init 2 61050 NULL
122846 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
122847 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 0-2 61062 NULL
122848 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
122849 +get_derived_key_61100 get_derived_key 4 61100 NULL
122850 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-4-3-2-1 61104 NULL
122851 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
122852 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
122853 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
122854 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
122855 +pair_device_61175 pair_device 4 61175 NULL nohasharray
122856 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
122857 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
122858 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
122859 +srp_create_fr_pool_61207 srp_create_fr_pool 3 61207 NULL
122860 +arch_hibernation_header_save_61212 arch_hibernation_header_save 0 61212 NULL
122861 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
122862 +v9fs_mmap_file_read_61262 v9fs_mmap_file_read 3 61262 NULL
122863 +kvm_age_hva_61267 kvm_age_hva 2-3 61267 NULL
122864 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 NULL nohasharray
122865 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 &find_get_pages_tag_61270 nohasharray
122866 +ifalias_store_61270 ifalias_store 4 61270 &btrfs_bio_alloc_61270
122867 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 NULL nohasharray
122868 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 &hfsplus_getxattr_finder_info_61283
122869 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
122870 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
122871 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
122872 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
122873 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
122874 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
122875 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
122876 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
122877 +f1x_map_sysaddr_to_csrow_61344 f1x_map_sysaddr_to_csrow 2 61344 NULL
122878 +wil_write_file_recovery_61354 wil_write_file_recovery 3 61354 NULL
122879 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
122880 +system_enable_write_61396 system_enable_write 3 61396 NULL
122881 +xfs_zero_remaining_bytes_61423 xfs_zero_remaining_bytes 3 61423 NULL
122882 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
122883 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
122884 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
122885 +erst_errno_61526 erst_errno 0 61526 NULL
122886 +proc_write_device_61541 proc_write_device 3 61541 NULL
122887 +compat_SyS_select_61542 compat_SyS_select 1 61542 NULL
122888 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
122889 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
122890 +parport_pc_fifo_write_block_dma_61568 parport_pc_fifo_write_block_dma 3 61568 NULL
122891 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
122892 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
122893 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
122894 +seq_open_private_61589 seq_open_private 3 61589 NULL
122895 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-1-2 61591 NULL
122896 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
122897 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
122898 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
122899 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
122900 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
122901 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL nohasharray
122902 +tcf_hashinfo_init_61643 tcf_hashinfo_init 2 61643 &snd_pcm_oss_read3_61643
122903 +resize_stripes_61650 resize_stripes 2 61650 NULL
122904 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
122905 +insert_one_name_61668 insert_one_name 7 61668 NULL
122906 +qib_format_hwmsg_61679 qib_format_hwmsg 2 61679 NULL
122907 +lock_loop_61681 lock_loop 1 61681 NULL
122908 +__do_tune_cpucache_61684 __do_tune_cpucache 2 61684 NULL
122909 +filter_read_61692 filter_read 3 61692 NULL
122910 +SyS_kexec_file_load_61715 SyS_kexec_file_load 3 61715 NULL
122911 +iov_length_61716 iov_length 0 61716 NULL
122912 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
122913 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
122914 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
122915 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
122916 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
122917 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
122918 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
122919 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
122920 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
122921 +__skb_flow_dissect_61855 __skb_flow_dissect 5 61855 NULL
122922 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
122923 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
122924 +get_fw_name_61874 get_fw_name 3 61874 NULL
122925 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
122926 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
122927 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
122928 +kernfs_name_61910 kernfs_name 3 61910 NULL
122929 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
122930 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
122931 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
122932 +efi_get_runtime_map_size_61927 efi_get_runtime_map_size 0 61927 NULL
122933 +SyS_kexec_load_61946 SyS_kexec_load 2 61946 NULL
122934 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
122935 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
122936 +fix_read_error_61965 fix_read_error 4 61965 NULL
122937 +ocfs2_quota_write_61972 ocfs2_quota_write 4-5 61972 NULL
122938 +fd_locked_ioctl_61978 fd_locked_ioctl 3 61978 NULL
122939 +cow_file_range_61979 cow_file_range 3 61979 NULL
122940 +dequeue_event_62000 dequeue_event 3 62000 NULL
122941 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
122942 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
122943 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
122944 +SYSC_select_62024 SYSC_select 1 62024 NULL
122945 +comedi_write_array_to_buffer_62032 comedi_write_array_to_buffer 3 62032 NULL
122946 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
122947 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
122948 +do_pselect_62061 do_pselect 1 62061 NULL
122949 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
122950 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
122951 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
122952 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
122953 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
122954 +qib_diag_write_62133 qib_diag_write 3 62133 NULL nohasharray
122955 +kobject_add_varg_62133 kobject_add_varg 0 62133 &qib_diag_write_62133
122956 +ql_status_62135 ql_status 5 62135 NULL nohasharray
122957 +device_add_attrs_62135 device_add_attrs 0 62135 &ql_status_62135
122958 +video_usercopy_62151 video_usercopy 2 62151 NULL
122959 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
122960 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
122961 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
122962 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
122963 +rounded_hashtable_size_62198 rounded_hashtable_size 0 62198 NULL
122964 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
122965 +smk_read_syslog_62227 smk_read_syslog 3 62227 NULL
122966 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
122967 +ion_handle_test_dma_62262 ion_handle_test_dma 4-5 62262 NULL
122968 +get_random_int_62279 get_random_int 0 62279 NULL
122969 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
122970 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
122971 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
122972 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
122973 +subseq_list_62332 subseq_list 3-0 62332 NULL
122974 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
122975 +flash_write_62354 flash_write 3 62354 NULL
122976 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
122977 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
122978 +altera_irscan_62396 altera_irscan 2 62396 NULL
122979 +set_ssp_62411 set_ssp 4 62411 NULL
122980 +tracing_saved_cmdlines_size_read_62491 tracing_saved_cmdlines_size_read 3 62491 NULL
122981 +srpc_alloc_bulk_62522 srpc_alloc_bulk 2 62522 NULL
122982 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
122983 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
122984 +debugfs_read_62535 debugfs_read 3 62535 NULL
122985 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
122986 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
122987 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
122988 +compat_SyS_rt_sigpending_62580 compat_SyS_rt_sigpending 2 62580 NULL
122989 +get_subdir_62581 get_subdir 3 62581 NULL
122990 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
122991 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
122992 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
122993 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
122994 +ieee80211_set_probe_resp_62700 ieee80211_set_probe_resp 3 62700 NULL
122995 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
122996 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
122997 +rdm_62719 rdm 0 62719 NULL
122998 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
122999 +key_replays_read_62746 key_replays_read 3 62746 NULL
123000 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
123001 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
123002 +mxt_obj_instances_62764 mxt_obj_instances 0 62764 NULL
123003 +copy_page_to_iter_iovec_62770 copy_page_to_iter_iovec 0-3 62770 NULL nohasharray
123004 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 &copy_page_to_iter_iovec_62770
123005 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
123006 +ptlrpc_req_set_repsize_62784 ptlrpc_req_set_repsize 2 62784 NULL
123007 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
123008 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
123009 +__add_action_62798 __add_action 4 62798 NULL
123010 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
123011 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
123012 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
123013 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
123014 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
123015 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
123016 +aoechr_write_62883 aoechr_write 3 62883 NULL
123017 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
123018 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
123019 +getdqbuf_62908 getdqbuf 1 62908 NULL
123020 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
123021 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
123022 +nvif_object_mthd_62960 nvif_object_mthd 4 62960 NULL
123023 +hwdep_read_62992 hwdep_read 3 62992 NULL
123024 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL
123025 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
123026 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
123027 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
123028 +unlink1_63059 unlink1 3 63059 NULL
123029 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
123030 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
123031 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
123032 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
123033 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
123034 +iwl_mvm_coex_dump_mbox_63153 iwl_mvm_coex_dump_mbox 4-3-0 63153 NULL
123035 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
123036 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
123037 +vme_master_read_63221 vme_master_read 0 63221 NULL
123038 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
123039 +ptp_read_63251 ptp_read 4 63251 NULL
123040 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
123041 +iwl_dbgfs_fw_error_dump_read_63263 iwl_dbgfs_fw_error_dump_read 3 63263 NULL
123042 +raid5_resize_63306 raid5_resize 2 63306 NULL
123043 +nfsd_vfs_read_63307 nfsd_vfs_read 5 63307 NULL
123044 +ath10k_read_fw_dbglog_63323 ath10k_read_fw_dbglog 3 63323 NULL
123045 +proc_info_read_63344 proc_info_read 3 63344 NULL
123046 +nvif_device_new_63358 nvif_device_new 5 63358 NULL
123047 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
123048 +idmouse_read_63374 idmouse_read 3 63374 NULL
123049 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL nohasharray
123050 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 &edac_pci_alloc_ctl_info_63388
123051 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
123052 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
123053 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
123054 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
123055 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
123056 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
123057 +read_kcore_63488 read_kcore 3 63488 NULL
123058 +iwl_dbgfs_bcast_filters_read_63489 iwl_dbgfs_bcast_filters_read 3 63489 NULL
123059 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
123060 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
123061 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
123062 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
123063 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
123064 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
123065 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
123066 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
123067 +write_debug_level_63613 write_debug_level 3 63613 NULL
123068 +__spi_validate_63618 __spi_validate 0 63618 NULL
123069 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
123070 +hid_report_len_63637 hid_report_len 0 63637 NULL
123071 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
123072 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
123073 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
123074 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
123075 +vbi_read_63673 vbi_read 3 63673 NULL
123076 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
123077 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
123078 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
123079 +ntb_debugfs_read_63728 ntb_debugfs_read 3 63728 NULL
123080 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
123081 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
123082 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
123083 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
123084 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
123085 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
123086 +C_SYSC_process_vm_readv_63811 C_SYSC_process_vm_readv 3-5 63811 NULL
123087 +regmap_multi_reg_write_63826 regmap_multi_reg_write 3 63826 NULL nohasharray
123088 +prepare_copy_63826 prepare_copy 2 63826 &regmap_multi_reg_write_63826
123089 +sel_write_load_63830 sel_write_load 3 63830 NULL
123090 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
123091 +nv10_gpio_intr_mask_63862 nv10_gpio_intr_mask 4-3 63862 NULL
123092 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
123093 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
123094 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
123095 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
123096 +__team_options_register_63941 __team_options_register 3 63941 NULL
123097 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
123098 +set_bredr_63975 set_bredr 4 63975 NULL
123099 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
123100 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
123101 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
123102 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
123103 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
123104 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
123105 +nl80211_send_rx_assoc_64040 nl80211_send_rx_assoc 4 64040 NULL
123106 +__sock_create_64069 __sock_create 0 64069 NULL
123107 +get_u8_64076 get_u8 0 64076 NULL
123108 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
123109 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
123110 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
123111 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
123112 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 NULL
123113 +to_bytes_64103 to_bytes 0-1 64103 NULL
123114 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
123115 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
123116 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
123117 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
123118 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
123119 +init_bch_64130 init_bch 1-2 64130 NULL
123120 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
123121 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
123122 +number_of_tds_64156 number_of_tds 0 64156 NULL
123123 +bnx2x_vf_mcast_64166 bnx2x_vf_mcast 4 64166 NULL
123124 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
123125 +kernfs_iop_setxattr_64220 kernfs_iop_setxattr 4 64220 NULL
123126 +read_pulse_64227 read_pulse 0-3 64227 NULL
123127 +ea_len_64229 ea_len 0 64229 NULL
123128 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
123129 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL nohasharray
123130 +bpf_check_classic_64278 bpf_check_classic 2 64278 &btrfs_file_extent_offset_64278
123131 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
123132 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 NULL nohasharray
123133 +event_id_read_64288 event_id_read 3 64288 &xfs_dir_cilookup_result_64288
123134 +info_debugfs_read_64291 info_debugfs_read 3 64291 NULL
123135 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
123136 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
123137 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
123138 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
123139 +ts_write_64336 ts_write 3 64336 NULL
123140 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
123141 +qlcnic_82xx_calculate_msix_vector_64354 qlcnic_82xx_calculate_msix_vector 0 64354 NULL
123142 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
123143 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
123144 +reg_create_64372 reg_create 5 64372 NULL nohasharray
123145 +bnx2_enable_msix_64372 bnx2_enable_msix 2 64372 &reg_create_64372
123146 +ilo_write_64378 ilo_write 3 64378 NULL
123147 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
123148 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
123149 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
123150 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
123151 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
123152 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
123153 +keyctl_get_security_64418 keyctl_get_security 3 64418 NULL
123154 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
123155 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
123156 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
123157 +single_open_size_64483 single_open_size 4 64483 NULL
123158 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
123159 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
123160 +remove_uuid_64505 remove_uuid 4 64505 NULL
123161 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
123162 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
123163 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
123164 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
123165 +SyS_bind_64544 SyS_bind 3 64544 NULL
123166 +rbd_obj_read_sync_64554 rbd_obj_read_sync 3-4 64554 NULL
123167 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
123168 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 NULL nohasharray
123169 +__spi_sync_64561 __spi_sync 0 64561 &ll_max_rw_chunk_seq_write_64561
123170 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
123171 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
123172 +do_erase_64574 do_erase 4 64574 NULL
123173 +fanotify_write_64623 fanotify_write 3 64623 NULL
123174 +_iwl_dbgfs_d0i3_refs_write_64642 _iwl_dbgfs_d0i3_refs_write 3 64642 NULL
123175 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
123176 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 NULL nohasharray
123177 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 &ocfs2_read_xattr_block_64661
123178 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
123179 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
123180 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
123181 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
123182 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
123183 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
123184 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
123185 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
123186 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
123187 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
123188 +hwdep_write_64776 hwdep_write 3 64776 NULL
123189 +message_for_md_64777 message_for_md 5 64777 NULL
123190 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
123191 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
123192 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
123193 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL nohasharray
123194 +nv_mask_64808 nv_mask 0 64808 &rfkill_fop_write_64808
123195 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
123196 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
123197 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
123198 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
123199 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
123200 +pci_vc_do_save_buffer_64876 pci_vc_do_save_buffer 0 64876 NULL
123201 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
123202 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
123203 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL nohasharray
123204 +tipc_port_iovec_reject_64958 tipc_port_iovec_reject 4 64958 &ip_options_get_from_user_64958
123205 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
123206 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
123207 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
123208 +insert_dent_65034 insert_dent 7 65034 NULL
123209 +snd_hda_get_pin_label_65035 snd_hda_get_pin_label 5 65035 NULL
123210 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
123211 +pcibios_enable_device_65059 pcibios_enable_device 0 65059 NULL
123212 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
123213 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
123214 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
123215 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 0-3 65090 NULL
123216 +usbtest_alloc_urb_65115 usbtest_alloc_urb 3-5 65115 NULL
123217 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
123218 +nouveau_event_create_65229 nouveau_event_create 2-1 65229 NULL
123219 +print_endpoint_stat_65232 print_endpoint_stat 0-4-3 65232 NULL
123220 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
123221 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
123222 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
123223 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
123224 +fat_direct_IO_65295 fat_direct_IO 4 65295 NULL
123225 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
123226 +get_var_len_65304 get_var_len 0 65304 NULL
123227 +unpack_array_65318 unpack_array 0 65318 NULL
123228 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
123229 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
123230 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
123231 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
123232 +SyS_writev_65372 SyS_writev 3 65372 NULL
123233 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
123234 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
123235 +__read_vmcore_65402 __read_vmcore 2 65402 NULL
123236 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
123237 +device_add_groups_65423 device_add_groups 0 65423 NULL
123238 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
123239 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
123240 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
123241 +clear_user_65470 clear_user 2 65470 NULL
123242 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
123243 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
123244 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
123245 +tree_mod_log_eb_copy_65535 tree_mod_log_eb_copy 6 65535 NULL
123246 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
123247 new file mode 100644
123248 index 0000000..560cd7b
123249 --- /dev/null
123250 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
123251 @@ -0,0 +1,92 @@
123252 +spa_set_aux_vdevs_746 spa_set_aux_vdevs 3 746 NULL
123253 +zfs_lookup_2144 zfs_lookup 0 2144 NULL
123254 +mappedread_2627 mappedread 2 2627 NULL
123255 +vdev_disk_dio_alloc_2957 vdev_disk_dio_alloc 1 2957 NULL
123256 +nv_alloc_pushpage_spl_4286 nv_alloc_pushpage_spl 2 4286 NULL
123257 +zpl_xattr_get_4574 zpl_xattr_get 0 4574 NULL
123258 +sa_replace_all_by_template_5699 sa_replace_all_by_template 3 5699 NULL
123259 +dmu_write_6048 dmu_write 4-3 6048 NULL
123260 +dmu_buf_hold_array_6095 dmu_buf_hold_array 4-3 6095 NULL
123261 +update_pages_6225 update_pages 2-3 6225 NULL
123262 +bio_nr_pages_7117 bio_nr_pages 0-2 7117 NULL
123263 +dmu_buf_hold_array_by_bonus_8562 dmu_buf_hold_array_by_bonus 3-2 8562 NULL
123264 +zpios_dmu_write_8858 zpios_dmu_write 4-5 8858 NULL
123265 +ddi_copyout_9401 ddi_copyout 3 9401 NULL
123266 +avl_numnodes_12384 avl_numnodes 0 12384 NULL
123267 +dmu_write_uio_dnode_12473 dmu_write_uio_dnode 3 12473 NULL
123268 +dmu_xuio_init_12866 dmu_xuio_init 2 12866 NULL
123269 +zpl_read_common_14389 zpl_read_common 0 14389 NULL
123270 +dmu_snapshot_realname_14632 dmu_snapshot_realname 4 14632 NULL
123271 +kmem_alloc_debug_14852 kmem_alloc_debug 1 14852 NULL
123272 +kmalloc_node_nofail_15151 kmalloc_node_nofail 1 15151 NULL
123273 +dmu_write_uio_16351 dmu_write_uio 4 16351 NULL
123274 +zfs_log_write_16524 zfs_log_write 6-5 16524 NULL
123275 +sa_build_layouts_16910 sa_build_layouts 3 16910 NULL
123276 +dsl_dir_namelen_17053 dsl_dir_namelen 0 17053 NULL
123277 +kcopy_copy_to_user_17336 kcopy_copy_to_user 5 17336 NULL
123278 +sa_add_layout_entry_17507 sa_add_layout_entry 3 17507 NULL
123279 +sa_attr_table_setup_18029 sa_attr_table_setup 3 18029 NULL
123280 +uiocopy_18680 uiocopy 2 18680 NULL
123281 +dmu_buf_hold_array_by_dnode_19125 dmu_buf_hold_array_by_dnode 2-3 19125 NULL
123282 +zpl_acl_from_xattr_21141 zpl_acl_from_xattr 2 21141 NULL
123283 +dsl_pool_tx_assign_init_22518 dsl_pool_tx_assign_init 2 22518 NULL
123284 +nvlist_lookup_byte_array_22527 nvlist_lookup_byte_array 0 22527 NULL
123285 +sa_replace_all_by_template_locked_22533 sa_replace_all_by_template_locked 3 22533 NULL
123286 +tsd_hash_table_init_22559 tsd_hash_table_init 1 22559 NULL
123287 +spa_vdev_remove_aux_23966 spa_vdev_remove_aux 4 23966 NULL
123288 +zpl_xattr_acl_set_access_24129 zpl_xattr_acl_set_access 4 24129 NULL
123289 +dmu_assign_arcbuf_24622 dmu_assign_arcbuf 2 24622 NULL
123290 +zap_lookup_norm_25166 zap_lookup_norm 9 25166 NULL
123291 +dmu_prealloc_25456 dmu_prealloc 4-3 25456 NULL
123292 +kmalloc_nofail_26347 kmalloc_nofail 1 26347 NULL
123293 +zfsctl_snapshot_zpath_27578 zfsctl_snapshot_zpath 2 27578 NULL
123294 +zpios_dmu_read_30015 zpios_dmu_read 4-5 30015 NULL
123295 +splat_write_30943 splat_write 3 30943 NULL
123296 +zpl_xattr_get_sa_31183 zpl_xattr_get_sa 0 31183 NULL
123297 +dmu_read_uio_31467 dmu_read_uio 4 31467 NULL
123298 +zfs_replay_fuids_31479 zfs_replay_fuids 4 31479 NULL
123299 +spa_history_log_to_phys_31632 spa_history_log_to_phys 0-1 31632 NULL
123300 +__zpl_xattr_get_32601 __zpl_xattr_get 0 32601 NULL
123301 +proc_copyout_string_34049 proc_copyout_string 2 34049 NULL
123302 +nv_alloc_sleep_spl_34544 nv_alloc_sleep_spl 2 34544 NULL
123303 +nv_alloc_nosleep_spl_34761 nv_alloc_nosleep_spl 2 34761 NULL
123304 +zap_leaf_array_match_36922 zap_leaf_array_match 4 36922 NULL
123305 +copyinstr_36980 copyinstr 3 36980 NULL
123306 +zpl_xattr_acl_set_default_37864 zpl_xattr_acl_set_default 4 37864 NULL
123307 +splat_read_38116 splat_read 3 38116 NULL
123308 +sa_setup_38756 sa_setup 4 38756 NULL
123309 +vdev_disk_physio_39898 vdev_disk_physio 3 39898 NULL
123310 +arc_buf_size_39982 arc_buf_size 0 39982 NULL
123311 +kzalloc_nofail_40719 kzalloc_nofail 1 40719 NULL
123312 +fuidstr_to_sid_40777 fuidstr_to_sid 4 40777 NULL
123313 +vdev_raidz_matrix_reconstruct_40852 vdev_raidz_matrix_reconstruct 2-3 40852 NULL
123314 +sa_find_layout_40892 sa_find_layout 4 40892 NULL
123315 +zpl_xattr_get_dir_41918 zpl_xattr_get_dir 0 41918 NULL
123316 +zfs_sa_get_xattr_42600 zfs_sa_get_xattr 0 42600 NULL
123317 +zpl_xattr_acl_set_42808 zpl_xattr_acl_set 4 42808 NULL
123318 +xdr_dec_array_43091 xdr_dec_array 5 43091 NULL
123319 +dsl_dataset_namelen_43136 dsl_dataset_namelen 0 43136 NULL
123320 +kcopy_write_43683 kcopy_write 3 43683 NULL
123321 +uiomove_44355 uiomove 2 44355 NULL
123322 +dmu_read_44418 dmu_read 4-3 44418 NULL
123323 +ddi_copyin_44846 ddi_copyin 3 44846 NULL
123324 +kcopy_do_get_45061 kcopy_do_get 5 45061 NULL
123325 +copyin_45945 copyin 3 45945 NULL
123326 +zil_itx_create_46555 zil_itx_create 2 46555 NULL
123327 +dmu_write_uio_dbuf_48064 dmu_write_uio_dbuf 3 48064 NULL
123328 +blk_rq_pos_48233 blk_rq_pos 0 48233 NULL
123329 +spa_history_write_49650 spa_history_write 3 49650 NULL
123330 +kcopy_copy_pages_to_user_49823 kcopy_copy_pages_to_user 3-4 49823 NULL
123331 +zfs_log_write_50162 zfs_log_write 6-5 50162 NULL
123332 +i_fm_alloc_51038 i_fm_alloc 2 51038 NULL
123333 +copyout_51409 copyout 3 51409 NULL
123334 +zvol_log_write_54898 zvol_log_write 4-3 54898 NULL
123335 +zfs_acl_node_alloc_55641 zfs_acl_node_alloc 1 55641 NULL
123336 +get_nvlist_56685 get_nvlist 2 56685 NULL
123337 +zprop_get_numprops_56820 zprop_get_numprops 0 56820 NULL
123338 +splat_taskq_test4_common_59829 splat_taskq_test4_common 5 59829 NULL
123339 +zfs_replay_domain_cnt_61399 zfs_replay_domain_cnt 0 61399 NULL
123340 +zpios_write_61823 zpios_write 3 61823 NULL
123341 +proc_copyin_string_62019 proc_copyin_string 4 62019 NULL
123342 +random_get_pseudo_bytes_64611 random_get_pseudo_bytes 2 64611 NULL
123343 +zpios_read_64734 zpios_read 3 64734 NULL
123344 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
123345 new file mode 100644
123346 index 0000000..95f7abd
123347 --- /dev/null
123348 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
123349 @@ -0,0 +1,259 @@
123350 +/*
123351 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
123352 + * Licensed under the GPL v2, or (at your option) v3
123353 + *
123354 + * Homepage:
123355 + * http://www.grsecurity.net/~ephox/overflow_plugin/
123356 + *
123357 + * Documentation:
123358 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
123359 + *
123360 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
123361 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
123362 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
123363 + *
123364 + * Usage:
123365 + * $ make
123366 + * $ make run
123367 + */
123368 +
123369 +#include "gcc-common.h"
123370 +#include "size_overflow.h"
123371 +
123372 +int plugin_is_GPL_compatible;
123373 +
123374 +tree report_size_overflow_decl;
123375 +
123376 +tree size_overflow_type_HI;
123377 +tree size_overflow_type_SI;
123378 +tree size_overflow_type_DI;
123379 +tree size_overflow_type_TI;
123380 +
123381 +static struct plugin_info size_overflow_plugin_info = {
123382 + .version = "20140725",
123383 + .help = "no-size-overflow\tturn off size overflow checking\n",
123384 +};
123385 +
123386 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
123387 +{
123388 + unsigned int arg_count;
123389 + enum tree_code code = TREE_CODE(*node);
123390 +
123391 + switch (code) {
123392 + case FUNCTION_DECL:
123393 + arg_count = type_num_arguments(TREE_TYPE(*node));
123394 + break;
123395 + case FUNCTION_TYPE:
123396 + case METHOD_TYPE:
123397 + arg_count = type_num_arguments(*node);
123398 + break;
123399 + default:
123400 + *no_add_attrs = true;
123401 + error("%s: %qE attribute only applies to functions", __func__, name);
123402 + return NULL_TREE;
123403 + }
123404 +
123405 + for (; args; args = TREE_CHAIN(args)) {
123406 + tree position = TREE_VALUE(args);
123407 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
123408 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
123409 + *no_add_attrs = true;
123410 + }
123411 + }
123412 + return NULL_TREE;
123413 +}
123414 +
123415 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
123416 +{
123417 + unsigned int arg_count;
123418 + enum tree_code code = TREE_CODE(*node);
123419 +
123420 + switch (code) {
123421 + case FUNCTION_DECL:
123422 + arg_count = type_num_arguments(TREE_TYPE(*node));
123423 + break;
123424 + case FUNCTION_TYPE:
123425 + case METHOD_TYPE:
123426 + arg_count = type_num_arguments(*node);
123427 + break;
123428 + case FIELD_DECL:
123429 + return NULL_TREE;
123430 + default:
123431 + *no_add_attrs = true;
123432 + error("%qE attribute only applies to functions", name);
123433 + return NULL_TREE;
123434 + }
123435 +
123436 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
123437 + return NULL_TREE;
123438 +
123439 + for (; args; args = TREE_CHAIN(args)) {
123440 + tree position = TREE_VALUE(args);
123441 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
123442 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
123443 + *no_add_attrs = true;
123444 + }
123445 + }
123446 + return NULL_TREE;
123447 +}
123448 +
123449 +static struct attribute_spec size_overflow_attr = {
123450 + .name = "size_overflow",
123451 + .min_length = 1,
123452 + .max_length = -1,
123453 + .decl_required = true,
123454 + .type_required = false,
123455 + .function_type_required = false,
123456 + .handler = handle_size_overflow_attribute,
123457 +#if BUILDING_GCC_VERSION >= 4007
123458 + .affects_type_identity = false
123459 +#endif
123460 +};
123461 +
123462 +static struct attribute_spec intentional_overflow_attr = {
123463 + .name = "intentional_overflow",
123464 + .min_length = 1,
123465 + .max_length = -1,
123466 + .decl_required = true,
123467 + .type_required = false,
123468 + .function_type_required = false,
123469 + .handler = handle_intentional_overflow_attribute,
123470 +#if BUILDING_GCC_VERSION >= 4007
123471 + .affects_type_identity = false
123472 +#endif
123473 +};
123474 +
123475 +static void register_attributes(void __unused *event_data, void __unused *data)
123476 +{
123477 + register_attribute(&size_overflow_attr);
123478 + register_attribute(&intentional_overflow_attr);
123479 +}
123480 +
123481 +static tree create_typedef(tree type, const char* ident)
123482 +{
123483 + tree new_type, decl;
123484 +
123485 + new_type = build_variant_type_copy(type);
123486 + decl = build_decl(BUILTINS_LOCATION, TYPE_DECL, get_identifier(ident), new_type);
123487 + DECL_ORIGINAL_TYPE(decl) = type;
123488 + TYPE_NAME(new_type) = decl;
123489 + return new_type;
123490 +}
123491 +
123492 +// Create the noreturn report_size_overflow() function decl.
123493 +static void size_overflow_start_unit(void __unused *gcc_data, void __unused *user_data)
123494 +{
123495 + tree const_char_ptr_type_node;
123496 + tree fntype;
123497 +
123498 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
123499 +
123500 + size_overflow_type_HI = create_typedef(intHI_type_node, "size_overflow_type_HI");
123501 + size_overflow_type_SI = create_typedef(intSI_type_node, "size_overflow_type_SI");
123502 + size_overflow_type_DI = create_typedef(intDI_type_node, "size_overflow_type_DI");
123503 + size_overflow_type_TI = create_typedef(intTI_type_node, "size_overflow_type_TI");
123504 +
123505 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
123506 + fntype = build_function_type_list(void_type_node,
123507 + const_char_ptr_type_node,
123508 + unsigned_type_node,
123509 + const_char_ptr_type_node,
123510 + const_char_ptr_type_node,
123511 + NULL_TREE);
123512 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
123513 +
123514 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
123515 + TREE_PUBLIC(report_size_overflow_decl) = 1;
123516 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
123517 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
123518 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
123519 +}
123520 +
123521 +
123522 +extern struct gimple_opt_pass pass_dce;
123523 +
123524 +static struct opt_pass *make_dce_pass(void)
123525 +{
123526 +#if BUILDING_GCC_VERSION >= 4009
123527 + return make_pass_dce(g);
123528 +#else
123529 + return &pass_dce.pass;
123530 +#endif
123531 +}
123532 +
123533 +
123534 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
123535 +{
123536 + int i;
123537 + const char * const plugin_name = plugin_info->base_name;
123538 + const int argc = plugin_info->argc;
123539 + const struct plugin_argument * const argv = plugin_info->argv;
123540 + bool enable = true;
123541 + struct register_pass_info insert_size_overflow_asm_pass_info;
123542 + struct register_pass_info __unused dump_before_pass_info;
123543 + struct register_pass_info __unused dump_after_pass_info;
123544 + struct register_pass_info insert_size_overflow_check_info;
123545 + struct register_pass_info dce_pass_info;
123546 + static const struct ggc_root_tab gt_ggc_r_gt_size_overflow[] = {
123547 + {
123548 + .base = &report_size_overflow_decl,
123549 + .nelt = 1,
123550 + .stride = sizeof(report_size_overflow_decl),
123551 + .cb = &gt_ggc_mx_tree_node,
123552 + .pchw = &gt_pch_nx_tree_node
123553 + },
123554 + LAST_GGC_ROOT_TAB
123555 + };
123556 +
123557 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
123558 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
123559 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
123560 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
123561 +
123562 + dump_before_pass_info.pass = make_dump_pass();
123563 + dump_before_pass_info.reference_pass_name = "increase_alignment";
123564 + dump_before_pass_info.ref_pass_instance_number = 1;
123565 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
123566 +
123567 + insert_size_overflow_check_info.pass = make_insert_size_overflow_check();
123568 + insert_size_overflow_check_info.reference_pass_name = "increase_alignment";
123569 + insert_size_overflow_check_info.ref_pass_instance_number = 1;
123570 + insert_size_overflow_check_info.pos_op = PASS_POS_INSERT_BEFORE;
123571 +
123572 + dump_after_pass_info.pass = make_dump_pass();
123573 + dump_after_pass_info.reference_pass_name = "increase_alignment";
123574 + dump_after_pass_info.ref_pass_instance_number = 1;
123575 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
123576 +
123577 + dce_pass_info.pass = make_dce_pass();
123578 + dce_pass_info.reference_pass_name = "vrp";
123579 + dce_pass_info.ref_pass_instance_number = 1;
123580 + dce_pass_info.pos_op = PASS_POS_INSERT_AFTER;
123581 +
123582 + if (!plugin_default_version_check(version, &gcc_version)) {
123583 + error(G_("incompatible gcc/plugin versions"));
123584 + return 1;
123585 + }
123586 +
123587 + for (i = 0; i < argc; ++i) {
123588 + if (!strcmp(argv[i].key, "no-size-overflow")) {
123589 + enable = false;
123590 + continue;
123591 + }
123592 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
123593 + }
123594 +
123595 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
123596 + if (enable) {
123597 + register_callback(plugin_name, PLUGIN_START_UNIT, &size_overflow_start_unit, NULL);
123598 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_size_overflow);
123599 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
123600 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
123601 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_check_info);
123602 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
123603 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dce_pass_info);
123604 + }
123605 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
123606 +
123607 + return 0;
123608 +}
123609 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
123610 new file mode 100644
123611 index 0000000..0888f6c
123612 --- /dev/null
123613 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
123614 @@ -0,0 +1,364 @@
123615 +/*
123616 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
123617 + * Licensed under the GPL v2, or (at your option) v3
123618 + *
123619 + * Homepage:
123620 + * http://www.grsecurity.net/~ephox/overflow_plugin/
123621 + *
123622 + * Documentation:
123623 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
123624 + *
123625 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
123626 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
123627 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
123628 + *
123629 + * Usage:
123630 + * $ make
123631 + * $ make run
123632 + */
123633 +
123634 +#include "gcc-common.h"
123635 +#include "size_overflow.h"
123636 +
123637 +#include "size_overflow_hash.h"
123638 +#include "size_overflow_hash_aux.h"
123639 +
123640 +#define CODES_LIMIT 32
123641 +
123642 +static unsigned char get_tree_code(const_tree type)
123643 +{
123644 + switch (TREE_CODE(type)) {
123645 + case ARRAY_TYPE:
123646 + return 0;
123647 + case BOOLEAN_TYPE:
123648 + return 1;
123649 + case ENUMERAL_TYPE:
123650 + return 2;
123651 + case FUNCTION_TYPE:
123652 + return 3;
123653 + case INTEGER_TYPE:
123654 + return 4;
123655 + case POINTER_TYPE:
123656 + return 5;
123657 + case RECORD_TYPE:
123658 + return 6;
123659 + case UNION_TYPE:
123660 + return 7;
123661 + case VOID_TYPE:
123662 + return 8;
123663 + case REAL_TYPE:
123664 + return 9;
123665 + case VECTOR_TYPE:
123666 + return 10;
123667 + case REFERENCE_TYPE:
123668 + return 11;
123669 + case OFFSET_TYPE:
123670 + return 12;
123671 + case COMPLEX_TYPE:
123672 + return 13;
123673 + default:
123674 + debug_tree((tree)type);
123675 + gcc_unreachable();
123676 + }
123677 +}
123678 +
123679 +struct function_hash {
123680 + size_t tree_codes_len;
123681 + unsigned char tree_codes[CODES_LIMIT];
123682 + const_tree fndecl;
123683 + unsigned int hash;
123684 +};
123685 +
123686 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
123687 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
123688 +{
123689 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
123690 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
123691 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
123692 +
123693 + unsigned int m = 0x57559429;
123694 + unsigned int n = 0x5052acdb;
123695 + const unsigned int *key4 = (const unsigned int *)key;
123696 + unsigned int h = len;
123697 + unsigned int k = len + seed + n;
123698 + unsigned long long p;
123699 +
123700 + while (len >= 8) {
123701 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
123702 + len -= 8;
123703 + }
123704 + if (len >= 4) {
123705 + cwmixb(key4[0]) key4 += 1;
123706 + len -= 4;
123707 + }
123708 + if (len)
123709 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
123710 + cwmixb(h ^ (k + n));
123711 + return k ^ h;
123712 +
123713 +#undef cwfold
123714 +#undef cwmixa
123715 +#undef cwmixb
123716 +}
123717 +
123718 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
123719 +{
123720 + unsigned int fn, codes, seed = 0;
123721 +
123722 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
123723 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
123724 +
123725 + fn_hash_data->hash = fn ^ codes;
123726 +}
123727 +
123728 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
123729 +{
123730 + gcc_assert(type != NULL_TREE);
123731 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
123732 +
123733 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
123734 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
123735 + fn_hash_data->tree_codes_len++;
123736 + type = TREE_TYPE(type);
123737 + }
123738 +}
123739 +
123740 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
123741 +{
123742 + const_tree result;
123743 +
123744 + gcc_assert(node != NULL_TREE);
123745 +
123746 + if (DECL_P(node)) {
123747 + result = DECL_RESULT(node);
123748 + if (result != NULL_TREE)
123749 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
123750 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
123751 + }
123752 +
123753 + gcc_assert(TYPE_P(node));
123754 +
123755 + if (TREE_CODE(node) == FUNCTION_TYPE)
123756 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
123757 +
123758 + return set_node_codes(node, fn_hash_data);
123759 +}
123760 +
123761 +static void set_function_codes(struct function_hash *fn_hash_data)
123762 +{
123763 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
123764 + enum tree_code code = TREE_CODE(type);
123765 +
123766 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
123767 +
123768 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
123769 +
123770 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
123771 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
123772 +}
123773 +
123774 +static const struct size_overflow_hash *get_proper_hash_chain(const struct size_overflow_hash *entry, const char *func_name)
123775 +{
123776 + while (entry) {
123777 + if (!strcmp(entry->name, func_name))
123778 + return entry;
123779 + entry = entry->next;
123780 + }
123781 + return NULL;
123782 +}
123783 +
123784 +const struct size_overflow_hash *get_function_hash(const_tree fndecl)
123785 +{
123786 + const struct size_overflow_hash *entry;
123787 + struct function_hash fn_hash_data;
123788 + const char *func_name;
123789 +
123790 + // skip builtins __builtin_constant_p
123791 + if (DECL_BUILT_IN(fndecl))
123792 + return NULL;
123793 +
123794 + fn_hash_data.fndecl = fndecl;
123795 + fn_hash_data.tree_codes_len = 0;
123796 +
123797 + set_function_codes(&fn_hash_data);
123798 + gcc_assert(fn_hash_data.tree_codes_len != 0);
123799 +
123800 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
123801 + set_hash(func_name, &fn_hash_data);
123802 +
123803 + entry = size_overflow_hash[fn_hash_data.hash];
123804 + entry = get_proper_hash_chain(entry, func_name);
123805 + if (entry)
123806 + return entry;
123807 + entry = size_overflow_hash_aux[fn_hash_data.hash];
123808 + return get_proper_hash_chain(entry, func_name);
123809 +}
123810 +
123811 +static void print_missing_msg(const_tree func, unsigned int argnum)
123812 +{
123813 + location_t loc;
123814 + const char *curfunc;
123815 + struct function_hash fn_hash_data;
123816 +
123817 + fn_hash_data.fndecl = DECL_ORIGIN(func);
123818 + fn_hash_data.tree_codes_len = 0;
123819 +
123820 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
123821 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
123822 +
123823 + set_function_codes(&fn_hash_data);
123824 + set_hash(curfunc, &fn_hash_data);
123825 +
123826 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
123827 +}
123828 +
123829 +unsigned int find_arg_number_tree(const_tree arg, const_tree func)
123830 +{
123831 + tree var;
123832 + unsigned int argnum = 1;
123833 +
123834 + if (TREE_CODE(arg) == SSA_NAME)
123835 + arg = SSA_NAME_VAR(arg);
123836 +
123837 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
123838 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
123839 + continue;
123840 + if (!skip_types(var))
123841 + return argnum;
123842 + }
123843 +
123844 + return CANNOT_FIND_ARG;
123845 +}
123846 +
123847 +static const char *get_asm_string(const_gimple stmt)
123848 +{
123849 + if (!stmt)
123850 + return NULL;
123851 + if (gimple_code(stmt) != GIMPLE_ASM)
123852 + return NULL;
123853 +
123854 + return gimple_asm_string(stmt);
123855 +}
123856 +
123857 +bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
123858 +{
123859 + const char *str;
123860 +
123861 + str = get_asm_string(stmt);
123862 + if (!str)
123863 + return false;
123864 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
123865 +}
123866 +
123867 +bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
123868 +{
123869 + const char *str;
123870 +
123871 + str = get_asm_string(stmt);
123872 + if (!str)
123873 + return false;
123874 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
123875 +}
123876 +
123877 +bool is_size_overflow_asm(const_gimple stmt)
123878 +{
123879 + const char *str;
123880 +
123881 + str = get_asm_string(stmt);
123882 + if (!str)
123883 + return false;
123884 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
123885 +}
123886 +
123887 +bool is_a_return_check(const_tree node)
123888 +{
123889 + if (TREE_CODE(node) == FUNCTION_DECL)
123890 + return true;
123891 +
123892 + gcc_assert(TREE_CODE(node) == PARM_DECL);
123893 + return false;
123894 +}
123895 +
123896 +// Get the argnum of a function decl, if node is a return then the argnum is 0
123897 +unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
123898 +{
123899 + if (is_a_return_check(node))
123900 + return 0;
123901 + else
123902 + return find_arg_number_tree(node, orig_fndecl);
123903 +}
123904 +
123905 +unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
123906 +{
123907 + const struct size_overflow_hash *hash;
123908 + unsigned int new_argnum;
123909 + tree arg;
123910 + const_tree origarg;
123911 +
123912 + if (argnum == 0)
123913 + return argnum;
123914 +
123915 + hash = get_function_hash(fndecl);
123916 + if (hash && hash->param & (1U << argnum))
123917 + return argnum;
123918 +
123919 + if (DECL_EXTERNAL(fndecl))
123920 + return argnum;
123921 +
123922 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
123923 + argnum--;
123924 + while (origarg && argnum) {
123925 + origarg = TREE_CHAIN(origarg);
123926 + argnum--;
123927 + }
123928 + gcc_assert(argnum == 0);
123929 + gcc_assert(origarg != NULL_TREE);
123930 +
123931 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
123932 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
123933 + return new_argnum;
123934 +
123935 + return CANNOT_FIND_ARG;
123936 +}
123937 +
123938 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
123939 +{
123940 + const struct size_overflow_hash *hash;
123941 +
123942 + hash = get_function_hash(fndecl);
123943 + if (hash && (hash->param & (1U << num)))
123944 + return true;
123945 + return false;
123946 +}
123947 +
123948 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
123949 + * If the function is missing everywhere then print the missing message into stderr.
123950 + */
123951 +bool is_missing_function(const_tree orig_fndecl, unsigned int num)
123952 +{
123953 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
123954 +#if BUILDING_GCC_VERSION >= 4008
123955 + case BUILT_IN_BSWAP16:
123956 +#endif
123957 + case BUILT_IN_BSWAP32:
123958 + case BUILT_IN_BSWAP64:
123959 + case BUILT_IN_EXPECT:
123960 + case BUILT_IN_MEMCMP:
123961 + return false;
123962 + default:
123963 + break;
123964 + }
123965 +
123966 + // skip test.c
123967 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
123968 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
123969 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
123970 + }
123971 +
123972 + if (is_in_hash_table(orig_fndecl, num))
123973 + return false;
123974 +
123975 + print_missing_msg(orig_fndecl, num);
123976 + return true;
123977 +}
123978 +
123979 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
123980 new file mode 100644
123981 index 0000000..924652b
123982 --- /dev/null
123983 +++ b/tools/gcc/stackleak_plugin.c
123984 @@ -0,0 +1,395 @@
123985 +/*
123986 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
123987 + * Licensed under the GPL v2
123988 + *
123989 + * Note: the choice of the license means that the compilation process is
123990 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
123991 + * but for the kernel it doesn't matter since it doesn't link against
123992 + * any of the gcc libraries
123993 + *
123994 + * gcc plugin to help implement various PaX features
123995 + *
123996 + * - track lowest stack pointer
123997 + *
123998 + * TODO:
123999 + * - initialize all local variables
124000 + *
124001 + * BUGS:
124002 + * - none known
124003 + */
124004 +
124005 +#include "gcc-common.h"
124006 +
124007 +int plugin_is_GPL_compatible;
124008 +
124009 +static int track_frame_size = -1;
124010 +static const char track_function[] = "pax_track_stack";
124011 +static const char check_function[] = "pax_check_alloca";
124012 +static tree track_function_decl, check_function_decl;
124013 +static bool init_locals;
124014 +
124015 +static struct plugin_info stackleak_plugin_info = {
124016 + .version = "201408011900",
124017 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
124018 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
124019 +};
124020 +
124021 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
124022 +{
124023 + gimple check_alloca;
124024 + tree alloca_size;
124025 +
124026 + // insert call to void pax_check_alloca(unsigned long size)
124027 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
124028 + check_alloca = gimple_build_call(check_function_decl, 1, alloca_size);
124029 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
124030 +}
124031 +
124032 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
124033 +{
124034 + gimple track_stack;
124035 +
124036 + // insert call to void pax_track_stack(void)
124037 + track_stack = gimple_build_call(track_function_decl, 0);
124038 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
124039 +}
124040 +
124041 +static bool is_alloca(gimple stmt)
124042 +{
124043 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
124044 + return true;
124045 +
124046 +#if BUILDING_GCC_VERSION >= 4007
124047 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
124048 + return true;
124049 +#endif
124050 +
124051 + return false;
124052 +}
124053 +
124054 +static unsigned int execute_stackleak_tree_instrument(void)
124055 +{
124056 + basic_block bb, entry_bb;
124057 + bool prologue_instrumented = false, is_leaf = true;
124058 +
124059 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
124060 +
124061 + // 1. loop through BBs and GIMPLE statements
124062 + FOR_EACH_BB_FN(bb, cfun) {
124063 + gimple_stmt_iterator gsi;
124064 +
124065 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
124066 + gimple stmt;
124067 +
124068 + stmt = gsi_stmt(gsi);
124069 +
124070 + if (is_gimple_call(stmt))
124071 + is_leaf = false;
124072 +
124073 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
124074 + if (!is_alloca(stmt))
124075 + continue;
124076 +
124077 + // 2. insert stack overflow check before each __builtin_alloca call
124078 + stackleak_check_alloca(&gsi);
124079 +
124080 + // 3. insert track call after each __builtin_alloca call
124081 + stackleak_add_instrumentation(&gsi);
124082 + if (bb == entry_bb)
124083 + prologue_instrumented = true;
124084 + }
124085 + }
124086 +
124087 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
124088 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
124089 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
124090 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
124091 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
124092 + return 0;
124093 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
124094 + return 0;
124095 +
124096 + // 4. insert track call at the beginning
124097 + if (!prologue_instrumented) {
124098 + gimple_stmt_iterator gsi;
124099 +
124100 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
124101 + if (dom_info_available_p(CDI_DOMINATORS))
124102 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
124103 + gsi = gsi_start_bb(bb);
124104 + stackleak_add_instrumentation(&gsi);
124105 + }
124106 +
124107 + return 0;
124108 +}
124109 +
124110 +static unsigned int execute_stackleak_final(void)
124111 +{
124112 + rtx insn, next;
124113 +
124114 + if (cfun->calls_alloca)
124115 + return 0;
124116 +
124117 + // keep calls only if function frame is big enough
124118 + if (get_frame_size() >= track_frame_size)
124119 + return 0;
124120 +
124121 + // 1. find pax_track_stack calls
124122 + for (insn = get_insns(); insn; insn = next) {
124123 + // rtl match: (call_insn 8 7 9 3 (call (mem (symbol_ref ("pax_track_stack") [flags 0x41] <function_decl 0xb7470e80 pax_track_stack>) [0 S1 A8]) (4)) -1 (nil) (nil))
124124 + rtx body;
124125 +
124126 + next = NEXT_INSN(insn);
124127 + if (!CALL_P(insn))
124128 + continue;
124129 + body = PATTERN(insn);
124130 + if (GET_CODE(body) != CALL)
124131 + continue;
124132 + body = XEXP(body, 0);
124133 + if (GET_CODE(body) != MEM)
124134 + continue;
124135 + body = XEXP(body, 0);
124136 + if (GET_CODE(body) != SYMBOL_REF)
124137 + continue;
124138 +// if (strcmp(XSTR(body, 0), track_function))
124139 + if (SYMBOL_REF_DECL(body) != track_function_decl)
124140 + continue;
124141 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
124142 + // 2. delete call
124143 + delete_insn_and_edges(insn);
124144 +#if BUILDING_GCC_VERSION >= 4007
124145 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
124146 + insn = next;
124147 + next = NEXT_INSN(insn);
124148 + delete_insn_and_edges(insn);
124149 + }
124150 +#endif
124151 + }
124152 +
124153 +// print_simple_rtl(stderr, get_insns());
124154 +// print_rtl(stderr, get_insns());
124155 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
124156 +
124157 + return 0;
124158 +}
124159 +
124160 +static bool gate_stackleak_track_stack(void)
124161 +{
124162 + tree section;
124163 +
124164 + if (ix86_cmodel != CM_KERNEL)
124165 + return false;
124166 +
124167 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
124168 + if (section && TREE_VALUE(section)) {
124169 + section = TREE_VALUE(TREE_VALUE(section));
124170 +
124171 + if (!strncmp(TREE_STRING_POINTER(section), ".init.text", 10))
124172 + return false;
124173 + if (!strncmp(TREE_STRING_POINTER(section), ".devinit.text", 13))
124174 + return false;
124175 + if (!strncmp(TREE_STRING_POINTER(section), ".cpuinit.text", 13))
124176 + return false;
124177 + if (!strncmp(TREE_STRING_POINTER(section), ".meminit.text", 13))
124178 + return false;
124179 + }
124180 +
124181 + return track_frame_size >= 0;
124182 +}
124183 +
124184 +static void stackleak_start_unit(void *gcc_data, void *user_data)
124185 +{
124186 + tree fntype;
124187 +
124188 + // void pax_track_stack(void)
124189 + fntype = build_function_type_list(void_type_node, NULL_TREE);
124190 + track_function_decl = build_fn_decl(track_function, fntype);
124191 + DECL_ASSEMBLER_NAME(track_function_decl); // for LTO
124192 + TREE_PUBLIC(track_function_decl) = 1;
124193 + DECL_EXTERNAL(track_function_decl) = 1;
124194 + DECL_ARTIFICIAL(track_function_decl) = 1;
124195 +
124196 + // void pax_check_alloca(unsigned long)
124197 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
124198 + check_function_decl = build_fn_decl(check_function, fntype);
124199 + DECL_ASSEMBLER_NAME(check_function_decl); // for LTO
124200 + TREE_PUBLIC(check_function_decl) = 1;
124201 + DECL_EXTERNAL(check_function_decl) = 1;
124202 + DECL_ARTIFICIAL(check_function_decl) = 1;
124203 +}
124204 +
124205 +#if BUILDING_GCC_VERSION >= 4009
124206 +static const struct pass_data stackleak_tree_instrument_pass_data = {
124207 +#else
124208 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
124209 + .pass = {
124210 +#endif
124211 + .type = GIMPLE_PASS,
124212 + .name = "stackleak_tree_instrument",
124213 +#if BUILDING_GCC_VERSION >= 4008
124214 + .optinfo_flags = OPTGROUP_NONE,
124215 +#endif
124216 +#if BUILDING_GCC_VERSION >= 4009
124217 + .has_gate = true,
124218 + .has_execute = true,
124219 +#else
124220 + .gate = gate_stackleak_track_stack,
124221 + .execute = execute_stackleak_tree_instrument,
124222 + .sub = NULL,
124223 + .next = NULL,
124224 + .static_pass_number = 0,
124225 +#endif
124226 + .tv_id = TV_NONE,
124227 + .properties_required = PROP_gimple_leh | PROP_cfg,
124228 + .properties_provided = 0,
124229 + .properties_destroyed = 0,
124230 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
124231 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa | TODO_rebuild_cgraph_edges
124232 +#if BUILDING_GCC_VERSION < 4009
124233 + }
124234 +#endif
124235 +};
124236 +
124237 +#if BUILDING_GCC_VERSION >= 4009
124238 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
124239 +#else
124240 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
124241 + .pass = {
124242 +#endif
124243 + .type = RTL_PASS,
124244 + .name = "stackleak_final",
124245 +#if BUILDING_GCC_VERSION >= 4008
124246 + .optinfo_flags = OPTGROUP_NONE,
124247 +#endif
124248 +#if BUILDING_GCC_VERSION >= 4009
124249 + .has_gate = true,
124250 + .has_execute = true,
124251 +#else
124252 + .gate = gate_stackleak_track_stack,
124253 + .execute = execute_stackleak_final,
124254 + .sub = NULL,
124255 + .next = NULL,
124256 + .static_pass_number = 0,
124257 +#endif
124258 + .tv_id = TV_NONE,
124259 + .properties_required = 0,
124260 + .properties_provided = 0,
124261 + .properties_destroyed = 0,
124262 + .todo_flags_start = 0,
124263 + .todo_flags_finish = TODO_dump_func
124264 +#if BUILDING_GCC_VERSION < 4009
124265 + }
124266 +#endif
124267 +};
124268 +
124269 +#if BUILDING_GCC_VERSION >= 4009
124270 +namespace {
124271 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
124272 +public:
124273 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
124274 + bool gate() { return gate_stackleak_track_stack(); }
124275 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
124276 +};
124277 +
124278 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
124279 +public:
124280 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
124281 + bool gate() { return gate_stackleak_track_stack(); }
124282 + unsigned int execute() { return execute_stackleak_final(); }
124283 +};
124284 +}
124285 +
124286 +static opt_pass *make_stackleak_tree_instrument_pass(void)
124287 +{
124288 + return new stackleak_tree_instrument_pass();
124289 +}
124290 +
124291 +static opt_pass *make_stackleak_final_rtl_opt_pass(void)
124292 +{
124293 + return new stackleak_final_rtl_opt_pass();
124294 +}
124295 +#else
124296 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
124297 +{
124298 + return &stackleak_tree_instrument_pass.pass;
124299 +}
124300 +
124301 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
124302 +{
124303 + return &stackleak_final_rtl_opt_pass.pass;
124304 +}
124305 +#endif
124306 +
124307 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
124308 +{
124309 + const char * const plugin_name = plugin_info->base_name;
124310 + const int argc = plugin_info->argc;
124311 + const struct plugin_argument * const argv = plugin_info->argv;
124312 + int i;
124313 + struct register_pass_info stackleak_tree_instrument_pass_info;
124314 + struct register_pass_info stackleak_final_pass_info;
124315 + static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
124316 + {
124317 + .base = &track_function_decl,
124318 + .nelt = 1,
124319 + .stride = sizeof(track_function_decl),
124320 + .cb = &gt_ggc_mx_tree_node,
124321 + .pchw = &gt_pch_nx_tree_node
124322 + },
124323 + {
124324 + .base = &check_function_decl,
124325 + .nelt = 1,
124326 + .stride = sizeof(check_function_decl),
124327 + .cb = &gt_ggc_mx_tree_node,
124328 + .pchw = &gt_pch_nx_tree_node
124329 + },
124330 + LAST_GGC_ROOT_TAB
124331 + };
124332 +
124333 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
124334 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
124335 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
124336 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
124337 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
124338 +
124339 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
124340 + stackleak_final_pass_info.reference_pass_name = "final";
124341 + stackleak_final_pass_info.ref_pass_instance_number = 1;
124342 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
124343 +
124344 + if (!plugin_default_version_check(version, &gcc_version)) {
124345 + error(G_("incompatible gcc/plugin versions"));
124346 + return 1;
124347 + }
124348 +
124349 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
124350 +
124351 + for (i = 0; i < argc; ++i) {
124352 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
124353 + if (!argv[i].value) {
124354 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
124355 + continue;
124356 + }
124357 + track_frame_size = atoi(argv[i].value);
124358 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
124359 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
124360 + continue;
124361 + }
124362 + if (!strcmp(argv[i].key, "initialize-locals")) {
124363 + if (argv[i].value) {
124364 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
124365 + continue;
124366 + }
124367 + init_locals = true;
124368 + continue;
124369 + }
124370 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
124371 + }
124372 +
124373 + register_callback(plugin_name, PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
124374 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_stackleak);
124375 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
124376 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
124377 +
124378 + return 0;
124379 +}
124380 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
124381 new file mode 100644
124382 index 0000000..4ee2231
124383 --- /dev/null
124384 +++ b/tools/gcc/structleak_plugin.c
124385 @@ -0,0 +1,274 @@
124386 +/*
124387 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
124388 + * Licensed under the GPL v2
124389 + *
124390 + * Note: the choice of the license means that the compilation process is
124391 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
124392 + * but for the kernel it doesn't matter since it doesn't link against
124393 + * any of the gcc libraries
124394 + *
124395 + * gcc plugin to forcibly initialize certain local variables that could
124396 + * otherwise leak kernel stack to userland if they aren't properly initialized
124397 + * by later code
124398 + *
124399 + * Homepage: http://pax.grsecurity.net/
124400 + *
124401 + * Usage:
124402 + * $ # for 4.5/4.6/C based 4.7
124403 + * $ gcc -I`gcc -print-file-name=plugin`/include -I`gcc -print-file-name=plugin`/include/c-family -fPIC -shared -O2 -o structleak_plugin.so structleak_plugin.c
124404 + * $ # for C++ based 4.7/4.8+
124405 + * $ g++ -I`g++ -print-file-name=plugin`/include -I`g++ -print-file-name=plugin`/include/c-family -fPIC -shared -O2 -o structleak_plugin.so structleak_plugin.c
124406 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
124407 + *
124408 + * TODO: eliminate redundant initializers
124409 + * increase type coverage
124410 + */
124411 +
124412 +#include "gcc-common.h"
124413 +
124414 +// unused C type flag in all versions 4.5-4.9
124415 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
124416 +
124417 +int plugin_is_GPL_compatible;
124418 +
124419 +static struct plugin_info structleak_plugin_info = {
124420 + .version = "201401260140",
124421 + .help = "disable\tdo not activate plugin\n",
124422 +};
124423 +
124424 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
124425 +{
124426 + *no_add_attrs = true;
124427 +
124428 + // check for types? for now accept everything linux has to offer
124429 + if (TREE_CODE(*node) != FIELD_DECL)
124430 + return NULL_TREE;
124431 +
124432 + *no_add_attrs = false;
124433 + return NULL_TREE;
124434 +}
124435 +
124436 +static struct attribute_spec user_attr = {
124437 + .name = "user",
124438 + .min_length = 0,
124439 + .max_length = 0,
124440 + .decl_required = false,
124441 + .type_required = false,
124442 + .function_type_required = false,
124443 + .handler = handle_user_attribute,
124444 +#if BUILDING_GCC_VERSION >= 4007
124445 + .affects_type_identity = true
124446 +#endif
124447 +};
124448 +
124449 +static void register_attributes(void *event_data, void *data)
124450 +{
124451 + register_attribute(&user_attr);
124452 +// register_attribute(&force_attr);
124453 +}
124454 +
124455 +static tree get_field_type(tree field)
124456 +{
124457 + return strip_array_types(TREE_TYPE(field));
124458 +}
124459 +
124460 +static bool is_userspace_type(tree type)
124461 +{
124462 + tree field;
124463 +
124464 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
124465 + tree fieldtype = get_field_type(field);
124466 + enum tree_code code = TREE_CODE(fieldtype);
124467 +
124468 + if (code == RECORD_TYPE || code == UNION_TYPE)
124469 + if (is_userspace_type(fieldtype))
124470 + return true;
124471 +
124472 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
124473 + return true;
124474 + }
124475 + return false;
124476 +}
124477 +
124478 +static void finish_type(void *event_data, void *data)
124479 +{
124480 + tree type = (tree)event_data;
124481 +
124482 + if (TYPE_USERSPACE(type))
124483 + return;
124484 +
124485 + if (is_userspace_type(type))
124486 + TYPE_USERSPACE(type) = 1;
124487 +}
124488 +
124489 +static void initialize(tree var)
124490 +{
124491 + basic_block bb;
124492 + gimple_stmt_iterator gsi;
124493 + tree initializer;
124494 + gimple init_stmt;
124495 +
124496 + // this is the original entry bb before the forced split
124497 + // TODO: check further BBs in case more splits occured before us
124498 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
124499 +
124500 + // first check if the variable is already initialized, warn otherwise
124501 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
124502 + gimple stmt = gsi_stmt(gsi);
124503 + tree rhs1;
124504 +
124505 + // we're looking for an assignment of a single rhs...
124506 + if (!gimple_assign_single_p(stmt))
124507 + continue;
124508 + rhs1 = gimple_assign_rhs1(stmt);
124509 +#if BUILDING_GCC_VERSION >= 4007
124510 + // ... of a non-clobbering expression...
124511 + if (TREE_CLOBBER_P(rhs1))
124512 + continue;
124513 +#endif
124514 + // ... to our variable...
124515 + if (gimple_get_lhs(stmt) != var)
124516 + continue;
124517 + // if it's an initializer then we're good
124518 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
124519 + return;
124520 + }
124521 +
124522 + // these aren't the 0days you're looking for
124523 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
124524 +
124525 + // build the initializer expression
124526 + initializer = build_constructor(TREE_TYPE(var), NULL);
124527 +
124528 + // build the initializer stmt
124529 + init_stmt = gimple_build_assign(var, initializer);
124530 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
124531 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
124532 + update_stmt(init_stmt);
124533 +}
124534 +
124535 +static unsigned int handle_function(void)
124536 +{
124537 + basic_block bb;
124538 + unsigned int ret = 0;
124539 + tree var;
124540 + unsigned int i;
124541 +
124542 + // split the first bb where we can put the forced initializers
124543 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
124544 + if (dom_info_available_p(CDI_DOMINATORS))
124545 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
124546 +
124547 + // enumarate all local variables and forcibly initialize our targets
124548 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
124549 + tree type = TREE_TYPE(var);
124550 +
124551 + gcc_assert(DECL_P(var));
124552 + if (!auto_var_in_fn_p(var, current_function_decl))
124553 + continue;
124554 +
124555 + // only care about structure types
124556 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
124557 + continue;
124558 +
124559 + // if the type is of interest, examine the variable
124560 + if (TYPE_USERSPACE(type))
124561 + initialize(var);
124562 + }
124563 +
124564 + return ret;
124565 +}
124566 +
124567 +#if BUILDING_GCC_VERSION >= 4009
124568 +static const struct pass_data structleak_pass_data = {
124569 +#else
124570 +static struct gimple_opt_pass structleak_pass = {
124571 + .pass = {
124572 +#endif
124573 + .type = GIMPLE_PASS,
124574 + .name = "structleak",
124575 +#if BUILDING_GCC_VERSION >= 4008
124576 + .optinfo_flags = OPTGROUP_NONE,
124577 +#endif
124578 +#if BUILDING_GCC_VERSION >= 4009
124579 + .has_gate = false,
124580 + .has_execute = true,
124581 +#else
124582 + .gate = NULL,
124583 + .execute = handle_function,
124584 + .sub = NULL,
124585 + .next = NULL,
124586 + .static_pass_number = 0,
124587 +#endif
124588 + .tv_id = TV_NONE,
124589 + .properties_required = PROP_cfg,
124590 + .properties_provided = 0,
124591 + .properties_destroyed = 0,
124592 + .todo_flags_start = 0,
124593 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa | TODO_ggc_collect | TODO_verify_flow
124594 +#if BUILDING_GCC_VERSION < 4009
124595 + }
124596 +#endif
124597 +};
124598 +
124599 +#if BUILDING_GCC_VERSION >= 4009
124600 +namespace {
124601 +class structleak_pass : public gimple_opt_pass {
124602 +public:
124603 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
124604 + unsigned int execute() { return handle_function(); }
124605 +};
124606 +}
124607 +
124608 +static opt_pass *make_structleak_pass(void)
124609 +{
124610 + return new structleak_pass();
124611 +}
124612 +#else
124613 +static struct opt_pass *make_structleak_pass(void)
124614 +{
124615 + return &structleak_pass.pass;
124616 +}
124617 +#endif
124618 +
124619 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
124620 +{
124621 + int i;
124622 + const char * const plugin_name = plugin_info->base_name;
124623 + const int argc = plugin_info->argc;
124624 + const struct plugin_argument * const argv = plugin_info->argv;
124625 + bool enable = true;
124626 + struct register_pass_info structleak_pass_info;
124627 +
124628 + structleak_pass_info.pass = make_structleak_pass();
124629 + structleak_pass_info.reference_pass_name = "ssa";
124630 + structleak_pass_info.ref_pass_instance_number = 1;
124631 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
124632 +
124633 + if (!plugin_default_version_check(version, &gcc_version)) {
124634 + error(G_("incompatible gcc/plugin versions"));
124635 + return 1;
124636 + }
124637 +
124638 + if (strcmp(lang_hooks.name, "GNU C")) {
124639 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
124640 + enable = false;
124641 + }
124642 +
124643 + for (i = 0; i < argc; ++i) {
124644 + if (!strcmp(argv[i].key, "disable")) {
124645 + enable = false;
124646 + continue;
124647 + }
124648 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
124649 + }
124650 +
124651 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
124652 + if (enable) {
124653 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
124654 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
124655 + }
124656 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
124657 +
124658 + return 0;
124659 +}
124660 diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
124661 index 88461f0..6fb70a0 100644
124662 --- a/tools/include/linux/compiler.h
124663 +++ b/tools/include/linux/compiler.h
124664 @@ -35,6 +35,14 @@
124665 # define unlikely(x) __builtin_expect(!!(x), 0)
124666 #endif
124667
124668 +#ifndef __size_overflow
124669 +# define __size_overflow(...)
124670 +#endif
124671 +
124672 +#ifndef __intentional_overflow
124673 +# define __intentional_overflow(...)
124674 +#endif
124675 +
124676 #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
124677
124678 #endif /* _TOOLS_LINUX_COMPILER_H */
124679 diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
124680 index 36c08b1..87c72d1 100644
124681 --- a/tools/lib/api/Makefile
124682 +++ b/tools/lib/api/Makefile
124683 @@ -21,7 +21,7 @@ LIB_OBJS += $(OUTPUT)fd/array.o
124684
124685 LIBFILE = libapikfs.a
124686
124687 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
124688 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
124689 EXTLIBS = -lelf -lpthread -lrt -lm
124690 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
124691 ALL_LDFLAGS = $(LDFLAGS)
124692 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
124693 index 6789d788..4afd019e 100644
124694 --- a/tools/perf/util/include/asm/alternative-asm.h
124695 +++ b/tools/perf/util/include/asm/alternative-asm.h
124696 @@ -5,4 +5,7 @@
124697
124698 #define altinstruction_entry #
124699
124700 + .macro pax_force_retaddr rip=0, reload=0
124701 + .endm
124702 +
124703 #endif
124704 diff --git a/tools/virtio/linux/uaccess.h b/tools/virtio/linux/uaccess.h
124705 index 0a578fe..b81f62d 100644
124706 --- a/tools/virtio/linux/uaccess.h
124707 +++ b/tools/virtio/linux/uaccess.h
124708 @@ -13,7 +13,7 @@ static inline void __chk_user_ptr(const volatile void *p, size_t size)
124709 ({ \
124710 typeof(ptr) __pu_ptr = (ptr); \
124711 __chk_user_ptr(__pu_ptr, sizeof(*__pu_ptr)); \
124712 - ACCESS_ONCE(*(__pu_ptr)) = x; \
124713 + ACCESS_ONCE_RW(*(__pu_ptr)) = x; \
124714 0; \
124715 })
124716
124717 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
124718 index 3cee7b1..29cb7d8 100644
124719 --- a/virt/kvm/kvm_main.c
124720 +++ b/virt/kvm/kvm_main.c
124721 @@ -78,12 +78,17 @@ LIST_HEAD(vm_list);
124722
124723 static cpumask_var_t cpus_hardware_enabled;
124724 static int kvm_usage_count = 0;
124725 -static atomic_t hardware_enable_failed;
124726 +static atomic_unchecked_t hardware_enable_failed;
124727
124728 struct kmem_cache *kvm_vcpu_cache;
124729 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
124730
124731 -static __read_mostly struct preempt_ops kvm_preempt_ops;
124732 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
124733 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
124734 +static struct preempt_ops kvm_preempt_ops = {
124735 + .sched_in = kvm_sched_in,
124736 + .sched_out = kvm_sched_out,
124737 +};
124738
124739 struct dentry *kvm_debugfs_dir;
124740
124741 @@ -786,7 +791,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
124742 /* We can read the guest memory with __xxx_user() later on. */
124743 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
124744 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
124745 - !access_ok(VERIFY_WRITE,
124746 + !access_ok_noprefault(VERIFY_WRITE,
124747 (void __user *)(unsigned long)mem->userspace_addr,
124748 mem->memory_size)))
124749 goto out;
124750 @@ -1690,9 +1695,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
124751
124752 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
124753 {
124754 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
124755 + int r;
124756 + unsigned long addr;
124757
124758 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
124759 + addr = gfn_to_hva(kvm, gfn);
124760 + if (kvm_is_error_hva(addr))
124761 + return -EFAULT;
124762 + r = __clear_user((void __user *)addr + offset, len);
124763 + if (r)
124764 + return -EFAULT;
124765 + mark_page_dirty(kvm, gfn);
124766 + return 0;
124767 }
124768 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
124769
124770 @@ -1941,7 +1954,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
124771 return 0;
124772 }
124773
124774 -static struct file_operations kvm_vcpu_fops = {
124775 +static file_operations_no_const kvm_vcpu_fops __read_only = {
124776 .release = kvm_vcpu_release,
124777 .unlocked_ioctl = kvm_vcpu_ioctl,
124778 #ifdef CONFIG_COMPAT
124779 @@ -2650,7 +2663,7 @@ out:
124780 }
124781 #endif
124782
124783 -static struct file_operations kvm_vm_fops = {
124784 +static file_operations_no_const kvm_vm_fops __read_only = {
124785 .release = kvm_vm_release,
124786 .unlocked_ioctl = kvm_vm_ioctl,
124787 #ifdef CONFIG_COMPAT
124788 @@ -2721,7 +2734,7 @@ out:
124789 return r;
124790 }
124791
124792 -static struct file_operations kvm_chardev_ops = {
124793 +static file_operations_no_const kvm_chardev_ops __read_only = {
124794 .unlocked_ioctl = kvm_dev_ioctl,
124795 .compat_ioctl = kvm_dev_ioctl,
124796 .llseek = noop_llseek,
124797 @@ -2747,7 +2760,7 @@ static void hardware_enable_nolock(void *junk)
124798
124799 if (r) {
124800 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
124801 - atomic_inc(&hardware_enable_failed);
124802 + atomic_inc_unchecked(&hardware_enable_failed);
124803 printk(KERN_INFO "kvm: enabling virtualization on "
124804 "CPU%d failed\n", cpu);
124805 }
124806 @@ -2803,10 +2816,10 @@ static int hardware_enable_all(void)
124807
124808 kvm_usage_count++;
124809 if (kvm_usage_count == 1) {
124810 - atomic_set(&hardware_enable_failed, 0);
124811 + atomic_set_unchecked(&hardware_enable_failed, 0);
124812 on_each_cpu(hardware_enable_nolock, NULL, 1);
124813
124814 - if (atomic_read(&hardware_enable_failed)) {
124815 + if (atomic_read_unchecked(&hardware_enable_failed)) {
124816 hardware_disable_all_nolock();
124817 r = -EBUSY;
124818 }
124819 @@ -3213,7 +3226,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
124820 kvm_arch_vcpu_put(vcpu);
124821 }
124822
124823 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
124824 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
124825 struct module *module)
124826 {
124827 int r;
124828 @@ -3260,7 +3273,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
124829 if (!vcpu_align)
124830 vcpu_align = __alignof__(struct kvm_vcpu);
124831 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
124832 - 0, NULL);
124833 + SLAB_USERCOPY, NULL);
124834 if (!kvm_vcpu_cache) {
124835 r = -ENOMEM;
124836 goto out_free_3;
124837 @@ -3270,9 +3283,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
124838 if (r)
124839 goto out_free;
124840
124841 + pax_open_kernel();
124842 kvm_chardev_ops.owner = module;
124843 kvm_vm_fops.owner = module;
124844 kvm_vcpu_fops.owner = module;
124845 + pax_close_kernel();
124846
124847 r = misc_register(&kvm_dev);
124848 if (r) {
124849 @@ -3282,9 +3297,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
124850
124851 register_syscore_ops(&kvm_syscore_ops);
124852
124853 - kvm_preempt_ops.sched_in = kvm_sched_in;
124854 - kvm_preempt_ops.sched_out = kvm_sched_out;
124855 -
124856 r = kvm_init_debug();
124857 if (r) {
124858 printk(KERN_ERR "kvm: create debugfs files failed\n");